All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpio: xra1403: Switch to a fixed upper bound for registers
@ 2018-04-09 21:07 Laura Abbott
  2018-04-10  8:08 ` Geert Uytterhoeven
  2018-04-12  8:17 ` Linus Walleij
  0 siblings, 2 replies; 3+ messages in thread
From: Laura Abbott @ 2018-04-09 21:07 UTC (permalink / raw)
  To: Nandor Han, Geert Uytterhoeven, Kees Cook, Linus Walleij
  Cc: Laura Abbott, linux-gpio, Linux Kernel Mailing List, kernel-hardening

Geert Uytterhoeven pointed out that the number of register was a
fixed upper bound so there's no need to use a dynamically allocated
array in place of a VLA. Use the defined upper bound.

Suggested-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Laura Abbott <labbott@redhat.com>
---
 drivers/gpio/gpio-xra1403.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/drivers/gpio/gpio-xra1403.c b/drivers/gpio/gpio-xra1403.c
index 8d4c8e99b251..8711a7907568 100644
--- a/drivers/gpio/gpio-xra1403.c
+++ b/drivers/gpio/gpio-xra1403.c
@@ -39,6 +39,7 @@
 #define XRA_REIR  0x10 /* Input Rising Edge Interrupt Enable */
 #define XRA_FEIR  0x12 /* Input Falling Edge Interrupt Enable */
 #define XRA_IFR   0x14 /* Input Filter Enable/Disable */
+#define XRA_LAST  0x15 /* Bounds */
 
 struct xra1403 {
 	struct gpio_chip  chip;
@@ -50,7 +51,7 @@ static const struct regmap_config xra1403_regmap_cfg = {
 		.pad_bits = 1,
 		.val_bits = 8,
 
-		.max_register = XRA_IFR | 0x01,
+		.max_register = XRA_LAST,
 };
 
 static unsigned int to_reg(unsigned int reg, unsigned int offset)
@@ -126,21 +127,16 @@ static void xra1403_dbg_show(struct seq_file *s, struct gpio_chip *chip)
 {
 	int reg;
 	struct xra1403 *xra = gpiochip_get_data(chip);
-	int *value;
+	int value[XRA_LAST];
 	int i;
 	unsigned int gcr;
 	unsigned int gsr;
 
-	value = kmalloc_array(xra1403_regmap_cfg.max_register, sizeof(*value),
-				GFP_KERNEL);
-	if (!value)
-		return;
-
 	seq_puts(s, "xra reg:");
-	for (reg = 0; reg <= xra1403_regmap_cfg.max_register; reg++)
+	for (reg = 0; reg <= XRA_LAST; reg++)
 		seq_printf(s, " %2.2x", reg);
 	seq_puts(s, "\n  value:");
-	for (reg = 0; reg < xra1403_regmap_cfg.max_register; reg++) {
+	for (reg = 0; reg < XRA_LAST; reg++) {
 		regmap_read(xra->regmap, reg, &value[reg]);
 		seq_printf(s, " %2.2x", value[reg]);
 	}
@@ -159,7 +155,6 @@ static void xra1403_dbg_show(struct seq_file *s, struct gpio_chip *chip)
 			   (gcr & BIT(i)) ? "in" : "out",
 			   (gsr & BIT(i)) ? "hi" : "lo");
 	}
-	kfree(value);
 }
 #else
 #define xra1403_dbg_show NULL
-- 
2.14.3

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

* Re: [PATCH] gpio: xra1403: Switch to a fixed upper bound for registers
  2018-04-09 21:07 [PATCH] gpio: xra1403: Switch to a fixed upper bound for registers Laura Abbott
@ 2018-04-10  8:08 ` Geert Uytterhoeven
  2018-04-12  8:17 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Geert Uytterhoeven @ 2018-04-10  8:08 UTC (permalink / raw)
  To: Laura Abbott
  Cc: Nandor Han, Kees Cook, Linus Walleij, open list:GPIO SUBSYSTEM,
	Linux Kernel Mailing List, kernel-hardening

Hi Laura,

On Mon, Apr 9, 2018 at 11:07 PM, Laura Abbott <labbott@redhat.com> wrote:
> Geert Uytterhoeven pointed out that the number of register was a
> fixed upper bound so there's no need to use a dynamically allocated
> array in place of a VLA. Use the defined upper bound.
>
> Suggested-by: Geert Uytterhoeven <geert@linux-m68k.org>
> Signed-off-by: Laura Abbott <labbott@redhat.com>

Thanks for your patch!

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH] gpio: xra1403: Switch to a fixed upper bound for registers
  2018-04-09 21:07 [PATCH] gpio: xra1403: Switch to a fixed upper bound for registers Laura Abbott
  2018-04-10  8:08 ` Geert Uytterhoeven
@ 2018-04-12  8:17 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2018-04-12  8:17 UTC (permalink / raw)
  To: Laura Abbott
  Cc: Nandor Han, Geert Uytterhoeven, Kees Cook,
	open list:GPIO SUBSYSTEM, Linux Kernel Mailing List,
	kernel-hardening

On Mon, Apr 9, 2018 at 11:07 PM, Laura Abbott <labbott@redhat.com> wrote:

> Geert Uytterhoeven pointed out that the number of register was a
> fixed upper bound so there's no need to use a dynamically allocated
> array in place of a VLA. Use the defined upper bound.
>
> Suggested-by: Geert Uytterhoeven <geert@linux-m68k.org>
> Signed-off-by: Laura Abbott <labbott@redhat.com>

Patch applied for v4.18!

Yours,
Linus Walleij

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

end of thread, other threads:[~2018-04-12  8:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-09 21:07 [PATCH] gpio: xra1403: Switch to a fixed upper bound for registers Laura Abbott
2018-04-10  8:08 ` Geert Uytterhoeven
2018-04-12  8:17 ` Linus Walleij

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.