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.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
ed16a22b09
commit
3a1e341c56
@ -42,9 +42,8 @@ struct snd_pcsp pcsp_chip;
|
||||
|
||||
static int snd_pcsp_create(struct snd_card *card)
|
||||
{
|
||||
static const struct snd_device_ops ops = { };
|
||||
unsigned int resolution = hrtimer_resolution;
|
||||
int err, div, min_div, order;
|
||||
int div, min_div, order;
|
||||
|
||||
if (!nopcm) {
|
||||
if (resolution > PCSP_MAX_PERIOD_NS) {
|
||||
@ -83,15 +82,18 @@ static int snd_pcsp_create(struct snd_card *card)
|
||||
pcsp_chip.port = 0x61;
|
||||
pcsp_chip.irq = -1;
|
||||
pcsp_chip.dma = -1;
|
||||
|
||||
/* Register device */
|
||||
err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, &pcsp_chip, &ops);
|
||||
if (err < 0)
|
||||
return err;
|
||||
card->private_data = &pcsp_chip;
|
||||
|
||||
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)
|
||||
{
|
||||
struct snd_card *card;
|
||||
@ -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);
|
||||
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)
|
||||
return err;
|
||||
|
||||
err = snd_pcsp_create(card);
|
||||
if (err < 0)
|
||||
goto free_card;
|
||||
return err;
|
||||
|
||||
if (!nopcm) {
|
||||
err = snd_pcsp_new_pcm(&pcsp_chip);
|
||||
if (err < 0)
|
||||
goto free_card;
|
||||
return err;
|
||||
}
|
||||
err = snd_pcsp_new_mixer(&pcsp_chip, nopcm);
|
||||
if (err < 0)
|
||||
goto free_card;
|
||||
return err;
|
||||
|
||||
strcpy(card->driver, "PC-Speaker");
|
||||
strcpy(card->shortname, "pcsp");
|
||||
@ -127,13 +129,10 @@ static int snd_card_pcsp_probe(int devnum, struct device *dev)
|
||||
|
||||
err = snd_card_register(card);
|
||||
if (err < 0)
|
||||
goto free_card;
|
||||
return err;
|
||||
card->private_free = alsa_card_pcsp_free;
|
||||
|
||||
return 0;
|
||||
|
||||
free_card:
|
||||
snd_card_free(card);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int alsa_card_pcsp_init(struct device *dev)
|
||||
@ -155,11 +154,6 @@ static int alsa_card_pcsp_init(struct device *dev)
|
||||
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)
|
||||
{
|
||||
int err;
|
||||
@ -169,23 +163,13 @@ static int pcsp_probe(struct platform_device *dev)
|
||||
return err;
|
||||
|
||||
err = alsa_card_pcsp_init(&dev->dev);
|
||||
if (err < 0) {
|
||||
pcspkr_input_remove(pcsp_chip.input_dev);
|
||||
if (err < 0)
|
||||
return err;
|
||||
}
|
||||
|
||||
platform_set_drvdata(dev, &pcsp_chip);
|
||||
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)
|
||||
{
|
||||
pcsp_sync_stop(chip);
|
||||
@ -218,7 +202,6 @@ static struct platform_driver pcsp_platform_driver = {
|
||||
.pm = PCSP_PM_OPS,
|
||||
},
|
||||
.probe = pcsp_probe,
|
||||
.remove = pcsp_remove,
|
||||
.shutdown = pcsp_shutdown,
|
||||
};
|
||||
|
||||
|
@ -78,7 +78,7 @@ int pcspkr_input_init(struct input_dev **rdev, struct device *dev)
|
||||
{
|
||||
int err;
|
||||
|
||||
struct input_dev *input_dev = input_allocate_device();
|
||||
struct input_dev *input_dev = devm_input_allocate_device(dev);
|
||||
if (!input_dev)
|
||||
return -ENOMEM;
|
||||
|
||||
@ -95,19 +95,9 @@ int pcspkr_input_init(struct input_dev **rdev, struct device *dev)
|
||||
input_dev->event = pcspkr_input_event;
|
||||
|
||||
err = input_register_device(input_dev);
|
||||
if (err) {
|
||||
input_free_device(input_dev);
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
|
||||
*rdev = input_dev;
|
||||
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 @@
|
||||
#define __PCSP_INPUT_H__
|
||||
|
||||
int pcspkr_input_init(struct input_dev **rdev, struct device *dev);
|
||||
int pcspkr_input_remove(struct input_dev *dev);
|
||||
void pcspkr_stop_sound(void);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user