Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: gamecon - store object at correct index

The variable i is used to check the port to attach to and we are
supposed to save the reference of struct gc in the location given by
gc_base[i]. But after finding out the index, i is getting modified again
so we saved in a wrong index.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Fixes: a517e87c3dfc ("Input: gamecon - use parallel port device model")
Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Sudip Mukherjee and committed by
Dmitry Torokhov
c36906c5 dd23bf10

+10 -9
+10 -9
drivers/input/joystick/gamecon.c
··· 931 931 { 932 932 struct gc *gc; 933 933 struct pardevice *pd; 934 - int i; 934 + int i, port_idx; 935 935 int count = 0; 936 936 int *pads, n_pads; 937 937 struct pardev_cb gc_parport_cb; 938 938 939 - for (i = 0; i < GC_MAX_PORTS; i++) { 940 - if (gc_cfg[i].nargs == 0 || gc_cfg[i].args[0] < 0) 939 + for (port_idx = 0; port_idx < GC_MAX_PORTS; port_idx++) { 940 + if (gc_cfg[port_idx].nargs == 0 || gc_cfg[port_idx].args[0] < 0) 941 941 continue; 942 942 943 - if (gc_cfg[i].args[0] == pp->number) 943 + if (gc_cfg[port_idx].args[0] == pp->number) 944 944 break; 945 945 } 946 946 947 - if (i == GC_MAX_PORTS) { 947 + if (port_idx == GC_MAX_PORTS) { 948 948 pr_debug("Not using parport%d.\n", pp->number); 949 949 return; 950 950 } 951 - pads = gc_cfg[i].args + 1; 952 - n_pads = gc_cfg[i].nargs - 1; 951 + pads = gc_cfg[port_idx].args + 1; 952 + n_pads = gc_cfg[port_idx].nargs - 1; 953 953 954 954 gc_parport_cb.flags = PARPORT_FLAG_EXCL; 955 955 956 - pd = parport_register_dev_model(pp, "gamecon", &gc_parport_cb, i); 956 + pd = parport_register_dev_model(pp, "gamecon", &gc_parport_cb, 957 + port_idx); 957 958 if (!pd) { 958 959 pr_err("parport busy already - lp.o loaded?\n"); 959 960 return; ··· 986 985 goto err_free_gc; 987 986 } 988 987 989 - gc_base[i] = gc; 988 + gc_base[port_idx] = gc; 990 989 return; 991 990 992 991 err_unreg_devs: