From: Geert Uytterhoeven <geert@linux-m68k.org>
To: Vladimir Oltean <olteanv@gmail.com>
Cc: Andrew Lunn <andrew@lunn.ch>,
Vivien Didelot <vivien.didelot@gmail.com>,
Florian Fainelli <f.fainelli@gmail.com>,
"David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, netdev <netdev@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] net: dsa: sja1105: Remove unneeded cast in sja1105_crc32()
Date: Thu, 25 Feb 2021 08:28:15 +0100 [thread overview]
Message-ID: <CAMuHMdVeAoPK_iB=Y73X_7zTEJnS6bFKkzCe8QyH8oyZA9OZ5A@mail.gmail.com> (raw)
In-Reply-To: <20210224224358.pysql5pu23zt7mtb@skbuf>
Hi Vladimir,
On Wed, Feb 24, 2021 at 11:44 PM Vladimir Oltean <olteanv@gmail.com> wrote:
> On Tue, Feb 23, 2021 at 12:20:03PM +0100, Geert Uytterhoeven wrote:
> > sja1105_unpack() takes a "const void *buf" as its first parameter, so
> > there is no need to cast away the "const" of the "buf" variable before
> > calling it.
> >
> > Drop the cast, as it prevents the compiler performing some checks.
> >
> > Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> > ---
>
> Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
Thanks!
> By the way, your email went straight to my spam box, I just found the
> patch by mistake on patchwork.
>
> Why is this message in spam?
> It is in violation of Google's recommended email sender guidelines.
Yeah, sometimes Gmail can be annoying. I recommend adding a filter
to never send emails with "PATCH" in the subject to spam.
> > Compile-tested only.
> >
> > BTW, sja1105_packing() and packing() are really bad APIs, as the input
> > pointer parameters cannot be const due to the direction depending on
> > "op". This means the compiler cannot do const checks. Worse, callers
> > are required to cast away constness to prevent the compiler from
> > issueing warnings. Please don't do this!
> > ---
>
> What const checks can the compiler not do?
If you have a const and a non-const buffer, and accidentally call
packing() with the two buffer pointers exchanged (this is a common
mistake), you won't get a compiler warning.
So having separate pack() and unpack() functions would be safer.
You can rename packing() to __packing() to make it clear this function
is not to be called directly without deep consideration, and have
pack() and unpack() as wrappers just calling __packing().
Of course that means callers that do need a separate "op" parameter
still need to call __packing(), but they can provide their own safer
wrappers, too.
> Also, if you know of an existing kernel API which can replace packing(),
> I'm all ears.
No idea.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
next prev parent reply other threads:[~2021-02-25 7:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-23 11:20 [PATCH] net: dsa: sja1105: Remove unneeded cast in sja1105_crc32() Geert Uytterhoeven
2021-02-24 22:43 ` Vladimir Oltean
2021-02-25 7:28 ` Geert Uytterhoeven [this message]
2021-02-25 17:50 ` patchwork-bot+netdevbpf
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='CAMuHMdVeAoPK_iB=Y73X_7zTEJnS6bFKkzCe8QyH8oyZA9OZ5A@mail.gmail.com' \
--to=geert@linux-m68k.org \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=f.fainelli@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=vivien.didelot@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).