staging: media: davinci_vpfe: Replace kzalloc with devm_kzalloc
Subsystems (2)
PATCH 1/1 staging: media: davinci_vpfe: Replace kzalloc with devm_kzalloc
Replace data allocated by kzalloc to managed data allocated by devm_kzalloc. Remove unnecessary kzfree.
Also remove a goto by replacing it with returns and dropping the unnecessary label.
--- .../staging/media/davinci_vpfe/vpfe_mc_capture.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-)
drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c +7 -15
@@ -579,22 +579,20 @@ 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;if (pdev->dev.platform_data ==NULL ) {v4l2_err (pdev->dev.driver,"Unable to get vpfe config\n" ); - ret = -ENOENT ; - goto probe_free_dev_mem; +return -ENOENT ; } vpfe_dev->cfg = pdev->dev.platform_data;if (vpfe_dev->cfg->card_name ==NULL || vpfe_dev->cfg->sub_devs ==NULL ) {v4l2_err (pdev->dev.driver,"null ptr in vpfe_cfg\n" ); - ret = -ENOENT ; - goto probe_free_dev_mem; +return -ENOENT ; }/* Get VINT0 irq resource */
@@ -602,8 +600,7 @@ static int vpfe_probe(struct platform_device *pdev)if (!res1) {v4l2_err (pdev->dev.driver,"Unable to get interrupt for VINT0\n" ); - ret = -ENOENT ; - goto probe_free_dev_mem; +return -ENOENT ; } vpfe_dev->ccdc_irq0 = res1->start;
@@ -612,8 +609,7 @@ static int vpfe_probe(struct platform_device *pdev)if (!res1) {v4l2_err (pdev->dev.driver,"Unable to get interrupt for VINT1\n" ); - ret = -ENOENT ; - goto probe_free_dev_mem; +return -ENOENT ; } vpfe_dev->ccdc_irq1 = res1->start;
@@ -622,8 +618,7 @@ static int vpfe_probe(struct platform_device *pdev)if (!res1) {v4l2_err (pdev->dev.driver,"Unable to get interrupt for DMA\n" ); - ret = -ENOENT ; - goto probe_free_dev_mem; +return -ENOENT ; } vpfe_dev->imp_dma_irq = res1->start;
@@ -632,7 +627,7 @@ static int vpfe_probe(struct platform_device *pdev)/* enable vpss clocks */ ret =vpfe_enable_clock (vpfe_dev);if (ret) - goto probe_free_dev_mem; +return ret; ret =vpfe_initialize_modules (vpfe_dev, pdev);if (ret)
@@ -680,8 +675,6 @@ probe_out_entities_cleanup:vpfe_cleanup_modules (vpfe_dev, pdev); probe_disable_clock:vpfe_disable_clock (vpfe_dev); -probe_free_dev_mem: -kzfree (vpfe_dev);return ret; }
@@ -702,7 +695,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
1.9.1
Quoted 2 lines · Amitoj Kaur Chawla
Replace data allocated by kzalloc to managed data allocated by
devm_kzalloc. Remove unnecessary kzfree.
Actually, this doesn't preserve the semantics. kzfree does more than just free. It also zeroes the data first. This could be useful if the data is sensitive in some way. On the other hand, I don't recall ever seeing a kzfree in a platform driver probe function.
Unfortunately, from the git logs, I don't have the impression that anyone is really taking responsability for this driver either, so I'm not sure who you could ask for more information.
julia
Quoted 104 lines
Also remove a goto by replacing it with returns and dropping the unnecessary label.
Signed-off-by Amitoj Kaur Chawla <[email protected]>--- .../staging/media/davinci_vpfe/vpfe_mc_capture.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-)drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c +7
-15@@ -579,22 +579,20 @@ 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;if (pdev->dev.platform_data ==NULL ) {v4l2_err (pdev->dev.driver,"Unable to get vpfe config\n" ); - ret = -ENOENT ; - goto probe_free_dev_mem; +return -ENOENT ; } vpfe_dev->cfg = pdev->dev.platform_data;if (vpfe_dev->cfg->card_name ==NULL || vpfe_dev->cfg->sub_devs ==NULL ) {v4l2_err (pdev->dev.driver,"null ptr in vpfe_cfg\n" ); - ret = -ENOENT ; - goto probe_free_dev_mem; +return -ENOENT ; }/* Get VINT0 irq resource */ @@ -602,8 +600,7 @@ static int vpfe_probe(struct platform_device *pdev)if (!res1) {v4l2_err (pdev->dev.driver,"Unable to get interrupt for VINT0\n" ); - ret = -ENOENT ; - goto probe_free_dev_mem; +return -ENOENT ; } vpfe_dev->ccdc_irq0 = res1->start;@@ -612,8 +609,7 @@ static int vpfe_probe(struct platform_device *pdev)if (!res1) {v4l2_err (pdev->dev.driver,"Unable to get interrupt for VINT1\n" ); - ret = -ENOENT ; - goto probe_free_dev_mem; +return -ENOENT ; } vpfe_dev->ccdc_irq1 = res1->start;@@ -622,8 +618,7 @@ static int vpfe_probe(struct platform_device *pdev)if (!res1) {v4l2_err (pdev->dev.driver,"Unable to get interrupt for DMA\n" ); - ret = -ENOENT ; - goto probe_free_dev_mem; +return -ENOENT ; } vpfe_dev->imp_dma_irq = res1->start;@@ -632,7 +627,7 @@ static int vpfe_probe(struct platform_device *pdev)/* enable vpss clocks */ ret =vpfe_enable_clock (vpfe_dev);if (ret) - goto probe_free_dev_mem; +return ret; ret =vpfe_initialize_modules (vpfe_dev, pdev);if (ret)@@ -680,8 +675,6 @@ probe_out_entities_cleanup:vpfe_cleanup_modules (vpfe_dev, pdev); probe_disable_clock:vpfe_disable_clock (vpfe_dev); -probe_free_dev_mem: -kzfree (vpfe_dev);return ret; }@@ -702,7 +695,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 · 8 lines
1.9.1 -- You received this message because you are subscribed to the Google Groups "outreachy-kernel" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20160226150029.GA32277%40amitoj-Inspiron-3542. For more options, visit https://groups.google.com/d/optout.
Quoted 8 lines · Julia Lawall
Quoted 2 lines
Replace data allocated by kzalloc to managed data allocated by
devm_kzalloc. Remove unnecessary kzfree.Actually, this doesn't preserve the semantics. kzfree does more than just free. It also zeroes the data first. This could be useful if the data is sensitive in some way. On the other hand, I don't recall ever seeing a kzfree in a platform driver probe function.
Yes, after reading this, I wrote a semantic patch to find if there are in fact any cases where kzfree is used with the platform driver probe function in any of the drivers and the only result was this case.
Quoted 5 lines
Unfortunately, from the git logs, I don't have the impression that anyone is really taking responsability for this driver either, so I'm not sure who you could ask for more information.
julia
Oh okay, this patch will probably be dropped then.
Amitoj
Quoted 13 lines · Amitoj Kaur Chawla
Quoted 8 lines · Julia Lawall
Quoted 2 lines
Replace data allocated by kzalloc to managed data allocated by
devm_kzalloc. Remove unnecessary kzfree.Actually, this doesn't preserve the semantics. kzfree does more than just free. It also zeroes the data first. This could be useful if the data is sensitive in some way. On the other hand, I don't recall ever seeing a kzfree in a platform driver probe function.
Yes, after reading this, I wrote a semantic patch to find if there are in fact any cases where kzfree is used with the platform driver probe function in any of the drivers and the only result was this case.
Quoted 7 lines
Quoted 5 lines
Unfortunately, from the git logs, I don't have the impression that anyone is really taking responsability for this driver either, so I'm not sure who you could ask for more information.
julia
Oh okay, this patch will probably be dropped then.
I think you should reply to it an say explicitly not to take it.
julia
Quoted 98 lines · Amitoj Kaur Chawla
Replace data allocated by kzalloc to managed data allocated by
devm_kzalloc. Remove unnecessary kzfree.Also remove a goto by replacing it with returns and dropping the unnecessary label.
Signed-off-by Amitoj Kaur Chawla <[email protected]>--- .../staging/media/davinci_vpfe/vpfe_mc_capture.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-)drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c +7
-16@@ -579,22 +579,20 @@ 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;if (pdev->dev.platform_data ==NULL ) {v4l2_err (pdev->dev.driver,"Unable to get vpfe config\n" ); - ret = -ENOENT ; - goto probe_free_dev_mem; +return -ENOENT ; } vpfe_dev->cfg = pdev->dev.platform_data;if (vpfe_dev->cfg->card_name ==NULL || vpfe_dev->cfg->sub_devs ==NULL ) {v4l2_err (pdev->dev.driver,"null ptr in vpfe_cfg\n" ); - ret = -ENOENT ; - goto probe_free_dev_mem; +return -ENOENT ; }/* Get VINT0 irq resource */ @@ -602,8 +600,7 @@ static int vpfe_probe(struct platform_device *pdev)if (!res1) {v4l2_err (pdev->dev.driver,"Unable to get interrupt for VINT0\n" ); - ret = -ENOENT ; - goto probe_free_dev_mem; +return -ENOENT ; } vpfe_dev->ccdc_irq0 = res1->start;@@ -612,8 +609,7 @@ static int vpfe_probe(struct platform_device *pdev)if (!res1) {v4l2_err (pdev->dev.driver,"Unable to get interrupt for VINT1\n" ); - ret = -ENOENT ; - goto probe_free_dev_mem; +return -ENOENT ; } vpfe_dev->ccdc_irq1 = res1->start;@@ -622,8 +618,7 @@ static int vpfe_probe(struct platform_device *pdev)if (!res1) {v4l2_err (pdev->dev.driver,"Unable to get interrupt for DMA\n" ); - ret = -ENOENT ; - goto probe_free_dev_mem; +return -ENOENT ; } vpfe_dev->imp_dma_irq = res1->start;@@ -632,7 +627,7 @@ static int vpfe_probe(struct platform_device *pdev)/* enable vpss clocks */ ret =vpfe_enable_clock (vpfe_dev);if (ret) - goto probe_free_dev_mem; +return ret; ret =vpfe_initialize_modules (vpfe_dev, pdev);if (ret)@@ -680,8 +675,6 @@ probe_out_entities_cleanup:vpfe_cleanup_modules (vpfe_dev, pdev); probe_disable_clock:vpfe_disable_clock (vpfe_dev); -probe_free_dev_mem: -kzfree (vpfe_dev);return ret; }@@ -702,7 +695,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 ; } --
Quoted 2 lines
1.9.1
This patch is incorrect and should not be taken.
Sorry for the inconvenience,
Amitoj