Skip to contentSkip to conversation

media: v4l2-subdev: Fix documentation of the subdev_notifier member

PATCH In review Paul Kocialkowski 2 participants 6 messages Jun 9, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 media: v4l2-subdev: Fix documentation of the subdev_notifier member

Fix the name of the function that registers the subdev_notifier member of the v4l2_subdev structure.

---
 include/media/v4l2-subdev.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/media/v4l2-subdev.h +1 -1
index d0e9a5bdb08b..f3b657dfe304 100644
@@ -854,7 +854,7 @@ struct v4l2_subdev_platform_data {
  * @asd: Pointer to respective &struct v4l2_async_subdev.
  * @notifier: Pointer to the managing notifier.
  * @subdev_notifier: A sub-device notifier implicitly registered for the sub-
- *		     device using v4l2_device_register_sensor_subdev().
+ *		     device using v4l2_async_register_subdev_sensor_common().
  * @pdata: common part of subdevice platform data
  *
  * Each instance of a subdev driver should create this struct, either
Signature · 1 line
2.31.1
#1 lore raw

PATCH 2/2 media: v4l2-async: Make subdev notifier cleanup conditional

A dedicated subdev notified is registered when using the helper dedicated to sensors (v4l2_async_register_subdev_sensor_common), but this is not the case when a driver uses v4l2_async_register_subdev directly.

As a result, add a conditional check to deal with the dedicated subdev notifier only when necessary at the async subdev unregister step (and avoid operating on/freeing an unallocated notifier).

Fixes aef69d54755d ("media: v4l: fwnode: Add a convenience function for registering sensors")
---
 drivers/media/v4l2-core/v4l2-async.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/media/v4l2-core/v4l2-async.c +6 -4
index cd9e78c63791..e0f4f7551ff3 100644
@@ -780,10 +780,12 @@ void v4l2_async_unregister_subdev(struct v4l2_subdev *sd)
 
 	mutex_lock(&list_lock);
 
-	__v4l2_async_notifier_unregister(sd->subdev_notifier);
-	__v4l2_async_notifier_cleanup(sd->subdev_notifier);
-	kfree(sd->subdev_notifier);
-	sd->subdev_notifier = NULL;
+	if (sd->subdev_notifier) {
+		__v4l2_async_notifier_unregister(sd->subdev_notifier);
+		__v4l2_async_notifier_cleanup(sd->subdev_notifier);
+		kfree(sd->subdev_notifier);
+		sd->subdev_notifier = NULL;
+	}
 
 	if (sd->asd) {
 		struct v4l2_async_notifier *notifier = sd->notifier;
Signature · 1 line
2.31.1
maintainer
#2 lore raw

Re: [PATCH 2/2] media: v4l2-async: Make subdev notifier cleanup conditional

Hi Paul,

Quoted 4 lines · Paul Kocialkowski

A dedicated subdev notified is registered when using the helper dedicated to sensors (v4l2_async_register_subdev_sensor_common), but this is not the case when a driver uses v4l2_async_register_subdev directly.

Is this a problem?

The notifier unregistration and cleanup functions should be safe to call on a notifier that's not been initialised or registered. The same goes for kfree with NULL argument.

Signature · 3 lines
Kind regards,

Sakari Ailus
#3 lore raw

Re: [PATCH 2/2] media: v4l2-async: Make subdev notifier cleanup conditional

Hi Sakari,

Quoted 8 lines · Sakari Ailus

Hi Paul,

Quoted 4 lines · Paul Kocialkowski

A dedicated subdev notified is registered when using the helper dedicated to sensors (v4l2_async_register_subdev_sensor_common), but this is not the case when a driver uses v4l2_async_register_subdev directly.

Quoted 5 lines

Is this a problem?

The notifier unregistration and cleanup functions should be safe to call on a notifier that's not been initialised or registered. The same goes for kfree with NULL argument.

I think you're right, the functions and kfree are indeed safe. I think I mixed things up with debugging an issue and assumed this was part of the fix I needed.

Sorry for the noise!

Paul

Signature · 3 lines
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
maintainer
#4 lore raw
In reply to Paul Kocialkowski

Hi Paul,

Quoted 13 lines · Paul Kocialkowski

Fix the name of the function that registers the subdev_notifier member of the v4l2_subdev structure.

---
 include/media/v4l2-subdev.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/media/v4l2-subdev.h +0 -0
index d0e9a5bdb08b..f3b657dfe304 100644

include/media/v4l2-subdev.h struct v4l2_subdev_platform_data { · line 857

Quoted 5 lines
include/media/v4l2-subdev.h +1 -1
@@ -854,7 +854,7 @@ struct v4l2_subdev_platform_data {
  * @asd: Pointer to respective &struct v4l2_async_subdev.
  * @notifier: Pointer to the managing notifier.
  * @subdev_notifier: A sub-device notifier implicitly registered for the sub-
- *		     device using v4l2_device_register_sensor_subdev().
+ *		     device using v4l2_async_register_subdev_sensor_common().

I agree in principle, but the function is nowadays called v4l2_async_register_subdev_sensor().

I can fix this while applying.

Signature · 3 lines
Regards,

Sakari Ailus
#5 lore raw

Hi Sakari,

Quoted 25 lines · Sakari Ailus

Hi Paul,

Quoted 13 lines · Paul Kocialkowski

Fix the name of the function that registers the subdev_notifier member of the v4l2_subdev structure.

---
 include/media/v4l2-subdev.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/media/v4l2-subdev.h +0 -0
index d0e9a5bdb08b..f3b657dfe304 100644

include/media/v4l2-subdev.h struct v4l2_subdev_platform_data { · line 857

Quoted 5 lines
include/media/v4l2-subdev.h +1 -1
@@ -854,7 +854,7 @@ struct v4l2_subdev_platform_data {
  * @asd: Pointer to respective &struct v4l2_async_subdev.
  * @notifier: Pointer to the managing notifier.
  * @subdev_notifier: A sub-device notifier implicitly registered for the sub-
- *		     device using v4l2_device_register_sensor_subdev().
+ *		     device using v4l2_async_register_subdev_sensor_common().

I agree in principle, but the function is nowadays called v4l2_async_register_subdev_sensor().

Quoted 1 line

I can fix this while applying.

Looks like I missed the rename when rebasing my patch on media/master! Of course, feel free to update with the new name.

Thanks,

Paul

Signature · 3 lines
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com