From: Michael Ellerman <mpe@ellerman.id.au>
To: Naresh Kamboju <naresh.kamboju@linaro.org>
Cc: linuxppc-dev@lists.ozlabs.org, arnd@arndb.de,
linux-kernel@vger.kernel.org, nathan@kernel.org
Subject: Re: [PATCH v2 1/2] powerpc/io: Avoid clang null pointer arithmetic warnings
Date: Fri, 10 May 2024 17:03:45 +1000 [thread overview]
Message-ID: <87fruqm9m6.fsf@mail.lhotse> (raw)
In-Reply-To: <CA+G9fYvo4--rSTHC1Vxdbbe62O6FhL_P2XdcF2Q7ZRku8HjpGg@mail.gmail.com>
Naresh Kamboju <naresh.kamboju@linaro.org> writes:
> On Fri, 3 May 2024 at 13:26, Michael Ellerman <mpe@ellerman.id.au> wrote:
>>
>> With -Wextra clang warns about pointer arithmetic using a null pointer.
>> When building with CONFIG_PCI=n, that triggers a warning in the IO
>> accessors, eg:
>>
>> In file included from linux/arch/powerpc/include/asm/io.h:672:
>> linux/arch/powerpc/include/asm/io-defs.h:23:1: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
>> 23 | DEF_PCI_AC_RET(inb, u8, (unsigned long port), (port), pio, port)
>> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> ...
>> linux/arch/powerpc/include/asm/io.h:591:53: note: expanded from macro '__do_inb'
>> 591 | #define __do_inb(port) readb((PCI_IO_ADDR)_IO_BASE + port);
>> | ~~~~~~~~~~~~~~~~~~~~~ ^
>>
>> That is because when CONFIG_PCI=n, _IO_BASE is defined as 0.
>>
>> Although _IO_BASE is defined as plain 0, the cast (PCI_IO_ADDR) converts
>> it to void * before the addition with port happens.
>>
>> Instead the addition can be done first, and then the cast. The resulting
>> value will be the same, but avoids the warning, and also avoids void
>> pointer arithmetic which is apparently non-standard.
>>
>> Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
>> Closes: https://lore.kernel.org/all/CA+G9fYtEh8zmq8k8wE-8RZwW-Qr927RLTn+KqGnq1F=ptaaNsA@mail.gmail.com
>> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
>
> Tested-by: Linux Kernel Functional Testing <lkft@linaro.org>
Thanks.
cheers
prev parent reply other threads:[~2024-05-10 7:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-03 7:56 [PATCH v2 1/2] powerpc/io: Avoid clang null pointer arithmetic warnings Michael Ellerman
2024-05-03 7:56 ` [PATCH v2 2/2] powerpc/64: Set _IO_BASE to POISON_POINTER_DELTA not 0 for CONFIG_PCI=n Michael Ellerman
2024-05-08 13:39 ` [PATCH v2 1/2] powerpc/io: Avoid clang null pointer arithmetic warnings Michael Ellerman
2024-05-08 14:34 ` Naresh Kamboju
2024-05-10 7:03 ` Michael Ellerman [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=87fruqm9m6.fsf@mail.lhotse \
--to=mpe@ellerman.id.au \
--cc=arnd@arndb.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=naresh.kamboju@linaro.org \
--cc=nathan@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox