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

Input: turbografx - store object in correct index

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

Fixes: 4de27a638a99 ("Input: turbografx - 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
c65cf815 c36906c5

+11 -9
+11 -9
drivers/input/joystick/turbografx.c
··· 162 162 struct tgfx *tgfx; 163 163 struct input_dev *input_dev; 164 164 struct pardevice *pd; 165 - int i, j; 165 + int i, j, port_idx; 166 166 int *n_buttons, n_devs; 167 167 struct pardev_cb tgfx_parport_cb; 168 168 169 - for (i = 0; i < TGFX_MAX_PORTS; i++) { 170 - if (tgfx_cfg[i].nargs == 0 || tgfx_cfg[i].args[0] < 0) 169 + for (port_idx = 0; port_idx < TGFX_MAX_PORTS; port_idx++) { 170 + if (tgfx_cfg[port_idx].nargs == 0 || 171 + tgfx_cfg[port_idx].args[0] < 0) 171 172 continue; 172 - if (tgfx_cfg[i].args[0] == pp->number) 173 + if (tgfx_cfg[port_idx].args[0] == pp->number) 173 174 break; 174 175 } 175 176 176 - if (i == TGFX_MAX_PORTS) { 177 + if (port_idx == TGFX_MAX_PORTS) { 177 178 pr_debug("Not using parport%d.\n", pp->number); 178 179 return; 179 180 } 180 - n_buttons = tgfx_cfg[i].args + 1; 181 - n_devs = tgfx_cfg[i].nargs - 1; 181 + n_buttons = tgfx_cfg[port_idx].args + 1; 182 + n_devs = tgfx_cfg[port_idx].nargs - 1; 182 183 183 184 tgfx_parport_cb.flags = PARPORT_FLAG_EXCL; 184 185 185 - pd = parport_register_dev_model(pp, "turbografx", &tgfx_parport_cb, i); 186 + pd = parport_register_dev_model(pp, "turbografx", &tgfx_parport_cb, 187 + port_idx); 186 188 if (!pd) { 187 189 pr_err("parport busy already - lp.o loaded?\n"); 188 190 return; ··· 252 250 goto err_free_tgfx; 253 251 } 254 252 255 - tgfx_base[i] = tgfx; 253 + tgfx_base[port_idx] = tgfx; 256 254 return; 257 255 258 256 err_free_dev: