media: v4l: Set sub-device's owner field to the caller's module
authorSakari Ailus <sakari.ailus@linux.intel.com>
Wed, 13 Mar 2024 14:03:19 +0000 (14:03 +0000)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Fri, 26 Apr 2024 10:30:43 +0000 (11:30 +0100)
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: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
drivers/media/v4l2-core/v4l2-async.c
drivers/media/v4l2-core/v4l2-device.c
drivers/media/v4l2-core/v4l2-i2c.c
drivers/media/v4l2-core/v4l2-spi.c
include/media/v4l2-device.h

index 4bb073587817c959f70ad844694e9579f7aa17b3..b28f6811a5f4498f11bfec1d3c7b96e4593f0213 100644 (file)
@@ -341,7 +341,7 @@ static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,
        int ret;
 
        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)
                        return ret;
                registered = true;
index d2e58ae91f9b446253d74828f04115343372d99b..5e537454f5cd71b3c50a2a2864642f7d5548047b 100644 (file)
@@ -108,8 +108,8 @@ void v4l2_device_unregister(struct v4l2_device *v4l2_dev)
 }
 EXPORT_SYMBOL_GPL(v4l2_device_unregister);
 
-int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
-                               struct v4l2_subdev *sd)
+int __v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
+                                 struct v4l2_subdev *sd, struct module *module)
 {
        int err;
 
@@ -125,9 +125,9 @@ int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
         * try_module_get() such sub-device owners.
         */
        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;
 
        sd->v4l2_dev = v4l2_dev;
@@ -152,6 +152,8 @@ int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
                        goto error_unregister;
        }
 
+       sd->owner = module;
+
        spin_lock(&v4l2_dev->lock);
        list_add_tail(&sd->list, &v4l2_dev->subdevs);
        spin_unlock(&v4l2_dev->lock);
@@ -168,7 +170,7 @@ error_module:
        sd->v4l2_dev = NULL;
        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)
 {
index b4acca75644beb42c2e129945e6abd1f697f5df4..586c46544255d67ece24089c77d04450c1dca181 100644 (file)
@@ -100,7 +100,7 @@ struct v4l2_subdev
         * Register with the v4l2_device which increases the module's
         * use count as well.
         */
-       if (v4l2_device_register_subdev(v4l2_dev, sd))
+       if (__v4l2_device_register_subdev(v4l2_dev, sd, sd->owner))
                sd = NULL;
        /* Decrease the module use count to match the first try_module_get. */
        module_put(client->dev.driver->owner);
index a7092c3930d627e90fc3754f78ce6a70a44ff14d..1baf8e63f19e047171cce1994958ebc2eaa4b5dc 100644 (file)
@@ -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
         * use count as well.
         */
-       if (v4l2_device_register_subdev(v4l2_dev, sd))
+       if (__v4l2_device_register_subdev(v4l2_dev, sd, sd->owner))
                sd = NULL;
 
        /* Decrease the module use count to match the first try_module_get. */
index f6f111fae33c0d528e2154d48cdab7fb3836e2a3..dd897a362f369bf2716e9f4f92a9e6e17e6d4c35 100644 (file)
@@ -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
  * to register it.
  */
-int __must_check v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
-                                            struct v4l2_subdev *sd);
+#define v4l2_device_register_subdev(v4l2_dev, 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.