All of lore.kernel.org
 help / color / mirror / Atom feed
* [lm-sensors] [PATCH RFT] hwmon: (twl4030-madc-hwmon) Convert to devm_hwmon_device_register_with_grou
@ 2014-06-14  3:38 Axel Lin
  2014-06-14  5:12 ` [lm-sensors] [PATCH RFT] hwmon: (twl4030-madc-hwmon) Convert to devm_hwmon_device_register_with_ Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Axel Lin @ 2014-06-14  3:38 UTC (permalink / raw)
  To: lm-sensors

Use ATTRIBUTE_GROUPS macro and devm_hwmon_device_register_with_groups() to
simplify the code a bit.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
Hi,
I don't have the h/w to test, I'd appreciate if someone can review and test this
patch.
Thanks,
Axel
 drivers/hwmon/twl4030-madc-hwmon.c | 37 +++++--------------------------------
 1 file changed, 5 insertions(+), 32 deletions(-)

diff --git a/drivers/hwmon/twl4030-madc-hwmon.c b/drivers/hwmon/twl4030-madc-hwmon.c
index 6c6d440..9904f3d 100644
--- a/drivers/hwmon/twl4030-madc-hwmon.c
+++ b/drivers/hwmon/twl4030-madc-hwmon.c
@@ -74,7 +74,7 @@ static SENSOR_DEVICE_ATTR(in11_input, S_IRUGO, madc_read, NULL, 11);
 static SENSOR_DEVICE_ATTR(in12_input, S_IRUGO, madc_read, NULL, 12);
 static SENSOR_DEVICE_ATTR(in15_input, S_IRUGO, madc_read, NULL, 15);
 
-static struct attribute *twl4030_madc_attributes[] = {
+static struct attribute *twl4030_madc_attrs[] = {
 	&sensor_dev_attr_in0_input.dev_attr.attr,
 	&sensor_dev_attr_temp1_input.dev_attr.attr,
 	&sensor_dev_attr_in2_input.dev_attr.attr,
@@ -91,46 +91,19 @@ static struct attribute *twl4030_madc_attributes[] = {
 	&sensor_dev_attr_in15_input.dev_attr.attr,
 	NULL
 };
-
-static const struct attribute_group twl4030_madc_group = {
-	.attrs = twl4030_madc_attributes,
-};
+ATTRIBUTE_GROUPS(twl4030_madc);
 
 static int twl4030_madc_hwmon_probe(struct platform_device *pdev)
 {
-	int ret;
 	struct device *hwmon;
 
-	ret = sysfs_create_group(&pdev->dev.kobj, &twl4030_madc_group);
-	if (ret)
-		goto err_sysfs;
-	hwmon = hwmon_device_register(&pdev->dev);
-	if (IS_ERR(hwmon)) {
-		dev_err(&pdev->dev, "hwmon_device_register failed.\n");
-		ret = PTR_ERR(hwmon);
-		goto err_reg;
-	}
-
-	return 0;
-
-err_reg:
-	sysfs_remove_group(&pdev->dev.kobj, &twl4030_madc_group);
-err_sysfs:
-
-	return ret;
-}
-
-static int twl4030_madc_hwmon_remove(struct platform_device *pdev)
-{
-	hwmon_device_unregister(&pdev->dev);
-	sysfs_remove_group(&pdev->dev.kobj, &twl4030_madc_group);
-
-	return 0;
+	hwmon = devm_hwmon_device_register_with_groups(&pdev->dev, NULL, NULL,
+						       twl4030_madc_groups);
+	return PTR_ERR_OR_ZERO(hwmon);
 }
 
 static struct platform_driver twl4030_madc_hwmon_driver = {
 	.probe = twl4030_madc_hwmon_probe,
-	.remove = twl4030_madc_hwmon_remove,
 	.driver = {
 		   .name = "twl4030_madc_hwmon",
 		   .owner = THIS_MODULE,
-- 
1.8.3.2




_______________________________________________
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 RFT] hwmon: (twl4030-madc-hwmon) Convert to devm_hwmon_device_register_with_
  2014-06-14  3:38 [lm-sensors] [PATCH RFT] hwmon: (twl4030-madc-hwmon) Convert to devm_hwmon_device_register_with_grou Axel Lin
@ 2014-06-14  5:12 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2014-06-14  5:12 UTC (permalink / raw)
  To: lm-sensors

On 06/13/2014 08:38 PM, Axel Lin wrote:
> Use ATTRIBUTE_GROUPS macro and devm_hwmon_device_register_with_groups() to
> simplify the code a bit.
>
> Signed-off-by: Axel Lin <axel.lin@ingics.com>
> ---
> Hi,
> I don't have the h/w to test, I'd appreciate if someone can review and test this
> patch.
> Thanks,
> Axel
>   drivers/hwmon/twl4030-madc-hwmon.c | 37 +++++--------------------------------
>   1 file changed, 5 insertions(+), 32 deletions(-)
>
> diff --git a/drivers/hwmon/twl4030-madc-hwmon.c b/drivers/hwmon/twl4030-madc-hwmon.c
> index 6c6d440..9904f3d 100644
> --- a/drivers/hwmon/twl4030-madc-hwmon.c
> +++ b/drivers/hwmon/twl4030-madc-hwmon.c
> @@ -74,7 +74,7 @@ static SENSOR_DEVICE_ATTR(in11_input, S_IRUGO, madc_read, NULL, 11);
>   static SENSOR_DEVICE_ATTR(in12_input, S_IRUGO, madc_read, NULL, 12);
>   static SENSOR_DEVICE_ATTR(in15_input, S_IRUGO, madc_read, NULL, 15);
>
> -static struct attribute *twl4030_madc_attributes[] = {
> +static struct attribute *twl4030_madc_attrs[] = {
>   	&sensor_dev_attr_in0_input.dev_attr.attr,
>   	&sensor_dev_attr_temp1_input.dev_attr.attr,
>   	&sensor_dev_attr_in2_input.dev_attr.attr,
> @@ -91,46 +91,19 @@ static struct attribute *twl4030_madc_attributes[] = {
>   	&sensor_dev_attr_in15_input.dev_attr.attr,
>   	NULL
>   };
> -
> -static const struct attribute_group twl4030_madc_group = {
> -	.attrs = twl4030_madc_attributes,
> -};
> +ATTRIBUTE_GROUPS(twl4030_madc);
>
>   static int twl4030_madc_hwmon_probe(struct platform_device *pdev)
>   {
> -	int ret;
>   	struct device *hwmon;
>
> -	ret = sysfs_create_group(&pdev->dev.kobj, &twl4030_madc_group);
> -	if (ret)
> -		goto err_sysfs;
> -	hwmon = hwmon_device_register(&pdev->dev);
> -	if (IS_ERR(hwmon)) {
> -		dev_err(&pdev->dev, "hwmon_device_register failed.\n");
> -		ret = PTR_ERR(hwmon);
> -		goto err_reg;
> -	}
> -
> -	return 0;
> -
> -err_reg:
> -	sysfs_remove_group(&pdev->dev.kobj, &twl4030_madc_group);
> -err_sysfs:
> -
> -	return ret;
> -}
> -
> -static int twl4030_madc_hwmon_remove(struct platform_device *pdev)
> -{
> -	hwmon_device_unregister(&pdev->dev);
> -	sysfs_remove_group(&pdev->dev.kobj, &twl4030_madc_group);
> -
> -	return 0;
> +	hwmon = devm_hwmon_device_register_with_groups(&pdev->dev, NULL, NULL,

Hi Axel,

You'll need to pass a name here. Hmmm... that wasn't there before either,
meaning the 'sensors' command never worked with this driver. I must
have had a bad day when I reviewed it, especially since
hwmon_device_unregister() takes the hwmon device as argument,
not the platform device.

I would suggest to use "twl4030_madc" as name string for simplicity.

Guenter


_______________________________________________
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:[~2014-06-14  5:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-14  3:38 [lm-sensors] [PATCH RFT] hwmon: (twl4030-madc-hwmon) Convert to devm_hwmon_device_register_with_grou Axel Lin
2014-06-14  5:12 ` [lm-sensors] [PATCH RFT] hwmon: (twl4030-madc-hwmon) Convert to devm_hwmon_device_register_with_ Guenter Roeck

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.