From patchwork Mon Sep 27 09:37:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 514668 Delivered-To: patch@linaro.org Received: by 2002:a02:c816:0:0:0:0:0 with SMTP id p22csp3937672jao; Mon, 27 Sep 2021 02:38:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBHMOTpsAfm5I0Q3gHIPcEe7He1nJhaOUH5jTQMjEZ4R5W5uFh/OMXP3Bczynan3Vkcygi X-Received: by 2002:a63:2261:: with SMTP id t33mr5515256pgm.274.1632735493116; Mon, 27 Sep 2021 02:38:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632735493; cv=none; d=google.com; s=arc-20160816; b=Y1eqZfA8rT0hzs6LV7IWkGfbbgCIjG52De3lQRuBNXSNWiufNd/X3YVYVBg2mifs4T wBF+91LZuYsEUrwiHNKucBlE+23uy8JBxdOdoYRHacntYoPhKJt9klV7dncLEoLyEQQG 3oFzp1eglY9ACWiLDG/2u+8ZW+PpMTBQyciugLWuimEbBA3mZqHVGzpYejHqF0wJV7HP GsLWwTrvlGTao6IdA0Yy9xh+1InPojW40Yo2hRURc7jbQWpVLghOZutSAJ4qTffpdeWF Hg9qMpDvmj7Zx84Mef3som5mz5civlerEoR3E67LhqMwIIzgnHoGAsXW35zBVEaRawET 3oUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=/mxzqXvcBvlB0rltUYTi05C1REOZIfhMmt74YjKdeAA=; b=e6dSMRp5hqhOQabUnjUjOBA89z2XkDCrFjTMNrIDHKcOXYQl42W4qk6RjKRGNkap1t VXlFirJ41Ijgpgnl5jaA+TlkO5rEs08PGt6hCGxfZhJy9/3u7isZFfmupSfrN/Qr5PJA M05xQ3XhJE9g30SNa6MI85fqEBpoJWIY2MyfkejKUO17V4G53CbdwKI/6adMwBGDjReF f+zIBGfZSKNIiOEx9R6cpRogBwb/umST55+1QDZ8foT8V9wQmvmjf7gcZ7ljvbye4MaR w39R4PTA2/2iQdyS19CQrvx2zZHMyxFWpgkYW1EoVlY3dCOq3YUImVliOrRrYCPuDfpF VciA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nOGLAXut; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id kb14si23849033pjb.24.2021.09.27.02.38.10; Mon, 27 Sep 2021 02:38:13 -0700 (PDT) Received-SPF: pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nOGLAXut; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233737AbhI0Jjq (ORCPT + 8 others); Mon, 27 Sep 2021 05:39:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:45370 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233722AbhI0Jjp (ORCPT ); Mon, 27 Sep 2021 05:39:45 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2650161157; Mon, 27 Sep 2021 09:38:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632735487; bh=r3unqzpj0fOYnSoUg73JGoF/nR4E/IrF3UzNJJ94Uo0=; h=From:To:Cc:Subject:Date:From; b=nOGLAXutnF5xHS+z4e+lVuOVwFQVbpfJgMEeXfRc0oKyftVekmdLpju/822dj9Bkz Y4CAR9PqjBSnWf36ZSUQ1ANnc/U0aI6mVlbkoVoxgNlMKz7RTunvfXCYu3XECMBe7V Fl03K7orN2moG2+rvewTgJlElMXTHirV9FQpv7MoC8RzxktNPeY++odzjn9RwfZ2r+ U59jA5Uf4scfxk2xdZ0GM6vwbHwlGzBEhCF5B2/rcNU97Mud4JDcndVGBt99aYSboA /Mr7fEhhl9MLByyRfQYSeLq7pa8GgG8g+BQR9QiUpyIZa2ySlxBtRwUmcxRcBOqrRq B4MDgsuiAVI+Q== From: Arnd Bergmann To: "David S. Miller" , Jakub Kicinski , Nathan Chancellor , Nick Desaulniers Cc: Arnd Bergmann , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH] am65-cpsw: avoid null pointer arithmetic Date: Mon, 27 Sep 2021 11:37:57 +0200 Message-Id: <20210927093803.474510-1-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Arnd Bergmann clang warns about arithmetic on NULL pointers: drivers/net/ethernet/ti/am65-cpsw-ethtool.c:71:2: error: performing pointer subtraction with a null pointer has undefined behavior [-Werror,-Wnull-pointer-subtraction] AM65_CPSW_REGDUMP_REC(AM65_CPSW_REGDUMP_MOD_NUSS, 0x0, 0x1c), ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/net/ethernet/ti/am65-cpsw-ethtool.c:64:29: note: expanded from macro 'AM65_CPSW_REGDUMP_REC' .hdr.len = (((u32 *)(end)) - ((u32 *)(start)) + 1) * sizeof(u32) * 2 + \ ^ ~~~~~~~~~~~~~~~~ The expression here is easily changed to a calculation based on integers that is no less readable. Signed-off-by: Arnd Bergmann --- drivers/net/ethernet/ti/am65-cpsw-ethtool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.29.2 diff --git a/drivers/net/ethernet/ti/am65-cpsw-ethtool.c b/drivers/net/ethernet/ti/am65-cpsw-ethtool.c index 6e4d4f9e32e0..b05de9b61ad6 100644 --- a/drivers/net/ethernet/ti/am65-cpsw-ethtool.c +++ b/drivers/net/ethernet/ti/am65-cpsw-ethtool.c @@ -61,7 +61,7 @@ struct am65_cpsw_regdump_item { #define AM65_CPSW_REGDUMP_REC(mod, start, end) { \ .hdr.module_id = (mod), \ - .hdr.len = (((u32 *)(end)) - ((u32 *)(start)) + 1) * sizeof(u32) * 2 + \ + .hdr.len = (end + 4 - start) * 2 + \ sizeof(struct am65_cpsw_regdump_hdr), \ .start_ofs = (start), \ .end_ofs = end, \