Skip to content

Commit db1005e

Browse files
committed
ALSA: riptide - Fix joystick resource handling
The current code doesn't handle the multiple gameports properly, and uses unnecessary global static variables to store the data. This patch changes the probe / remove routines to use the driver data assigned to the dedicated pci device, and adds the support of multiple devices. Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent a693a26 commit db1005e

1 file changed

Lines changed: 26 additions & 35 deletions

File tree

‎sound/pci/riptide/riptide.c‎

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,14 +2014,12 @@ static int __devinit snd_riptide_mixer(struct snd_riptide *chip)
20142014
}
20152015

20162016
#ifdef SUPPORT_JOYSTICK
2017-
static int have_joystick;
2018-
static struct pci_dev *riptide_gameport_pci;
2019-
static struct gameport *riptide_gameport;
20202017

20212018
static int __devinit
20222019
snd_riptide_joystick_probe(struct pci_dev *pci, const struct pci_device_id *id)
20232020
{
20242021
static int dev;
2022+
struct gameport *gameport;
20252023

20262024
if (dev >= SNDRV_CARDS)
20272025
return -ENODEV;
@@ -2030,36 +2028,33 @@ snd_riptide_joystick_probe(struct pci_dev *pci, const struct pci_device_id *id)
20302028
return -ENOENT;
20312029
}
20322030

2033-
if (joystick_port[dev]) {
2034-
riptide_gameport = gameport_allocate_port();
2035-
if (riptide_gameport) {
2036-
if (!request_region
2037-
(joystick_port[dev], 8, "Riptide gameport")) {
2038-
snd_printk(KERN_WARNING
2039-
"Riptide: cannot grab gameport 0x%x\n",
2040-
joystick_port[dev]);
2041-
gameport_free_port(riptide_gameport);
2042-
riptide_gameport = NULL;
2043-
} else {
2044-
riptide_gameport_pci = pci;
2045-
riptide_gameport->io = joystick_port[dev];
2046-
gameport_register_port(riptide_gameport);
2047-
}
2048-
}
2031+
if (!joystick_port[dev++])
2032+
return 0;
2033+
2034+
gameport = gameport_allocate_port();
2035+
if (!gameport)
2036+
return -ENOMEM;
2037+
if (!request_region(joystick_port[dev], 8, "Riptide gameport")) {
2038+
snd_printk(KERN_WARNING
2039+
"Riptide: cannot grab gameport 0x%x\n",
2040+
joystick_port[dev]);
2041+
gameport_free_port(gameport);
2042+
return -EBUSY;
20492043
}
2050-
dev++;
2044+
2045+
gameport->io = joystick_port[dev];
2046+
gameport_register_port(gameport);
2047+
pci_set_drvdata(pci, gameport);
20512048
return 0;
20522049
}
20532050

20542051
static void __devexit snd_riptide_joystick_remove(struct pci_dev *pci)
20552052
{
2056-
if (riptide_gameport) {
2057-
if (riptide_gameport_pci == pci) {
2058-
release_region(riptide_gameport->io, 8);
2059-
riptide_gameport_pci = NULL;
2060-
gameport_unregister_port(riptide_gameport);
2061-
riptide_gameport = NULL;
2062-
}
2053+
struct gameport *gameport = pci_get_drvdata(pci);
2054+
if (gameport) {
2055+
release_region(gameport->io, 8);
2056+
gameport_unregister_port(gameport);
2057+
pci_set_drvdata(pci, NULL);
20632058
}
20642059
}
20652060
#endif
@@ -2198,14 +2193,11 @@ static struct pci_driver joystick_driver = {
21982193
static int __init alsa_card_riptide_init(void)
21992194
{
22002195
int err;
2201-
if ((err = pci_register_driver(&driver)) < 0)
2196+
err = pci_register_driver(&driver);
2197+
if (err < 0)
22022198
return err;
22032199
#if defined(SUPPORT_JOYSTICK)
2204-
if (pci_register_driver(&joystick_driver) < 0) {
2205-
have_joystick = 0;
2206-
snd_printk(KERN_INFO "no joystick found\n");
2207-
} else
2208-
have_joystick = 1;
2200+
pci_register_driver(&joystick_driver);
22092201
#endif
22102202
return 0;
22112203
}
@@ -2214,8 +2206,7 @@ static void __exit alsa_card_riptide_exit(void)
22142206
{
22152207
pci_unregister_driver(&driver);
22162208
#if defined(SUPPORT_JOYSTICK)
2217-
if (have_joystick)
2218-
pci_unregister_driver(&joystick_driver);
2209+
pci_unregister_driver(&joystick_driver);
22192210
#endif
22202211
}
22212212

0 commit comments

Comments
 (0)