Skip to contentSkip to conversation

Staging:media:davinci_vpfe: used devm_kzalloc in place of kzalloc

PATCH In review Nadim Almas 3 participants 3 messages Nov 2, 2016 – Nov 22, 2016

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

PATCH 1/1 Staging:media:davinci_vpfe: used devm_kzalloc in place of kzalloc

Switch to resource-managed function devm_kzalloc instead of kzolloc and remove unneeded kzfree

Also, remove kzfree in probe function and remove function,vpfe_remove as it is now has nothing to do.
The Coccinelle semantic patch used to make this change is as follows:
/<smpl>
@platform@
identifier p, probefn, removefn;
@@
struct platform_driver p = {
.probe = probefn,
.remove = removefn,
};

@prb@
identifier platform.probefn, pdev;
expression e, e1, e2;
@@
probefn(struct platform_device *pdev, ...) {
<+...
- e = kzalloc(e1, e2)
+ e = devm_kzalloc(&pdev->dev, e1, e2)
...
?-kzfree(e);
...+>
}
@rem depends on prb@
identifier platform.removefn;
expression prb.e;
@@
removefn(...) {
<...
- kzfree(e);
...>
}
//</smpl>

---
 drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c +1 -3
index bf077f8..cd44f0f 100644
@@ -579,7 +579,7 @@ static int vpfe_probe(struct platform_device *pdev)
 	struct resource *res1;
 	int ret = -ENOMEM;
 
-	vpfe_dev = kzalloc(sizeof(*vpfe_dev), GFP_KERNEL);
+	vpfe_dev = devm_kzalloc(&pdev->dev, sizeof(*vpfe_dev), GFP_KERNEL);
 	if (!vpfe_dev)
 		return ret;
 
@@ -681,7 +681,6 @@ static int vpfe_probe(struct platform_device *pdev)
 probe_disable_clock:
 	vpfe_disable_clock(vpfe_dev);
 probe_free_dev_mem:
-	kzfree(vpfe_dev);
 
 	return ret;
 }
@@ -702,7 +701,6 @@ static int vpfe_remove(struct platform_device *pdev)
 	v4l2_device_unregister(&vpfe_dev->v4l2_dev);
 	media_device_unregister(&vpfe_dev->media_dev);
 	vpfe_disable_clock(vpfe_dev);
-	kzfree(vpfe_dev);
 
 	return 0;
 }
Signature · 1 line
2.7.4
#1 lore raw
Quoted 57 lines · Nadim Almas

Switch to resource-managed function devm_kzalloc instead of kzolloc and remove unneeded kzfree

Also, remove kzfree in probe function and remove function,vpfe_remove as it is now has nothing to do.
The Coccinelle semantic patch used to make this change is as follows:
/<smpl>
@platform@
identifier p, probefn, removefn;
@@
struct platform_driver p = {
.probe = probefn,
.remove = removefn,
};

@prb@
identifier platform.probefn, pdev;
expression e, e1, e2;
@@
probefn(struct platform_device *pdev, ...) {
<+...
- e = kzalloc(e1, e2)
+ e = devm_kzalloc(&pdev->dev, e1, e2)
...
?-kzfree(e);
...+>
}
@rem depends on prb@
identifier platform.removefn;
expression prb.e;
@@
removefn(...) {
<...
- kzfree(e);
...>
}
//</smpl>

---
 drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c +1 -1
index bf077f8..cd44f0f 100644
@@ -579,7 +579,7 @@ static int vpfe_probe(struct platform_device *pdev)
 	struct resource *res1;
 	int ret = -ENOMEM;
 
-	vpfe_dev = kzalloc(sizeof(*vpfe_dev), GFP_KERNEL);
+	vpfe_dev = devm_kzalloc(&pdev->dev, sizeof(*vpfe_dev), GFP_KERNEL);
 	if (!vpfe_dev)
 		return ret;
 

drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c static int vpfe_probe(struct platform_device *pdev) · line 684

Quoted 4 lines
drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c +0 -1
@@ -681,7 +681,6 @@ static int vpfe_probe(struct platform_device *pdev)
 probe_disable_clock:
 	vpfe_disable_clock(vpfe_dev);
 probe_free_dev_mem:
