[Devel] [PATCH rh7] ve/drivers: Do not forget to release mismatched device found
Vladimir Davydov
vdavydov at parallels.com
Fri Jul 17 09:30:48 PDT 2015
On Thu, Jul 09, 2015 at 12:49:25PM +0300, Cyrill Gorcunov wrote:
[...]
> --- linux-pcs7.git.orig/drivers/base/core.c
> +++ linux-pcs7.git/drivers/base/core.c
> @@ -1838,15 +1838,12 @@ EXPORT_SYMBOL_GPL(device_destroy);
>
> void device_destroy_namespace(struct class *class, dev_t devt, void *ns)
> {
> - struct device *dev = NULL;
> + struct device *dev = NULL, *prev = NULL;
>
> - for (;;) {
> - dev = class_find_device(class, dev, &devt, __match_devt);
> - if (!dev)
> - break;
> - if (!class->namespace ||
> - (class->namespace(dev) == ns))
> - break;
> + for (dev = class_find_device(class, dev, &devt, __match_devt);
> + dev && (class->namespace && class->namespace(dev) != ns);) {
> + prev = dev, dev = class_find_device(class, dev, &devt, __match_devt);
> + put_device(prev);
> }
>
> if (dev) {
>
I think class_find_device is already capable of doing this. It just
needs a bit tweaked match function. Something like this, may be?
---
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 6583bece847f..6b0e8139269a 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -1836,19 +1836,28 @@ void device_destroy(struct class *class, dev_t devt)
}
EXPORT_SYMBOL_GPL(device_destroy);
-void device_destroy_namespace(struct class *class, dev_t devt, void *ns)
+struct __match_devt_ns_arg {
+ dev_t devt;
+ void *ns;
+};
+
+static int __match_devt_ns(struct device *dev, const void *data)
{
- struct device *dev = NULL;
+ const __match_devt_ns_arg *arg = data;
- for (;;) {
- dev = class_find_device(class, dev, &devt, __match_devt);
- if (!dev)
- break;
- if (!class->namespace ||
- (class->namespace(dev) == ns))
- break;
- }
+ return dev->devt == arg->devt &&
+ (!dev->class->namespace || dev->class->namespace(dev) == ns);
+}
+
+void device_destroy_namespace(struct class *class, dev_t devt, void *ns)
+{
+ struct __match_devt_ns_arg arg = {
+ .devt = devt,
+ .ns = ns,
+ };
+ struct device *dev;
+ dev = class_find_device(class, NULL, &arg, __match_devt_ns);
if (dev) {
put_device(dev);
device_unregister(dev);
More information about the Devel
mailing list