Skip to content

Commit c909e68

Browse files
hkallweitgroeck
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] [groeck: Update API document] Signed-off-by: Guenter Roeck <[email protected]>
1 parent 788bd79 commit c909e68

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Documentation/hwmon/hwmon-kernel-api.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ hwmon_device_register_with_info.
6464

6565
All supported hwmon device registration functions only accept valid device
6666
names. Device names including invalid characters (whitespace, '*', or '-')
67-
will be rejected. The 'name' parameter is mandatory.
67+
will be rejected. If NULL is passed as name parameter, the hardware monitoring
68+
device name will be derived from the parent device name.
6869

6970
If the driver doesn't use a static device name (for example it uses
7071
dev_name()), and therefore cannot make sure the name only contains valid

drivers/hwmon/hwmon.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,12 @@ devm_hwmon_device_register_with_info(struct device *dev, const char *name,
11701170
if (!dev)
11711171
return ERR_PTR(-EINVAL);
11721172

1173+
if (!name) {
1174+
name = devm_hwmon_sanitize_name(dev, dev_name(dev));
1175+
if (IS_ERR(name))
1176+
return ERR_CAST(name);
1177+
}
1178+
11731179
ptr = devres_alloc(devm_hwmon_release, sizeof(*ptr), GFP_KERNEL);
11741180
if (!ptr)
11751181
return ERR_PTR(-ENOMEM);

0 commit comments

Comments
 (0)