From: Wolfram Sang <wsa@the-dreams.de>
To: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
Cc: Grant Likely <grant.likely@linaro.org>,
Rob Herring <robh+dt@kernel.org>,
Jingoo Han <jg1.han@samsung.com>,
Leilei Shang <shangll@marvell.com>, Daniel Drake <dsd@laptop.org>,
linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org
Subject: Re: [PATCH] i2c: busses: i2c-pxa.c: Fix for possible null pointer dereferenc
Date: Fri, 27 Jun 2014 14:21:48 +0200 [thread overview]
Message-ID: <20140627122147.GF2641@katana> (raw)
In-Reply-To: <1401831034-30255-1-git-send-email-rickard_strandqvist@spectrumdigital.se>
[-- Attachment #1: Type: text/plain, Size: 1722 bytes --]
On Tue, Jun 03, 2014 at 11:30:34PM +0200, Rickard Strandqvist wrote:
> Fix for possible null pointer dereferenc, and there is a risk
> for memory leak in when something unexpected happens and the
> function returns.
>
> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
> ---
> drivers/i2c/busses/i2c-pxa.c | 19 +++++++++++--------
> 1 file changed, 11 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
> index bbe6dfb..948a3c7 100644
> --- a/drivers/i2c/busses/i2c-pxa.c
> +++ b/drivers/i2c/busses/i2c-pxa.c
> @@ -1142,10 +1142,8 @@ static int i2c_pxa_probe(struct platform_device *dev)
> int ret, irq;
>
> i2c = kzalloc(sizeof(struct pxa_i2c), GFP_KERNEL);
> - if (!i2c) {
> - ret = -ENOMEM;
> - goto emalloc;
> - }
> + if (!i2c)
> + return -ENOMEM;
>
> /* Default adapter num to device id; i2c_pxa_probe_dt can override. */
> i2c->adap.nr = dev->id;
> @@ -1154,11 +1152,16 @@ static int i2c_pxa_probe(struct platform_device *dev)
> if (ret > 0)
> ret = i2c_pxa_probe_pdata(dev, i2c, &i2c_type);
> if (ret < 0)
> - goto eclk;
> + goto emalloc;
>
> res = platform_get_resource(dev, IORESOURCE_MEM, 0);
> + if (res == NULL) {
> + ret = -ENODEV;
> + goto emalloc;
> + }
> +
> irq = platform_get_irq(dev, 0);
> - if (res == NULL || irq < 0) {
> + if (irq < 0) {
> ret = -ENODEV;
> goto eclk;
Nope, those should be emalloc as well since the region was not requested
here. May I ask you to just convert this driver to managed devices (devm_*
functions)? They are made to exactly avoid this hazzle and cleanup the
driver.
Thanks,
Wolfram
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
prev parent reply other threads:[~2014-06-27 12:21 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-03 21:30 [PATCH] i2c: busses: i2c-pxa.c: Fix for possible null pointer dereferenc Rickard Strandqvist
2014-06-27 12:21 ` Wolfram Sang [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=20140627122147.GF2641@katana \
--to=wsa@the-dreams.de \
--cc=devicetree@vger.kernel.org \
--cc=dsd@laptop.org \
--cc=grant.likely@linaro.org \
--cc=jg1.han@samsung.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rickard_strandqvist@spectrumdigital.se \
--cc=robh+dt@kernel.org \
--cc=shangll@marvell.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;
as well as URLs for NNTP newsgroup(s).