aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci
diff options
context:
space:
mode:
authorDan Carpenter <dan.carpenter@oracle.com>2015-02-09 08:51:40 -0500
committerTakashi Iwai <tiwai@suse.de>2015-02-09 08:57:15 -0500
commite4940626defdf6c92da1052ad3f12741c1a28c90 (patch)
treed230cc342be6f3b28138351eae7025d6b60404fe /sound/pci
parentd1612c80edaab7ac9170cb2fc86b538ab2e5a741 (diff)
ALSA: off by one bug in snd_riptide_joystick_probe()
The problem here is that we check: if (dev >= SNDRV_CARDS) Then we increment "dev". if (!joystick_port[dev++]) Then we use it as an offset into a array with SNDRV_CARDS elements. if (!request_region(joystick_port[dev], 8, "Riptide gameport")) { This has 3 effects: 1) If you use the module option to specify the joystick port then it has to be shifted one space over. 2) The wrong error message will be printed on failure if you have over 32 cards. 3) Static checkers will correctly complain that are off by one. Fixes: db1005ec6ff8 ('ALSA: riptide - Fix joystick resource handling') Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci')
-rw-r--r--sound/pci/riptide/riptide.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/sound/pci/riptide/riptide.c b/sound/pci/riptide/riptide.c
index 29f28273b2cc..94639d6b5fb5 100644
--- a/sound/pci/riptide/riptide.c
+++ b/sound/pci/riptide/riptide.c
@@ -2011,32 +2011,43 @@ snd_riptide_joystick_probe(struct pci_dev *pci, const struct pci_device_id *id)
2011{ 2011{
2012 static int dev; 2012 static int dev;
2013 struct gameport *gameport; 2013 struct gameport *gameport;
2014 int ret;
2014 2015
2015 if (dev >= SNDRV_CARDS) 2016 if (dev >= SNDRV_CARDS)
2016 return -ENODEV; 2017 return -ENODEV;
2018
2017 if (!enable[dev]) { 2019 if (!enable[dev]) {
2018 dev++; 2020 ret = -ENOENT;
2019 return -ENOENT; 2021 goto inc_dev;
2020 } 2022 }
2021 2023
2022 if (!joystick_port[dev++]) 2024 if (!joystick_port[dev]) {
2023 return 0; 2025 ret = 0;
2026 goto inc_dev;
2027 }
2024 2028
2025 gameport = gameport_allocate_port(); 2029 gameport = gameport_allocate_port();
2026 if (!gameport) 2030 if (!gameport) {
2027 return -ENOMEM; 2031 ret = -ENOMEM;
2032 goto inc_dev;
2033 }
2028 if (!request_region(joystick_port[dev], 8, "Riptide gameport")) { 2034 if (!request_region(joystick_port[dev], 8, "Riptide gameport")) {
2029 snd_printk(KERN_WARNING 2035 snd_printk(KERN_WARNING
2030 "Riptide: cannot grab gameport 0x%x\n", 2036 "Riptide: cannot grab gameport 0x%x\n",
2031 joystick_port[dev]); 2037 joystick_port[dev]);
2032 gameport_free_port(gameport); 2038 gameport_free_port(gameport);
2033 return -EBUSY; 2039 ret = -EBUSY;
2040 goto inc_dev;
2034 } 2041 }
2035 2042
2036 gameport->io = joystick_port[dev]; 2043 gameport->io = joystick_port[dev];
2037 gameport_register_port(gameport); 2044 gameport_register_port(gameport);
2038 pci_set_drvdata(pci, gameport); 2045 pci_set_drvdata(pci, gameport);
2039 return 0; 2046
2047 ret = 0;
2048inc_dev:
2049 dev++;
2050 return ret;
2040} 2051}
2041 2052
2042static void snd_riptide_joystick_remove(struct pci_dev *pci) 2053static void snd_riptide_joystick_remove(struct pci_dev *pci)