Commit 3a1e341c authored by Takashi Iwai's avatar Takashi Iwai

ALSA: pcsp: Allocate resources with device-managed APIs

Use the new snd_devm_card_new() for the card object allocation and the
devres version for the input device, and clean up the superfluous
remove callback.

Link: https://lore.kernel.org/r/20210715075941.23332-80-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent ed16a22b
...@@ -42,9 +42,8 @@ struct snd_pcsp pcsp_chip; ...@@ -42,9 +42,8 @@ struct snd_pcsp pcsp_chip;
static int snd_pcsp_create(struct snd_card *card) static int snd_pcsp_create(struct snd_card *card)
{ {
static const struct snd_device_ops ops = { };
unsigned int resolution = hrtimer_resolution; unsigned int resolution = hrtimer_resolution;
int err, div, min_div, order; int div, min_div, order;
if (!nopcm) { if (!nopcm) {
if (resolution > PCSP_MAX_PERIOD_NS) { if (resolution > PCSP_MAX_PERIOD_NS) {
...@@ -83,15 +82,18 @@ static int snd_pcsp_create(struct snd_card *card) ...@@ -83,15 +82,18 @@ static int snd_pcsp_create(struct snd_card *card)
pcsp_chip.port = 0x61; pcsp_chip.port = 0x61;
pcsp_chip.irq = -1; pcsp_chip.irq = -1;
pcsp_chip.dma = -1; pcsp_chip.dma = -1;
card->private_data = &pcsp_chip;
/* Register device */
err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, &pcsp_chip, &ops);
if (err < 0)
return err;
return 0; return 0;
} }
static void pcsp_stop_beep(struct snd_pcsp *chip);
static void alsa_card_pcsp_free(struct snd_card *card)
{
pcsp_stop_beep(card->private_data);
}
static int snd_card_pcsp_probe(int devnum, struct device *dev) static int snd_card_pcsp_probe(int devnum, struct device *dev)
{ {
struct snd_card *card; struct snd_card *card;
...@@ -103,22 +105,22 @@ static int snd_card_pcsp_probe(int devnum, struct device *dev) ...@@ -103,22 +105,22 @@ static int snd_card_pcsp_probe(int devnum, struct device *dev)
hrtimer_init(&pcsp_chip.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); hrtimer_init(&pcsp_chip.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
pcsp_chip.timer.function = pcsp_do_timer; pcsp_chip.timer.function = pcsp_do_timer;
err = snd_card_new(dev, index, id, THIS_MODULE, 0, &card); err = snd_devm_card_new(dev, index, id, THIS_MODULE, 0, &card);
if (err < 0) if (err < 0)
return err; return err;
err = snd_pcsp_create(card); err = snd_pcsp_create(card);
if (err < 0) if (err < 0)
goto free_card; return err;
if (!nopcm) { if (!nopcm) {
err = snd_pcsp_new_pcm(&pcsp_chip); err = snd_pcsp_new_pcm(&pcsp_chip);
if (err < 0) if (err < 0)
goto free_card; return err;
} }
err = snd_pcsp_new_mixer(&pcsp_chip, nopcm); err = snd_pcsp_new_mixer(&pcsp_chip, nopcm);
if (err < 0) if (err < 0)
goto free_card; return err;
strcpy(card->driver, "PC-Speaker"); strcpy(card->driver, "PC-Speaker");
strcpy(card->shortname, "pcsp"); strcpy(card->shortname, "pcsp");
...@@ -127,13 +129,10 @@ static int snd_card_pcsp_probe(int devnum, struct device *dev) ...@@ -127,13 +129,10 @@ static int snd_card_pcsp_probe(int devnum, struct device *dev)
err = snd_card_register(card); err = snd_card_register(card);
if (err < 0) if (err < 0)
goto free_card; return err;
card->private_free = alsa_card_pcsp_free;
return 0; return 0;
free_card:
snd_card_free(card);
return err;
} }
static int alsa_card_pcsp_init(struct device *dev) static int alsa_card_pcsp_init(struct device *dev)
...@@ -155,11 +154,6 @@ static int alsa_card_pcsp_init(struct device *dev) ...@@ -155,11 +154,6 @@ static int alsa_card_pcsp_init(struct device *dev)
return 0; return 0;
} }
static void alsa_card_pcsp_exit(struct snd_pcsp *chip)
{
snd_card_free(chip->card);
}
static int pcsp_probe(struct platform_device *dev) static int pcsp_probe(struct platform_device *dev)
{ {
int err; int err;
...@@ -169,23 +163,13 @@ static int pcsp_probe(struct platform_device *dev) ...@@ -169,23 +163,13 @@ static int pcsp_probe(struct platform_device *dev)
return err; return err;
err = alsa_card_pcsp_init(&dev->dev); err = alsa_card_pcsp_init(&dev->dev);
if (err < 0) { if (err < 0)
pcspkr_input_remove(pcsp_chip.input_dev);
return err; return err;
}
platform_set_drvdata(dev, &pcsp_chip); platform_set_drvdata(dev, &pcsp_chip);
return 0; return 0;
} }
static int pcsp_remove(struct platform_device *dev)
{
struct snd_pcsp *chip = platform_get_drvdata(dev);
pcspkr_input_remove(chip->input_dev);
alsa_card_pcsp_exit(chip);
return 0;
}
static void pcsp_stop_beep(struct snd_pcsp *chip) static void pcsp_stop_beep(struct snd_pcsp *chip)
{ {
pcsp_sync_stop(chip); pcsp_sync_stop(chip);
...@@ -218,7 +202,6 @@ static struct platform_driver pcsp_platform_driver = { ...@@ -218,7 +202,6 @@ static struct platform_driver pcsp_platform_driver = {
.pm = PCSP_PM_OPS, .pm = PCSP_PM_OPS,
}, },
.probe = pcsp_probe, .probe = pcsp_probe,
.remove = pcsp_remove,
.shutdown = pcsp_shutdown, .shutdown = pcsp_shutdown,
}; };
......
...@@ -78,7 +78,7 @@ int pcspkr_input_init(struct input_dev **rdev, struct device *dev) ...@@ -78,7 +78,7 @@ int pcspkr_input_init(struct input_dev **rdev, struct device *dev)
{ {
int err; int err;
struct input_dev *input_dev = input_allocate_device(); struct input_dev *input_dev = devm_input_allocate_device(dev);
if (!input_dev) if (!input_dev)
return -ENOMEM; return -ENOMEM;
...@@ -95,19 +95,9 @@ int pcspkr_input_init(struct input_dev **rdev, struct device *dev) ...@@ -95,19 +95,9 @@ int pcspkr_input_init(struct input_dev **rdev, struct device *dev)
input_dev->event = pcspkr_input_event; input_dev->event = pcspkr_input_event;
err = input_register_device(input_dev); err = input_register_device(input_dev);
if (err) { if (err)
input_free_device(input_dev);
return err; return err;
}
*rdev = input_dev; *rdev = input_dev;
return 0; return 0;
} }
int pcspkr_input_remove(struct input_dev *dev)
{
pcspkr_stop_sound();
input_unregister_device(dev); /* this also does kfree() */
return 0;
}
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#define __PCSP_INPUT_H__ #define __PCSP_INPUT_H__
int pcspkr_input_init(struct input_dev **rdev, struct device *dev); int pcspkr_input_init(struct input_dev **rdev, struct device *dev);
int pcspkr_input_remove(struct input_dev *dev);
void pcspkr_stop_sound(void); void pcspkr_stop_sound(void);
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment