* [PATCH net-next] netlink: gc useless variable in nlmsg_attrdata()
@ 2021-08-12 21:24 Alexey Dobriyan
2021-08-12 22:05 ` Jakub Kicinski
0 siblings, 1 reply; 4+ messages in thread
From: Alexey Dobriyan @ 2021-08-12 21:24 UTC (permalink / raw)
To: davem; +Cc: netdev
Kernel permits pointer arithmetic on "void*" so might as well use it
without casts back and forth.
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---
include/net/netlink.h | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
--- a/include/net/netlink.h
+++ b/include/net/netlink.h
@@ -587,8 +587,7 @@ static inline int nlmsg_len(const struct nlmsghdr *nlh)
static inline struct nlattr *nlmsg_attrdata(const struct nlmsghdr *nlh,
int hdrlen)
{
- unsigned char *data = nlmsg_data(nlh);
- return (struct nlattr *) (data + NLMSG_ALIGN(hdrlen));
+ return nlmsg_data(nlh) + NLMSG_ALIGN(hdrlen);
}
/**
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net-next] netlink: gc useless variable in nlmsg_attrdata()
2021-08-12 21:24 [PATCH net-next] netlink: gc useless variable in nlmsg_attrdata() Alexey Dobriyan
@ 2021-08-12 22:05 ` Jakub Kicinski
2021-08-13 5:27 ` Alexey Dobriyan
0 siblings, 1 reply; 4+ messages in thread
From: Jakub Kicinski @ 2021-08-12 22:05 UTC (permalink / raw)
To: Alexey Dobriyan; +Cc: davem, netdev
On Fri, 13 Aug 2021 00:24:01 +0300 Alexey Dobriyan wrote:
> Kernel permits pointer arithmetic on "void*" so might as well use it
> without casts back and forth.
But why change existing code? It's perfectly fine, right?
> --- a/include/net/netlink.h
> +++ b/include/net/netlink.h
> @@ -587,8 +587,7 @@ static inline int nlmsg_len(const struct nlmsghdr *nlh)
> static inline struct nlattr *nlmsg_attrdata(const struct nlmsghdr *nlh,
> int hdrlen)
> {
> - unsigned char *data = nlmsg_data(nlh);
> - return (struct nlattr *) (data + NLMSG_ALIGN(hdrlen));
> + return nlmsg_data(nlh) + NLMSG_ALIGN(hdrlen);
> }
>
> /**
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net-next] netlink: gc useless variable in nlmsg_attrdata()
2021-08-12 22:05 ` Jakub Kicinski
@ 2021-08-13 5:27 ` Alexey Dobriyan
2021-08-13 17:29 ` Jakub Kicinski
0 siblings, 1 reply; 4+ messages in thread
From: Alexey Dobriyan @ 2021-08-13 5:27 UTC (permalink / raw)
To: Jakub Kicinski; +Cc: davem, netdev
On Thu, Aug 12, 2021 at 03:05:52PM -0700, Jakub Kicinski wrote:
> On Fri, 13 Aug 2021 00:24:01 +0300 Alexey Dobriyan wrote:
> > Kernel permits pointer arithmetic on "void*" so might as well use it
> > without casts back and forth.
>
> But why change existing code? It's perfectly fine, right?
It is harder to read (marginally of course).
> > --- a/include/net/netlink.h
> > +++ b/include/net/netlink.h
> > @@ -587,8 +587,7 @@ static inline int nlmsg_len(const struct nlmsghdr *nlh)
> > static inline struct nlattr *nlmsg_attrdata(const struct nlmsghdr *nlh,
> > int hdrlen)
> > {
> > - unsigned char *data = nlmsg_data(nlh);
> > - return (struct nlattr *) (data + NLMSG_ALIGN(hdrlen));
> > + return nlmsg_data(nlh) + NLMSG_ALIGN(hdrlen);
> > }
> >
> > /**
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net-next] netlink: gc useless variable in nlmsg_attrdata()
2021-08-13 5:27 ` Alexey Dobriyan
@ 2021-08-13 17:29 ` Jakub Kicinski
0 siblings, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2021-08-13 17:29 UTC (permalink / raw)
To: Alexey Dobriyan; +Cc: davem, netdev
On Fri, 13 Aug 2021 08:27:30 +0300 Alexey Dobriyan wrote:
> On Thu, Aug 12, 2021 at 03:05:52PM -0700, Jakub Kicinski wrote:
> > On Fri, 13 Aug 2021 00:24:01 +0300 Alexey Dobriyan wrote:
> > > Kernel permits pointer arithmetic on "void*" so might as well use it
> > > without casts back and forth.
> >
> > But why change existing code? It's perfectly fine, right?
>
> It is harder to read (marginally of course).
TBH I prefer the current code, I don't have to wonder what type
nlmsg_data() returns and whether it's okay to do void* arithmetic
in this header (if it's uAPI). Sorry :(
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-08-13 17:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-12 21:24 [PATCH net-next] netlink: gc useless variable in nlmsg_attrdata() Alexey Dobriyan
2021-08-12 22:05 ` Jakub Kicinski
2021-08-13 5:27 ` Alexey Dobriyan
2021-08-13 17:29 ` Jakub Kicinski
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).