Skip to contentSkip to conversation

media: mali-c55: Fix double mutex_destroy on capture dev register error

PATCH In review David Carlier 2 participants 3 messages Jun 28 – Jun 30

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

PATCH 1/1 media: mali-c55: Fix double mutex_destroy on capture dev register error

In mali_c55_register_cap_dev(), a failure of media_entity_pads_init() destroys cap_dev->lock inline and then jumps to err_destroy_mutex, which destroys the same mutex a second time. The switch default case just above already handles this correctly by jumping straight to the label without an inline destroy.

Drop the inline mutex_destroy() and rely on the err_destroy_mutex label, so the mutex is destroyed exactly once on every error path.

Fixes d5f281f3dd29 ("media: mali-c55: Add Mali-C55 ISP driver")
---
 drivers/media/platform/arm/mali-c55/mali-c55-capture.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/media/platform/arm/mali-c55/mali-c55-capture.c +1 -3
index 7aaa5c3f7..ff0155302 100644
@@ -857,10 +857,8 @@ static int mali_c55_register_cap_dev(struct mali_c55 *mali_c55,
 
 	cap_dev->pad.flags = MEDIA_PAD_FL_SINK;
 	ret = media_entity_pads_init(&cap_dev->vdev.entity, 1, &cap_dev->pad);
-	if (ret) {
-		mutex_destroy(&cap_dev->lock);
+	if (ret)
 		goto err_destroy_mutex;
-	}
 
 	vb2q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
 	vb2q->io_modes = VB2_MMAP | VB2_DMABUF;
Signature · 1 line
2.53.0
maintainer Reviewed-by on v1 1/1
#1 lore raw

Hi David

Quoted 10 lines · David Carlier

In mali_c55_register_cap_dev(), a failure of media_entity_pads_init() destroys cap_dev->lock inline and then jumps to err_destroy_mutex, which destroys the same mutex a second time. The switch default case just above already handles this correctly by jumping straight to the label without an inline destroy.

Drop the inline mutex_destroy() and rely on the err_destroy_mutex label, so the mutex is destroyed exactly once on every error path.

Fixes d5f281f3dd29 ("media: mali-c55: Add Mali-C55 ISP driver")

Calling mutex_destroy() twice should be harmless, I don't think this qualfies as a fix ?

And in any case, remember to Cc: stable whenever you send a Fixes.

Quoted 10 lines
---
 drivers/media/platform/arm/mali-c55/mali-c55-capture.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/media/platform/arm/mali-c55/mali-c55-capture.c +0 -0
index 7aaa5c3f7..ff0155302 100644

drivers/media/platform/arm/mali-c55/mali-c55-capture.c static int mali_c55_register_cap_dev(struct mali_c55 *mali_c55, · line 863

Quoted 8 lines
drivers/media/platform/arm/mali-c55/mali-c55-capture.c +1 -3
@@ -857,10 +857,8 @@ static int mali_c55_register_cap_dev(struct mali_c55 *mali_c55,
 
 	cap_dev->pad.flags = MEDIA_PAD_FL_SINK;
 	ret = media_entity_pads_init(&cap_dev->vdev.entity, 1, &cap_dev->pad);
-	if (ret) {
-		mutex_destroy(&cap_dev->lock);
+	if (ret)
 		goto err_destroy_mutex;
-	}

Indeed!

Quoted 7 lines
drivers/media/platform/arm/mali-c55/mali-c55-capture.c +0 -1
 	vb2q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
 	vb2q->io_modes = VB2_MMAP | VB2_DMABUF;
--

2.53.0

#2 lore raw

PATCH v2 1/1 media: mali-c55: Drop redundant mutex_destroy in capture register error path

In mali_c55_register_cap_dev(), a failure of media_entity_pads_init() destroys cap_dev->lock inline and then jumps to err_destroy_mutex, which destroys the same mutex a second time. Calling mutex_destroy() twice is harmless, so this is not a bugfix, but the inline call is redundant: the err_destroy_mutex label already covers this path, just like the switch default case immediately above.

Drop the inline mutex_destroy() and rely solely on the err_destroy_mutex label, so the mutex is destroyed exactly once on every error path.

---
 drivers/media/platform/arm/mali-c55/mali-c55-capture.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/media/platform/arm/mali-c55/mali-c55-capture.c +1 -3
index 7aaa5c3f7..ff0155302 100644
@@ -857,10 +857,8 @@ static int mali_c55_register_cap_dev(struct mali_c55 *mali_c55,
 
 	cap_dev->pad.flags = MEDIA_PAD_FL_SINK;
 	ret = media_entity_pads_init(&cap_dev->vdev.entity, 1, &cap_dev->pad);
-	if (ret) {
-		mutex_destroy(&cap_dev->lock);
+	if (ret)
 		goto err_destroy_mutex;
-	}
 
 	vb2q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
 	vb2q->io_modes = VB2_MMAP | VB2_DMABUF;
Signature · 1 line
2.53.0