mirror of
https://github.com/torvalds/linux.git
synced 2024-11-21 19:41:42 +00:00
ALSA: hwdep: Don't embed device
Like control and PCM devices, it's better to avoid the embedded struct device for hwdep (although it's more or less well working), too. Change it to allocate via snd_device_alloc(), and free the memory at the common snd_hwdep_free(). Reviewed-by: Jaroslav Kysela <perex@perex.cz> Signed-off-by: Curtis Malainey <cujomalainey@chromium.org> Tested-by: Curtis Malainey <cujomalainey@chromium.org> Link: https://lore.kernel.org/r/20230816160252.23396-5-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
bc41a7228c
commit
897c8882df
@ -53,7 +53,7 @@ struct snd_hwdep {
|
|||||||
wait_queue_head_t open_wait;
|
wait_queue_head_t open_wait;
|
||||||
void *private_data;
|
void *private_data;
|
||||||
void (*private_free) (struct snd_hwdep *hwdep);
|
void (*private_free) (struct snd_hwdep *hwdep);
|
||||||
struct device dev;
|
struct device *dev;
|
||||||
|
|
||||||
struct mutex open_mutex;
|
struct mutex open_mutex;
|
||||||
int used; /* reference counter */
|
int used; /* reference counter */
|
||||||
|
@ -338,9 +338,14 @@ static const struct file_operations snd_hwdep_f_ops =
|
|||||||
.mmap = snd_hwdep_mmap,
|
.mmap = snd_hwdep_mmap,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void release_hwdep_device(struct device *dev)
|
static void snd_hwdep_free(struct snd_hwdep *hwdep)
|
||||||
{
|
{
|
||||||
kfree(container_of(dev, struct snd_hwdep, dev));
|
if (!hwdep)
|
||||||
|
return;
|
||||||
|
if (hwdep->private_free)
|
||||||
|
hwdep->private_free(hwdep);
|
||||||
|
put_device(hwdep->dev);
|
||||||
|
kfree(hwdep);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -382,16 +387,20 @@ int snd_hwdep_new(struct snd_card *card, char *id, int device,
|
|||||||
if (id)
|
if (id)
|
||||||
strscpy(hwdep->id, id, sizeof(hwdep->id));
|
strscpy(hwdep->id, id, sizeof(hwdep->id));
|
||||||
|
|
||||||
snd_device_initialize(&hwdep->dev, card);
|
err = snd_device_alloc(&hwdep->dev, card);
|
||||||
hwdep->dev.release = release_hwdep_device;
|
if (err < 0) {
|
||||||
dev_set_name(&hwdep->dev, "hwC%iD%i", card->number, device);
|
snd_hwdep_free(hwdep);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
dev_set_name(hwdep->dev, "hwC%iD%i", card->number, device);
|
||||||
#ifdef CONFIG_SND_OSSEMUL
|
#ifdef CONFIG_SND_OSSEMUL
|
||||||
hwdep->oss_type = -1;
|
hwdep->oss_type = -1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
err = snd_device_new(card, SNDRV_DEV_HWDEP, hwdep, &ops);
|
err = snd_device_new(card, SNDRV_DEV_HWDEP, hwdep, &ops);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
put_device(&hwdep->dev);
|
snd_hwdep_free(hwdep);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -403,12 +412,7 @@ EXPORT_SYMBOL(snd_hwdep_new);
|
|||||||
|
|
||||||
static int snd_hwdep_dev_free(struct snd_device *device)
|
static int snd_hwdep_dev_free(struct snd_device *device)
|
||||||
{
|
{
|
||||||
struct snd_hwdep *hwdep = device->device_data;
|
snd_hwdep_free(device->device_data);
|
||||||
if (!hwdep)
|
|
||||||
return 0;
|
|
||||||
if (hwdep->private_free)
|
|
||||||
hwdep->private_free(hwdep);
|
|
||||||
put_device(&hwdep->dev);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -426,9 +430,9 @@ static int snd_hwdep_dev_register(struct snd_device *device)
|
|||||||
list_add_tail(&hwdep->list, &snd_hwdep_devices);
|
list_add_tail(&hwdep->list, &snd_hwdep_devices);
|
||||||
err = snd_register_device(SNDRV_DEVICE_TYPE_HWDEP,
|
err = snd_register_device(SNDRV_DEVICE_TYPE_HWDEP,
|
||||||
hwdep->card, hwdep->device,
|
hwdep->card, hwdep->device,
|
||||||
&snd_hwdep_f_ops, hwdep, &hwdep->dev);
|
&snd_hwdep_f_ops, hwdep, hwdep->dev);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
dev_err(&hwdep->dev, "unable to register\n");
|
dev_err(hwdep->dev, "unable to register\n");
|
||||||
list_del(&hwdep->list);
|
list_del(&hwdep->list);
|
||||||
mutex_unlock(®ister_mutex);
|
mutex_unlock(®ister_mutex);
|
||||||
return err;
|
return err;
|
||||||
@ -439,12 +443,12 @@ static int snd_hwdep_dev_register(struct snd_device *device)
|
|||||||
if (hwdep->oss_type >= 0) {
|
if (hwdep->oss_type >= 0) {
|
||||||
if (hwdep->oss_type == SNDRV_OSS_DEVICE_TYPE_DMFM &&
|
if (hwdep->oss_type == SNDRV_OSS_DEVICE_TYPE_DMFM &&
|
||||||
hwdep->device)
|
hwdep->device)
|
||||||
dev_warn(&hwdep->dev,
|
dev_warn(hwdep->dev,
|
||||||
"only hwdep device 0 can be registered as OSS direct FM device!\n");
|
"only hwdep device 0 can be registered as OSS direct FM device!\n");
|
||||||
else if (snd_register_oss_device(hwdep->oss_type,
|
else if (snd_register_oss_device(hwdep->oss_type,
|
||||||
card, hwdep->device,
|
card, hwdep->device,
|
||||||
&snd_hwdep_f_ops, hwdep) < 0)
|
&snd_hwdep_f_ops, hwdep) < 0)
|
||||||
dev_warn(&hwdep->dev,
|
dev_warn(hwdep->dev,
|
||||||
"unable to register OSS compatibility device\n");
|
"unable to register OSS compatibility device\n");
|
||||||
else
|
else
|
||||||
hwdep->ossreg = 1;
|
hwdep->ossreg = 1;
|
||||||
@ -471,7 +475,7 @@ static int snd_hwdep_dev_disconnect(struct snd_device *device)
|
|||||||
if (hwdep->ossreg)
|
if (hwdep->ossreg)
|
||||||
snd_unregister_oss_device(hwdep->oss_type, hwdep->card, hwdep->device);
|
snd_unregister_oss_device(hwdep->oss_type, hwdep->card, hwdep->device);
|
||||||
#endif
|
#endif
|
||||||
snd_unregister_device(&hwdep->dev);
|
snd_unregister_device(hwdep->dev);
|
||||||
list_del_init(&hwdep->list);
|
list_del_init(&hwdep->list);
|
||||||
mutex_unlock(&hwdep->open_mutex);
|
mutex_unlock(&hwdep->open_mutex);
|
||||||
mutex_unlock(®ister_mutex);
|
mutex_unlock(®ister_mutex);
|
||||||
|
@ -114,8 +114,8 @@ int snd_hda_create_hwdep(struct hda_codec *codec)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* for sysfs */
|
/* for sysfs */
|
||||||
hwdep->dev.groups = snd_hda_dev_attr_groups;
|
hwdep->dev->groups = snd_hda_dev_attr_groups;
|
||||||
dev_set_drvdata(&hwdep->dev, codec);
|
dev_set_drvdata(hwdep->dev, codec);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user