From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 270E6C04AB4 for ; Thu, 16 May 2019 08:49:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 00CFD205C9 for ; Thu, 16 May 2019 08:49:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726861AbfEPItp (ORCPT ); Thu, 16 May 2019 04:49:45 -0400 Received: from mx2.suse.de ([195.135.220.15]:33294 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726383AbfEPIto (ORCPT ); Thu, 16 May 2019 04:49:44 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id AE74AAEDB; Thu, 16 May 2019 08:49:43 +0000 (UTC) Date: Thu, 16 May 2019 10:49:43 +0200 Message-ID: From: Takashi Iwai To: "Gen Zhang" Cc: , Subject: Re: [Patch] hdac_sysfs: Fix a memory leaking bug in sound/hda/hdac_sysfs.c file of Linux 5.1 In-Reply-To: <20190516084003.GA20821@zhanggen-UX430UQ> References: <20190516084003.GA20821@zhanggen-UX430UQ> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 16 May 2019 10:40:03 +0200, Gen Zhang wrote: > > tree->root and tree->nodes are allocated by memory allocation > functions. And tree is also an allocated memory. When allocation of > tree->root and tree->nodes fails, not freeing tree will leak memory. > Thus we should free tree in this situation. No, the leftover is freed in the caller side by calling widget_tree_free(). thanks, Takashi > > Signed-off-by: Gen Zhang > > --- > diff --git a/sound/hda/hdac_sysfs.c b/sound/hda/hdac_sysfs.c > index fb2aa34..5d8a939 100644 > --- a/sound/hda/hdac_sysfs.c > +++ b/sound/hda/hdac_sysfs.c > @@ -370,12 +370,12 @@ static int widget_tree_create(struct hdac_device *codec) > > tree->root = kobject_create_and_add("widgets", &codec->dev.kobj); > if (!tree->root) > - return -ENOMEM; > + goto free_tree; > > tree->nodes = kcalloc(codec->num_nodes + 1, sizeof(*tree->nodes), > GFP_KERNEL); > if (!tree->nodes) > - return -ENOMEM; > + goto free_tree; > > for (i = 0, nid = codec->start_nid; i < codec->num_nodes; i++, nid++) { > err = add_widget_node(tree->root, nid, &widget_node_group, > @@ -393,6 +393,9 @@ static int widget_tree_create(struct hdac_device *codec) > > kobject_uevent(tree->root, KOBJ_CHANGE); > return 0; > +free_tree: > + kfree(tree); > + return -ENOMEM; > } > > int hda_widget_sysfs_init(struct hdac_device *codec) > --- >