Skip to content

Commit 35bc3ef

Browse files
Uwe Kleine-Königtiwai
authored andcommitted
ALSA: pcmtest: Don't use static storage to track per device data
While there is probably only ever a single instance of such a pcmtst device, it's still bad style to use a static variable to store per device data. Make use of platform_get_drvdata() and platform_set_drvdata() which fixes a data corruption if there should be two or more such devices (or this driver is used as a template for another driver). Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Acked-by: Ivan Orlov <ivan.orlov0322@gmail.com> Link: https://lore.kernel.org/r/20230707075058.3402832-2-u.kleine-koenig@pengutronix.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent cb2bffd commit 35bc3ef

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

sound/drivers/pcmtest.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ struct pcmtst_buf_iter {
110110
struct timer_list timer_instance;
111111
};
112112

113-
static struct pcmtst *pcmtst;
114-
115113
static struct snd_pcm_hardware snd_pcmtst_hw = {
116114
.info = (SNDRV_PCM_INFO_INTERLEAVED |
117115
SNDRV_PCM_INFO_BLOCK_TRANSFER |
@@ -552,6 +550,7 @@ static int snd_pcmtst_create(struct snd_card *card, struct platform_device *pdev
552550
static int pcmtst_probe(struct platform_device *pdev)
553551
{
554552
struct snd_card *card;
553+
struct pcmtst *pcmtst;
555554
int err;
556555

557556
err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
@@ -573,11 +572,15 @@ static int pcmtst_probe(struct platform_device *pdev)
573572
if (err < 0)
574573
return err;
575574

575+
platform_set_drvdata(pdev, pcmtst);
576+
576577
return 0;
577578
}
578579

579-
static void pdev_remove(struct platform_device *dev)
580+
static void pdev_remove(struct platform_device *pdev)
580581
{
582+
struct pcmtst *pcmtst = platform_get_drvdata(pdev);
583+
581584
snd_pcmtst_free(pcmtst);
582585
}
583586

0 commit comments

Comments
 (0)