Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1624514lqm; Fri, 3 May 2024 00:57:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUsnMpxvcVWUtN3iXNw23hhCXf9WBnxTn1JTs2yRRHWdhhq7XjCPAHFYYhKvN9GdnjSVtH6E3cskcZvflViH3qn7/fBwRoamGazvSuOfA== X-Google-Smtp-Source: AGHT+IEwzToZ6V8bJAbYNL4syUEw3g/3kjTk1gx5poG5ItuldUwGe4ptAytGXPCsgkPQ08URkpf9 X-Received: by 2002:a17:903:1c2:b0:1e4:6243:8543 with SMTP id e2-20020a17090301c200b001e462438543mr2061669plh.5.1714723020660; Fri, 03 May 2024 00:57:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714723020; cv=pass; d=google.com; s=arc-20160816; b=E1XtSz/ntktjHGqvBlYDJVfZmcZAf2aliabHpUyyZxg69P/TDIkvCt4trDcTHKWrE9 obmwgplm+YUTJ5AP7CoVCpomYehpK1pXQziS/cieU+IfSYnUuCLFb99Emw8/R1ae3SRX J4XVkLngj/eGXNjje4Wa+JwBiTc03gMrZReW/X8S3sun5aMESjIrc5y8uJWmHv9zcOTH nQ2lfr/OhN8woQMQSWxSsQrdOP3k2/9ScA23hAEgGjiyq+axL5Ivvh/s5+L0RO858eg1 UTEW4Nouuh3yPhfAOwBT3xdUwomlsygZb911exvIFBFCP1t3tMUqOmSh9UfAZVmt2su5 AiZQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=UjLD++sCprS88MnBhqOqFETPu+2OZQ+7tRYQ68fD7jM=; fh=L38zScl+VZHDFmp+iaH+R3rKFjWPXZcHLMoDD9gWZ8M=; b=vyZ0qy1jIkNPIJIU0byN+fwe3ZrxAim1Ilh8BtdLDCySGIoIXvnFgLgmvNL+qanWgz wTEuYqsL0VpKB+LLrZVbDNLgSQpa1AJaoqFuRy7JXaFL7oCPJFvduX0EdbwqB0saWLkK URuaD8oOmmmPmjR67L4VeWphAcaoA3fy+DFqqSQYAAPooQX1rrZohTSzrzS1y+BOsSoM 4FEt/D423hFbnaTbWEWkNx7ACsqxu58B8qb97xmqntUAIUeSgu8Hz1cZWI4+zRXHv/Or dsJB1lm1DBHjJ17qQf8hMg2wCP99P4ObJdyqrhrxPrcp5eHH+M4HxdNGgrdjBX35oWKh 9wOA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=QIqslCSC; arc=pass (i=1 spf=pass spfdomain=ellerman.id.au dkim=pass dkdomain=ellerman.id.au); spf=pass (google.com: domain of linux-kernel+bounces-167341-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167341-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id y8-20020a17090322c800b001e7a248eaafsi2537838plg.6.2024.05.03.00.57.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 00:57:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-167341-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=QIqslCSC; arc=pass (i=1 spf=pass spfdomain=ellerman.id.au dkim=pass dkdomain=ellerman.id.au); spf=pass (google.com: domain of linux-kernel+bounces-167341-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167341-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 1F352B2181F for ; Fri, 3 May 2024 07:56:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5974B1487D8; Fri, 3 May 2024 07:56:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ellerman.id.au header.i=@ellerman.id.au header.b="QIqslCSC" Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A3A412B89 for ; Fri, 3 May 2024 07:56:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=150.107.74.76 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714722995; cv=none; b=k5IkHQQIPtP/ioCaYI4QEt9B9s2CtyNLhgSVDzmZhtiKrPhxk2SnxLItFYYgANdx7sOq1eWwsHx2rVc+k6dlqa94xagGNWMw5KyIzeFPxGxEJudmiBtYKV+j2F15WkcpUR03/ooOUGcYomkQN7+ysbbjS9UGDuCWkLlsYpQiD1M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714722995; c=relaxed/simple; bh=R8T1v8EZH/ISTf7ox7ECemx6mr1HcouHkvC0u50vIbk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=qPMX4s/0FwpvtmS0wJWI+/KpijPbywClzyfBvoCIf6kIbN78hK9Hdo+ffbn0JugGfTPXpQrpkGU3kTY5ICCThKucYzlxq4lEOOR+duE60KGKCCvwGbe5rM4vN4kakRPpumaCyIirGw7FdkGE38+V9z8aYyaZPMfq6qTyJyFHdkM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ellerman.id.au; spf=pass smtp.mailfrom=ellerman.id.au; dkim=pass (2048-bit key) header.d=ellerman.id.au header.i=@ellerman.id.au header.b=QIqslCSC; arc=none smtp.client-ip=150.107.74.76 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ellerman.id.au Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ellerman.id.au DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ellerman.id.au; s=201909; t=1714722991; bh=UjLD++sCprS88MnBhqOqFETPu+2OZQ+7tRYQ68fD7jM=; h=From:To:Cc:Subject:Date:From; b=QIqslCSC6eNXBXzKXle8voU3oFdZO3C+zysmqRxMpHw/vwcUaM8Y3IIqUSTtM1r2C WCUsuQ6U7hOky2ZeRbctD7TAcTJqrvNcFbjsEeGqeltJ+55QqepjThflzU8jjWXTE6 FNfBolzylSeMXzEp3RECifsnFFb9T8k7tRZnijg+ln2jglAcZgI8heQkXXr0ZZ/pjw 8BFuwe6nM4U56Pbpn+kePz9lC3e66cQyhVXCFxzc9Ln+UD5KTn5SJ5AeyAP0FJjP41 R5Zb4lnZNJ+nsrmeo3OpX+cLZiTOmp1Rx9Zi8PCx4ukB9kGp2YaN6YvNHrR+fokFCO qiIvbYq15hLkg== Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4VW3670lMSz4wcr; Fri, 3 May 2024 17:56:31 +1000 (AEST) From: Michael Ellerman To: Cc: , naresh.kamboju@linaro.org, , Subject: [PATCH v2 1/2] powerpc/io: Avoid clang null pointer arithmetic warnings Date: Fri, 3 May 2024 17:56:18 +1000 Message-ID: <20240503075619.394467-1-mpe@ellerman.id.au> X-Mailer: git-send-email 2.44.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Closes: https://lore.kernel.org/all/CA+G9fYtEh8zmq8k8wE-8RZwW-Qr927RLTn+KqGnq1F=ptaaNsA@mail.gmail.com Signed-off-by: Michael Ellerman --- arch/powerpc/include/asm/io.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) v2: New. diff --git a/arch/powerpc/include/asm/io.h b/arch/powerpc/include/asm/io.h index 08c550ed49be..ba2e13bb879d 100644 --- a/arch/powerpc/include/asm/io.h +++ b/arch/powerpc/include/asm/io.h @@ -585,12 +585,12 @@ __do_out_asm(_rec_outl, "stwbrx") #define __do_inw(port) _rec_inw(port) #define __do_inl(port) _rec_inl(port) #else /* CONFIG_PPC32 */ -#define __do_outb(val, port) writeb(val,(PCI_IO_ADDR)_IO_BASE+port); -#define __do_outw(val, port) writew(val,(PCI_IO_ADDR)_IO_BASE+port); -#define __do_outl(val, port) writel(val,(PCI_IO_ADDR)_IO_BASE+port); -#define __do_inb(port) readb((PCI_IO_ADDR)_IO_BASE + port); -#define __do_inw(port) readw((PCI_IO_ADDR)_IO_BASE + port); -#define __do_inl(port) readl((PCI_IO_ADDR)_IO_BASE + port); +#define __do_outb(val, port) writeb(val,(PCI_IO_ADDR)(_IO_BASE+port)); +#define __do_outw(val, port) writew(val,(PCI_IO_ADDR)(_IO_BASE+port)); +#define __do_outl(val, port) writel(val,(PCI_IO_ADDR)(_IO_BASE+port)); +#define __do_inb(port) readb((PCI_IO_ADDR)(_IO_BASE + port)); +#define __do_inw(port) readw((PCI_IO_ADDR)(_IO_BASE + port)); +#define __do_inl(port) readl((PCI_IO_ADDR)(_IO_BASE + port)); #endif /* !CONFIG_PPC32 */ #ifdef CONFIG_EEH @@ -606,12 +606,12 @@ __do_out_asm(_rec_outl, "stwbrx") #define __do_writesw(a, b, n) _outsw(PCI_FIX_ADDR(a),(b),(n)) #define __do_writesl(a, b, n) _outsl(PCI_FIX_ADDR(a),(b),(n)) -#define __do_insb(p, b, n) readsb((PCI_IO_ADDR)_IO_BASE+(p), (b), (n)) -#define __do_insw(p, b, n) readsw((PCI_IO_ADDR)_IO_BASE+(p), (b), (n)) -#define __do_insl(p, b, n) readsl((PCI_IO_ADDR)_IO_BASE+(p), (b), (n)) -#define __do_outsb(p, b, n) writesb((PCI_IO_ADDR)_IO_BASE+(p),(b),(n)) -#define __do_outsw(p, b, n) writesw((PCI_IO_ADDR)_IO_BASE+(p),(b),(n)) -#define __do_outsl(p, b, n) writesl((PCI_IO_ADDR)_IO_BASE+(p),(b),(n)) +#define __do_insb(p, b, n) readsb((PCI_IO_ADDR)(_IO_BASE+(p)), (b), (n)) +#define __do_insw(p, b, n) readsw((PCI_IO_ADDR)(_IO_BASE+(p)), (b), (n)) +#define __do_insl(p, b, n) readsl((PCI_IO_ADDR)(_IO_BASE+(p)), (b), (n)) +#define __do_outsb(p, b, n) writesb((PCI_IO_ADDR)(_IO_BASE+(p)),(b),(n)) +#define __do_outsw(p, b, n) writesw((PCI_IO_ADDR)(_IO_BASE+(p)),(b),(n)) +#define __do_outsl(p, b, n) writesl((PCI_IO_ADDR)(_IO_BASE+(p)),(b),(n)) #define __do_memset_io(addr, c, n) \ _memset_io(PCI_FIX_ADDR(addr), c, n) -- 2.44.0