Skip to content

Commit c560a67

Browse files
committed
ALSA: core: Remove child proc file elements recursively
This patch changes the way to manage the resource release of proc files: namely, let snd_info_free_entry() freeing the whole children. This makes it us possible to drop the snd_device_*() management. Then snd_card_proc_new() becomes merely a wrapper to snd_info_create_card_entry(). Together with this change, now you need to call snd_info_free_entry() for a proc entry created via snd_card_proc_new(), while it was freed via snd_device_free() beforehand. Acked-by: Jaroslav Kysela <perex@perex.cz> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 886364f commit c560a67

3 files changed

Lines changed: 21 additions & 69 deletions

File tree

‎include/sound/info.h‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include <linux/poll.h>
2626
#include <linux/seq_file.h>
27+
#include <sound/core.h>
2728

2829
/* buffer for information */
2930
struct snd_info_buffer {
@@ -146,8 +147,12 @@ void snd_info_card_id_change(struct snd_card *card);
146147
int snd_info_register(struct snd_info_entry *entry);
147148

148149
/* for card drivers */
149-
int snd_card_proc_new(struct snd_card *card, const char *name,
150-
struct snd_info_entry **entryp);
150+
static inline int snd_card_proc_new(struct snd_card *card, const char *name,
151+
struct snd_info_entry **entryp)
152+
{
153+
*entryp = snd_info_create_card_entry(card, name, card->proc_root);
154+
return *entryp ? 0 : -ENOMEM;
155+
}
151156

152157
static inline void snd_info_set_text_ops(struct snd_info_entry *entry,
153158
void *private_data,

‎sound/core/info.c‎

Lines changed: 13 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -760,92 +760,39 @@ EXPORT_SYMBOL(snd_info_create_card_entry);
760760

761761
static void snd_info_disconnect(struct snd_info_entry *entry)
762762
{
763-
struct list_head *p, *n;
763+
struct snd_info_entry *p, *n;
764764

765-
list_for_each_safe(p, n, &entry->children) {
766-
snd_info_disconnect(list_entry(p, struct snd_info_entry, list));
767-
}
768-
769-
if (! entry->p)
765+
if (!entry->p)
770766
return;
767+
list_for_each_entry_safe(p, n, &entry->children, list)
768+
snd_info_disconnect(p);
771769
list_del_init(&entry->list);
772770
proc_remove(entry->p);
773771
entry->p = NULL;
774772
}
775773

776-
static int snd_info_dev_free_entry(struct snd_device *device)
777-
{
778-
struct snd_info_entry *entry = device->device_data;
779-
snd_info_free_entry(entry);
780-
return 0;
781-
}
782-
783-
static int snd_info_dev_register_entry(struct snd_device *device)
784-
{
785-
struct snd_info_entry *entry = device->device_data;
786-
return snd_info_register(entry);
787-
}
788-
789-
/**
790-
* snd_card_proc_new - create an info entry for the given card
791-
* @card: the card instance
792-
* @name: the file name
793-
* @entryp: the pointer to store the new info entry
794-
*
795-
* Creates a new info entry and assigns it to the given card.
796-
* Unlike snd_info_create_card_entry(), this function registers the
797-
* info entry as an ALSA device component, so that it can be
798-
* unregistered/released without explicit call.
799-
* Also, you don't have to register this entry via snd_info_register(),
800-
* since this will be registered by snd_card_register() automatically.
801-
*
802-
* The parent is assumed as card->proc_root.
803-
*
804-
* For releasing this entry, use snd_device_free() instead of
805-
* snd_info_free_entry().
806-
*
807-
* Return: Zero if successful, or a negative error code on failure.
808-
*/
809-
int snd_card_proc_new(struct snd_card *card, const char *name,
810-
struct snd_info_entry **entryp)
811-
{
812-
static struct snd_device_ops ops = {
813-
.dev_free = snd_info_dev_free_entry,
814-
.dev_register = snd_info_dev_register_entry,
815-
/* disconnect is done via snd_info_card_disconnect() */
816-
};
817-
struct snd_info_entry *entry;
818-
int err;
819-
820-
entry = snd_info_create_card_entry(card, name, card->proc_root);
821-
if (! entry)
822-
return -ENOMEM;
823-
if ((err = snd_device_new(card, SNDRV_DEV_INFO, entry, &ops)) < 0) {
824-
snd_info_free_entry(entry);
825-
return err;
826-
}
827-
if (entryp)
828-
*entryp = entry;
829-
return 0;
830-
}
831-
832-
EXPORT_SYMBOL(snd_card_proc_new);
833-
834774
/**
835775
* snd_info_free_entry - release the info entry
836776
* @entry: the info entry
837777
*
838-
* Releases the info entry. Don't call this after registered.
778+
* Releases the info entry.
839779
*/
840780
void snd_info_free_entry(struct snd_info_entry * entry)
841781
{
842-
if (entry == NULL)
782+
struct snd_info_entry *p, *n;
783+
784+
if (!entry)
843785
return;
844786
if (entry->p) {
845787
mutex_lock(&info_mutex);
846788
snd_info_disconnect(entry);
847789
mutex_unlock(&info_mutex);
848790
}
791+
792+
/* free all children at first */
793+
list_for_each_entry_safe(p, n, &entry->children, list)
794+
snd_info_free_entry(p);
795+
849796
kfree(entry->name);
850797
if (entry->private_free)
851798
entry->private_free(entry);

‎sound/pci/hda/patch_hdmi.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ static int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index)
592592
static void eld_proc_free(struct hdmi_spec_per_pin *per_pin)
593593
{
594594
if (!per_pin->codec->bus->shutdown && per_pin->proc_entry) {
595-
snd_device_free(per_pin->codec->card, per_pin->proc_entry);
595+
snd_info_free_entry(per_pin->proc_entry);
596596
per_pin->proc_entry = NULL;
597597
}
598598
}

0 commit comments

Comments
 (0)