hwmon: (w83627ehf) Fix memory leak in probe function
Guenter Roeck
maintainerPATCH 2/2 hwmon: (w83627ehf) Fix memory leak in probe function
The driver probe function leaked memory if creating the cpu0_vid attribute file failed. Fix by converting the driver to use devm_kzalloc.
--- drivers/hwmon/w83627ehf.c | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-)
drivers/hwmon/w83627ehf.c +3 -4
@@ -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 ; }
Signature · 7 lines
1.7.5.4 _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 34 lines · Guenter Roeck
The driver probe function leaked memory if creating the
cpu0_vidattribute file failed. Fix by converting the driver to usedevm_kzalloc.Signed-off-by Guenter Roeck <[email protected]>--- drivers/hwmon/w83627ehf.c | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-)drivers/hwmon/w83627ehf.c +3
-3@@ -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;
drivers/hwmon/w83627ehf.c static int __devexit w83627ehf_remove(struct platform_device *pdev) · line 2535
Quoted 7 lines
drivers/hwmon/w83627ehf.c +0
-1@@ -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.
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 40 lines · Jean Delvare
Quoted 39 lines · Guenter Roeck
The driver probe function leaked memory if creating the
cpu0_vidattribute file failed. Fix by converting the driver to usedevm_kzalloc.Signed-off-by Guenter Roeck <[email protected]>--- drivers/hwmon/w83627ehf.c | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-)drivers/hwmon/w83627ehf.c +3
-4@@ -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);
Quoted 4 lines
drivers/hwmon/w83627ehf.c static int __devexit w83627ehf_remove(struct platform_device *pdev) · line 2535
Quoted 2 lines
drivers/hwmon/w83627ehf.c +0
-0return 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
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 2 lines · Guenter Roeck
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.
Any driver relying on it has always been buggy, anything might happen to the value while the driver isn't bound. I keep thinking we should have a debugging option to write random data there for unbound devices just in case.
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 4 lines · Mark Brown
Quoted 2 lines · Guenter Roeck
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.
I checked if the devm infrastructure was doing it but it appears it doesn't, which is why I didn't object to keeping it.
In the i2c subsystem, we have moved this to i2c-core itself, and I would tend to think every subsystem should do the same. Or even the driver core...
Quoted 4 lines
Any driver relying on it has always been buggy, anything might happen to the value while the driver isn't bound. I keep thinking we should have a debugging option to write random data there for unbound devices just in case.
Writing a random value isn't going to help you spot anything. If anything, you'd have to write a well-defined poison value so that you can spot problems. But then NULL is just as good a poison value as any other - and that's what we are using today. Just, I'd prefer if every driver didn't have to do it.
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 8 lines · Jean Delvare
Quoted 4 lines · Mark Brown
Quoted 2 lines · Guenter Roeck
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.I checked if the devm infrastructure was doing it but it appears it doesn't, which is why I didn't object to keeping it.
Well, there's no reason why it should as it's unrelated.
Quoted 3 lines
In the i2c subsystem, we have moved this to i2c-core itself, and I would tend to think every subsystem should do the same. Or even the driver core...
Driver core possibly, within subsystems it's one of these things where it shouldn't be needed.
Quoted 8 lines
Quoted 4 lines
Any driver relying on it has always been buggy, anything might happen to the value while the driver isn't bound. I keep thinking we should have a debugging option to write random data there for unbound devices just in case.
Writing a random value isn't going to help you spot anything. If anything, you'd have to write a well-defined poison value so that you can spot problems. But then NULL is just as good a poison value as any
I was thinking of a predictable random bit of data, yes - just not something like NULL which is obviously meaningful. NULL feels like it's propping up drivers that try to do suspicious things.
Quoted 2 lines
other - and that's what we are using today. Just, I'd prefer if every driver didn't have to do it.
They don't have to do it, they can happily not rely on the value till after they've set it and there's no problem.
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors