Commit d9fd7397 authored by Takashi Iwai's avatar Takashi Iwai
Browse files

ALSA: cmi8328: Allocate resources with device-managed APIs

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/20210715075941.23332-60-tiwai@suse.de


Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 39c4f9aa
Loading
Loading
Loading
Loading
+10 −21
Original line number Original line Diff line number Diff line
@@ -294,7 +294,7 @@ static int snd_cmi8328_probe(struct device *pdev, unsigned int ndev)
	}
	}
	outb(val, port);
	outb(val, port);


	err = snd_card_new(pdev, index[ndev], id[ndev], THIS_MODULE,
	err = snd_devm_card_new(pdev, index[ndev], id[ndev], THIS_MODULE,
				sizeof(struct snd_cmi8328), &card);
				sizeof(struct snd_cmi8328), &card);
	if (err < 0)
	if (err < 0)
		return err;
		return err;
@@ -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],
	err = snd_wss_create(card, port + 4, -1, irq[ndev], dma1[ndev],
			dma2[ndev], WSS_HW_DETECT, 0, &cmi->wss);
			dma2[ndev], WSS_HW_DETECT, 0, &cmi->wss);
	if (err < 0)
	if (err < 0)
		goto error;
		return err;


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


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


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

	return err;
}
}


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


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


#ifdef CONFIG_PM
#ifdef CONFIG_PM