Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mtd: bf5xx_nand: use the managed version of kzalloc

This patch moves data allocated using kzalloc to managed data allocated
using devm_kzalloc and cleans now unnecessary kfrees in probe and remove
functions. Also, the now unnecessary label out_err_hw_init is done away
with and the label out_err_kzalloc is renamed to out_err.

The following Coccinelle semantic patch was used for making the change:

@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)
...
?-kfree(e);
...+>
}

@rem depends on prb@
identifier platform.removefn;
expression e;
@@
removefn(...) {
<...
- kfree(e);
...>
}

Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>

authored by

Himangi Saraogi and committed by
Brian Norris
0c53be9d b7e46062

+4 -9
+4 -9
drivers/mtd/nand/bf5xx_nand.c
··· 679 679 peripheral_free_list(bfin_nfc_pin_req); 680 680 bf5xx_nand_dma_remove(info); 681 681 682 - /* free the common resources */ 683 - kfree(info); 684 - 685 682 return 0; 686 683 } 687 684 ··· 739 742 return -EFAULT; 740 743 } 741 744 742 - info = kzalloc(sizeof(*info), GFP_KERNEL); 745 + info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); 743 746 if (info == NULL) { 744 747 err = -ENOMEM; 745 - goto out_err_kzalloc; 748 + goto out_err; 746 749 } 747 750 748 751 platform_set_drvdata(pdev, info); ··· 787 790 /* initialise the hardware */ 788 791 err = bf5xx_nand_hw_init(info); 789 792 if (err) 790 - goto out_err_hw_init; 793 + goto out_err; 791 794 792 795 /* setup hardware ECC data struct */ 793 796 if (hardware_ecc) { ··· 824 827 825 828 out_err_nand_scan: 826 829 bf5xx_nand_dma_remove(info); 827 - out_err_hw_init: 828 - kfree(info); 829 - out_err_kzalloc: 830 + out_err: 830 831 peripheral_free_list(bfin_nfc_pin_req); 831 832 832 833 return err;