* [lm-sensors] [PATCH 03/39] hwmon: (ad7314) Convert to use devm_ functions
@ 2012-08-07 15:19 Guenter Roeck
0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2012-08-07 15:19 UTC (permalink / raw)
To: lm-sensors
Convert to use devm_ functions to reduce code size and simplify the code.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
drivers/hwmon/ad7314.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/drivers/hwmon/ad7314.c b/drivers/hwmon/ad7314.c
index cfec802..455294f 100644
--- a/drivers/hwmon/ad7314.c
+++ b/drivers/hwmon/ad7314.c
@@ -104,16 +104,16 @@ static int __devinit ad7314_probe(struct spi_device *spi_dev)
int ret;
struct ad7314_data *chip;
- chip = kzalloc(sizeof(*chip), GFP_KERNEL);
- if (chip = NULL) {
- ret = -ENOMEM;
- goto error_ret;
- }
+ chip = devm_kzalloc(&spi_dev->dev, sizeof(*chip), GFP_KERNEL);
+ if (chip = NULL)
+ return -ENOMEM;
+
dev_set_drvdata(&spi_dev->dev, chip);
ret = sysfs_create_group(&spi_dev->dev.kobj, &ad7314_group);
if (ret < 0)
- goto error_free_chip;
+ return ret;
+
chip->hwmon_dev = hwmon_device_register(&spi_dev->dev);
if (IS_ERR(chip->hwmon_dev)) {
ret = PTR_ERR(chip->hwmon_dev);
@@ -124,9 +124,6 @@ static int __devinit ad7314_probe(struct spi_device *spi_dev)
return 0;
error_remove_group:
sysfs_remove_group(&spi_dev->dev.kobj, &ad7314_group);
-error_free_chip:
- kfree(chip);
-error_ret:
return ret;
}
@@ -136,7 +133,6 @@ static int __devexit ad7314_remove(struct spi_device *spi_dev)
hwmon_device_unregister(chip->hwmon_dev);
sysfs_remove_group(&spi_dev->dev.kobj, &ad7314_group);
- kfree(chip);
return 0;
}
--
1.7.9.7
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [lm-sensors] [PATCH 03/39] hwmon: (ad7314) Convert to use devm_ functions
@ 2012-09-17 19:31 Jean Delvare
0 siblings, 0 replies; 2+ messages in thread
From: Jean Delvare @ 2012-09-17 19:31 UTC (permalink / raw)
To: lm-sensors
On Tue, 7 Aug 2012 08:19:52 -0700, Guenter Roeck wrote:
> Convert to use devm_ functions to reduce code size and simplify the code.
>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
> drivers/hwmon/ad7314.c | 16 ++++++----------
> 1 file changed, 6 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/hwmon/ad7314.c b/drivers/hwmon/ad7314.c
> index cfec802..455294f 100644
> --- a/drivers/hwmon/ad7314.c
> +++ b/drivers/hwmon/ad7314.c
> @@ -104,16 +104,16 @@ static int __devinit ad7314_probe(struct spi_device *spi_dev)
> int ret;
> struct ad7314_data *chip;
>
> - chip = kzalloc(sizeof(*chip), GFP_KERNEL);
> - if (chip = NULL) {
> - ret = -ENOMEM;
> - goto error_ret;
> - }
> + chip = devm_kzalloc(&spi_dev->dev, sizeof(*chip), GFP_KERNEL);
> + if (chip = NULL)
> + return -ENOMEM;
> +
> dev_set_drvdata(&spi_dev->dev, chip);
>
> ret = sysfs_create_group(&spi_dev->dev.kobj, &ad7314_group);
> if (ret < 0)
> - goto error_free_chip;
> + return ret;
> +
> chip->hwmon_dev = hwmon_device_register(&spi_dev->dev);
> if (IS_ERR(chip->hwmon_dev)) {
> ret = PTR_ERR(chip->hwmon_dev);
> @@ -124,9 +124,6 @@ static int __devinit ad7314_probe(struct spi_device *spi_dev)
> return 0;
> error_remove_group:
> sysfs_remove_group(&spi_dev->dev.kobj, &ad7314_group);
> -error_free_chip:
> - kfree(chip);
> -error_ret:
> return ret;
> }
Same comment here as for the ads7871 driver. But still functionally
correct so:
Acked-by: Jean Delvare <khali@linux-fr.org>
>
> @@ -136,7 +133,6 @@ static int __devexit ad7314_remove(struct spi_device *spi_dev)
>
> hwmon_device_unregister(chip->hwmon_dev);
> sysfs_remove_group(&spi_dev->dev.kobj, &ad7314_group);
> - kfree(chip);
>
> return 0;
> }
--
Jean Delvare
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-09-17 19:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-07 15:19 [lm-sensors] [PATCH 03/39] hwmon: (ad7314) Convert to use devm_ functions Guenter Roeck
2012-09-17 19:31 Jean Delvare
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.