Re: [bug report] hwmon: Add "label" attribute

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Le jeu., janv. 27 2022 at 11:52:45 +0300, Dan Carpenter <dan.carpenter@xxxxxxxxxx> a écrit :
Hello Paul Cercueil,

This is a semi-automatic email about new static checker warnings.

The patch 073c3ea6c530: "hwmon: Add "label" attribute" from Jan 10,
2022, leads to the following Smatch complaint:

    drivers/hwmon/hwmon.c:825 __hwmon_device_register()
    warn: variable dereferenced before check 'dev' (see line 810)

drivers/hwmon/hwmon.c
   809
   810		if (device_property_present(dev, "label")) {
                                            ^^^
The patch adds a new unchecked dereference

I will send a patch to address that.

I'm surprised that this function can be called with dev == NULL in the first place, though.

Cheers,
-Paul

   811			err = device_property_read_string(dev, "label", &label);
   812			if (err < 0)
   813				goto free_hwmon;
   814
   815			hwdev->label = kstrdup(label, GFP_KERNEL);
   816			if (hwdev->label == NULL) {
   817				err = -ENOMEM;
   818				goto free_hwmon;
   819			}
   820		}
   821
   822		hwdev->name = name;
   823		hdev->class = &hwmon_class;
   824		hdev->parent = dev;
   825		hdev->of_node = dev ? dev->of_node : NULL;
                                ^^^
Existing code checked for NULL

   826		hwdev->chip = chip;
   827		dev_set_drvdata(hdev, drvdata);

regards,
dan carpenter





[Index of Archives]     [LM Sensors]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux