mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-02 23:27:06 +00:00
gpio: mockup: dynamically allocate memory for chip name
[ Upstream commit ad6d8004fa
]
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>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
d47162bdba
commit
86aa023fa6
1 changed files with 7 additions and 3 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue