Skip to content

Commit ddaefa2

Browse files
committed
hwmon: Make chip parameter for with_info API mandatory
Various attempts were made recently to "convert" the old hwmon_device_register() API to devm_hwmon_device_register_with_info() by just changing the function name without actually converting the driver. Prevent this from happening by making the 'chip' parameter of devm_hwmon_device_register_with_info() mandatory. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent 87743bc commit ddaefa2

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

Documentation/hwmon/hwmon-kernel-api.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ hwmon_device_register_with_info is the most comprehensive and preferred means
7676
to register a hardware monitoring device. It creates the standard sysfs
7777
attributes in the hardware monitoring core, letting the driver focus on reading
7878
from and writing to the chip instead of having to bother with sysfs attributes.
79-
The parent device parameter cannot be NULL with non-NULL chip info. Its
79+
The parent device parameter as well as the chip parameter must not be NULL. Its
8080
parameters are described in more detail below.
8181

8282
devm_hwmon_device_register_with_info is similar to

drivers/hwmon/hwmon.c

+7-9
Original file line numberDiff line numberDiff line change
@@ -886,11 +886,12 @@ EXPORT_SYMBOL_GPL(hwmon_device_register_with_groups);
886886

887887
/**
888888
* hwmon_device_register_with_info - register w/ hwmon
889-
* @dev: the parent device
890-
* @name: hwmon name attribute
891-
* @drvdata: driver data to attach to created device
892-
* @chip: pointer to hwmon chip information
889+
* @dev: the parent device (mandatory)
890+
* @name: hwmon name attribute (mandatory)
891+
* @drvdata: driver data to attach to created device (optional)
892+
* @chip: pointer to hwmon chip information (mandatory)
893893
* @extra_groups: pointer to list of additional non-standard attribute groups
894+
* (optional)
894895
*
895896
* hwmon_device_unregister() must be called when the device is no
896897
* longer needed.
@@ -903,13 +904,10 @@ hwmon_device_register_with_info(struct device *dev, const char *name,
903904
const struct hwmon_chip_info *chip,
904905
const struct attribute_group **extra_groups)
905906
{
906-
if (!name)
907-
return ERR_PTR(-EINVAL);
908-
909-
if (chip && (!chip->ops || !chip->ops->is_visible || !chip->info))
907+
if (!dev || !name || !chip)
910908
return ERR_PTR(-EINVAL);
911909

912-
if (chip && !dev)
910+
if (!chip->ops || !chip->ops->is_visible || !chip->info)
913911
return ERR_PTR(-EINVAL);
914912

915913
return __hwmon_device_register(dev, name, drvdata, chip, extra_groups);

0 commit comments

Comments
 (0)