From: Dan Carpenter <dan.carpenter@linaro.org>
To: SilverPlate3 <arielsilver77@gmail.com>
Cc: forest@alittletooquiet.net, gregkh@linuxfoundation.org,
linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Staging: vt6655: Fix sparse warning. Restricted cast.
Date: Tue, 9 Jan 2024 15:22:19 +0300 [thread overview]
Message-ID: <d6489a61-3985-4fc2-9eda-333ea8fa02ae@moroto.mountain> (raw)
In-Reply-To: <20240109072704.44582-1-arielsilver77@gmail.com>
On Tue, Jan 09, 2024 at 09:27:04AM +0200, SilverPlate3 wrote:
> Running 'make M=drivers/staging/vt6655 C=2'
> causes sparse to generate few warnings.
> This patch fixes the following warnings by ensuring le64_to_cpu
> handles only __le64 values, thus dismissing chances of bad endianness.
> * drivers/staging/vt6655/card.c:302:45: warning: cast to restricted __le64
> * drivers/staging/vt6655/card.c:336:23: warning: cast to restricted __le64
> * drivers/staging/vt6655/card.c:804:23: warning: cast to restricted __le64
> * drivers/staging/vt6655/card.c:831:18: warning: cast to restricted __le64
>
> Signed-off-by: Ariel Silver <arielsilver77@gmail.com>
> ---
> drivers/staging/vt6655/card.c | 16 ++++++++++++----
> 1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/staging/vt6655/card.c b/drivers/staging/vt6655/card.c
> index 350ab8f3778a..5dc2200466b7 100644
> --- a/drivers/staging/vt6655/card.c
> +++ b/drivers/staging/vt6655/card.c
> @@ -292,6 +292,7 @@ bool card_update_tsf(struct vnt_private *priv, unsigned char rx_rate,
> {
> u64 local_tsf;
> u64 qwTSFOffset = 0;
> + __le64 le_qwTSFOffset = 0;
>
> local_tsf = vt6655_get_current_tsf(priv);
>
> @@ -299,7 +300,8 @@ bool card_update_tsf(struct vnt_private *priv, unsigned char rx_rate,
> qwTSFOffset = CARDqGetTSFOffset(rx_rate, qwBSSTimestamp,
> local_tsf);
> /* adjust TSF, HW's TSF add TSF Offset reg */
> - qwTSFOffset = le64_to_cpu(qwTSFOffset);
> + le_qwTSFOffset = cpu_to_le64(qwTSFOffset);
> + qwTSFOffset = le64_to_cpu(le_qwTSFOffset);
This isn't right at all. You've just to convert it and then convert it
back. (In other words do nothing but in a very complicated way).
This isn't a bug, it's just an issue of annotations. The code is
re-using a single variable to hold both cpu and little endian data. So
the way to write the annotations is to create two variables, one that's
cpu endian and one that's little endian.
regards,
dan carpenter
next prev parent reply other threads:[~2024-01-09 12:22 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-09 7:27 [PATCH] Staging: vt6655: Fix sparse warning. Restricted cast SilverPlate3
2024-01-09 7:49 ` Greg KH
2024-01-09 12:22 ` Dan Carpenter [this message]
[not found] ` <CACKMdf=Kppts=NzTVsNNuFcYge2HU+vG83b2C2QNyPEsiFHnkw@mail.gmail.com>
2024-01-10 7:25 ` Dan Carpenter
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=d6489a61-3985-4fc2-9eda-333ea8fa02ae@moroto.mountain \
--to=dan.carpenter@linaro.org \
--cc=arielsilver77@gmail.com \
--cc=forest@alittletooquiet.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
/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