gpio: mockup: bug fixes and tweaks
Subsystems (2)
cover gpio: mockup: bug fixes and tweaks
While trying to use the gpio-mockup driver for testing purposes I noticed there's an issue with the gpiochip's label. It turned out the label pointer points to invalid memory area. This series fixes it and adds some minor changes in other places too.
Bartosz Golaszewski (3):
gpio: mockup: make pins_name_start static
gpio: mockup: dynamically allocate memory for chip name
gpio: mockup: coding style fixes
drivers/gpio/gpio-mockup.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)
Signature · 1 line
2.9.3
PATCH 1/3 gpio: mockup: make pins_name_start static
This variable is not used outside this module. Make it static.
--- drivers/gpio/gpio-mockup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-mockup.c +1 -1
@@ -43,7 +43,7 @@ static int gpio_mockup_ranges[MAX_GC << 1];static int gpio_mockup_params_nr;module_param_array (gpio_mockup_ranges, int, &gpio_mockup_params_nr,0400 ); -const char pins_name_start ='A' ; +static const char pins_name_start ='A' ;static int mockup_gpio_get (struct gpio_chip *gc,unsigned int offset) {
Signature · 1 line
2.9.3
Re: [PATCH 1/3] gpio: mockup: make pins_name_start static
Quoted 3 lines · Bartosz Golaszewski
This variable is not used outside this module. Make it static.
Signed-off-by Bartosz Golaszewski <[email protected]>
Patch applied.
Yours,
Linus Walleij
PATCH 2/3 gpio: mockup: dynamically allocate memory for chip name
In reply to Bartosz GolaszewskiCurrently 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.
--- drivers/gpio/gpio-mockup.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/gpio/gpio-mockup.c +7 -3
@@ -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 {
Signature · 1 line
2.9.3
Re: [PATCH 2/3] gpio: mockup: dynamically allocate memory for chip name
Quoted 7 lines · Bartosz Golaszewski
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 <[email protected]>
Patch applied.
Yours,
Linus Walleij
PATCH 3/3 gpio: mockup: coding style fixes
In reply to Bartosz GolaszewskiFix whitespace errors and arrange local variables for better readability.
--- drivers/gpio/gpio-mockup.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/gpio/gpio-mockup.c +4 -7
@@ -120,12 +120,9 @@ static int mockup_gpio_add(struct device *dev,static int mockup_gpio_probe (struct platform_device *pdev) { -struct device *dev = &pdev->dev;struct mockup_gpio_controller *cntr; -int ret; -int i; -int base; -int ngpio; +struct device *dev = &pdev->dev; +int ret, i, base, ngpio;char *chip_name;if (gpio_mockup_params_nr <2 )
@@ -174,8 +171,8 @@ static int mockup_gpio_probe(struct platform_device *pdev)static struct platform_driver mockup_gpio_driver = { .driver = { - .name =GPIO_NAME , - }, + .name =GPIO_NAME , + }, .probe = mockup_gpio_probe, };
Signature · 1 line
2.9.3
Re: [PATCH 3/3] gpio: mockup: coding style fixes
Quoted 4 lines · Bartosz Golaszewski
Fix whitespace errors and arrange local variables for better readability.
Signed-off-by Bartosz Golaszewski <[email protected]>
Patch applied.
Yours,
Linus Walleij