diff mbox series

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

Message ID 20210609115457.822085-2-paul.kocialkowski@bootlin.com
State New
Headers show
Series None | expand

Commit Message

Paul Kocialkowski June 9, 2021, 11:54 a.m. UTC
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")
Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
---
 drivers/media/v4l2-core/v4l2-async.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Sakari Ailus June 9, 2021, 12:27 p.m. UTC | #1
Hi Paul,

On Wed, Jun 09, 2021 at 01:54:57PM +0200, Paul Kocialkowski wrote:
> 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.
Paul Kocialkowski June 9, 2021, 1:01 p.m. UTC | #2
Hi Sakari,

On Wed 09 Jun 21, 15:27, Sakari Ailus wrote:
> Hi Paul,
> 
> On Wed, Jun 09, 2021 at 01:54:57PM +0200, Paul Kocialkowski wrote:
> > 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.

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
diff mbox series

Patch

diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
index cd9e78c63791..e0f4f7551ff3 100644
--- a/drivers/media/v4l2-core/v4l2-async.c
+++ b/drivers/media/v4l2-core/v4l2-async.c
@@ -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;