Skip to content

Commit

Permalink
ix86/mid/thermal: Introduce the use of the managed version of kzalloc
Browse files Browse the repository at this point in the history
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);
  ...>
}

Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>
  • Loading branch information
Himangi Saraogi authored and Matthew Garrett committed Jun 10, 2014
1 parent eec3b95 commit 14627e3
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions drivers/platform/x86/intel_mid_thermal.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,15 +481,15 @@ static int mid_thermal_probe(struct platform_device *pdev)
int i;
struct platform_info *pinfo;

pinfo = kzalloc(sizeof(struct platform_info), GFP_KERNEL);
pinfo = devm_kzalloc(&pdev->dev, sizeof(struct platform_info),
GFP_KERNEL);
if (!pinfo)
return -ENOMEM;

/* Initializing the hardware */
ret = mid_initialize_adc(&pdev->dev);
if (ret) {
dev_err(&pdev->dev, "ADC init failed");
kfree(pinfo);
return ret;
}

Expand Down Expand Up @@ -520,7 +520,6 @@ static int mid_thermal_probe(struct platform_device *pdev)
thermal_zone_device_unregister(pinfo->tzd[i]);
}
configure_adc(0);
kfree(pinfo);
return ret;
}

Expand All @@ -541,8 +540,6 @@ static int mid_thermal_remove(struct platform_device *pdev)
thermal_zone_device_unregister(pinfo->tzd[i]);
}

kfree(pinfo);

/* Stop the ADC */
return configure_adc(0);
}
Expand Down

0 comments on commit 14627e3

Please sign in to comment.