param: add error check to __dev_add_param()
If strdup() fails with out-of-memory, __dev_add_param() should fail with -ENOMEM. (Note strdup() is always given with a non-NULL pointer. If the argument name is given with NULL, the system would already have crashed in the get_param_by_name() function.) Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
2f025305ae
commit
03dabc0fe4
|
@ -130,6 +130,10 @@ static int __dev_add_param(struct param_d *param, struct device_d *dev, const ch
|
||||||
if (get_param_by_name(dev, name))
|
if (get_param_by_name(dev, name))
|
||||||
return -EEXIST;
|
return -EEXIST;
|
||||||
|
|
||||||
|
param->name = strdup(name);
|
||||||
|
if (!param->name)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
if (set)
|
if (set)
|
||||||
param->set = set;
|
param->set = set;
|
||||||
else
|
else
|
||||||
|
@ -139,7 +143,6 @@ static int __dev_add_param(struct param_d *param, struct device_d *dev, const ch
|
||||||
else
|
else
|
||||||
param->get = param_get_generic;
|
param->get = param_get_generic;
|
||||||
|
|
||||||
param->name = strdup(name);
|
|
||||||
param->flags = flags;
|
param->flags = flags;
|
||||||
param->dev = dev;
|
param->dev = dev;
|
||||||
list_add_tail(¶m->list, &dev->parameters);
|
list_add_tail(¶m->list, &dev->parameters);
|
||||||
|
|
Loading…
Reference in New Issue