mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Barebox List <barebox@lists.infradead.org>
Subject: Re: [PATCH 1/3] Fix return check of dev_request_mem_region
Date: Fri, 19 Feb 2016 11:12:24 -0800	[thread overview]
Message-ID: <CAHQ1cqGi2M1hKD0sMMWp=NRGyOmgtDvTOopE41UzUurErhXwyw@mail.gmail.com> (raw)
In-Reply-To: <20160219082915.GO3939@pengutronix.de>

On Fri, Feb 19, 2016 at 12:29 AM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> On Thu, Feb 18, 2016 at 04:58:49PM -0800, Andrey Smirnov wrote:
>> On Thu, Feb 18, 2016 at 2:50 AM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
>> > dev_request_mem_region returns an ERR_PTR, fix places which check for a
>> > NULL pointer instead. This patch has been generated with this semantic
>> > patch:
>> >
>> > // <smpl>
>> > @@
>> > expression e,e1,e2;
>> > @@
>> >
>> > e = dev_request_mem_region(...)
>> > ... when != e = e1
>> > if (
>> > -   e == NULL
>> > +   IS_ERR(e)
>> >    ) {
>> >      ...
>> >      return
>> > -      e2
>> > +      PTR_ERR(e)
>> >      ;
>> >      }
>> > // </smpl>
>>
>> This wouldn't handle correctly the cases where code bails out using
>> goto (look for example at diff for phy-am335x.c in this patch). I
>> played around with Cocinelle as well and here's what I came up with:
>>
>>
>> // <smpl>
>> @i@
>> @@
>>
>> #define CONFIG_TSE_USE_DEDICATED_DESC_MEM
>
> This doesn't work for me. I assume you want to define
> CONFIG_TSE_USE_DEDICATED_DESC_MEM to let coccinelle walk into the
> correct path in drivers/net/altera_tse.c, but for me it still changes
> the !CONFIG_TSE_USE_DEDICATED_DESC_MEM code path.

Hmmm, that is very strange. You are correct, I did include that bit
for that exact purpose. Perhaps we are using different versions of the
tool? Mine is "spatch version 1.0.1 with Python support and with PCRE
support". The way I invoked it was "spatch --sp-file check.cocci
--very-quiet --dir barebox"

>
>>
>>
>> // Handle immediate returns
>> @@
>> expression e;
>> expression e1;
>> @@
>>
>> e = dev_request_mem_region(...);
>>
>> ...
>>
>> - if (e == NULL)
>> -    return e1;
>> + if (IS_ERR(e))
>> +    return PTR_ERR(e);
>>
>> @ rule1 @
>> expression e;
>> @@
>>
>> e = dev_request_mem_region(...);
>>
>> // Fix exit codepath first
>> @@
>> expression rule1.e;
>> identifier ret, label;
>> constant errno;
>> @@
>>
>> if (e == NULL)
>> {
>>
>>   ...
>>
>> // Setting the ret code and jumping to error handling code
>> (
>> - ret = -errno;
>> + ret = PTR_ERR(e);
>>
>>   ...
>>
>>   goto label;
>>
>> // Return after doing some extra steps
>> |
>>
>> - return -errno;
>> + return PTR_ERR(e);
>> )
>> }
>>
>> // Fix the check itself. Having this as a standalone rule allows
>> // to catch cases where error codepath doesn't bail out
>> @depends on i@
>
> I assume you mean "depends on rule1", because otherwise it never
> actually changes the wrong error check.
>

Darn! I missed that regression. The problem with making it depending
on "rule1" is that it misses the cases where only the incorrect check
is performed and no bailing out is done (atmel_nand.c).


> Overall this looks better than my version. I recreated the patch with
> your version and fixed up the altera-tse driver manually.

In case you missed it there's also "dove.c" that needs to be corrected manually.

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2016-02-19 19:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-18 10:50 [PATCH] dev_request_mem_region -> dev_request_mem_resource conversion Sascha Hauer
2016-02-18 10:50 ` [PATCH 1/3] Fix return check of dev_request_mem_region Sascha Hauer
2016-02-19  0:58   ` Andrey Smirnov
2016-02-19  8:29     ` Sascha Hauer
2016-02-19 19:12       ` Andrey Smirnov [this message]
2016-02-23  7:15         ` Sascha Hauer
2016-02-18 10:50 ` [PATCH 2/3] driver: Introduce dev_request_mem_resource Sascha Hauer
2016-02-18 10:50 ` [PATCH 3/3] driver: replace dev_request_mem_region with dev_request_mem_resource Sascha Hauer
2016-02-26  8:37   ` Teresa Remmet
2016-02-29  6:41     ` Sascha Hauer

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='CAHQ1cqGi2M1hKD0sMMWp=NRGyOmgtDvTOopE41UzUurErhXwyw@mail.gmail.com' \
    --to=andrew.smirnov@gmail.com \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@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