All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] input: ipaq-micro-keys: simplify allocation
@ 2026-06-08  4:50 Rosen Penev
  2026-06-08 16:49 ` Dmitry Torokhov
  0 siblings, 1 reply; 3+ messages in thread
From: Rosen Penev @ 2026-06-08  4:50 UTC (permalink / raw)
  To: linux-input; +Cc: Dmitry Torokhov, open list

Use a flexible array member to have a single allocation.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/input/keyboard/ipaq-micro-keys.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/input/keyboard/ipaq-micro-keys.c b/drivers/input/keyboard/ipaq-micro-keys.c
index ca7ec054b1ce..0fc5b5dcdef5 100644
--- a/drivers/input/keyboard/ipaq-micro-keys.c
+++ b/drivers/input/keyboard/ipaq-micro-keys.c
@@ -23,7 +23,7 @@
 struct ipaq_micro_keys {
 	struct ipaq_micro *micro;
 	struct input_dev *input;
-	u16 *codes;
+	u16 codes[];
 };
 
 static const u16 micro_keycodes[] = {
@@ -90,10 +90,11 @@ static int micro_key_probe(struct platform_device *pdev)
 	int error;
 	int i;
 
-	keys = devm_kzalloc(&pdev->dev, sizeof(*keys), GFP_KERNEL);
+	keys = devm_kzalloc(&pdev->dev, struct_size(keys, codes, ARRAY_SIZE(micro_keycodes)), GFP_KERNEL);
 	if (!keys)
 		return -ENOMEM;
 
+	memcpy(keys->codes, micro_keycodes, ARRAY_SIZE(micro_keycodes) * sizeof(*keys->codes));
 	keys->micro = dev_get_drvdata(pdev->dev.parent);
 
 	keys->input = devm_input_allocate_device(&pdev->dev);
@@ -102,10 +103,6 @@ static int micro_key_probe(struct platform_device *pdev)
 
 	keys->input->keycodesize = sizeof(micro_keycodes[0]);
 	keys->input->keycodemax = ARRAY_SIZE(micro_keycodes);
-	keys->codes = devm_kmemdup_array(&pdev->dev, micro_keycodes, keys->input->keycodemax,
-					 keys->input->keycodesize, GFP_KERNEL);
-	if (!keys->codes)
-		return -ENOMEM;
 
 	keys->input->keycode = keys->codes;
 
-- 
2.54.0


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

* Re: [PATCH] input: ipaq-micro-keys: simplify allocation
  2026-06-08  4:50 [PATCH] input: ipaq-micro-keys: simplify allocation Rosen Penev
@ 2026-06-08 16:49 ` Dmitry Torokhov
  2026-06-08 20:20   ` Rosen Penev
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Torokhov @ 2026-06-08 16:49 UTC (permalink / raw)
  To: Rosen Penev; +Cc: linux-input, open list

Hi Rosen,

On Sun, Jun 07, 2026 at 09:50:41PM -0700, Rosen Penev wrote:
> Use a flexible array member to have a single allocation.

Why does it have to be flexible? The size is known.

> 
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>  drivers/input/keyboard/ipaq-micro-keys.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/input/keyboard/ipaq-micro-keys.c b/drivers/input/keyboard/ipaq-micro-keys.c
> index ca7ec054b1ce..0fc5b5dcdef5 100644
> --- a/drivers/input/keyboard/ipaq-micro-keys.c
> +++ b/drivers/input/keyboard/ipaq-micro-keys.c
> @@ -23,7 +23,7 @@
>  struct ipaq_micro_keys {
>  	struct ipaq_micro *micro;
>  	struct input_dev *input;
> -	u16 *codes;
> +	u16 codes[];
>  };
>  
>  static const u16 micro_keycodes[] = {
> @@ -90,10 +90,11 @@ static int micro_key_probe(struct platform_device *pdev)
>  	int error;
>  	int i;
>  
> -	keys = devm_kzalloc(&pdev->dev, sizeof(*keys), GFP_KERNEL);
> +	keys = devm_kzalloc(&pdev->dev, struct_size(keys, codes, ARRAY_SIZE(micro_keycodes)), GFP_KERNEL);

Please keep to the limits for the kernel. 100 columns is acceptable when
leads to better readability, but I prefer 80 when it makes sense.

checkpatch.pl would have warned you.

Thanks.

-- 
Dmitry

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

* Re: [PATCH] input: ipaq-micro-keys: simplify allocation
  2026-06-08 16:49 ` Dmitry Torokhov
@ 2026-06-08 20:20   ` Rosen Penev
  0 siblings, 0 replies; 3+ messages in thread
From: Rosen Penev @ 2026-06-08 20:20 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input, open list

On Mon, Jun 8, 2026 at 9:49 AM Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
>
> Hi Rosen,
>
> On Sun, Jun 07, 2026 at 09:50:41PM -0700, Rosen Penev wrote:
> > Use a flexible array member to have a single allocation.
>
> Why does it have to be flexible? The size is known.
From a quick glance, that would be a compilation error. micro_keycodes
gets declared after ipaq_micro_keys

From looking at a bunch of struct definitions, [ARRAY_SIZE(foo)] seems
to be atypical.
>
> >
> > Signed-off-by: Rosen Penev <rosenp@gmail.com>
> > ---
> >  drivers/input/keyboard/ipaq-micro-keys.c | 9 +++------
> >  1 file changed, 3 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/input/keyboard/ipaq-micro-keys.c b/drivers/input/keyboard/ipaq-micro-keys.c
> > index ca7ec054b1ce..0fc5b5dcdef5 100644
> > --- a/drivers/input/keyboard/ipaq-micro-keys.c
> > +++ b/drivers/input/keyboard/ipaq-micro-keys.c
> > @@ -23,7 +23,7 @@
> >  struct ipaq_micro_keys {
> >       struct ipaq_micro *micro;
> >       struct input_dev *input;
> > -     u16 *codes;
> > +     u16 codes[];
> >  };
> >
> >  static const u16 micro_keycodes[] = {
> > @@ -90,10 +90,11 @@ static int micro_key_probe(struct platform_device *pdev)
> >       int error;
> >       int i;
> >
> > -     keys = devm_kzalloc(&pdev->dev, sizeof(*keys), GFP_KERNEL);
> > +     keys = devm_kzalloc(&pdev->dev, struct_size(keys, codes, ARRAY_SIZE(micro_keycodes)), GFP_KERNEL);
>
> Please keep to the limits for the kernel. 100 columns is acceptable when
> leads to better readability, but I prefer 80 when it makes sense.
Seems I forgot to run git clang-format here. Will resend.
>
> checkpatch.pl would have warned you.
>
> Thanks.
>
> --
> Dmitry

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

end of thread, other threads:[~2026-06-08 20:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-08  4:50 [PATCH] input: ipaq-micro-keys: simplify allocation Rosen Penev
2026-06-08 16:49 ` Dmitry Torokhov
2026-06-08 20:20   ` Rosen Penev

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.