Re: [bug report] hwmon: (pmbus) Register with thermal for PSC_TEMPERATURE

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

 



On 7/19/24 13:55, Dan Carpenter wrote:
Hello Eduardo Valentin,

Commit 3aa74796cfd0 ("hwmon: (pmbus) Register with thermal for
PSC_TEMPERATURE") from Apr 28, 2022 (linux-next), leads to the
following Smatch static checker warning:

	drivers/hwmon/pmbus/pmbus_core.c:1375 pmbus_add_sensor()
	error: we previously assumed 'type' could be null (see line 1347)

drivers/hwmon/pmbus/pmbus_core.c
     1331 static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
     1332                                              const char *name, const char *type,
     1333                                              int seq, int page, int phase,
     1334                                              int reg,
     1335                                              enum pmbus_sensor_classes class,
     1336                                              bool update, bool readonly,
     1337                                              bool convert)
     1338 {
     1339         struct pmbus_sensor *sensor;
     1340         struct device_attribute *a;
     1341
     1342         sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
     1343         if (!sensor)
     1344                 return NULL;
     1345         a = &sensor->attribute;
     1346
     1347         if (type)
                      ^^^^
This code assumes type can be NULL

     1348                 snprintf(sensor->name, sizeof(sensor->name), "%s%d_%s",
     1349                          name, seq, type);
     1350         else
     1351                 snprintf(sensor->name, sizeof(sensor->name), "%s%d",
     1352                          name, seq);
     1353
     1354         if (data->flags & PMBUS_WRITE_PROTECTED)
     1355                 readonly = true;
     1356
     1357         sensor->page = page;
     1358         sensor->phase = phase;
     1359         sensor->reg = reg;
     1360         sensor->class = class;
     1361         sensor->update = update;
     1362         sensor->convert = convert;
     1363         sensor->data = -ENODATA;
     1364         pmbus_dev_attr_init(a, sensor->name,
     1365                             readonly ? 0444 : 0644,
     1366                             pmbus_show_sensor, pmbus_set_sensor);
     1367
     1368         if (pmbus_add_attribute(data, &a->attr))
     1369                 return NULL;
     1370
     1371         sensor->next = data->sensors;
     1372         data->sensors = sensor;
     1373
     1374         /* temperature sensors with _input values are registered with thermal */
--> 1375         if (class == PSC_TEMPERATURE && strcmp(type, "input") == 0)
                                                         ^^^^
Unchecked dereference


It is only NULL for PSC_PWM, never for PSC_TEMPERATURE. We could add a check to
make the static checker happy but it won't make a practical difference.

Guenter





[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