2016-12-20 11:28:38

by Bartosz Golaszewski

[permalink] [raw]
Subject: [PATCH 0/3] 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(-)

--
2.9.3


2016-12-20 11:28:46

by Bartosz Golaszewski

[permalink] [raw]
Subject: [PATCH 3/3] gpio: mockup: coding style fixes

Fix whitespace errors and arrange local variables for better
readability.

Signed-off-by: Bartosz Golaszewski <[email protected]>
---
drivers/gpio/gpio-mockup.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c
index 10f6bf6..82a9efd 100644
--- a/drivers/gpio/gpio-mockup.c
+++ b/drivers/gpio/gpio-mockup.c
@@ -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,
};

--
2.9.3

2016-12-20 11:29:26

by Bartosz Golaszewski

[permalink] [raw]
Subject: [PATCH 1/3] gpio: mockup: make pins_name_start static

This variable is not used outside this module. Make it static.

Signed-off-by: Bartosz Golaszewski <[email protected]>
---
drivers/gpio/gpio-mockup.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c
index 1ef85b0..af0c1e8 100644
--- a/drivers/gpio/gpio-mockup.c
+++ b/drivers/gpio/gpio-mockup.c
@@ -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)
{
--
2.9.3

2016-12-20 11:29:20

by Bartosz Golaszewski

[permalink] [raw]
Subject: [PATCH 2/3] 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 <[email protected]>
---
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

2016-12-28 13:12:35

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH 1/3] gpio: mockup: make pins_name_start static

On Tue, Dec 20, 2016 at 12:28 PM, Bartosz Golaszewski
<[email protected]> wrote:

> This variable is not used outside this module. Make it static.
>
> Signed-off-by: Bartosz Golaszewski <[email protected]>

Patch applied.

Yours,
Linus Walleij

2016-12-28 13:13:24

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH 2/3] gpio: mockup: dynamically allocate memory for chip name

On Tue, Dec 20, 2016 at 12:28 PM, Bartosz Golaszewski
<[email protected]> 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 <[email protected]>

Patch applied.

Yours,
Linus Walleij

2016-12-28 13:14:07

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH 3/3] gpio: mockup: coding style fixes

On Tue, Dec 20, 2016 at 12:28 PM, Bartosz Golaszewski
<[email protected]> wrote:

> Fix whitespace errors and arrange local variables for better
> readability.
>
> Signed-off-by: Bartosz Golaszewski <[email protected]>

Patch applied.

Yours,
Linus Walleij