On Mon, 2012-03-12 at 13:58 -0400, Jean Delvare wrote: > On Mon, 12 Mar 2012 08:43:25 -0700, Guenter Roeck wrote: > > The driver probe function leaked memory if creating the cpu0_vid attribute file > > failed. Fix by converting the driver to use devm_kzalloc. > > > > Signed-off-by: Guenter Roeck <linux@xxxxxxxxxxxx> > > --- > > drivers/hwmon/w83627ehf.c | 7 +++---- > > 1 files changed, 3 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c > > index 378142c..60e929c 100644 > > --- a/drivers/hwmon/w83627ehf.c > > +++ b/drivers/hwmon/w83627ehf.c > > @@ -2021,7 +2021,8 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev) > > goto exit; > > } > > > > - data = kzalloc(sizeof(struct w83627ehf_data), GFP_KERNEL); > > + data = devm_kzalloc(&pdev->dev, sizeof(struct w83627ehf_data), > > + GFP_KERNEL); > > if (!data) { > > err = -ENOMEM; > > goto exit_release; > > @@ -2514,9 +2515,8 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev) > > > > exit_remove: > > w83627ehf_device_remove_files(dev); > > - kfree(data); > > - platform_set_drvdata(pdev, NULL); > > exit_release: > > + platform_set_drvdata(pdev, NULL); > > release_region(res->start, IOREGION_LENGTH); > > exit: > > return err; > > @@ -2530,7 +2530,6 @@ static int __devexit w83627ehf_remove(struct platform_device *pdev) > > w83627ehf_device_remove_files(&pdev->dev); > > release_region(data->addr, IOREGION_LENGTH); > > platform_set_drvdata(pdev, NULL); > > - kfree(data); > > > > return 0; > > } > > I'm not familiar with devm but this looks correct. Hi Jean, I just noticed it recently, as more and mode drivers are converted to use it. It auto-frees memory when the device is released. It typically reduces driver size by some 80+ bytes, and it ensures that there are no memory leaks. Quite convenient. The only thing I don't know for sure is if platform_set_drvdata(pdev, NULL); is still needed. It doesn't hurt, though, so I don't remove it. Guenter _______________________________________________ lm-sensors mailing list lm-sensors@xxxxxxxxxxxxxx http://lists.lm-sensors.org/mailman/listinfo/lm-sensors