From: "Russell King (Oracle)" <linux@armlinux.org.uk>
To: Alfredo Cruz <alfredo.carlon@gmail.com>
Cc: arnd@arndb.de, u.kleine-koenig@pengutronix.de,
shawnguo@kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ARM: sa1111: fix put_device() before device_add() in error path
Date: Wed, 21 Feb 2024 21:57:06 +0000 [thread overview]
Message-ID: <ZdZxsrhLNCt+bCOB@shell.armlinux.org.uk> (raw)
In-Reply-To: <20240221213837.27605-1-alfredo.carlon@gmail.com>
On Wed, Feb 21, 2024 at 10:38:37PM +0100, Alfredo Cruz wrote:
> When request_resource() fails, a jump is made to err_resource label which
> calls put_device() on &dev->res without adding it first.
> Kept the err_resource label and moved put_device() to err_add label.
You fail to explain why this is incorrect. I think this patch is
incorrect. The reason is as follows:
"dev" is allocated.
dev->dev is then initialised. This initialises the struct device,
setting its initial refcount to '1'.
We then request the resource. If this fails, then the device needs to
be released. As refcounting has been initialised, it is *not*
appropriate to simply kfree() "dev". The correct action, as noted by
the device_initialize() documentation is to call put_device() on it.
This is what the code does.
I _do_ hope you haven't submitted other patches like this, because if
you have, they could well also be wrong.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
prev parent reply other threads:[~2024-02-21 21:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-21 21:38 [PATCH] ARM: sa1111: fix put_device() before device_add() in error path Alfredo Cruz
2024-02-21 21:57 ` Russell King (Oracle) [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=ZdZxsrhLNCt+bCOB@shell.armlinux.org.uk \
--to=linux@armlinux.org.uk \
--cc=alfredo.carlon@gmail.com \
--cc=arnd@arndb.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=shawnguo@kernel.org \
--cc=u.kleine-koenig@pengutronix.de \
/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