cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
From: Michael Walle <michael@walle.cc>
To: Mansour Moufid <mansourmoufid@gmail.com>
Cc: cocci@systeme.lip6.fr
Subject: Re: [Cocci] changing of_get_mac_address() to pass a buffer
Date: Mon, 05 Apr 2021 23:50:12 +0200	[thread overview]
Message-ID: <80c602de0af4fd3c578714dc837bb6fe@walle.cc> (raw)
In-Reply-To: <CALogXGVkTv8eDpNxDnh38qPk0jwMHNpE0HShb4tmGZS3CSF-gQ@mail.gmail.com>

Hi Mansour,

Am 2021-04-04 19:48, schrieb Mansour Moufid:
> On Thu, Apr 1, 2021 at 4:13 AM Michael Walle <michael@walle.cc> wrote:
>> 
>> Hi,
>> 
>> so first I need to say I've never used coccinelle before,
>> so please bear with me ;)
>> 
>> To make of_get_mac_address() work with DSA ports (and a nvmem
>> provider) I'd need to change the semantics of of_get_mac_address().
>> Right now it returns a pointer to "const char *", I'd need to change
>> that so a buffer will be passed as a parameter in which the MAC
>> address gets stored.
>> 
>> (1) Usually the call is something like:
>> 
>>    const char *mac;
>>    mac = of_get_mac_address(np);
>>    if (!IS_ERR(mac))
>>      ether_addr_copy(ndev->dev_addr, mac);
>> 
>> This would need to be changed to:
>> 
>>    of_get_mac_address(np, ndev->dev_addr);
> 
> Here is one possible approach, doing the API change first then
> handling the conditionals. It seems to work.
> 
> @a@
> identifier x;
> expression y, z;
> @@
> -   x = of_get_mac_address(y);
> +   x = of_get_mac_address(y, z);
>     <...
> -   ether_addr_copy(z, x);
>     ...>
> 
> @@
> identifier a.x;
> @@
> -   if (<+... x ...+>) {}
> 
> @@
> identifier a.x;
> @@
>     if (<+... x ...+>) {
>         ...
>     }
> -   else {}
> 
> @@
> identifier a.x;
> expression e;
> @@
> -   if (<+... x ...+>@e)
> -       {}
> -   else
> +   if (!(e))
>         {...}
> 
> @@
> expression x, y, z;
> @@
> -   x = of_get_mac_address(y, z);
> +   of_get_mac_address(y, z);
>     ... when != x

Thanks a lot!

See also 
https://lore.kernel.org/netdev/20210405164643.21130-1-michael@walle.cc/

There were some "if (!(!IS_ERR(x))", which I needed to simplify
manually. Didn't noticed that in my previous script. I'm just
curious, is that also something coccinelle can simplify on its
own?

-michael
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

  parent reply	other threads:[~2021-04-05 21:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-01  8:13 [Cocci] changing of_get_mac_address() to pass a buffer Michael Walle
2021-04-01 17:06 ` Markus Elfring
2021-04-04 17:48 ` Mansour Moufid
2021-04-04 18:34   ` Julia Lawall
2021-04-05 21:50   ` Michael Walle [this message]
2021-04-05 21:58     ` Julia Lawall

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=80c602de0af4fd3c578714dc837bb6fe@walle.cc \
    --to=michael@walle.cc \
    --cc=cocci@systeme.lip6.fr \
    --cc=mansourmoufid@gmail.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).