Skip to content

Commit

Permalink
hwmon: (pmbus) Fix krealloc() misuse in pmbus_add_attribute()
Browse files Browse the repository at this point in the history
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: David Woodhouse <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
  • Loading branch information
dwmw2 authored and groeck committed Mar 14, 2013
1 parent df06907 commit 6975404
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions drivers/hwmon/pmbus/pmbus_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
if (data->num_attributes >= data->max_attributes - 1) {
data->max_attributes += PMBUS_ATTR_ALLOC_SIZE;
data->group.attrs = krealloc(data->group.attrs,
sizeof(struct attribute *) *
data->max_attributes, GFP_KERNEL);
if (data->group.attrs == NULL)
int new_max_attrs = data->max_attributes + PMBUS_ATTR_ALLOC_SIZE;
void *new_attrs = krealloc(data->group.attrs,
new_max_attrs * sizeof(void *),
GFP_KERNEL);
if (!new_attrs)
return -ENOMEM;
data->group.attrs = new_attrs;
data->max_attributes = new_max_attrs;
}

data->group.attrs[data->num_attributes++] = attr;
Expand Down

0 comments on commit 6975404

Please sign in to comment.