History

hwmon: (pmbus) Fix krealloc() misuse in pmbus_add_attribute()

If krealloc() returns NULL, it *doesn't* free the original. So any code of the form 'foo = krealloc(foo, …);' is almost certainly a bug.

David Woodhouse committed 13 years ago

Commit 69754041 parent df069071 file · +7 −5Browse files

Unified · Split

drivers/hwmon/pmbus/pmbus_core.c+7−5
@@ -766,12 +766,14 @@ static ssize_t pmbus_show_label(struct device *dev, · 765 unmodified lines
766static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)766static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
767{767{
768 if (data->num_attributes >= data->max_attributes - 1) {768 if (data->num_attributes >= data->max_attributes - 1) {
769 data->max_attributes += PMBUS_ATTR_ALLOC_SIZE;769 int new_max_attrs = data->max_attributes + PMBUS_ATTR_ALLOC_SIZE;
770 data->group.attrs = krealloc(data->group.attrs,770 void *new_attrs = krealloc(data->group.attrs,
771 sizeof(struct attribute *) *771 new_max_attrs * sizeof(void *),
772 data->max_attributes, GFP_KERNEL);772 GFP_KERNEL);
773 if (data->group.attrs == NULL)773 if (!new_attrs)
774 return -ENOMEM;774 return -ENOMEM;
775 data->group.attrs = new_attrs;
776 data->max_attributes = new_max_attrs;
775 }777 }
776 778
777 data->group.attrs[data->num_attributes++] = attr;779 data->group.attrs[data->num_attributes++] = attr;