hwmon: (core) check parent dev != NULL when chip != NULL
authorLucas Magasweran <lucas.magasweran@ieee.org>
Tue, 8 May 2018 11:43:33 +0000 (04:43 -0700)
committerGuenter Roeck <linux@roeck-us.net>
Mon, 21 May 2018 14:51:59 +0000 (07:51 -0700)
hwmon_device_register_with_info() registration API requires a
non-NULL parent device when chip is non-NULL.

This commit adds a check and documents this requirement.

Signed-off-by: Lucas Magasweran <lucas.magasweran@ieee.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Documentation/hwmon/hwmon-kernel-api.txt
drivers/hwmon/hwmon.c

index 53a8066..eb7a78a 100644 (file)
@@ -71,7 +71,8 @@ hwmon_device_register_with_info is the most comprehensive and preferred means
 to register a hardware monitoring device. It creates the standard sysfs
 attributes in the hardware monitoring core, letting the driver focus on reading
 from and writing to the chip instead of having to bother with sysfs attributes.
 to register a hardware monitoring device. It creates the standard sysfs
 attributes in the hardware monitoring core, letting the driver focus on reading
 from and writing to the chip instead of having to bother with sysfs attributes.
-Its parameters are described in more detail below.
+The parent device parameter cannot be NULL with non-NULL chip info. Its
+parameters are described in more detail below.
 
 devm_hwmon_device_register_with_info is similar to
 hwmon_device_register_with_info. However, it is device managed, meaning the
 
 devm_hwmon_device_register_with_info is similar to
 hwmon_device_register_with_info. However, it is device managed, meaning the
index 32083e4..e88c019 100644 (file)
@@ -698,6 +698,9 @@ hwmon_device_register_with_info(struct device *dev, const char *name,
        if (chip && (!chip->ops || !chip->ops->is_visible || !chip->info))
                return ERR_PTR(-EINVAL);
 
        if (chip && (!chip->ops || !chip->ops->is_visible || !chip->info))
                return ERR_PTR(-EINVAL);
 
+       if (chip && !dev)
+               return ERR_PTR(-EINVAL);
+
        return __hwmon_device_register(dev, name, drvdata, chip, extra_groups);
 }
 EXPORT_SYMBOL_GPL(hwmon_device_register_with_info);
        return __hwmon_device_register(dev, name, drvdata, chip, extra_groups);
 }
 EXPORT_SYMBOL_GPL(hwmon_device_register_with_info);