Input: amijoy - mark amijoy_phys as __initconst
Subsystems (2)
PATCH 1/1 Input: amijoy - mark amijoy_phys as __initconst
amijoy_phys is only read by the __init function amijoy_init().
Also declare amijoy_phys as const.
--- drivers/input/joystick/amijoy.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/input/joystick/amijoy.c +4 -1
@@ -30,7 +30,10 @@ MODULE_PARM_DESC(map, "Map of attached joysticks in form of <a>,<b> (default isstatic 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) {
Dmitry Torokhov
maintainerHi Thorsten,
Quoted 3 lines · Thorsten Blum
amijoy_physis only read by the__initfunctionamijoy_init().Also declare
amijoy_physas const.
...
drivers/input/joystick/amijoy.c MODULE_PARM_DESC(map, "Map of attached joysticks in form of <a>,<b> (default is · line 36
Quoted 5 lines
drivers/input/joystick/amijoy.c +4
-1-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.
Signature · 1 line
Dmitry
Hi Dmitry,
Quoted 7 lines · Dmitry Torokhov
Hi Thorsten,
Quoted 3 lines · Thorsten Blum
amijoy_physis only read by the__initfunctionamijoy_init().Also declare
amijoy_physas const....
Quoted 14 lines
drivers/input/joystick/amijoy.c MODULE_PARM_DESC(map, "Map of attached joysticks in form of <a>,<b> (default is · line 36
Quoted 5 lines
drivers/input/joystick/amijoy.c +4
-1-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
__initconstonly 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 thedev->physpointer for the entire lifetime of the input device, so if anyone later turnsamijoy_physinto a 2D char array to avoid pointer indirection, the strings themselves will move into .init.rodata anddev->physwill become a dangling pointer after init (with no warning from modpost since the reference is insideamijoy_init()).
Thanks for the feedback.
Quoted 6 lines
Could we either just mark
amijoy_physas const without__initconst(it is only 8 bytes on m68k), or dropamijoy_physaltogether 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/[email protected]/
Thanks,
Thorsten