Skip to content

Commit

Permalink
ALSA: cmi8328: Allocate resources with device-managed APIs
Browse files Browse the repository at this point in the history
This patch converts the resource management in ISA cmi8328 driver with
devres as a clean up.  Each manual resource management is converted
with the corresponding devres helper.

This should give no user-visible functional changes.

Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
tiwai committed Jul 19, 2021
1 parent 39c4f9a commit d9fd739
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions sound/isa/cmi8328.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ static int snd_cmi8328_probe(struct device *pdev, unsigned int ndev)
}
outb(val, port);

err = snd_card_new(pdev, index[ndev], id[ndev], THIS_MODULE,
sizeof(struct snd_cmi8328), &card);
err = snd_devm_card_new(pdev, index[ndev], id[ndev], THIS_MODULE,
sizeof(struct snd_cmi8328), &card);
if (err < 0)
return err;
cmi = card->private_data;
Expand All @@ -306,18 +306,18 @@ static int snd_cmi8328_probe(struct device *pdev, unsigned int ndev)
err = snd_wss_create(card, port + 4, -1, irq[ndev], dma1[ndev],
dma2[ndev], WSS_HW_DETECT, 0, &cmi->wss);
if (err < 0)
goto error;
return err;

err = snd_wss_pcm(cmi->wss, 0);
if (err < 0)
goto error;
return err;

err = snd_wss_mixer(cmi->wss);
if (err < 0)
goto error;
return err;
err = snd_cmi8328_mixer(cmi->wss);
if (err < 0)
goto error;
return err;

if (snd_wss_timer(cmi->wss, 0) < 0)
snd_printk(KERN_WARNING "error initializing WSS timer\n");
Expand Down Expand Up @@ -371,24 +371,21 @@ static int snd_cmi8328_probe(struct device *pdev, unsigned int ndev)
dev_set_drvdata(pdev, card);
err = snd_card_register(card);
if (err < 0)
goto error;
return err;
#ifdef SUPPORT_JOYSTICK
if (!gameport[ndev])
return 0;
/* gameport is hardwired to 0x200 */
res = request_region(0x200, 8, "CMI8328 gameport");
res = devm_request_region(pdev, 0x200, 8, "CMI8328 gameport");
if (!res)
snd_printk(KERN_WARNING "unable to allocate gameport I/O port\n");
else {
struct gameport *gp = cmi->gameport = gameport_allocate_port();
if (!cmi->gameport)
release_and_free_resource(res);
else {
if (cmi->gameport) {
gameport_set_name(gp, "CMI8328 Gameport");
gameport_set_phys(gp, "%s/gameport0", dev_name(pdev));
gameport_set_dev_parent(gp, pdev);
gp->io = 0x200;
gameport_set_port_data(gp, res);
/* Enable gameport */
snd_cmi8328_cfg_write(port, CFG1,
CFG1_SB_DISABLE | CFG1_GAMEPORT);
Expand All @@ -397,10 +394,6 @@ static int snd_cmi8328_probe(struct device *pdev, unsigned int ndev)
}
#endif
return 0;
error:
snd_card_free(card);

return err;
}

static void snd_cmi8328_remove(struct device *pdev, unsigned int dev)
Expand All @@ -409,17 +402,13 @@ static void snd_cmi8328_remove(struct device *pdev, unsigned int dev)
struct snd_cmi8328 *cmi = card->private_data;

#ifdef SUPPORT_JOYSTICK
if (cmi->gameport) {
struct resource *res = gameport_get_port_data(cmi->gameport);
if (cmi->gameport)
gameport_unregister_port(cmi->gameport);
release_and_free_resource(res);
}
#endif
/* disable everything */
snd_cmi8328_cfg_write(cmi->port, CFG1, CFG1_SB_DISABLE);
snd_cmi8328_cfg_write(cmi->port, CFG2, 0);
snd_cmi8328_cfg_write(cmi->port, CFG3, 0);
snd_card_free(card);
}

#ifdef CONFIG_PM
Expand Down

0 comments on commit d9fd739

Please sign in to comment.