From: Rickard Strandqvist <rickard_strandqvist-IW2WV5XWFqGZkjO+N0TKoMugMpMbD5Xr@public.gmane.org>
To: Wolfram Sang <wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
Cc: Grant Likely
<grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
Jingoo Han <jg1.han-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>,
Leilei Shang <shangll-eYqpPyKDWXRBDgjK7y7TUQ@public.gmane.org>,
Peter Korsgaard <peter-+2lRwdCCLRT2eFz/2MeuCQ@public.gmane.org>,
linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
"linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
<linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
"devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
<devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: [PATCH v4] i2c: busses: i2c-pxa.c: Fix for possible null pointer dereference
Date: Sat, 16 Aug 2014 23:32:16 +0200 [thread overview]
Message-ID: <CAFo99gb3vASH8k3nhKiQ9+0sST4oeKL=sOK27JjOurAvwWxEJg@mail.gmail.com> (raw)
In-Reply-To: <20140802113001.GC2739@katana>
2014-08-02 13:30 GMT+02:00 Wolfram Sang <wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>:
> Hi,
>
>> res = platform_get_resource(dev, IORESOURCE_MEM, 0);
>> irq = platform_get_irq(dev, 0);
>> - if (res == NULL || irq < 0) {
>> - ret = -ENODEV;
>> - goto eclk;
>> - }
>> + if (res == NULL || irq < 0)
>> + return -ENODEV;
>
> No need to check for valid 'res' here...
>
>>
>> - if (!request_mem_region(res->start, resource_size(res), res->name)) {
>> - ret = -ENOMEM;
>> - goto eclk;
>> - }
>> + if (!devm_request_mem_region(&dev->dev, res->start,
>> + resource_size(res), res->name))
>> + return -ENOMEM;
>
> ... and no need to use 'devm_request_mem_region' ...
>
>> - i2c->reg_base = ioremap(res->start, resource_size(res));
>> - if (!i2c->reg_base) {
>> - ret = -EIO;
>> - goto eremap;
>> - }
>> + i2c->reg_base = devm_ioremap_resource(&adev->dev, res));
>> + if (IS_ERR(i2c->reg_base))
>> + return -EIO;
>
> ... because devm_ioremap_resource does all that for you. Also, don't
> return -EIO but the PTR_ERR given from the function. Just check other
> drivers how they do it.
>
>>
>> i2c->reg_ibmr = i2c->reg_base + pxa_reg_layout[i2c_type].ibmr;
>> i2c->reg_idbr = i2c->reg_base + pxa_reg_layout[i2c_type].idbr;
>> @@ -1227,10 +1218,12 @@ static int i2c_pxa_probe(struct platform_device *dev)
>> i2c->adap.algo = &i2c_pxa_pio_algorithm;
>> } else {
>> i2c->adap.algo = &i2c_pxa_algorithm;
>> - ret = request_irq(irq, i2c_pxa_handler, IRQF_SHARED,
>> - dev_name(&dev->dev), i2c);
>> - if (ret)
>> - goto ereqirq;
>> + ret = devm_request_irq(&dev->dev, irq, i2c_pxa_handler,
>> + IRQF_SHARED, dev_name(&dev->dev), i2c);
>> + if (ret) {
>> + clk_disable_unprepare(i2c->clk);
>> + return ret;
>
> Maybe you should make a error path with 'goto' out of it...
>
>
>> + }
>> }
>>
>> i2c_pxa_reset(i2c);
>> @@ -1244,7 +1237,7 @@ static int i2c_pxa_probe(struct platform_device *dev)
>> ret = i2c_add_numbered_adapter(&i2c->adap);
>> if (ret < 0) {
>> printk(KERN_INFO "I2C: Failed to add bus\n");
>> - goto eadapt;
>> + return ret;
>
> ... since you forgot disable_unprepare here and could simply reuse it.
>
>
>> }
>>
>> platform_set_drvdata(dev, i2c);
>> @@ -1257,20 +1250,6 @@ static int i2c_pxa_probe(struct platform_device *dev)
>> dev_name(&i2c->adap.dev));
>> #endif
>> return 0;
>> -
>> -eadapt:
>> - if (!i2c->use_pio)
>> - free_irq(irq, i2c);
>> -ereqirq:
>> - clk_disable_unprepare(i2c->clk);
>> - iounmap(i2c->reg_base);
>> -eremap:
>> - clk_put(i2c->clk);
>> -eclk:
>> - kfree(i2c);
>> -emalloc:
>> - release_mem_region(res->start, resource_size(res));
>> - return ret;
>> }
>
> You forgot to cleanup the remove function.
>
> BTW I forgot, can you test this patch on real hardware? If not, is there
> somebody who does?
>
> All the best,
>
> Wolfram
Hi
I have made a lot of changes on changes to changes, and have really
tried to ensure that all would be right.
But I feel like that's enough, Wolfram or anyone else may end this.
And no as I replied earlier, I lack this kind of hardware...
Kind regards
Rickard Strandqvist
prev parent reply other threads:[~2014-08-16 21:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-16 21:14 [PATCH v4] i2c: busses: i2c-pxa.c: Fix for possible null pointer dereference Rickard Strandqvist
[not found] ` <1405545251-13087-1-git-send-email-rickard_strandqvist-IW2WV5XWFqGZkjO+N0TKoMugMpMbD5Xr@public.gmane.org>
2014-07-16 21:14 ` Rickard Strandqvist
2014-08-02 11:30 ` Wolfram Sang
2014-08-16 21:32 ` Rickard Strandqvist [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='CAFo99gb3vASH8k3nhKiQ9+0sST4oeKL=sOK27JjOurAvwWxEJg@mail.gmail.com' \
--to=rickard_strandqvist-iw2wv5xwfqgzkjo+n0tkomugmpmbd5xr@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=jg1.han-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org \
--cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=peter-+2lRwdCCLRT2eFz/2MeuCQ@public.gmane.org \
--cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=shangll-eYqpPyKDWXRBDgjK7y7TUQ@public.gmane.org \
--cc=wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org \
/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).