mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: Abdun Nihaal <nihaal@cse.iitm.ac.in>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] mfd: mc13xxx-core: Fix memory leak in mc13xxx_add_subdevice_pdata()
Date: Thu, 8 Jan 2026 10:21:23 +0000	[thread overview]
Message-ID: <20260108102123.GB302752@google.com> (raw)
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 <nihaal@cse.iitm.ac.in>
> ---
> 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 <linux/of_device.h>
>  #include <linux/platform_device.h>
>  #include <linux/mfd/core.h>
> +#include <linux/slab.h>
>  
>  #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 [李琼斯]

      reply	other threads:[~2026-01-08 10:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-27  4:44 Abdun Nihaal
2026-01-08 10:21 ` Lee Jones [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260108102123.GB302752@google.com \
    --to=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nihaal@cse.iitm.ac.in \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®