media: mali-c55: Fix double mutex_destroy on capture dev register error
Subsystems (2)
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.
--- 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
@@ -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
Hi David
Quoted 10 lines · David Carlier
In
mali_c55_register_cap_dev(), a failure ofmedia_entity_pads_init()destroyscap_dev->lockinline and then jumps toerr_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 theerr_destroy_mutexlabel, 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
Signed-off-by David Carlier <[email protected]>--- 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
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
-1vb2q->type =V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ; vb2q->io_modes =VB2_MMAP |VB2_DMABUF ; --2.53.0
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
@@ -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