Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp316071lqo; Fri, 10 May 2024 00:03:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUAEIcLBWm12GJfsljy614MeD6g/46nRszuvtA2GIWB+zm8g1SXLCFgaj/Iyh4Nh79eeOUUNsyDqvEuUX8pnywPhqweUD5gJfWQniWYnQ== X-Google-Smtp-Source: AGHT+IFjsIpjNFZbS6/tASeLJgeiphTTfdkrOyZT8s6OXdb9b0Y9IEAe50URzjW0FtcpZkT6aEbQ X-Received: by 2002:a05:622a:40e:b0:43d:f5bd:d41 with SMTP id d75a77b69052e-43dfdb22fe8mr18680411cf.39.1715324638791; Fri, 10 May 2024 00:03:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715324638; cv=pass; d=google.com; s=arc-20160816; b=t1Pp28PXDVZr5k15u912NNXxGiGVF3kB9xb8txBAmwGiqzIQ3ADmRp1Pz83sSRuVt8 tQCab5uh6/VRm1ZqpUik0MhqAa5J7pfyGw0g2LnkfFniIls4kjDnj5+uCyVmzuvZ3YNf seCAcMiCIM66b0sLzUy6tjFqVkU/KNwAu7lgWR7KEP8n0Ol0/a4rHsdbK3RNN3eUfeVe mE4Le/aZ9VZIFNvLyRgUp7ZQN2hp5Ao/WU0er3Bj6bONKG0+qPNVvrQ1/Z1NanABJkcp +4inH8clSZxHjc5J5jiNMJXHY8H/aactFc4zMxp3ZTcIRtiO2kUbZ3QcE9ijhaaQ5X1u KFtA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:references:in-reply-to:subject:cc:to:from :dkim-signature; bh=Wwz7PGF/2JLHmkgwfEtn4Lag7AXqlkDZb7B4D9iEdQI=; fh=ZtxnfsDAlUDYKRhpnPYxQ108QO1eymHrwUfCRQlg3+M=; b=K5brYwptC5UwaxVRUsiDER3Nv7Yc2/xDs90jfrgiOO5zoKpy5dUNmwbzX/Iif04n0L byvQWw/v4kWYp76KKxLVtKO64U/MwomAE3+6PUS4RnM2Y4MAvxT/pm3VhLuGoVbEL3hL 4PCvwawpyfX3oktddVreuc7Dwus4RqhZimm1MCqXNDpQwjh3bfsQ34k71vgPyE5Rxvlm sHYHbv0WIRbvTe/Qr74DRRLmJ5gi9917mMQagJAnC0IzRJPANilMODV/10thp5foSWf4 2w3SsLWjo/Qop4978a8O5v1yNABPEtOxtFGL9fxHiiRjoLcvsYElXRT9qD1oekZZDw2O Tn6A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=d1Z7pyrE; 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-175374-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175374-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-43df568910asi29310551cf.392.2024.05.10.00.03.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 00:03:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-175374-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=d1Z7pyrE; 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-175374-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175374-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 8583C1C221B7 for ; Fri, 10 May 2024 07:03:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2384F15D5BD; Fri, 10 May 2024 07:03:52 +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="d1Z7pyrE" 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 7410715217A for ; Fri, 10 May 2024 07:03:47 +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=1715324631; cv=none; b=QV+ir/64jo7i6HamQs/kXHwSdkVXUiXjs6eiJWMb1uHZv0IBjGOJrJyzqeO/fxlmpGUSpbk24y1el18df7lCVsOmU/VNKsDoDdFx3uVZu5nPPi3+tOBHBd0SPIQz+Dv3HtkSVHx/LWV0yOer9OGWB0E0uowGrd7oRHvIHkhOUQ0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715324631; c=relaxed/simple; bh=SoDlZE87hfnURumY7SGIdDEMti6ngKTU8lVyyVE7Jgo=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=t+TWzuXCB3kr5I97BZuD65MsPymxvU5iDzCO7Ok1TL8Np/ikkhrH5k6zzrbeeG9IjbwNxaHGfvLWPOs93uWgyB37Z6j41REFSeNP13jViU7lrorbV5Ee9rnYg1R+1P5vCwe9fXeLrmZ2tUtP30NJr/YFbsskEsvzw0p1lJ3VDKI= 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=d1Z7pyrE; 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=1715324626; bh=Wwz7PGF/2JLHmkgwfEtn4Lag7AXqlkDZb7B4D9iEdQI=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=d1Z7pyrEGBrs6L0dz6cxVggbbbxS4Owx0CmDlA2znN4HgBBG3unC7rP44d4u5muzJ sW6V4HKKp5OuQRS5dDqKiVPOAJJdFBRzJjXVfKWS3xawstBOT548LbQUjb0K9AUi3m TIPnWU/d63yWYygXxoAoPG5Eu0nYq0rJy2yqmDx61YaPDYITg0L9haUpysurM+9Jis mNZz4QMY4q9wj8LBHjY47tQGLA2B4LSyqC0YLLcgDY6kyAZtOH/+cv9gtLPWhh7W3D /t0FWdL/FzbE3P03a5nRQSfQjoSC9TGSahFl4bvIlbbzVPdT15a51DEFnQfpQp5AB6 yHZ62XQb2poTw== 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 4VbKc13n7cz4wcC; Fri, 10 May 2024 17:03:45 +1000 (AEST) From: Michael Ellerman To: Naresh Kamboju 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 In-Reply-To: References: <20240503075619.394467-1-mpe@ellerman.id.au> Date: Fri, 10 May 2024 17:03:45 +1000 Message-ID: <87fruqm9m6.fsf@mail.lhotse> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Naresh Kamboju writes: > On Fri, 3 May 2024 at 13:26, Michael Ellerman 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 >> Closes: https://lore.kernel.org/all/CA+G9fYtEh8zmq8k8wE-8RZwW-Qr927RLTn+KqGnq1F=ptaaNsA@mail.gmail.com >> Signed-off-by: Michael Ellerman > > Tested-by: Linux Kernel Functional Testing Thanks. cheers