From: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
To: Justin Stitt <justinstitt@google.com>
Cc: Linus Walleij <linus.walleij@linaro.org>,
Miquel Raynal <miquel.raynal@bootlin.com>,
Richard Weinberger <richard@nod.at>,
Vignesh Raghavendra <vigneshr@ti.com>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Tom Rix <trix@redhat.com>,
linux-arm-kernel@lists.infradead.org,
linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev
Subject: Re: [PATCH] mtd: maps: fix -Wvoid-pointer-to-enum-cast warning
Date: Wed, 16 Aug 2023 07:34:53 +0200 [thread overview]
Message-ID: <1c4aa5ce-df78-b69c-0dc2-2859b0c1c3df@linaro.org> (raw)
In-Reply-To: <CAFhGd8rTU0o8uiGT1qUKbsOZTgqLR7Sw5h-+07y4SJ6QOd9KsA@mail.gmail.com>
On 16/08/2023 01:06, Justin Stitt wrote:
> On Tue, Aug 15, 2023 at 2:15 PM Krzysztof Kozlowski
> <krzysztof.kozlowski@linaro.org> wrote:
>>
>> On 15/08/2023 23:11, Justin Stitt wrote:
>>> When building with clang 18 I see the following warning:
>>> | drivers/mtd/maps/physmap-versatile.c:209:25: warning: cast to smaller
>>> | integer type 'enum versatile_flashprot' from 'const void *' [-Wvoid-pointer-to-enum-cast]
>>> | 209 | versatile_flashprot = (enum versatile_flashprot)devid->data;
>>>
>>> This is due to the fact that `devid->data` is a void* while `enum
>>> versatile_flashprot` has the size of an int. This leads to truncation
>>> and possible data loss.
>>
>> Cast does not solve truncation. This part of commit msg suggests that
>> you actually fix real issue... and that is an issue, because then
>> AUTOSEL will grab it. This is just compiler warning silencing and rather
>> coding standard correctness, no real fix, so please drop the sentence.
> OK, makes sense about this not technically solving an issue and thus
> AUTOSEL may pick it up. Can you elaborate, though, on how the cast
> doesn't solve truncation.
Because that is no how the C language work?
Casting UINTMAX+1 to unsigned int, does not magically change the
unsigned int into something else...
> Is the initial implementation not a
> pointer-width down to int-width cast?
These are different widths, so cast cannot solve truncation.
> Surely we're losing the top half
> of bits.
If we are losing top half then how is the truncation and data loss solved?
> I'm still not saying there's data loss, to be clear. Just
> that the compiler is warning because of the truncation.
Sorry, what truncation? The one which will happen always regardless of
the cast and warning?
Best regards,
Krzysztof
prev parent reply other threads:[~2023-08-16 5:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-15 21:11 Justin Stitt
2023-08-15 21:15 ` Krzysztof Kozlowski
2023-08-15 23:06 ` Justin Stitt
2023-08-16 5:34 ` Krzysztof Kozlowski [this message]
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=1c4aa5ce-df78-b69c-0dc2-2859b0c1c3df@linaro.org \
--to=krzysztof.kozlowski@linaro.org \
--cc=justinstitt@google.com \
--cc=linus.walleij@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=llvm@lists.linux.dev \
--cc=miquel.raynal@bootlin.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=richard@nod.at \
--cc=trix@redhat.com \
--cc=vigneshr@ti.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
all inboxes | Powered by JetHome®