ALSA: Yet more cleanups for procfs
cover ALSA: Yet more cleanups for procfs
Hi,
this is the last part of my procfs cleanup patches. These are merely cleanups, no functional changes are expected.
The whole patches are found in topic/proc-fixes in sound git tree.
thanks,
Takashi
===
Takashi Iwai (4):
ALSA: info: Drop unused snd_info_entry.card field
ALSA: info: Minor optimization
ALSA: info: Move card id proc creation into info.c
ALSA: cs46xx: Clean up proc file creations
include/sound/core.h | 1 - include/sound/info.h | 1 - sound/core/info.c | 36 +++++++-------- sound/core/init.c | 31 ++----------- sound/pci/cs46xx/cs46xx_dsp_spos.h | 6 --- sound/pci/cs46xx/dsp_spos.c | 87 ++++++++++++------------------------- sound/pci/cs46xx/dsp_spos_scb_lib.c | 13 +++--- 7 files changed, 55 insertions(+), 120 deletions(-)
Signature · 1 line
2.16.4
PATCH 1/4 ALSA: info: Drop unused snd_info_entry.card field
It's referred only in snd_card_id_read() which can receive the card object via private_data.
--- include/sound/info.h | 1 - sound/core/info.c | 4 +--- sound/core/init.c | 6 ++++-- 3 files changed, 5 insertions(+), 6 deletions(-)
include/sound/info.h +0 -1
@@ -82,7 +82,6 @@ struct snd_info_entry {struct snd_info_entry_ops *ops; } c;struct snd_info_entry *parent; -struct snd_card *card;struct module *module;void *private_data;void (*private_free)(struct snd_info_entry *entry);
sound/core/info.c +1 -3
@@ -750,10 +750,8 @@ struct snd_info_entry *snd_info_create_card_entry(struct snd_card *card,if (!parent) parent = card->proc_root; entry =snd_info_create_entry (name, parent); -if (entry) { +if (entry) entry->module = card->module; - entry->card = card; - }return entry; }EXPORT_SYMBOL (snd_info_create_card_entry);
sound/core/init.c +4 -2
@@ -104,7 +104,9 @@ EXPORT_SYMBOL(snd_mixer_oss_notify_callback);static void snd_card_id_read (struct snd_info_entry *entry,struct snd_info_buffer *buffer) { -snd_iprintf (buffer,"%s\n" , entry->card->id); +struct snd_card *card = entry->private_data; + +snd_iprintf (buffer,"%s\n" , card->id); }static int init_info_for_card (struct snd_card *card)
@@ -116,7 +118,7 @@ static int init_info_for_card(struct snd_card *card)dev_dbg (card->dev,"unable to create card entry\n" );return -ENOMEM ; } - entry->c.text.read = snd_card_id_read; +snd_info_set_text_ops (entry, card, snd_card_id_read); card->proc_id = entry;return snd_info_card_register (card);
Signature · 1 line
2.16.4
PATCH 2/4 ALSA: info: Minor optimization
In reply to Takashi IwaiJust a minor code optimization to reduce the source code size slightly. No functional changes.
--- sound/core/info.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-)
sound/core/info.c +8 -15
@@ -463,11 +463,12 @@ static struct snd_info_entry *create_subdir(struct module *mod, }static struct snd_info_entry * -snd_info_create_entry (const char *name,struct snd_info_entry *parent); +snd_info_create_entry (const char *name,struct snd_info_entry *parent, +struct module *module);int __init snd_info_init (void ) { - snd_proc_root =snd_info_create_entry ("asound" ,NULL ); + snd_proc_root =snd_info_create_entry ("asound" ,NULL ,THIS_MODULE );if (!snd_proc_root)return -ENOMEM ; snd_proc_root->mode =S_IFDIR |0555 ;
@@ -684,7 +685,8 @@ EXPORT_SYMBOL(snd_info_get_str);* Return: The pointer of the new instance, or %NULL on failure. */ static struct snd_info_entry * -snd_info_create_entry (const char *name,struct snd_info_entry *parent) +snd_info_create_entry (const char *name,struct snd_info_entry *parent, +struct module *module) {struct snd_info_entry *entry; entry =kzalloc (sizeof (*entry),GFP_KERNEL );
@@ -701,6 +703,7 @@ snd_info_create_entry(const char *name, struct snd_info_entry *parent)INIT_LIST_HEAD (&entry->children);INIT_LIST_HEAD (&entry->list); entry->parent = parent; + entry->module = module;if (parent)list_add_tail (&entry->list, &parent->children);return entry;
@@ -720,14 +723,9 @@ struct snd_info_entry *snd_info_create_module_entry(struct module * module,const char *name, struct snd_info_entry *parent) { - struct snd_info_entry *entry; - if (!parent) parent = snd_proc_root; - entry =snd_info_create_entry (name, parent); -if (entry) - entry->module = module; -return entry; +return snd_info_create_entry (name, parent, module); }EXPORT_SYMBOL (snd_info_create_module_entry);
@@ -745,14 +743,9 @@ struct snd_info_entry *snd_info_create_card_entry(struct snd_card *card,const char *name, struct snd_info_entry * parent) { - struct snd_info_entry *entry; - if (!parent) parent = card->proc_root; - entry =snd_info_create_entry (name, parent); -if (entry) - entry->module = card->module; -return entry; +return snd_info_create_entry (name, parent, card->module); }EXPORT_SYMBOL (snd_info_create_card_entry);
Signature · 1 line
2.16.4
Jaroslav Kysela
maintainerRe: [PATCH 2/4] ALSA: info: Minor optimization
Dne 5.2.2019 v 17:07 Takashi Iwai napsal(a):
Quoted 66 lines
Just a minor code optimization to reduce the source code size slightly. No functional changes.
Signed-off-by Takashi Iwai <[email protected]>--- sound/core/info.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-)sound/core/info.c +7
-10@@ -463,11 +463,12 @@ static struct snd_info_entry *create_subdir(struct module *mod, }static struct snd_info_entry * -snd_info_create_entry (const char *name,struct snd_info_entry *parent); +snd_info_create_entry (const char *name,struct snd_info_entry *parent, +struct module *module);int __init snd_info_init (void ) { - snd_proc_root =snd_info_create_entry ("asound" ,NULL ); + snd_proc_root =snd_info_create_entry ("asound" ,NULL ,THIS_MODULE );if (!snd_proc_root)return -ENOMEM ; snd_proc_root->mode =S_IFDIR |0555 ;@@ -684,7 +685,8 @@ EXPORT_SYMBOL(snd_info_get_str);* Return: The pointer of the new instance, or %NULL on failure. */ static struct snd_info_entry * -snd_info_create_entry (const char *name,struct snd_info_entry *parent) +snd_info_create_entry (const char *name,struct snd_info_entry *parent, +struct module *module) {struct snd_info_entry *entry; entry =kzalloc (sizeof (*entry),GFP_KERNEL );@@ -701,6 +703,7 @@ snd_info_create_entry(const char *name, struct snd_info_entry *parent)INIT_LIST_HEAD (&entry->children);INIT_LIST_HEAD (&entry->list); entry->parent = parent; + entry->module = module;if (parent)list_add_tail (&entry->list, &parent->children);return entry;@@ -720,14 +723,9 @@ struct snd_info_entry *snd_info_create_module_entry(struct module * module,const char *name, struct snd_info_entry *parent) { - struct snd_info_entry *entry; - if (!parent) parent = snd_proc_root; - entry =snd_info_create_entry (name, parent); -if (entry) - entry->module = module; -return entry; +return snd_info_create_entry (name, parent, module); }EXPORT_SYMBOL (snd_info_create_module_entry);@@ -745,14 +743,9 @@ struct snd_info_entry *snd_info_create_card_entry(struct snd_card *card,const char *name, struct snd_info_entry * parent) { - struct snd_info_entry *entry;
sound/core/info.c struct snd_info_entry *snd_info_create_card_entry(struct snd_card *card, · line 750
Quoted 10 lines
sound/core/info.c +1
-5-if (!parent) parent = card->proc_root; - entry =snd_info_create_entry (name, parent); -if (entry) - entry->module = card->module; -return entry; +return snd_info_create_entry (name, parent, card->module); }EXPORT_SYMBOL (snd_info_create_card_entry);
Won't be better to define those two above functions as inline now?
For rest: Reviewed-by: Jaroslav Kysela <[email protected]>
Thanks,
Jaroslav
Signature · 2 lines
Jaroslav Kysela <[email protected]> Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
Re: [PATCH 2/4] ALSA: info: Minor optimization
Quoted 72 lines · Jaroslav Kysela
Dne 5.2.2019 v 17:07 Takashi Iwai napsal(a):
Quoted 70 lines
Just a minor code optimization to reduce the source code size slightly. No functional changes.
Signed-off-by Takashi Iwai <[email protected]>--- sound/core/info.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-)sound/core/info.c +7
-12@@ -463,11 +463,12 @@ static struct snd_info_entry *create_subdir(struct module *mod, }static struct snd_info_entry * -snd_info_create_entry (const char *name,struct snd_info_entry *parent); +snd_info_create_entry (const char *name,struct snd_info_entry *parent, +struct module *module);int __init snd_info_init (void ) { - snd_proc_root =snd_info_create_entry ("asound" ,NULL ); + snd_proc_root =snd_info_create_entry ("asound" ,NULL ,THIS_MODULE );if (!snd_proc_root)return -ENOMEM ; snd_proc_root->mode =S_IFDIR |0555 ;@@ -684,7 +685,8 @@ EXPORT_SYMBOL(snd_info_get_str);* Return: The pointer of the new instance, or %NULL on failure. */ static struct snd_info_entry * -snd_info_create_entry (const char *name,struct snd_info_entry *parent) +snd_info_create_entry (const char *name,struct snd_info_entry *parent, +struct module *module) {struct snd_info_entry *entry; entry =kzalloc (sizeof (*entry),GFP_KERNEL );@@ -701,6 +703,7 @@ snd_info_create_entry(const char *name, struct snd_info_entry *parent)INIT_LIST_HEAD (&entry->children);INIT_LIST_HEAD (&entry->list); entry->parent = parent; + entry->module = module;if (parent)list_add_tail (&entry->list, &parent->children);return entry;@@ -720,14 +723,9 @@ struct snd_info_entry *snd_info_create_module_entry(struct module * module,const char *name, struct snd_info_entry *parent) { - struct snd_info_entry *entry; - if (!parent) parent = snd_proc_root; - entry =snd_info_create_entry (name, parent); -if (entry) - entry->module = module; -return entry; +return snd_info_create_entry (name, parent, module); }EXPORT_SYMBOL (snd_info_create_module_entry);@@ -745,14 +743,9 @@ struct snd_info_entry *snd_info_create_card_entry(struct snd_card *card,const char *name, struct snd_info_entry * parent) { - struct snd_info_entry *entry; - if (!parent) parent = card->proc_root; - entry =snd_info_create_entry (name, parent);
Quoted 8 lines
sound/core/info.c struct snd_info_entry *snd_info_create_card_entry(struct snd_card *card, · line 750
Quoted 6 lines
sound/core/info.c +1
-3-if (entry) - entry->module = card->module; -return entry; +return snd_info_create_entry (name, parent, card->module); }EXPORT_SYMBOL (snd_info_create_card_entry);Won't be better to define those two above functions as inline now?
That's possible, but then we'd need to export snd_proc_root. Also snd_info_create_entry() is a local function right now, so we'll need to export this one, too. Overall, there won't be any big gain, I guess.
thanks,
Takashi
Quoted 10 lines
For rest: Reviewed-by: Jaroslav Kysela <[email protected]>
Thanks,
JaroslavSignature · 2 lines
Jaroslav Kysela <[email protected]> Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
PATCH 3/4 ALSA: info: Move card id proc creation into info.c
In reply to Takashi IwaiThe creation of card's id proc file can be moved gracefully into info.c. Also, the assignment of card->proc_id is superfluous and can be dropped. So let's do it.
Basically this is no functional change but code refactoring, but one potential behavior change is that now it returns properly the error code from snd_info_card_register().
--- include/sound/core.h | 1 - sound/core/info.c | 11 ++++++++++- sound/core/init.c | 33 ++++----------------------------- 3 files changed, 14 insertions(+), 31 deletions(-)
include/sound/core.h +0 -1
@@ -120,7 +120,6 @@ struct snd_card {struct list_head ctl_files;/* active control files */ struct snd_info_entry *proc_root;/* root for soundcard specific files */ -struct snd_info_entry *proc_id;/* the card id */ struct proc_dir_entry *proc_root_link;/* number link to real id */ struct list_head files_list;/* all files associated to this card */
sound/core/info.c +10 -1
@@ -504,6 +504,14 @@ int __exit snd_info_done(void)return 0 ; } +static void snd_card_id_read (struct snd_info_entry *entry, +struct snd_info_buffer *buffer) +{ +struct snd_card *card = entry->private_data; + +snd_iprintf (buffer,"%s\n" , card->id); +} +/* * create a card proc file * called from init.c
@@ -521,7 +529,8 @@ int snd_info_card_create(struct snd_card *card)if (!entry)return -ENOMEM ; card->proc_root = entry; -return 0 ; + +return snd_card_ro_proc_new (card,"id" , card, snd_card_id_read); }/*
sound/core/init.c +4 -29
@@ -100,33 +100,6 @@ int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int free_flag);EXPORT_SYMBOL (snd_mixer_oss_notify_callback);#endif -#ifdef CONFIG_SND_PROC_FS -static void snd_card_id_read (struct snd_info_entry *entry, -struct snd_info_buffer *buffer) -{ -struct snd_card *card = entry->private_data; - -snd_iprintf (buffer,"%s\n" , card->id); -} - -static int init_info_for_card (struct snd_card *card) -{ -struct snd_info_entry *entry; - - entry =snd_info_create_card_entry (card,"id" , card->proc_root); -if (!entry) { -dev_dbg (card->dev,"unable to create card entry\n" ); -return -ENOMEM ; - } -snd_info_set_text_ops (entry, card, snd_card_id_read); - card->proc_id = entry; - -return snd_info_card_register (card); -} -#else /* !CONFIG_SND_PROC_FS */ -#define init_info_for_card (card) -#endif -static int check_empty_slot (struct module *module,int slot) {return !slots[slot] || !*slots[slot];
@@ -493,7 +466,6 @@ static int snd_card_do_free(struct snd_card *card)snd_device_free_all (card);if (card->private_free) card->private_free (card); -snd_info_free_entry (card->proc_id);if (snd_info_card_free (card) <0 ) {dev_warn (card->dev,"unable to free card info\n" );/* Not fatal error */
@@ -797,7 +769,10 @@ int snd_card_register(struct snd_card *card) } snd_cards[card->number] = card;mutex_unlock (&snd_card_mutex); -init_info_for_card (card); + err =snd_info_card_register (card); +if (err <0 ) +return err; +#if IS_ENABLED (CONFIG_SND_MIXER_OSS )if (snd_mixer_oss_notify_callback)snd_mixer_oss_notify_callback (card,SND_MIXER_OSS_NOTIFY_REGISTER );
Signature · 1 line
2.16.4
PATCH 4/4 ALSA: cs46xx: Clean up proc file creations
In reply to Takashi IwaiAgain no functional changes, but only code clean up.
Use a standard macro for initializing the procfs entries, also drop the info entries stored in dsp_spos_instance, as they are removed recursively by a single snd_info_free_entry() calls.
--- sound/pci/cs46xx/cs46xx_dsp_spos.h | 6 --- sound/pci/cs46xx/dsp_spos.c | 87 ++++++++++++------------------------- sound/pci/cs46xx/dsp_spos_scb_lib.c | 13 +++--- 3 files changed, 33 insertions(+), 73 deletions(-)
sound/pci/cs46xx/cs46xx_dsp_spos.h +0 -6
@@ -177,22 +177,16 @@ struct dsp_spos_instance {/* proc fs */ struct snd_card *snd_card;struct snd_info_entry * proc_dsp_dir; -struct snd_info_entry * proc_sym_info_entry; -struct snd_info_entry * proc_modules_info_entry; -struct snd_info_entry * proc_parameter_dump_info_entry; -struct snd_info_entry * proc_sample_dump_info_entry;/* SCB's descriptors */ int nscb;int scb_highest_frag_index;struct dsp_scb_descriptor scbs[DSP_MAX_SCB_DESC ]; -struct snd_info_entry * proc_scb_info_entry;struct dsp_scb_descriptor * the_null_scb;/* Task's descriptors */ int ntask;struct dsp_task_descriptor tasks[DSP_MAX_TASK_DESC ]; -struct snd_info_entry * proc_task_info_entry;/* SPDIF status */ int spdif_status_out;
sound/pci/cs46xx/dsp_spos.c +28 -59
104 lines not on this page · raw message
sound/pci/cs46xx/dsp_spos_scb_lib.c +5 -8
@@ -254,8 +254,9 @@ void cs46xx_dsp_proc_register_scb_desc (struct snd_cs46xx *chip,if (ins->snd_card !=NULL && ins->proc_dsp_dir !=NULL && scb->proc_info ==NULL ) { -if ((entry =snd_info_create_card_entry (ins->snd_card, scb->scb_name, - ins->proc_dsp_dir)) !=NULL ) { + entry =snd_info_create_card_entry (ins->snd_card, scb->scb_name, + ins->proc_dsp_dir); +if (entry) { scb_info =kmalloc (sizeof (struct proc_scb_info ),GFP_KERNEL );if (!scb_info) {snd_info_free_entry (entry);
@@ -265,12 +266,8 @@ void cs46xx_dsp_proc_register_scb_desc (struct snd_cs46xx *chip, scb_info->chip = chip; scb_info->scb_desc = scb; - - entry->content =SNDRV_INFO_CONTENT_TEXT ; - entry->private_data = scb_info; - entry->mode =S_IFREG |0644 ; - - entry->c.text.read = cs46xx_dsp_proc_scb_info_read; +snd_info_set_text_ops (entry, scb_info, + cs46xx_dsp_proc_scb_info_read); } out: scb->proc_info = entry;
Signature · 1 line
2.16.4