linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] gpio: mockup: bug fixes and tweaks
@ 2016-12-20 11:28 Bartosz Golaszewski
  2016-12-20 11:28 ` [PATCH 1/3] gpio: mockup: make pins_name_start static Bartosz Golaszewski
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Bartosz Golaszewski @ 2016-12-20 11:28 UTC (permalink / raw)
  To: Bamvor Jian Zhang, Linus Walleij, Alexandre Courbot
  Cc: linux-gpio, linux-kernel, Bartosz Golaszewski

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] gpio: mockup: make pins_name_start static
  2016-12-20 11:28 [PATCH 0/3] gpio: mockup: bug fixes and tweaks Bartosz Golaszewski
@ 2016-12-20 11:28 ` Bartosz Golaszewski
  2016-12-28 13:12   ` Linus Walleij
  2016-12-20 11:28 ` [PATCH 2/3] gpio: mockup: dynamically allocate memory for chip name Bartosz Golaszewski
  2016-12-20 11:28 ` [PATCH 3/3] gpio: mockup: coding style fixes Bartosz Golaszewski
  2 siblings, 1 reply; 7+ messages in thread
From: Bartosz Golaszewski @ 2016-12-20 11:28 UTC (permalink / raw)
  To: Bamvor Jian Zhang, Linus Walleij, Alexandre Courbot
  Cc: linux-gpio, linux-kernel, Bartosz Golaszewski

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

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] gpio: mockup: dynamically allocate memory for chip name
  2016-12-20 11:28 [PATCH 0/3] gpio: mockup: bug fixes and tweaks Bartosz Golaszewski
  2016-12-20 11:28 ` [PATCH 1/3] gpio: mockup: make pins_name_start static Bartosz Golaszewski
@ 2016-12-20 11:28 ` Bartosz Golaszewski
  2016-12-28 13:13   ` Linus Walleij
  2016-12-20 11:28 ` [PATCH 3/3] gpio: mockup: coding style fixes Bartosz Golaszewski
  2 siblings, 1 reply; 7+ messages in thread
From: Bartosz Golaszewski @ 2016-12-20 11:28 UTC (permalink / raw)
  To: Bamvor Jian Zhang, Linus Walleij, Alexandre Courbot
  Cc: linux-gpio, linux-kernel, 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 <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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] gpio: mockup: coding style fixes
  2016-12-20 11:28 [PATCH 0/3] gpio: mockup: bug fixes and tweaks Bartosz Golaszewski
  2016-12-20 11:28 ` [PATCH 1/3] gpio: mockup: make pins_name_start static Bartosz Golaszewski
  2016-12-20 11:28 ` [PATCH 2/3] gpio: mockup: dynamically allocate memory for chip name Bartosz Golaszewski
@ 2016-12-20 11:28 ` Bartosz Golaszewski
  2016-12-28 13:14   ` Linus Walleij
  2 siblings, 1 reply; 7+ messages in thread
From: Bartosz Golaszewski @ 2016-12-20 11:28 UTC (permalink / raw)
  To: Bamvor Jian Zhang, Linus Walleij, Alexandre Courbot
  Cc: linux-gpio, linux-kernel, Bartosz Golaszewski

Fix whitespace errors and arrange local variables for better
readability.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] gpio: mockup: make pins_name_start static
  2016-12-20 11:28 ` [PATCH 1/3] gpio: mockup: make pins_name_start static Bartosz Golaszewski
@ 2016-12-28 13:12   ` Linus Walleij
  0 siblings, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2016-12-28 13:12 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Bamvor Jian Zhang, Alexandre Courbot, linux-gpio, linux-kernel

On Tue, Dec 20, 2016 at 12:28 PM, Bartosz Golaszewski
<bgolaszewski@baylibre.com> wrote:

> This variable is not used outside this module. Make it static.
>
> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>

Patch applied.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] gpio: mockup: dynamically allocate memory for chip name
  2016-12-20 11:28 ` [PATCH 2/3] gpio: mockup: dynamically allocate memory for chip name Bartosz Golaszewski
@ 2016-12-28 13:13   ` Linus Walleij
  0 siblings, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2016-12-28 13:13 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Bamvor Jian Zhang, Alexandre Courbot, linux-gpio, linux-kernel

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] gpio: mockup: coding style fixes
  2016-12-20 11:28 ` [PATCH 3/3] gpio: mockup: coding style fixes Bartosz Golaszewski
@ 2016-12-28 13:14   ` Linus Walleij
  0 siblings, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2016-12-28 13:14 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Bamvor Jian Zhang, Alexandre Courbot, linux-gpio, linux-kernel

On Tue, Dec 20, 2016 at 12:28 PM, Bartosz Golaszewski
<bgolaszewski@baylibre.com> wrote:

> Fix whitespace errors and arrange local variables for better
> readability.
>
> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>

Patch applied.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-12-28 13:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-20 11:28 [PATCH 0/3] gpio: mockup: bug fixes and tweaks Bartosz Golaszewski
2016-12-20 11:28 ` [PATCH 1/3] gpio: mockup: make pins_name_start static Bartosz Golaszewski
2016-12-28 13:12   ` Linus Walleij
2016-12-20 11:28 ` [PATCH 2/3] gpio: mockup: dynamically allocate memory for chip name Bartosz Golaszewski
2016-12-28 13:13   ` Linus Walleij
2016-12-20 11:28 ` [PATCH 3/3] gpio: mockup: coding style fixes Bartosz Golaszewski
2016-12-28 13:14   ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).