From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82DD47B for ; Wed, 23 Nov 2022 08:53:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF73FC433C1; Wed, 23 Nov 2022 08:53:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1669193613; bh=eajCaM8wkk1agCpDXI7qjFENGV8/iUU8UjuoL8MlOlM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LBh2gyoV8e98gctjw1DRNkxprIyTeC/8Pk2Nm9o6cRAIYf5EhlQ26PVieZmciEuHF C3QiR/+sFsKQYj70KSUCqoTcvG8nO58cD/ChQZ02Im4/gGLiZGWngKtqaoHFV8/3p9 2+ofLaK3hrFXx+3iNwDn3GGJQKFqP6R6kqwwsQsk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ye Bin , Takashi Iwai Subject: [PATCH 4.9 16/76] ALSA: hda: fix potential memleak in add_widget_node Date: Wed, 23 Nov 2022 09:50:15 +0100 Message-Id: <20221123084547.262488085@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221123084546.742331901@linuxfoundation.org> References: <20221123084546.742331901@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Ye Bin commit 9a5523f72bd2b0d66eef3d58810c6eb7b5ffc143 upstream. As 'kobject_add' may allocated memory for 'kobject->name' when return error. And in this function, if call 'kobject_add' failed didn't free kobject. So call 'kobject_put' to recycling resources. Signed-off-by: Ye Bin Cc: Link: https://lore.kernel.org/r/20221110144539.2989354-1-yebin@huaweicloud.com Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/hda/hdac_sysfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/sound/hda/hdac_sysfs.c +++ b/sound/hda/hdac_sysfs.c @@ -345,8 +345,10 @@ static int add_widget_node(struct kobjec return -ENOMEM; kobject_init(kobj, &widget_ktype); err = kobject_add(kobj, parent, "%02x", nid); - if (err < 0) + if (err < 0) { + kobject_put(kobj); return err; + } err = sysfs_create_group(kobj, group); if (err < 0) { kobject_put(kobj);