ACPI / AC: Introduce the use of the managed version of kzalloc
PATCH 1/1 ACPI / AC: Introduce the use of 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.
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);
...>
}
--- drivers/acpi/ac.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/acpi/ac.c +1 -6
@@ -205,7 +205,7 @@ static int acpi_ac_probe(struct platform_device *pdev)if (!adev)return -ENODEV ; - ac =kzalloc (sizeof (struct acpi_ac ),GFP_KERNEL ); + ac =devm_kzalloc (&pdev->dev,sizeof (struct acpi_ac ),GFP_KERNEL );if (!ac)return -ENOMEM ;
@@ -240,9 +240,6 @@ static int acpi_ac_probe(struct platform_device *pdev) ac->battery_nb.notifier_call = acpi_ac_battery_notify;register_acpi_notifier (&ac->battery_nb); end: -if (result) -kfree (ac); -dmi_check_system (ac_dmi_table);return result; }
@@ -287,8 +284,6 @@ static int acpi_ac_remove(struct platform_device *pdev)power_supply_unregister (&ac->charger);unregister_acpi_notifier (&ac->battery_nb); -kfree (ac); -return 0 ; }
Signature · 1 line
1.9.1
2014-05-04 20:35 GMT+08:00 Himangi Saraogi <[email protected]>:
Quoted 3 lines
This patch moves data allocated using kzalloc to managed data allocated using
devm_kzallocand cleans now unnecessary kfrees in probe and remove functions.
Quoted 77 lines
The following Coccinelle semantic patch was used for making the change:
@platform@
identifier p, probefn, removefn;
@@
structplatform_driverp = {
.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 <[email protected]>--- drivers/acpi/ac.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)drivers/acpi/ac.c +1
-7@@ -205,7 +205,7 @@ static int acpi_ac_probe(struct platform_device *pdev)if (!adev)return -ENODEV ; - ac =kzalloc (sizeof (struct acpi_ac ),GFP_KERNEL ); + ac =devm_kzalloc (&pdev->dev,sizeof (struct acpi_ac ),GFP_KERNEL );if (!ac)return -ENOMEM ;@@ -240,9 +240,6 @@ static int acpi_ac_probe(struct platform_device *pdev) ac->battery_nb.notifier_call = acpi_ac_battery_notify;register_acpi_notifier (&ac->battery_nb); end: -if (result) -kfree (ac); -dmi_check_system (ac_dmi_table);return result; }@@ -287,8 +284,6 @@ static int acpi_ac_remove(struct platform_device *pdev)power_supply_unregister (&ac->charger);unregister_acpi_notifier (&ac->battery_nb); -kfree (ac); -return 0 ; } --1.9.1
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Best regards Tianyu Lan