Skip to content

Commit b591b6e

Browse files
committed
ALSA: core: Don't ignore errors at creating proc files
So far we've ignored the errors at creating proc files in many places. But they should be rather treated seriously. Also, by assuring the error handling, we can get rid of superfluous snd_info_free_entry() calls as they will be removed by the parent in the caller side. This patch fixes the missing error checks and reduces the superfluous free calls. Acked-by: Jaroslav Kysela <perex@perex.cz> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent b046d24 commit b591b6e

5 files changed

Lines changed: 35 additions & 35 deletions

File tree

‎sound/core/info.c‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,11 @@ int __init snd_info_init(void)
482482
if (!snd_seq_root)
483483
goto error;
484484
#endif
485-
snd_info_version_init();
486-
snd_minor_info_init();
487-
snd_minor_info_oss_init();
488-
snd_card_info_init();
485+
if (snd_info_version_init() < 0 ||
486+
snd_minor_info_init() < 0 ||
487+
snd_minor_info_oss_init() < 0 ||
488+
snd_card_info_init() < 0)
489+
goto error;
489490
return 0;
490491

491492
error:
@@ -847,11 +848,7 @@ static int __init snd_info_version_init(void)
847848
if (entry == NULL)
848849
return -ENOMEM;
849850
entry->c.text.read = snd_info_version_read;
850-
if (snd_info_register(entry) < 0) {
851-
snd_info_free_entry(entry);
852-
return -ENOMEM;
853-
}
854-
return 0;
851+
return snd_info_register(entry); /* freed in error path */
855852
}
856853

857854
#endif /* CONFIG_PROC_FS */

‎sound/core/init.c‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -853,18 +853,16 @@ int __init snd_card_info_init(void)
853853
if (! entry)
854854
return -ENOMEM;
855855
entry->c.text.read = snd_card_info_read;
856-
if (snd_info_register(entry) < 0) {
857-
snd_info_free_entry(entry);
858-
return -ENOMEM;
859-
}
856+
if (snd_info_register(entry) < 0)
857+
return -ENOMEM; /* freed in error path */
860858

861859
#ifdef MODULE
862860
entry = snd_info_create_module_entry(THIS_MODULE, "modules", NULL);
863-
if (entry) {
864-
entry->c.text.read = snd_card_module_info_read;
865-
if (snd_info_register(entry) < 0)
866-
snd_info_free_entry(entry);
867-
}
861+
if (!entry)
862+
return -ENOMEM;
863+
entry->c.text.read = snd_card_module_info_read;
864+
if (snd_info_register(entry) < 0)
865+
return -ENOMEM; /* freed in error path */
868866
#endif
869867

870868
return 0;

‎sound/core/seq/seq_info.c‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ create_info_entry(char *name, void (*read)(struct snd_info_entry *,
5151
return entry;
5252
}
5353

54+
static void free_info_entries(void)
55+
{
56+
snd_info_free_entry(queues_entry);
57+
snd_info_free_entry(clients_entry);
58+
snd_info_free_entry(timer_entry);
59+
}
60+
5461
/* create all our /proc entries */
5562
int __init snd_seq_info_init(void)
5663
{
@@ -59,14 +66,18 @@ int __init snd_seq_info_init(void)
5966
clients_entry = create_info_entry("clients",
6067
snd_seq_info_clients_read);
6168
timer_entry = create_info_entry("timer", snd_seq_info_timer_read);
69+
if (!queues_entry || !clients_entry || !timer_entry)
70+
goto error;
6271
return 0;
72+
73+
error:
74+
free_info_entries();
75+
return -ENOMEM;
6376
}
6477

6578
int __exit snd_seq_info_done(void)
6679
{
67-
snd_info_free_entry(queues_entry);
68-
snd_info_free_entry(clients_entry);
69-
snd_info_free_entry(timer_entry);
80+
free_info_entries();
7081
return 0;
7182
}
7283
#endif

‎sound/core/sound.c‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -386,14 +386,10 @@ int __init snd_minor_info_init(void)
386386
struct snd_info_entry *entry;
387387

388388
entry = snd_info_create_module_entry(THIS_MODULE, "devices", NULL);
389-
if (entry) {
390-
entry->c.text.read = snd_minor_info_read;
391-
if (snd_info_register(entry) < 0) {
392-
snd_info_free_entry(entry);
393-
entry = NULL;
394-
}
395-
}
396-
return 0;
389+
if (!entry)
390+
return -ENOMEM;
391+
entry->c.text.read = snd_minor_info_read;
392+
return snd_info_register(entry); /* freed in error path */
397393
}
398394
#endif /* CONFIG_PROC_FS */
399395

‎sound/core/sound_oss.c‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,10 @@ int __init snd_minor_info_oss_init(void)
260260
struct snd_info_entry *entry;
261261

262262
entry = snd_info_create_module_entry(THIS_MODULE, "devices", snd_oss_root);
263-
if (entry) {
264-
entry->c.text.read = snd_minor_info_oss_read;
265-
if (snd_info_register(entry) < 0)
266-
snd_info_free_entry(entry);
267-
}
268-
return 0;
263+
if (!entry)
264+
return -ENOMEM;
265+
entry->c.text.read = snd_minor_info_oss_read;
266+
return snd_info_register(entry); /* freed in error path */
269267
}
270268
#endif /* CONFIG_PROC_FS */
271269

0 commit comments

Comments
 (0)