diff options
author | Heiner Kallweit <hkallweit1@gmail.com> | 2025-01-09 20:53:55 +0100 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2025-01-09 12:42:35 -0800 |
commit | c909e68f81279cb5147c6f4a7ecf80e4c6c19b04 (patch) | |
tree | e3f857e03c66baba689b5cfac94a8dfa3afc4255 | |
parent | 788bd792c74a3d1ddd0e49f5ddd68102dbbbe351 (diff) |
hwmon: (core) Use device name as a fallback in devm_hwmon_device_register_with_info
A number of network PHY drivers use the following code:
name = devm_hwmon_sanitize_name(dev, dev_name(dev));
if (IS_ERR(name))
return PTR_ERR(name);
devm_hwmon_device_register_with_info(dev, name, ..);
Make this a generic fallback option and use the device name if no name
is provided to devm_hwmon_device_register_with_info(). This would allow
to simplify the affected drivers.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Link: https://lore.kernel.org/r/1ebe6961-6445-4408-bfb4-b56173af9db5@gmail.com
[groeck: Update API document]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r-- | Documentation/hwmon/hwmon-kernel-api.rst | 3 | ||||
-rw-r--r-- | drivers/hwmon/hwmon.c | 6 |
2 files changed, 8 insertions, 1 deletions
diff --git a/Documentation/hwmon/hwmon-kernel-api.rst b/Documentation/hwmon/hwmon-kernel-api.rst index 8297acfa3a2d..e47fc757e63e 100644 --- a/Documentation/hwmon/hwmon-kernel-api.rst +++ b/Documentation/hwmon/hwmon-kernel-api.rst @@ -64,7 +64,8 @@ hwmon_device_register_with_info. All supported hwmon device registration functions only accept valid device names. Device names including invalid characters (whitespace, '*', or '-') -will be rejected. The 'name' parameter is mandatory. +will be rejected. If NULL is passed as name parameter, the hardware monitoring +device name will be derived from the parent device name. If the driver doesn't use a static device name (for example it uses dev_name()), and therefore cannot make sure the name only contains valid diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c index 9ed750d4c4f5..b7c0b1e3c23b 100644 --- a/drivers/hwmon/hwmon.c +++ b/drivers/hwmon/hwmon.c @@ -1170,6 +1170,12 @@ devm_hwmon_device_register_with_info(struct device *dev, const char *name, if (!dev) return ERR_PTR(-EINVAL); + if (!name) { + name = devm_hwmon_sanitize_name(dev, dev_name(dev)); + if (IS_ERR(name)) + return ERR_CAST(name); + } + ptr = devres_alloc(devm_hwmon_release, sizeof(*ptr), GFP_KERNEL); if (!ptr) return ERR_PTR(-ENOMEM); |