From: Sabrina Dubroca <sd@queasysnail.net>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: linux-wireless@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [RFC PATCH 2/2] net: convert to nla_get_*_default()
Date: Thu, 24 Oct 2024 16:28:55 +0200 [thread overview]
Message-ID: <ZxpZp5KYN_VofWZ0@hog> (raw)
In-Reply-To: <6461c18e0be520b4f7ecefc910af5d8dd205bce9.camel@sipsolutions.net>
2024-10-24, 14:11:05 +0200, Johannes Berg wrote:
> On Thu, 2024-10-24 at 13:18 +0200, Johannes Berg wrote:
> > From: Johannes Berg <johannes.berg@intel.com>
> >
> > This is mostly to illustrate, done with the following spatch:
> >
>
> And we can extend that and get bunch more:
>
> @@
> expression attr, def;
> expression val;
> identifier fn =~ "^nla_get_.*";
> fresh identifier dfn = fn ## "_default";
> @@
> (
> -if (attr)
> - val = fn(attr);
> -else
> - val = def;
> +val = dfn(attr, def);
> |
> -if (!attr)
> - val = def;
> -else
> - val = fn(attr);
> +val = dfn(attr, def);
> |
> -val = def;
> ... where != val;
> -if (attr)
> - val = fn(attr);
> +val = dfn(attr, def);
> |
> -if (!attr)
> - return def;
> -return fn(attr);
> +return dfn(attr, def);
> )
Not really familiar with spatch, but I'm guessing this won't cover:
val = attr ? getter(attr) : default;
See macsec_validate_attr in drivers/net/macsec.c for some
examples. There are also some cases where we have "if (data &&
data[IFLA_MACSEC_*])" guarding the attribute fetch
(drivers/net/macvlan.c does that too), but I guess you can't really
cover that without adding some kind of "default_with_cond" helpers.
--
Sabrina
next prev parent reply other threads:[~2024-10-24 14:28 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-24 11:18 [RFC PATCH 1/2] net: netlink: add nla_get_*_default() accessors Johannes Berg
2024-10-24 11:18 ` [RFC PATCH 2/2] net: convert to nla_get_*_default() Johannes Berg
2024-10-24 12:11 ` Johannes Berg
2024-10-24 14:28 ` Sabrina Dubroca [this message]
2024-10-24 14:31 ` Johannes Berg
2024-10-24 14:40 ` Johannes Berg
2024-10-24 13:41 ` Johannes Berg
2024-10-24 14:48 ` Sabrina Dubroca
2024-10-24 14:52 ` Johannes Berg
2024-10-24 15:17 ` Sabrina Dubroca
2024-10-24 15:29 ` Johannes Berg
2024-10-29 15:57 ` Jakub Kicinski
2024-10-24 11:29 ` [RFC PATCH 1/2] net: netlink: add nla_get_*_default() accessors Johannes Berg
2024-10-24 12:51 ` Toke Høiland-Jørgensen
2024-10-24 15:42 ` kernel test robot
2024-10-24 16:35 ` kernel test robot
2024-10-29 15:54 ` Jakub Kicinski
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=ZxpZp5KYN_VofWZ0@hog \
--to=sd@queasysnail.net \
--cc=johannes@sipsolutions.net \
--cc=linux-wireless@vger.kernel.org \
--cc=netdev@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.