Commit aa7b1488 authored by Sakari Ailus's avatar Sakari Ailus Committed by Mauro Carvalho Chehab

media: v4l: Set sub-device's owner field to the caller's module

Set a sub-device's owner field to the caller's module, provided as an
argument to the function. v4l2_device_register_subdev() becomes a macro
passing THIS_MODULE to the __v4l2_device_register_subdev() function.
Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
parent 03479d56
...@@ -341,7 +341,7 @@ static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier, ...@@ -341,7 +341,7 @@ static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,
int ret; int ret;
if (list_empty(&sd->asc_list)) { if (list_empty(&sd->asc_list)) {
ret = v4l2_device_register_subdev(v4l2_dev, sd); ret = __v4l2_device_register_subdev(v4l2_dev, sd, sd->owner);
if (ret < 0) if (ret < 0)
return ret; return ret;
registered = true; registered = true;
......
...@@ -108,8 +108,8 @@ void v4l2_device_unregister(struct v4l2_device *v4l2_dev) ...@@ -108,8 +108,8 @@ void v4l2_device_unregister(struct v4l2_device *v4l2_dev)
} }
EXPORT_SYMBOL_GPL(v4l2_device_unregister); EXPORT_SYMBOL_GPL(v4l2_device_unregister);
int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev, int __v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
struct v4l2_subdev *sd) struct v4l2_subdev *sd, struct module *module)
{ {
int err; int err;
...@@ -125,9 +125,9 @@ int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev, ...@@ -125,9 +125,9 @@ int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
* try_module_get() such sub-device owners. * try_module_get() such sub-device owners.
*/ */
sd->owner_v4l2_dev = v4l2_dev->dev && v4l2_dev->dev->driver && sd->owner_v4l2_dev = v4l2_dev->dev && v4l2_dev->dev->driver &&
sd->owner == v4l2_dev->dev->driver->owner; module == v4l2_dev->dev->driver->owner;
if (!sd->owner_v4l2_dev && !try_module_get(sd->owner)) if (!sd->owner_v4l2_dev && !try_module_get(module))
return -ENODEV; return -ENODEV;
sd->v4l2_dev = v4l2_dev; sd->v4l2_dev = v4l2_dev;
...@@ -152,6 +152,8 @@ int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev, ...@@ -152,6 +152,8 @@ int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
goto error_unregister; goto error_unregister;
} }
sd->owner = module;
spin_lock(&v4l2_dev->lock); spin_lock(&v4l2_dev->lock);
list_add_tail(&sd->list, &v4l2_dev->subdevs); list_add_tail(&sd->list, &v4l2_dev->subdevs);
spin_unlock(&v4l2_dev->lock); spin_unlock(&v4l2_dev->lock);
...@@ -168,7 +170,7 @@ int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev, ...@@ -168,7 +170,7 @@ int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
sd->v4l2_dev = NULL; sd->v4l2_dev = NULL;
return err; return err;
} }
EXPORT_SYMBOL_GPL(v4l2_device_register_subdev); EXPORT_SYMBOL_GPL(__v4l2_device_register_subdev);
static void v4l2_subdev_release(struct v4l2_subdev *sd) static void v4l2_subdev_release(struct v4l2_subdev *sd)
{ {
......
...@@ -100,7 +100,7 @@ struct v4l2_subdev ...@@ -100,7 +100,7 @@ struct v4l2_subdev
* Register with the v4l2_device which increases the module's * Register with the v4l2_device which increases the module's
* use count as well. * use count as well.
*/ */
if (v4l2_device_register_subdev(v4l2_dev, sd)) if (__v4l2_device_register_subdev(v4l2_dev, sd, sd->owner))
sd = NULL; sd = NULL;
/* Decrease the module use count to match the first try_module_get. */ /* Decrease the module use count to match the first try_module_get. */
module_put(client->dev.driver->owner); module_put(client->dev.driver->owner);
......
...@@ -59,7 +59,7 @@ struct v4l2_subdev *v4l2_spi_new_subdev(struct v4l2_device *v4l2_dev, ...@@ -59,7 +59,7 @@ struct v4l2_subdev *v4l2_spi_new_subdev(struct v4l2_device *v4l2_dev,
* Register with the v4l2_device which increases the module's * Register with the v4l2_device which increases the module's
* use count as well. * use count as well.
*/ */
if (v4l2_device_register_subdev(v4l2_dev, sd)) if (__v4l2_device_register_subdev(v4l2_dev, sd, sd->owner))
sd = NULL; sd = NULL;
/* Decrease the module use count to match the first try_module_get. */ /* Decrease the module use count to match the first try_module_get. */
......
...@@ -156,8 +156,11 @@ void v4l2_device_unregister(struct v4l2_device *v4l2_dev); ...@@ -156,8 +156,11 @@ void v4l2_device_unregister(struct v4l2_device *v4l2_dev);
* An error is returned if the module is no longer loaded on any attempts * An error is returned if the module is no longer loaded on any attempts
* to register it. * to register it.
*/ */
int __must_check v4l2_device_register_subdev(struct v4l2_device *v4l2_dev, #define v4l2_device_register_subdev(v4l2_dev, sd) \
struct v4l2_subdev *sd); __v4l2_device_register_subdev(v4l2_dev, sd, THIS_MODULE)
int __must_check __v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
struct v4l2_subdev *sd,
struct module *module);
/** /**
* v4l2_device_unregister_subdev - Unregisters a subdev with a v4l2 device. * v4l2_device_unregister_subdev - Unregisters a subdev with a v4l2 device.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment