Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2151878lqb; Mon, 27 May 2024 09:23:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXkAij/bCkulBfUesuJYqzS2ul1cnT6v0es4M24aLb61htRBdMkFX243AW2CqMLr6Srn6u1oApQw+MSLYUZ0HYSQdMSSzMoZp3xavkiCQ== X-Google-Smtp-Source: AGHT+IHsBmiIHGglVAJ/7f9BpjV0qzdvQN+120oc2be2pOk1cArRKoALroHSwDLEu1+ne0oGCXnr X-Received: by 2002:a05:6358:cc29:b0:186:b3e5:abb2 with SMTP id e5c5f4694b2df-197e5467a99mr922388055d.22.1716826994173; Mon, 27 May 2024 09:23:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716826994; cv=pass; d=google.com; s=arc-20160816; b=grOn3pQySL1gfAeCcf0u2ytMi/8PL6clUrYthwvsXaLTHFj3fzWVg2NlrhAkhyEc3X vNZR4cm5VqPlSuvjgsrFTr8UFIC3h8+dW+JpJb3rdTfmHVsx57gGyNEQjO6l3jx/Gs/v a53mxiLd5GnBbGjy8AwtpnBsseTP5RiDufG6eGh5f/uSVZ13UtXmmv6KmN1pCfdUn/O8 xHEl3i3ghWq70MWxgkji3cs5fX/pGRvwyWBUMKt40ToAsqQQmxSI+ayTxpuUDslbCMna yI1vUudGeWdt1RozmHUs63/5vOAba6kCwYjLYUeyjSGVor/qPL4Pe2L6m5Ib+yjqg+vn 8k6Q== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Wb+ME3loIs679ZYgQB0MM0anCbrj8gYeMHj977l6zmc=; fh=xcr817tY8DaNp95AjexYsu2fTi4SSzzUjb4A+hR/L6g=; b=jPLS5Iby02fBSOxvFRejLnETf5a2QkJ1ZBYYfN1NIxpOkfZ9H7CCvEeMBtaA8Qf/E6 dmlrKyEiPAvxd2snztD+T8mpwvylke8+ZS6T7s5LoFgLVKRm/Dz3WNP1DGO5vI+3Q1p2 EJUIX41riiATpGkCLzHNRDT2u6lYKF1ZTh/lmK1xnkXlPK7fyyU3i25g9826R+MwAmqO dFocEOjEdPgAgv3QkAM/ZrcW9ZNxeqGzkOtHjN0Q+HD8ioRz3HX96S6e/puD8XbfaqQv 21T24EQumjaLZXVwpVIh0A4u9H/0s7lQA8+l+XSxEEm2uFOeDwN3melOUt9zdUTWkWof IUvQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=R6XlWeNF; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-191158-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-191158-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-68229935fc4si6577810a12.625.2024.05.27.09.23.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 09:23:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-191158-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=R6XlWeNF; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-191158-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-191158-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 9F312291D49 for ; Mon, 27 May 2024 16:04:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A7EB516D4E1; Mon, 27 May 2024 15:56:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="R6XlWeNF" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 BE1D07345B; Mon, 27 May 2024 15:56:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716825406; cv=none; b=FeV3TkLqFdquj1XP7nx9tLKqMW3yVInr8Cvlaq1ABW2hS4rKMceuP7+jRDcffLKby3EpU+mibLBa/R82/jruPUnXhgy7AHG+RdFNw3xJ6w8NOK/aG/wVNxxVhWUWH1uQE81REwdhT8a05w3usR2gkX/HQKxT56NOCQ4kLXdgeaI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716825406; c=relaxed/simple; bh=+AC7xpRWLi6eiPgRbMT4SkLSvtDXs5ycUktdEd2xH2E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DSnt96D55aCZoPa9I/2hPNPXxJXDlU5G0403nvuFpXlCzA8Kn2K9SgrzvnL430hX+0aKg1iBMt4gFy1QhRyyE/S5/vnMV+FHN92AM4jy8I/V5UaH1vVS/OzaK4lFB5hHkwHpI/uTAlWG4vAzIGJTyv5LyB19E8NH3wvD/hQSwkA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=R6XlWeNF; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id DCC26C32789; Mon, 27 May 2024 15:56:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716825406; bh=+AC7xpRWLi6eiPgRbMT4SkLSvtDXs5ycUktdEd2xH2E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R6XlWeNF/bGiKpSy3XdvMOWQ5e1C4wn6manIK4xF7XoY5WZpWsau+utLZQ3uTNcIV KwZMMAefy2hS1GnmgitCP8o9wkzG+PrCE4KYm+SrM3Mi+JbZ9kGkW70WsdYk48LYQJ NNrC2kN0Inp4e+2TvtNPcbfGxz3/0XBf5oweuHC3BZLya4fGLwPaRxQbWkJQmpvASG b9oeuiJtCvZ53m8OKoDe+JEzf1YmCgC+ftrlBGVTj6ZrFaF2YXUNLJFIckUcG7oRmM NO6UOEuhrNyUXoqaikKk+xR2wiTbVrOTk/l0PnH+7J8gKfBC4VSJHYyTG3KdLrPzsr +Mhse3vAU8vTQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Michael Ellerman , Naresh Kamboju , Sasha Levin , nathan@kernel.org, arnd@arndb.de, bhe@redhat.com, geert@linux-m68k.org, rppt@kernel.org, wangkefeng.wang@huawei.com, stanislav.kinsburskii@gmail.com, bhelgaas@google.com, christophe.leroy@csgroup.eu, linuxppc-dev@lists.ozlabs.org, llvm@lists.linux.dev Subject: [PATCH AUTOSEL 6.6 15/16] powerpc/io: Avoid clang null pointer arithmetic warnings Date: Mon, 27 May 2024 11:55:06 -0400 Message-ID: <20240527155541.3865428-15-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240527155541.3865428-1-sashal@kernel.org> References: <20240527155541.3865428-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.6.32 Content-Transfer-Encoding: 8bit From: Michael Ellerman [ Upstream commit 03c0f2c2b2220fc9cf8785cd7b61d3e71e24a366 ] 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 Link: https://msgid.link/20240503075619.394467-1-mpe@ellerman.id.au Signed-off-by: Sasha Levin --- arch/powerpc/include/asm/io.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/arch/powerpc/include/asm/io.h b/arch/powerpc/include/asm/io.h index 0732b743e0996..59cc25cb4578e 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.43.0