-	kzfree(vpfe_dev);

Kzfree zeroes the data before freeing it. Devm_kzalloc only causes a kfree to happen, not a kzfree. If the kzfree is needed, then a memset 0 would need to replace the calls to kzfree.

There are some other minor issues with the patch. In the subject line, there is normally a space after each :. There is a spelling mistake in the commit message. In the commit message there should be one space betwee words within a sentence, and there should be a space after a comma, or other puctuation.

julia

Quoted 15 lines
drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c +0 -2
 	return ret;
 }
@@ -702,7 +701,6 @@ static int vpfe_remove(struct platform_device *pdev)
 	v4l2_device_unregister(&vpfe_dev->v4l2_dev);
 	media_device_unregister(&vpfe_dev->media_dev);
 	vpfe_disable_clock(vpfe_dev);
-	kzfree(vpfe_dev);
 
 	return 0;
 }
--

2.7.4

#2 lore raw

Hi Julia,

Quoted 59 lines · On Wednesday 02 Nov 2016 07:24:29 Julia Lawall wrote:
Quoted 58 lines · Nadim Almas

Switch to resource-managed function devm_kzalloc instead of kzolloc and remove unneeded kzfree

Also, remove kzfree in probe function and remove function,vpfe_remove as it is now has nothing to do.
The Coccinelle semantic patch used to make this change is as follows:
/<smpl>
@platform@
identifier p, probefn, removefn;
@@
struct platform_driver p = {
.probe = probefn,
.remove = removefn,
};

@prb@
identifier platform.probefn, pdev;
expression e, e1, e2;
@@
probefn(struct platform_device *pdev, ...) {
<+...
- e = kzalloc(e1, e2)
+ e = devm_kzalloc(&pdev->dev, e1, e2)
...
?-kzfree(e);
...+>
}
@rem depends on prb@
identifier platform.removefn;
expression prb.e;
@@
removefn(...) {
<...
- kzfree(e);
...>
}
//</smpl>

---

 drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c index bf077f8..cd44f0f 100644

drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c +1 -1
@@ -579,7 +579,7 @@ static int vpfe_probe(struct platform_device *pdev)
 	struct resource *res1;
 	int ret = -ENOMEM;
 
-	vpfe_dev = kzalloc(sizeof(*vpfe_dev), GFP_KERNEL);
+	vpfe_dev = devm_kzalloc(&pdev->dev, sizeof(*vpfe_dev), GFP_KERNEL);
 	if (!vpfe_dev)
 		return ret;
 
Quoted 9 lines

drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c static int vpfe_probe(struct platform_device *pdev) · line 684

Quoted 5 lines
drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c +0 -1
@@ -681,7 +681,6 @@ static int vpfe_probe(struct platform_device *pdev)
 probe_disable_clock:
 	vpfe_disable_clock(vpfe_dev);
 probe_free_dev_mem:
-	kzfree(vpfe_dev);

Kzfree zeroes the data before freeing it. Devm_kzalloc only causes a kfree to happen, not a kzfree. If the kzfree is needed, then a memset 0 would need to replace the calls to kzfree.

I don't think kzfree() is needed in this case.

Quoted 5 lines

There are some other minor issues with the patch. In the subject line, there is normally a space after each :. There is a spelling mistake in the commit message. In the commit message there should be one space betwee words within a sentence, and there should be a space after a comma, or other puctuation.

Beside, I don't think devm_kzalloc() is a good idea. The vpfe_device structure embeds data accessible from userspace through ioctls, and thus potentially needs to survive unbinding the driver from the device. This isn't currently implemented now, but devm_kzalloc() just goes in the wrong direction.

Quoted 11 lines
Quoted 11 lines
drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c +0 -1
 	return ret;
 }
 
@@ -702,7 +701,6 @@ static int vpfe_remove(struct platform_device *pdev)
 	v4l2_device_unregister(&vpfe_dev->v4l2_dev);
 	media_device_unregister(&vpfe_dev->media_dev);
 	vpfe_disable_clock(vpfe_dev);
-	kzfree(vpfe_dev);
 	return 0;
 }
 
Signature · 3 lines
Regards,

Laurent Pinchart