Commit 6975404f authored by David Woodhouse's avatar David Woodhouse Committed by Guenter Roeck

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.
Signed-off-by: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent df069079
...@@ -766,12 +766,14 @@ static ssize_t pmbus_show_label(struct device *dev, ...@@ -766,12 +766,14 @@ static ssize_t pmbus_show_label(struct device *dev,
static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr) static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
{ {
if (data->num_attributes >= data->max_attributes - 1) { if (data->num_attributes >= data->max_attributes - 1) {
data->max_attributes += PMBUS_ATTR_ALLOC_SIZE; int new_max_attrs = data->max_attributes + PMBUS_ATTR_ALLOC_SIZE;
data->group.attrs = krealloc(data->group.attrs, void *new_attrs = krealloc(data->group.attrs,
sizeof(struct attribute *) * new_max_attrs * sizeof(void *),
data->max_attributes, GFP_KERNEL); GFP_KERNEL);
if (data->group.attrs == NULL) if (!new_attrs)
return -ENOMEM; return -ENOMEM;
data->group.attrs = new_attrs;
data->max_attributes = new_max_attrs;
} }
data->group.attrs[data->num_attributes++] = attr; data->group.attrs[data->num_attributes++] = attr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment