]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.14/pinctrl-sx150x-handle-failure-case-of-devm_kstrdup.patch
autosel patches for 4.14
[thirdparty/kernel/stable-queue.git] / queue-4.14 / pinctrl-sx150x-handle-failure-case-of-devm_kstrdup.patch
1 From 8dbef8479caea63f056744dbf667671ee28d49ff Mon Sep 17 00:00:00 2001
2 From: Nicholas Mc Guire <hofrat@osadl.org>
3 Date: Sun, 2 Dec 2018 11:04:17 +0100
4 Subject: pinctrl: sx150x: handle failure case of devm_kstrdup
5
6 [ Upstream commit a9d9f6b83f1bb05da849b3540e6d1f70ef1c2343 ]
7
8 devm_kstrdup() may return NULL if internal allocation failed.
9 Thus using label, name is unsafe without checking. Therefor
10 in the unlikely case of allocation failure, sx150x_probe() simply
11 returns -ENOMEM.
12
13 Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
14 Fixes: 9e80f9064e73 ("pinctrl: Add SX150X GPIO Extender Pinctrl Driver")
15 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
16 Signed-off-by: Sasha Levin <sashal@kernel.org>
17 ---
18 drivers/pinctrl/pinctrl-sx150x.c | 11 ++++++++---
19 1 file changed, 8 insertions(+), 3 deletions(-)
20
21 diff --git a/drivers/pinctrl/pinctrl-sx150x.c b/drivers/pinctrl/pinctrl-sx150x.c
22 index 70a0228f4e7f..2d0f4f760326 100644
23 --- a/drivers/pinctrl/pinctrl-sx150x.c
24 +++ b/drivers/pinctrl/pinctrl-sx150x.c
25 @@ -1166,7 +1166,6 @@ static int sx150x_probe(struct i2c_client *client,
26 }
27
28 /* Register GPIO controller */
29 - pctl->gpio.label = devm_kstrdup(dev, client->name, GFP_KERNEL);
30 pctl->gpio.base = -1;
31 pctl->gpio.ngpio = pctl->data->npins;
32 pctl->gpio.get_direction = sx150x_gpio_get_direction;
33 @@ -1180,6 +1179,10 @@ static int sx150x_probe(struct i2c_client *client,
34 pctl->gpio.of_node = dev->of_node;
35 #endif
36 pctl->gpio.can_sleep = true;
37 + pctl->gpio.label = devm_kstrdup(dev, client->name, GFP_KERNEL);
38 + if (!pctl->gpio.label)
39 + return -ENOMEM;
40 +
41 /*
42 * Setting multiple pins is not safe when all pins are not
43 * handled by the same regmap register. The oscio pin (present
44 @@ -1200,13 +1203,15 @@ static int sx150x_probe(struct i2c_client *client,
45
46 /* Add Interrupt support if an irq is specified */
47 if (client->irq > 0) {
48 - pctl->irq_chip.name = devm_kstrdup(dev, client->name,
49 - GFP_KERNEL);
50 pctl->irq_chip.irq_mask = sx150x_irq_mask;
51 pctl->irq_chip.irq_unmask = sx150x_irq_unmask;
52 pctl->irq_chip.irq_set_type = sx150x_irq_set_type;
53 pctl->irq_chip.irq_bus_lock = sx150x_irq_bus_lock;
54 pctl->irq_chip.irq_bus_sync_unlock = sx150x_irq_bus_sync_unlock;
55 + pctl->irq_chip.name = devm_kstrdup(dev, client->name,
56 + GFP_KERNEL);
57 + if (!pctl->irq_chip.name)
58 + return -ENOMEM;
59
60 pctl->irq.masked = ~0;
61 pctl->irq.sense = 0;
62 --
63 2.19.1
64