Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1545058 > unrolled thread
| Started by | Bartosz Golaszewski <bgolaszewski@baylibre.com> |
|---|---|
| First post | 2016-12-20 12:30 +0100 |
| Last post | 2016-12-28 14:20 +0100 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH 2/3] gpio: mockup: dynamically allocate memory for chip name Bartosz Golaszewski <bgolaszewski@baylibre.com> - 2016-12-20 12:30 +0100
Re: [PATCH 2/3] gpio: mockup: dynamically allocate memory for chip name Linus Walleij <linus.walleij@linaro.org> - 2016-12-28 14:20 +0100
| From | Bartosz Golaszewski <bgolaszewski@baylibre.com> |
|---|---|
| Date | 2016-12-20 12:30 +0100 |
| Subject | [PATCH 2/3] gpio: mockup: dynamically allocate memory for chip name |
| Message-ID | <sQqMi-4Vr-31@gated-at.bofh.it> |
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>
---
drivers/gpio/gpio-mockup.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c
index af0c1e8..10f6bf6 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 {
--
2.9.3
[toc] | [next] | [standalone]
| From | Linus Walleij <linus.walleij@linaro.org> |
|---|---|
| Date | 2016-12-28 14:20 +0100 |
| Message-ID | <sTmj7-gu-5@gated-at.bofh.it> |
| In reply to | #1545058 |
On Tue, Dec 20, 2016 at 12:28 PM, Bartosz Golaszewski <bgolaszewski@baylibre.com> wrote: > 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> Patch applied. Yours, Linus Walleij
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web