mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] Input: amijoy - mark amijoy_phys as __initconst
@ 2026-11-07 17:47 Thorsten Blum
  2026-11-07 23:19 ` Dmitry Torokhov
  0 siblings, 1 reply; 3+ messages in thread
From: Thorsten Blum @ 2026-11-07 17:47 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: Thorsten Blum, linux-input, linux-kernel

amijoy_phys is only read by the __init function amijoy_init().

Also declare amijoy_phys as const.

Signed-off-by: Thorsten Blum <blum@kernel.org>
---
 drivers/input/joystick/amijoy.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/input/joystick/amijoy.c b/drivers/input/joystick/amijoy.c
index 3752dc2a2086..cdb2b8f15348 100644
--- a/drivers/input/joystick/amijoy.c
+++ b/drivers/input/joystick/amijoy.c
@@ -30,7 +30,10 @@ MODULE_PARM_DESC(map, "Map of attached joysticks in form of <a>,<b> (default is
 static int amijoy_used;
 static DEFINE_MUTEX(amijoy_mutex);
 static struct input_dev *amijoy_dev[2];
-static char *amijoy_phys[2] = { "amijoy/input0", "amijoy/input1" };
+static const char * const amijoy_phys[2] __initconst = {
+	"amijoy/input0",
+	"amijoy/input1",
+};
 
 static irqreturn_t amijoy_interrupt(int irq, void *dummy)
 {

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

* Re: [PATCH] Input: amijoy - mark amijoy_phys as __initconst
  2026-11-07 17:47 [PATCH] Input: amijoy - mark amijoy_phys as __initconst Thorsten Blum
@ 2026-11-07 23:19 ` Dmitry Torokhov
  2026-11-07 23:59   ` Thorsten Blum
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Torokhov @ 2026-11-07 23:19 UTC (permalink / raw)
  To: Thorsten Blum; +Cc: linux-input, linux-kernel

Hi Thorsten,

On Sat, Nov 07, 2026 at 06:47:38PM +0100, Thorsten Blum wrote:
> amijoy_phys is only read by the __init function amijoy_init().
>
> Also declare amijoy_phys as const.
...
> -static char *amijoy_phys[2] = { "amijoy/input0", "amijoy/input1" };
> +static const char * const amijoy_phys[2] __initconst = {
> +	"amijoy/input0",
> +	"amijoy/input1",
> +};

While this technically works because __initconst only places the pointer
array itself into .init.rodata and leaves the string literals in .rodata,
I find it too subtle and fragile. input_register_device() retains the
dev->phys pointer for the entire lifetime of the input device, so if
anyone later turns amijoy_phys into a 2D char array to avoid pointer
indirection, the strings themselves will move into .init.rodata and
dev->phys will become a dangling pointer after init (with no warning
from modpost since the reference is inside amijoy_init()).

Could we either just mark amijoy_phys as const without __initconst (it
is only 8 bytes on m68k), or drop amijoy_phys altogether and do:

	amijoy_dev[i]->phys = i ? "amijoy/input1" : "amijoy/input0";

in amijoy_init() (which stays in .init.text anyway)?

Thanks.

-- 
Dmitry

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

* Re: [PATCH] Input: amijoy - mark amijoy_phys as __initconst
  2026-11-07 23:19 ` Dmitry Torokhov
@ 2026-11-07 23:59   ` Thorsten Blum
  0 siblings, 0 replies; 3+ messages in thread
From: Thorsten Blum @ 2026-11-07 23:59 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input, linux-kernel

Hi Dmitry,

On Sat, Nov 07, 2026 at 03:19:38PM -0800, Dmitry Torokhov wrote:
> Hi Thorsten,
> 
> On Sat, Nov 07, 2026 at 06:47:38PM +0100, Thorsten Blum wrote:
> > amijoy_phys is only read by the __init function amijoy_init().
> >
> > Also declare amijoy_phys as const.
> ...
> > -static char *amijoy_phys[2] = { "amijoy/input0", "amijoy/input1" };
> > +static const char * const amijoy_phys[2] __initconst = {
> > +	"amijoy/input0",
> > +	"amijoy/input1",
> > +};
> 
> While this technically works because __initconst only places the pointer
> array itself into .init.rodata and leaves the string literals in .rodata,
> I find it too subtle and fragile. input_register_device() retains the
> dev->phys pointer for the entire lifetime of the input device, so if
> anyone later turns amijoy_phys into a 2D char array to avoid pointer
> indirection, the strings themselves will move into .init.rodata and
> dev->phys will become a dangling pointer after init (with no warning
> from modpost since the reference is inside amijoy_init()).

Thanks for the feedback.

> Could we either just mark amijoy_phys as const without __initconst (it
> is only 8 bytes on m68k), or drop amijoy_phys altogether and do:
> 
> 	amijoy_dev[i]->phys = i ? "amijoy/input1" : "amijoy/input0";
> 
> in amijoy_init() (which stays in .init.text anyway)?

I prefer to drop it then. v2 is here:
https://lore.kernel.org/lkml/20261107234349.382944-3-blum@kernel.org/

Thanks,
Thorsten

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

end of thread, other threads:[~2026-11-07 23:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-07 17:47 [PATCH] Input: amijoy - mark amijoy_phys as __initconst Thorsten Blum
2026-11-07 23:19 ` Dmitry Torokhov
2026-11-07 23:59   ` Thorsten Blum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®