From patchwork Thu Apr 23 14:49:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 6263781 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 140489F1C4 for ; Thu, 23 Apr 2015 14:52:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3C04E202E5 for ; Thu, 23 Apr 2015 14:52:47 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id F34012025A for ; Thu, 23 Apr 2015 14:52:45 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 246DE2666EC; Thu, 23 Apr 2015 16:52:45 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 44714265A78; Thu, 23 Apr 2015 16:49:57 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id C80B4264ED3; Thu, 23 Apr 2015 16:49:48 +0200 (CEST) Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id 5D6C8264F74 for ; Thu, 23 Apr 2015 16:49:38 +0200 (CEST) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 145C6AD28 for ; Thu, 23 Apr 2015 14:49:38 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Date: Thu, 23 Apr 2015 16:49:24 +0200 Message-Id: <1429800570-10153-3-git-send-email-tiwai@suse.de> X-Mailer: git-send-email 2.3.5 In-Reply-To: <1429800570-10153-1-git-send-email-tiwai@suse.de> References: <1429800570-10153-1-git-send-email-tiwai@suse.de> Subject: [alsa-devel] [PATCH 2/8] ALSA: core: Fix possible memory leaks at error path in info.c X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP snd_info_init() just returns an error without releasing the previously assigned resources at error path. The assigned proc and info entries have to be released properly. While we are at it, refactor the code a bit, too. Signed-off-by: Takashi Iwai --- sound/core/info.c | 62 +++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/sound/core/info.c b/sound/core/info.c index 8c1275f0fcbd..9c6db5c24da7 100644 --- a/sound/core/info.c +++ b/sound/core/info.c @@ -446,6 +446,22 @@ static const struct file_operations snd_info_text_entry_ops = .read = seq_read, }; +static struct snd_info_entry *create_subdir(struct module *mod, + const char *name) +{ + struct snd_info_entry *entry; + + entry = snd_info_create_module_entry(mod, name, NULL); + if (!entry) + return NULL; + entry->mode = S_IFDIR | S_IRUGO | S_IXUGO; + if (snd_info_register(entry) < 0) { + snd_info_free_entry(entry); + return NULL; + } + return entry; +} + int __init snd_info_init(void) { struct proc_dir_entry *p; @@ -455,36 +471,27 @@ int __init snd_info_init(void) return -ENOMEM; snd_proc_root = p; #ifdef CONFIG_SND_OSSEMUL - { - struct snd_info_entry *entry; - if ((entry = snd_info_create_module_entry(THIS_MODULE, "oss", NULL)) == NULL) - return -ENOMEM; - entry->mode = S_IFDIR | S_IRUGO | S_IXUGO; - if (snd_info_register(entry) < 0) { - snd_info_free_entry(entry); - return -ENOMEM; - } - snd_oss_root = entry; - } + snd_oss_root = create_subdir(THIS_MODULE, "oss"); + if (!snd_oss_root) + goto error; #endif #if IS_ENABLED(CONFIG_SND_SEQUENCER) - { - struct snd_info_entry *entry; - if ((entry = snd_info_create_module_entry(THIS_MODULE, "seq", NULL)) == NULL) - return -ENOMEM; - entry->mode = S_IFDIR | S_IRUGO | S_IXUGO; - if (snd_info_register(entry) < 0) { - snd_info_free_entry(entry); - return -ENOMEM; - } - snd_seq_root = entry; - } + snd_seq_root = create_subdir(THIS_MODULE, "seq"); + if (!snd_seq_root) + goto error; #endif snd_info_version_init(); snd_minor_info_init(); snd_minor_info_oss_init(); snd_card_info_init(); return 0; + + error: +#ifdef CONFIG_SND_OSSEMUL + snd_info_free_entry(snd_oss_root); +#endif + proc_remove(snd_proc_root); + return -ENOMEM; } int __exit snd_info_done(void) @@ -523,13 +530,9 @@ int snd_info_card_create(struct snd_card *card) return -ENXIO; sprintf(str, "card%i", card->number); - if ((entry = snd_info_create_module_entry(card->module, str, NULL)) == NULL) - return -ENOMEM; - entry->mode = S_IFDIR | S_IRUGO | S_IXUGO; - if (snd_info_register(entry) < 0) { - snd_info_free_entry(entry); + entry = create_subdir(card->module, str); + if (!entry) return -ENOMEM; - } card->proc_root = entry; return 0; } @@ -758,7 +761,6 @@ EXPORT_SYMBOL(snd_info_create_card_entry); static void snd_info_disconnect(struct snd_info_entry *entry) { struct list_head *p, *n; - struct proc_dir_entry *root; list_for_each_safe(p, n, &entry->children) { snd_info_disconnect(list_entry(p, struct snd_info_entry, list)); @@ -767,8 +769,6 @@ static void snd_info_disconnect(struct snd_info_entry *entry) if (! entry->p) return; list_del_init(&entry->list); - root = entry->parent == NULL ? snd_proc_root : entry->parent->p; - snd_BUG_ON(!root); proc_remove(entry->p); entry->p = NULL; }