diff options
author | Bartosz Golaszewski <bgolaszewski@baylibre.com> | 2016-12-20 12:28:19 +0100 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2016-12-28 14:12:51 +0100 |
commit | ad6d8004fa29a8958381b60215e32d1e903b0492 (patch) | |
tree | 5e059a240bc3e8a0e50580194d2181bbbbdce467 /drivers/gpio/gpio-mockup.c | |
parent | e53c60289dfaba57fd8bf108406b94a71bb9bac1 (diff) | |
download | talos-op-linux-ad6d8004fa29a8958381b60215e32d1e903b0492.tar.gz talos-op-linux-ad6d8004fa29a8958381b60215e32d1e903b0492.zip |
gpio: mockup: dynamically allocate memory for chip name
Currently the chip name buffer is allocated on the stack and the
address of the buffer is passed to the gpio framework. It's invalid
after probe() returns, so the sysfs label attribute displays garbage.
Use devm_kasprintf() for each string instead.
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio/gpio-mockup.c')
-rw-r--r-- | drivers/gpio/gpio-mockup.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index af0c1e835605..10f6bf6f1660 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -126,7 +126,7 @@ static int mockup_gpio_probe(struct platform_device *pdev) int i; int base; int ngpio; - char chip_name[sizeof(GPIO_NAME) + 3]; + char *chip_name; if (gpio_mockup_params_nr < 2) return -EINVAL; @@ -146,8 +146,12 @@ static int mockup_gpio_probe(struct platform_device *pdev) ngpio = gpio_mockup_ranges[i * 2 + 1] - base; if (ngpio >= 0) { - sprintf(chip_name, "%s-%c", GPIO_NAME, - pins_name_start + i); + chip_name = devm_kasprintf(dev, GFP_KERNEL, + "%s-%c", GPIO_NAME, + pins_name_start + i); + if (!chip_name) + return -ENOMEM; + ret = mockup_gpio_add(dev, &cntr[i], chip_name, base, ngpio); } else { |