2022-05-02 22:57:23

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH 2/2] hwmon: acpi_power_meter: convert to hwmon_device_register_with_info

On 5/2/22 05:42, Corentin Labbe wrote:
> Booting lead to a hwmon_device_register() is deprecated. Please convert the driver to use hwmon_device_register_with_info().
> So let's convert the driver to use hwmon_device_register_with_info().
>
> Signed-off-by: Corentin Labbe <[email protected]>
> ---
> drivers/hwmon/acpi_power_meter.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
> index d2545a1be9fc..98293727f980 100644
> --- a/drivers/hwmon/acpi_power_meter.c
> +++ b/drivers/hwmon/acpi_power_meter.c
> @@ -891,7 +891,10 @@ static int acpi_power_meter_add(struct acpi_device *device)
> if (res)
> goto exit_free_capability;
>
> - resource->hwmon_dev = hwmon_device_register(&device->dev);
> + resource->hwmon_dev = hwmon_device_register_with_info(&device->dev,
> + ACPI_POWER_METER_DEVICE_NAME,
> + NULL, NULL,
> + NULL);

NACK. That isn't a conversion to the new API, it just abuses the fact
that the new API has to accept a NULL info pointer for historic reasons.

Guenter


2022-05-02 23:01:33

by Corentin LABBE

[permalink] [raw]
Subject: Re: [PATCH 2/2] hwmon: acpi_power_meter: convert to hwmon_device_register_with_info

Le Mon, May 02, 2022 at 06:34:44AM -0700, Guenter Roeck a ?crit :
> On 5/2/22 05:42, Corentin Labbe wrote:
> > Booting lead to a hwmon_device_register() is deprecated. Please convert the driver to use hwmon_device_register_with_info().
> > So let's convert the driver to use hwmon_device_register_with_info().
> >
> > Signed-off-by: Corentin Labbe <[email protected]>
> > ---
> > drivers/hwmon/acpi_power_meter.c | 5 ++++-
> > 1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
> > index d2545a1be9fc..98293727f980 100644
> > --- a/drivers/hwmon/acpi_power_meter.c
> > +++ b/drivers/hwmon/acpi_power_meter.c
> > @@ -891,7 +891,10 @@ static int acpi_power_meter_add(struct acpi_device *device)
> > if (res)
> > goto exit_free_capability;
> >
> > - resource->hwmon_dev = hwmon_device_register(&device->dev);
> > + resource->hwmon_dev = hwmon_device_register_with_info(&device->dev,
> > + ACPI_POWER_METER_DEVICE_NAME,
> > + NULL, NULL,
> > + NULL);
>
> NACK. That isn't a conversion to the new API, it just abuses the fact
> that the new API has to accept a NULL info pointer for historic reasons.
>

Hello

I am sorry, I found a driver doing it, so I believed it was okay.
Converting seems not to hard but, by using the new API, how can I convert power1_model_number/power1_is_battery attribute ?
There are the remaining attributes I dont find how to convert.

Regards

2022-05-03 00:20:02

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH 2/2] hwmon: acpi_power_meter: convert to hwmon_device_register_with_info

On 5/2/22 11:59, LABBE Corentin wrote:
> Le Mon, May 02, 2022 at 06:34:44AM -0700, Guenter Roeck a écrit :
>> On 5/2/22 05:42, Corentin Labbe wrote:
>>> Booting lead to a hwmon_device_register() is deprecated. Please convert the driver to use hwmon_device_register_with_info().
>>> So let's convert the driver to use hwmon_device_register_with_info().
>>>
>>> Signed-off-by: Corentin Labbe <[email protected]>
>>> ---
>>> drivers/hwmon/acpi_power_meter.c | 5 ++++-
>>> 1 file changed, 4 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
>>> index d2545a1be9fc..98293727f980 100644
>>> --- a/drivers/hwmon/acpi_power_meter.c
>>> +++ b/drivers/hwmon/acpi_power_meter.c
>>> @@ -891,7 +891,10 @@ static int acpi_power_meter_add(struct acpi_device *device)
>>> if (res)
>>> goto exit_free_capability;
>>>
>>> - resource->hwmon_dev = hwmon_device_register(&device->dev);
>>> + resource->hwmon_dev = hwmon_device_register_with_info(&device->dev,
>>> + ACPI_POWER_METER_DEVICE_NAME,
>>> + NULL, NULL,
>>> + NULL);
>>
>> NACK. That isn't a conversion to the new API, it just abuses the fact
>> that the new API has to accept a NULL info pointer for historic reasons.
>>
>
> Hello
>
> I am sorry, I found a driver doing it, so I believed it was okay.

Yeah, that is what happens if an API is flexible: It is prone to
abuse, and once the abuse starts others start to abuse it as well
"because that other driver did it".

> Converting seems not to hard but, by using the new API, how can I convert power1_model_number/power1_is_battery attribute ?
> There are the remaining attributes I dont find how to convert.
>

It is ok to use the pointer to sysfs attribute groups
for non-standard attributes.

Guenter

2022-05-03 00:44:00

by Armin Wolf

[permalink] [raw]
Subject: Re: [PATCH 2/2] hwmon: acpi_power_meter: convert to hwmon_device_register_with_info

Am 02.05.22 um 20:59 schrieb LABBE Corentin:

> Le Mon, May 02, 2022 at 06:34:44AM -0700, Guenter Roeck a écrit :
>> On 5/2/22 05:42, Corentin Labbe wrote:
>>> Booting lead to a hwmon_device_register() is deprecated. Please convert the driver to use hwmon_device_register_with_info().
>>> So let's convert the driver to use hwmon_device_register_with_info().
>>>
>>> Signed-off-by: Corentin Labbe <[email protected]>
>>> ---
>>> drivers/hwmon/acpi_power_meter.c | 5 ++++-
>>> 1 file changed, 4 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
>>> index d2545a1be9fc..98293727f980 100644
>>> --- a/drivers/hwmon/acpi_power_meter.c
>>> +++ b/drivers/hwmon/acpi_power_meter.c
>>> @@ -891,7 +891,10 @@ static int acpi_power_meter_add(struct acpi_device *device)
>>> if (res)
>>> goto exit_free_capability;
>>>
>>> - resource->hwmon_dev = hwmon_device_register(&device->dev);
>>> + resource->hwmon_dev = hwmon_device_register_with_info(&device->dev,
>>> + ACPI_POWER_METER_DEVICE_NAME,
>>> + NULL, NULL,
>>> + NULL);
>> NACK. That isn't a conversion to the new API, it just abuses the fact
>> that the new API has to accept a NULL info pointer for historic reasons.
>>
> Hello
>
> I am sorry, I found a driver doing it, so I believed it was okay.
> Converting seems not to hard but, by using the new API, how can I convert power1_model_number/power1_is_battery attribute ?
> There are the remaining attributes I dont find how to convert.
>
> Regards

Hi,

for allowing the driver to provide nonstandard attributes, hwmon_device_register_with_info()
has the argument "extra_groups" which is an pointer to a list of sysfs attribute groups.
There are some drivers which are using this functionality, maybe you can use them as an
inspiration.

Just a question: what is the name of the driver you originally used as an inspiration?

Armin Wolf