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 C39BF488509 for ; Thu, 8 Jan 2026 10:21:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767867687; cv=none; b=kjrphODMH/5DU+FQ1sRbPDjHcOmtnvkgkzJRJVEI+ViGew4WJwXWJJrOel7eiKG4hOpkwSXfT5Y/y/PEtqu8BZDATo0rL1ho0unadS1G8rI7x2dp2j18QUiouBvz3RxwT23eaCvQrG9ChcKogj+XfPszVH4yKtHDk7EOYfLD3i8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767867687; c=relaxed/simple; bh=8dkAEMnoGUkb/iUWpdkoPRbOTk/M5TAEjwnKaTDUfNU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=atwqpKR6xDDQGCRJ1IavZoHMvglcuY1FgG6x71rC10yxpSy0iSvG7HAdPRYLVohOc1tLNdI6EUe3IK0BGyPdE9VdbwIneId6WJKkQd2EUD63vNYA1aqEh2zB3v9rUK/S2BsTApNuK3NDAdVgzJfUMNKr4d9YRuGz+aHPsgHKlwQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VykpLyWP; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VykpLyWP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C83E8C16AAE; Thu, 8 Jan 2026 10:21:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767867687; bh=8dkAEMnoGUkb/iUWpdkoPRbOTk/M5TAEjwnKaTDUfNU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=VykpLyWPV9cDK6cXxhNJ9H3RnoSYnIQ8P2A8v/yI97QQFfsKzjYU2U50VNczW5RZt IRES3+i5kw1WOGK4wQ6sieYkypDUDvtJlkiJ7Vwi5JI7wJN/jvRiBDyz10bMygORBe 9gQK8AfZDnvG0rTUZBnsTL/6uGs15luTso4XI42MYO8A2D+4DADP8AW8pv6hY0XSVz nH+aIXLEbOrJBYY9v61azn2WwNk+rlfrcQv1d8tn+77sXFcuNJRJxeCbs8XQ/tl4v4 j6mY4jSWrbqw/MrC8aO0fh3fql7hI0F51/vwAsKUNCjHSFpaP0rH6byQyIdS5d2a/5 cm2+WYZ00C1ow== Date: Thu, 8 Jan 2026 10:21:23 +0000 From: Lee Jones To: Abdun Nihaal Cc: linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mfd: mc13xxx-core: Fix memory leak in mc13xxx_add_subdevice_pdata() Message-ID: <20260108102123.GB302752@google.com> References: <20251127044500.44820-1-nihaal@cse.iitm.ac.in> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20251127044500.44820-1-nihaal@cse.iitm.ac.in> On Thu, 27 Nov 2025, Abdun Nihaal wrote: > The memory allocated for cell.name using kmemdup() is not freed when > mfd_add_devices() fails. Fix that by checking return code and freeing. > > Fixes: 8e00593557c3 ("mfd: Add mc13892 support to mc13xxx") > Signed-off-by: Abdun Nihaal > --- > v1->v2: > - Added the include of slab.h to ensure kfree is declared before use, to > fix the compiler warning pointed out by kernel test robot. > > drivers/mfd/mc13xxx-core.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/drivers/mfd/mc13xxx-core.c b/drivers/mfd/mc13xxx-core.c > index 920797b806ce..a6eebad16026 100644 > --- a/drivers/mfd/mc13xxx-core.c > +++ b/drivers/mfd/mc13xxx-core.c > @@ -13,6 +13,7 @@ > #include > #include > #include > +#include > > #include "mc13xxx.h" > > @@ -365,6 +366,7 @@ EXPORT_SYMBOL_GPL(mc13xxx_adc_do_conversion); > static int mc13xxx_add_subdevice_pdata(struct mc13xxx *mc13xxx, > const char *format, void *pdata, size_t pdata_size) > { > + int ret; > char buf[30]; > const char *name = mc13xxx_get_chipname(mc13xxx); > > @@ -381,8 +383,11 @@ static int mc13xxx_add_subdevice_pdata(struct mc13xxx *mc13xxx, > if (!cell.name) > return -ENOMEM; > > - return mfd_add_devices(mc13xxx->dev, -1, &cell, 1, NULL, 0, > + ret = mfd_add_devices(mc13xxx->dev, -1, &cell, 1, NULL, 0, > regmap_irq_get_domain(mc13xxx->irq_data)); > + if (ret) > + kfree(cell.name); > + return ret; Why not simply use devm_kmemdup() instead? -- Lee Jones [李琼斯]