Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2134621lqb; Mon, 27 May 2024 08:56:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUuvChjUeDqW1oSCtixdsoBzWv+CKpA7hcGm1pdtU+hLZcWh1T7xl8ueocl3mthWWm2Ap2lixoKAZAVdUTMRBizV2h+8+U/Z0QDd/OnIA== X-Google-Smtp-Source: AGHT+IEbKtOr92klfUCTEwz3VFw3+f/dEuJYBzTwvTm5OchL6eViS4nhEzbnQxb3aeYMETQ1yONS X-Received: by 2002:ac2:4462:0:b0:528:70db:5bc6 with SMTP id 2adb3069b0e04-52964aba746mr5899787e87.21.1716825392727; Mon, 27 May 2024 08:56:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716825392; cv=pass; d=google.com; s=arc-20160816; b=ZJuwV3aIhu2e0FxFcE/tGgUcnQ6Ez1ICZL65rMWi2ZZ86SmddWPuwIF5RliGsjNENf 7Q7sjSYZTANA0UMQts1L1q4XzzTfuAhvgaAYc4vtQrmxem7qRC3gDXZ5yHDGlTW1y/78 HiAqwdKTc7Ykv7PTEgy3Qru9Wm3oPC6qc7t+auuh6gBzV/YDSxPG7UA0MeoZn42wPc7G cogZ+px9+tIvLWrOqWu0TskHuB5nYRxKwgUVB+R6zUWvA6Ytz+U03f71aWGSe8pjgCBK Kf8twf0D/w8SR8zLGyNLNDZRFIIjHg9RbyjBzVIz/DkyZd0zSVzeHV4maIEPH3T8ecRj b34Q== 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=VezIZ8ufywHqRTcu9vicYZbEG6AXNLNHjdbHLg8Bafg=; fh=dDEHqx8+2Cdbhj2erMSrBXJBYLmZ9M87lDEG6vXcLzU=; b=G/vupPRCYjJdWgYDXcURw0DzQopj7yZYZIscttfZtTMo+xSqBjtAASsRosgppp4zay AYWaqQIE45madip554YNhD76QMv7eRuy9Yp7Ku+vzTcHLpMJvVvaATem91037/BYsp78 4uLClycgHr3HXiHuGA+ypbqyz+EiPRczPPfgBqUkSc3xeRIKitYlUH3NyE5m9NZOCyP6 2jSMAnr053af4bQHR1X/FuCDHI5S4ex6SIW79HEOQDmt8iO740GR6COQW+Mkd0fBrao3 96Vus1hEXPRk0NIyKAxmcgVUjYnNbl9xKwiL39nuX/wJi2pV2ITjupFf6+D5qb6CEQpz z95w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MiNOe5Ec; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-191121-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-191121-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57859f090f8si3896282a12.73.2024.05.27.08.56.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 08:56:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-191121-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MiNOe5Ec; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-191121-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-191121-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 733991F22A22 for ; Mon, 27 May 2024 15:56:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5A94F15A861; Mon, 27 May 2024 15:53:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MiNOe5Ec" 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 736AA15A84F; Mon, 27 May 2024 15:53:00 +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=1716825180; cv=none; b=Ur2slnA9S1+4ioHCf6PJv7MUGg6GerAAfcsMskvwOomNiPY0qX9wsfKIMBH4Q/nVUlBldau9iktl8/K895diu9ga+D0KkANsT8LKELm3tKh0Y5k8pE85l6L0V44sssf9mC9H3gJO0ubQjy9yh3Bre1p+sEIp8XiMWX4JI20ap3Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716825180; c=relaxed/simple; bh=QyS69jgg7CJB7UMnlbRSwr6HqSkeIzryJsG90rMbXzk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CW7KYt1FNVjuFmNE9DhWUCsVJV103t7tK8ghe1F1ZbMPb11AVc3CmKCgRE58dTAgaU9wTwC8QP60/QeTsEzE+zHfRww/du1NRhjFXHHom6fEkP+4kwT/GFOoPoK+ONgG796uMHsiJPQh7+4VDf5EVwHS95KCQLJ/reHSQD85q4c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MiNOe5Ec; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3DEF8C32781; Mon, 27 May 2024 15:52:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716825180; bh=QyS69jgg7CJB7UMnlbRSwr6HqSkeIzryJsG90rMbXzk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MiNOe5Ec+3n8O3gWt4qynzdnUzgb8bEPGDg618O9GOcUYbI76xSzRvjPQq5w2HeQ2 e41lp6spg85nI5lxQBZkAgfxMkL/ElAXccqLlVZlME5PaiWvYpm4M7HWfwGUVpJeYo mEB+MoVlGyxoJcpALTTlMhvfbtlho5vOosRrI6pLW0L5g8Xd645x3xgCys0VHJb5fj yFQaBhExSoWdxCZTtuJwYzkovMGPH2a16EuxGAFHu7/3enqspH2Q2HJox2PxFMg3mE OizrEqWK4cIkkIS4ioAmDRVfEe/I60qDAiNqDhNDj0NBt9+gy6dCBXBumFTLV5n1Ie xK5v6JXXCD8Zg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Michael Ellerman , Naresh Kamboju , Sasha Levin , nathan@kernel.org, bhe@redhat.com, arnd@arndb.de, akpm@linux-foundation.org, rppt@kernel.org, wangkefeng.wang@huawei.com, christophe.leroy@csgroup.eu, bhelgaas@google.com, stanislav.kinsburskii@gmail.com, linuxppc-dev@lists.ozlabs.org, llvm@lists.linux.dev Subject: [PATCH AUTOSEL 6.9 22/23] powerpc/io: Avoid clang null pointer arithmetic warnings Date: Mon, 27 May 2024 11:50:23 -0400 Message-ID: <20240527155123.3863983-22-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240527155123.3863983-1-sashal@kernel.org> References: <20240527155123.3863983-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.9.2 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 08c550ed49be6..ba2e13bb879dc 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