public inbox for linuxppc-dev@ozlabs.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@linaro.org>
To: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn>
Cc: ioana.ciornei@nxp.com, stuart.yoder@freescale.com, agraf@suse.de,
	German.Rivera@freescale.com, gregkh@linuxfoundation.org,
	linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org, Su Hui <suhui@nfschina.com>,
	Christophe Leroy <chleroy@kernel.org>
Subject: Re: [PATCH v3] bus: fsl-mc: fix an error handling in fsl_mc_device_add()
Date: Sat, 24 Jan 2026 13:47:24 +0300	[thread overview]
Message-ID: <aXSjPNWzsEPhYhv6@stanley.mountain> (raw)
In-Reply-To: <20260124102054.1613093-1-lihaoxiang@isrc.iscas.ac.cn>

On Sat, Jan 24, 2026 at 06:20:54PM +0800, Haoxiang Li wrote:
> In fsl_mc_device_add(), device_initialize() is called first.
> put_device() should be called to drop the reference if error
> occurs. And other resources would be released via put_device
> -> fsl_mc_device_release. So remove redundant kfree() in
> error handling path.
> 

It is true that we shouldn't free things directly after calling
device_initialize().  I don't know the impact of this bug in
real life.  Is it a leak?

> Fixes: bbf9d17d9875 ("staging: fsl-mc: Freescale Management Complex (fsl-mc) bus driver")
> Cc: stable@vger.kernel.org
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Closes: https://lore.kernel.org/all/b767348e-d89c-416e-acea-1ebbff3bea20@stanley.mountain/

Heh.  What was I even talking about when I wrote this???

In my head I remember the code as looking like this:
https://lore.kernel.org/all/20251222074958.992911-1-lihaoxiang@isrc.iscas.ac.cn/
But that's not the version of the code that I copy and pasted into my
email.

The release function looks like this:

drivers/bus/fsl-mc/fsl-mc-bus.c
   757  static void fsl_mc_device_release(struct device *dev)
   758  {
   759          struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
   760  
   761          kfree(mc_dev->regions);
   762  
   763          if (is_fsl_mc_bus_dprc(mc_dev))
   764                  kfree(to_fsl_mc_bus(mc_dev));
   765          else
   766                  kfree(mc_dev);
   767  }

The problem is that if this function call fails:

	mc_dev->dev.type = fsl_mc_get_device_type(obj_desc->type);

Then the is_fsl_mc_bus_dprc() check might not work.  In the current
code the to_fsl_mc_bus() pointer math is a no-op because mc_dev is
the first struct member of mc_bus.  So it works for now, but it
feels wrong.

The fsl_mc_get_device_type() function can't really fail in real
life.

regards,
dan carpenter



  reply	other threads:[~2026-01-24 10:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-24 10:20 [PATCH v3] bus: fsl-mc: fix an error handling in fsl_mc_device_add() Haoxiang Li
2026-01-24 10:47 ` Dan Carpenter [this message]
2026-01-26  9:45   ` Ioana Ciornei
2026-01-28 12:15 ` Ioana Ciornei
2026-01-28 12:43 ` Christophe Leroy (CS GROUP)

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=aXSjPNWzsEPhYhv6@stanley.mountain \
    --to=dan.carpenter@linaro.org \
    --cc=German.Rivera@freescale.com \
    --cc=agraf@suse.de \
    --cc=chleroy@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=ioana.ciornei@nxp.com \
    --cc=lihaoxiang@isrc.iscas.ac.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=stable@vger.kernel.org \
    --cc=stuart.yoder@freescale.com \
    --cc=suhui@nfschina.com \
    /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