hwmon: (core) Use device name as a fallback in devm_hwmon_device_register_with_info
PATCH v2 1/1 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.
---
v2:
- move IS_ERR() check into if clause
--- drivers/hwmon/hwmon.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/hwmon/hwmon.c +6 -0
@@ -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 );
Signature · 1 line
2.47.1
Quoted 4 lines · Heiner Kallweit
A number of network PHY drivers use the following code:
name =
devm_hwmon_sanitize_name(dev, dev_name(dev)); if (IS_ERR(name))
Quoted 8 lines
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 <[email protected]>
Applied, after updating the API document to reflect that NULL may be passed as hwmon device name.
Guenter