Skip to contentSkip to conversation

davinci: don't return under lock on error path

PATCH In review Dan Carpenter 2 participants 2 messages Apr 7, 2010

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

PATCH 1/1 davinci: don't return under lock on error path

If the kmalloc() failed for "ccdc_cfg = kmalloc(...);" then we would exit with the lock held. I moved the mutex_lock() below the allocation because it isn't protecting anything in that block and allocations are allocations are sometimes slow.

drivers/media/video/davinci/vpfe_capture.c +2 -1
index 7cf042f..5c83f90 100644
@@ -1824,7 +1824,6 @@ static __init int vpfe_probe(struct platform_device *pdev)
 		goto probe_free_dev_mem;
 	}
 
-	mutex_lock(&ccdc_lock);
 	/* Allocate memory for ccdc configuration */
 	ccdc_cfg = kmalloc(sizeof(struct ccdc_config), GFP_KERNEL);
 	if (NULL = ccdc_cfg) {
@@ -1833,6 +1832,8 @@ static __init int vpfe_probe(struct platform_device *pdev)
 		goto probe_free_dev_mem;
 	}
 
+	mutex_lock(&ccdc_lock);
+
 	strncpy(ccdc_cfg->name, vpfe_cfg->ccdc, 32);
 	/* Get VINT0 irq resource */
 	res1 = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines

-----Original Message-----
From: Dan Carpenter [mailto:[email protected]]
Sent: Wednesday, April 07, 2010 2:51 PM
To: Mauro Carvalho Chehab
Cc: Hans Verkuil; Hiremath, Vaibhav; Laurent Pinchart; Karicheri, Muralidharan; [email protected]; [email protected]
Subject: [patch] davinci: don't return under lock on error path

Quoted 4 lines

If the kmalloc() failed for "ccdc_cfg = kmalloc(...);" then we would exit with the lock held. I moved the mutex_lock() below the allocation because it isn't protecting anything in that block and allocations are allocations are sometimes slow.

[Hiremath, Vaibhav] Good catch and thanks for the patch.

Thanks,
Vaibhav

Quoted 27 lines
drivers/media/video/davinci/vpfe_capture.c +0 -1
index 7cf042f..5c83f90 100644
@@ -1824,7 +1824,6 @@ static __init int vpfe_probe(struct platform_device
 *pdev)
 		goto probe_free_dev_mem;
 	}
 
-	mutex_lock(&ccdc_lock);
 	/* Allocate memory for ccdc configuration */
 	ccdc_cfg = kmalloc(sizeof(struct ccdc_config), GFP_KERNEL);
drivers/media/video/davinci/vpfe_capture.c +2 -0
 	if (NULL == ccdc_cfg) {
@@ -1833,6 +1832,8 @@ static __init int vpfe_probe(struct platform_device
 *pdev)
 		goto probe_free_dev_mem;
 	}
 
+	mutex_lock(&ccdc_lock);
+
 	strncpy(ccdc_cfg->name, vpfe_cfg->ccdc, 32);
 	/* Get VINT0 irq resource */

res1 = platform_get_resource(pdev, IORESOURCE_IRQ, 0);