mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Huisong Li <lihuisong@huawei.com>, jdelvare@suse.com
Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org,
	zhanjie9@hisilicon.com, zhenglifeng1@huawei.com,
	liuyonglong@huawei.com
Subject: Re: [PATCH v2] hwmon: (acpi_power_meter) Replace the deprecated hwmon_device_register
Date: Fri, 14 Mar 2025 08:01:08 -0700	[thread overview]
Message-ID: <899edff7-eba1-49fb-9626-576798452f30@roeck-us.net> (raw)
In-Reply-To: <20250314081834.3243243-1-lihuisong@huawei.com>

On 3/14/25 01:18, Huisong Li wrote:
> When load this mode, we can see the following log:
> "power_meter ACPI000D:00: hwmon_device_register() is deprecated. Please
>   convert the driver to use hwmon_device_register_with_info()."
> 
> So replace hwmon_device_register with hwmon_device_register_with_info.
> 
> These attributes, 'power_accuracy', 'power_cap_hyst', 'power_average_min'
> and 'power_average_max', should have been placed in hwmon_chip_info as
> power data type. But these attributes are displayed as string format on
> the following case:
> a) power1_accuracy  --> display like '90.0%'
> b) power1_cap_hyst  --> display 'unknown' when its value is 0xFFFFFFFF
> c) power1_average_min/max --> display 'unknown' when its value is
> 			      negative.
> To avoid any changes in the display of these sysfs interfaces, we can't
> modifiy the type of these attributes in hwmon core and have to put them
> to extra_groups.
> 
> Please note that the path of these sysfs interfaces are modified
> accordingly if use hwmon_device_register_with_info():
> old: all sysfs interfaces are under acpi device, namely,
>       /sys/class/hwmon/hwmonX/device/
> now: all sysfs interfaces are under hwmon device, namely,
>       /sys/class/hwmon/hwmonX/
> The new ABI does not guarantee that the underlying path remains the same.
> But we have to accept this change so as to replace the deprecated API.
> Fortunately, some userspace application, like libsensors, would scan
> the two path and handles this automatically. So to drop the deprecated
> message, we can accept this change.
> 
> Signed-off-by: Huisong Li <lihuisong@huawei.com>
> ---
>   drivers/hwmon/acpi_power_meter.c | 861 +++++++++++++++----------------
>   1 file changed, 427 insertions(+), 434 deletions(-)
> 
> diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
> index f05986e4f379..46e8a0b6b210 100644
> --- a/drivers/hwmon/acpi_power_meter.c
> +++ b/drivers/hwmon/acpi_power_meter.c
...
> +
> +// depend on POWER_METER_CAN_TRIP

Please di not intermix C++ comments with a driver using C comments.

> +static DEVICE_ATTR_RW(power1_average_max);
> +static DEVICE_ATTR_RW(power1_average_min);
> +
> +// depend on POWER_METER_CAN_CAP
> +static DEVICE_ATTR_RO(power1_cap_hyst);
> +
> +// depend on POWER_METER_CAN_MEASURE
> +static DEVICE_ATTR_RO(power1_accuracy);
> +static DEVICE_ATTR_RO(power1_is_battery);
> +
> +static DEVICE_ATTR_RO(power1_model_number);
> +static DEVICE_ATTR_RO(power1_oem_info);
> +static DEVICE_ATTR_RO(power1_serial_number);
> +
> +#define EXTRA_FIRST_DYNAMIC_ATTR_ID	3
> +#define EXTRA_ATTR_MAX	10
> +
> +static struct attribute *power_extra_attrs[EXTRA_ATTR_MAX] = {
> +	&dev_attr_power1_model_number.attr,
> +	&dev_attr_power1_oem_info.attr,
> +	&dev_attr_power1_serial_number.attr,
> +	NULL
> +};
> +
> +ATTRIBUTE_GROUPS(power_extra);
> +
> +static void fill_extra_dynamic_attr(struct attribute *attr)
> +{
> +	int idx = EXTRA_FIRST_DYNAMIC_ATTR_ID;
> +
> +	for (idx = EXTRA_FIRST_DYNAMIC_ATTR_ID; idx < EXTRA_ATTR_MAX; idx++) {
> +		if (!power_extra_attrs[idx])
> +			break;
> +	}
> +
> +	power_extra_attrs[idx] = attr;
> +}
> +

Please use the .is_visible() callback in attribute_group to determine
attribute visibility.

That means you'll have to code attribute_group manually, but that is
still better than re-implementing the is_visible() callback.
Something like

static const struct attribute_group power_extra_group = {
	.attrs = power_extra_attrs,
	.is_visible = power_extra_is_visible;
};

__ATTRIBUTE_GROUPS(power_extra);

should do.

Thanks,
Guenter


  reply	other threads:[~2025-03-14 15:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-14  8:18 Huisong Li
2025-03-14 15:01 ` Guenter Roeck [this message]
2025-03-19  2:17   ` lihuisong (C)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=899edff7-eba1-49fb-9626-576798452f30@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=jdelvare@suse.com \
    --cc=lihuisong@huawei.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liuyonglong@huawei.com \
    --cc=zhanjie9@hisilicon.com \
    --cc=zhenglifeng1@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®