Commit a9d9f6b8 authored by Nicholas Mc Guire's avatar Nicholas Mc Guire Committed by Linus Walleij

pinctrl: sx150x: handle failure case of devm_kstrdup

devm_kstrdup() may return NULL if internal allocation failed.
Thus using  label, name  is unsafe without checking. Therefor
in the unlikely case of allocation failure, sx150x_probe() simply
returns -ENOMEM.
Signed-off-by: default avatarNicholas Mc Guire <hofrat@osadl.org>
Fixes: 9e80f906 ("pinctrl: Add SX150X GPIO Extender Pinctrl Driver")
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent 0819dc72
...@@ -1166,7 +1166,6 @@ static int sx150x_probe(struct i2c_client *client, ...@@ -1166,7 +1166,6 @@ static int sx150x_probe(struct i2c_client *client,
} }
/* Register GPIO controller */ /* Register GPIO controller */
pctl->gpio.label = devm_kstrdup(dev, client->name, GFP_KERNEL);
pctl->gpio.base = -1; pctl->gpio.base = -1;
pctl->gpio.ngpio = pctl->data->npins; pctl->gpio.ngpio = pctl->data->npins;
pctl->gpio.get_direction = sx150x_gpio_get_direction; pctl->gpio.get_direction = sx150x_gpio_get_direction;
...@@ -1180,6 +1179,10 @@ static int sx150x_probe(struct i2c_client *client, ...@@ -1180,6 +1179,10 @@ static int sx150x_probe(struct i2c_client *client,
pctl->gpio.of_node = dev->of_node; pctl->gpio.of_node = dev->of_node;
#endif #endif
pctl->gpio.can_sleep = true; pctl->gpio.can_sleep = true;
pctl->gpio.label = devm_kstrdup(dev, client->name, GFP_KERNEL);
if (!pctl->gpio.label)
return -ENOMEM;
/* /*
* Setting multiple pins is not safe when all pins are not * Setting multiple pins is not safe when all pins are not
* handled by the same regmap register. The oscio pin (present * handled by the same regmap register. The oscio pin (present
...@@ -1200,13 +1203,15 @@ static int sx150x_probe(struct i2c_client *client, ...@@ -1200,13 +1203,15 @@ static int sx150x_probe(struct i2c_client *client,
/* Add Interrupt support if an irq is specified */ /* Add Interrupt support if an irq is specified */
if (client->irq > 0) { if (client->irq > 0) {
pctl->irq_chip.name = devm_kstrdup(dev, client->name,
GFP_KERNEL);
pctl->irq_chip.irq_mask = sx150x_irq_mask; pctl->irq_chip.irq_mask = sx150x_irq_mask;
pctl->irq_chip.irq_unmask = sx150x_irq_unmask; pctl->irq_chip.irq_unmask = sx150x_irq_unmask;
pctl->irq_chip.irq_set_type = sx150x_irq_set_type; pctl->irq_chip.irq_set_type = sx150x_irq_set_type;
pctl->irq_chip.irq_bus_lock = sx150x_irq_bus_lock; pctl->irq_chip.irq_bus_lock = sx150x_irq_bus_lock;
pctl->irq_chip.irq_bus_sync_unlock = sx150x_irq_bus_sync_unlock; pctl->irq_chip.irq_bus_sync_unlock = sx150x_irq_bus_sync_unlock;
pctl->irq_chip.name = devm_kstrdup(dev, client->name,
GFP_KERNEL);
if (!pctl->irq_chip.name)
return -ENOMEM;
pctl->irq.masked = ~0; pctl->irq.masked = ~0;
pctl->irq.sense = 0; pctl->irq.sense = 0;
......
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