From patchwork Tue Mar 23 12:53:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 406866 Delivered-To: patch@linaro.org Received: by 2002:a17:906:5290:0:0:0:0 with SMTP id c16csp2115149ejm; Tue, 23 Mar 2021 05:54:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRbe9xkslzpJgoayGMmSyWk+PhSP9rltIxky8kPTvId2uhY4oqU3XUSMbwo+WIq7+AASJ3 X-Received: by 2002:a50:e882:: with SMTP id f2mr4550424edn.184.1616504072442; Tue, 23 Mar 2021 05:54:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616504072; cv=none; d=google.com; s=arc-20160816; b=vT1K1Y1HSQQNn8ZnFwn1TDV0LhVhW3qd5d+f4oMbXcPFk17t0aeanwCMlrAJkCzv7a mXopfJZ+zlOnL8K4NDFp/jVrh2d9wUKLcP7+xZ2mADiJbP6bXB1oh/YCn6Uak0jKYVgb W2WQ8TdEWyG96ltF5Bcni979mLJlVdx4j3shUYS5gq7wiR5iZyIRWMdbRVbszhKPjuts c1Lv6/tRFTG06ZhNI7jwzcdadq9llTIpQwnPcAVvq3n5rYbA3EmQ7WBDqU8NrZxm3NrI puqN5np6mjbg11lDBBwrFl3NmZQHR47VvLgQj9CbAneB4d0CWcGNfKDTOf+Kyu+CCQFN AGSA== 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=U4uv/j0Ulgm+8lPZkCr5i3JBEeXXJ6F3A462e7aOpR0=; b=Gs/6T0EE7azuDum+nY3k2f+ykDj3JnSQloM1JV0RrPM8JptYDA1bgSULS7qdfd7rw6 1KEwG+cPo7kMhAhFWqFdt6MTiOW9MzpOTkJBOIeB8QdGnFNDcGPwyBE1zhFJZOzttbJL jFE4a7DGFbMpjsiEOy/0Tnu9Ja4z3s27Zq0P/lRaA6T6mXXC/znT4CK5zPG7hVi6hvK/ kN7hqNSO73Tkrjz1QbzumaQUGI5DTU7Ava4e7fYmZ6dL2TFO0yzR0C7vdgykSHC+mJsT 7c8bckp5pEcXKzPG6VmfXloIl29kyvbQ/s7hAZ9feXDTpENxzefUYRrnUAmxkBNmL8c0 17TA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oKP9MQbS; 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 hp17si10154019ejc.744.2021.03.23.05.54.32; Tue, 23 Mar 2021 05:54:32 -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=oKP9MQbS; 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 S231334AbhCWMyA (ORCPT + 8 others); Tue, 23 Mar 2021 08:54:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:40394 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230258AbhCWMxn (ORCPT ); Tue, 23 Mar 2021 08:53:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8A8B9619B8; Tue, 23 Mar 2021 12:53:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616504023; bh=B7zKP0wEFU2/3CWm2Zth2CEFBBqTytn5CoddIaTYU+I=; h=From:To:Cc:Subject:Date:From; b=oKP9MQbSO7Nq/q3n9+857PVW8po2CYEGWqF9iMOK0snF3j70JImIfLbBlYJNV2NTu K0lac8eIdd4H2GuhddVgKlWxnxl52/XouEIc/0nSF0mUhb2KXeTyHUZ6d0M7TVhd1x PETGi0NGmQqcDedfAQ9Tpewc8sVKByJ9xlH9BRHXNDsBjitZEyPtVQlGqAsP1NST9t 9B3DCJyeViYxuIA8Hl+HhHIBVt1VsgR5W6VuxTBCTlDZNLF4ryqYoO0H/7Ya8egFsc xajjxOnlxieXLWYOWAgf7mAw7eqb2Y1xkwYAVsg2V4m+a81HKpbFx9gOTH0ykT2Xqu lr2TE7kBTaTSQ== From: Arnd Bergmann To: Sunil Goutham , Linu Cherian , Geetha sowjanya , Jerin Jacob , hariprasad , Subbaraya Sundeep , "David S. Miller" , Jakub Kicinski Cc: Arnd Bergmann , Christina Jacob , Zyta Szpak , Colin Ian King , Rakesh Babu , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next] octeontx2: fix -Wnonnull warning Date: Tue, 23 Mar 2021 13:53:29 +0100 Message-Id: <20210323125337.1783611-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 When compile testing this driver on a platform on which probe() is known to fail at compile time, gcc warns about the cgx_lmactype_string[] array being uninitialized: In function 'strncpy', inlined from 'link_status_user_format' at /git/arm-soc/drivers/net/ethernet/marvell/octeontx2/af/cgx.c:838:2, inlined from 'cgx_link_change_handler' at /git/arm-soc/drivers/net/ethernet/marvell/octeontx2/af/cgx.c:853:2: include/linux/fortify-string.h:27:30: error: argument 2 null where non-null expected [-Werror=nonnull] 27 | #define __underlying_strncpy __builtin_strncpy Address this by turning the runtime initialization into a fixed array, which should also produce better code. Signed-off-by: Arnd Bergmann --- .../net/ethernet/marvell/octeontx2/af/cgx.c | 60 +++++++++---------- 1 file changed, 28 insertions(+), 32 deletions(-) -- 2.29.2 Acked-by: Sunil Goutham diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c b/drivers/net/ethernet/marvell/octeontx2/af/cgx.c index 9caa375d01b1..ea5a033a1d0b 100644 --- a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c +++ b/drivers/net/ethernet/marvell/octeontx2/af/cgx.c @@ -30,10 +30,35 @@ static LIST_HEAD(cgx_list); /* Convert firmware speed encoding to user format(Mbps) */ -static u32 cgx_speed_mbps[CGX_LINK_SPEED_MAX]; +static const u32 cgx_speed_mbps[CGX_LINK_SPEED_MAX] = { + [CGX_LINK_NONE] = 0, + [CGX_LINK_10M] = 10, + [CGX_LINK_100M] = 100, + [CGX_LINK_1G] = 1000, + [CGX_LINK_2HG] = 2500, + [CGX_LINK_5G] = 5000, + [CGX_LINK_10G] = 10000, + [CGX_LINK_20G] = 20000, + [CGX_LINK_25G] = 25000, + [CGX_LINK_40G] = 40000, + [CGX_LINK_50G] = 50000, + [CGX_LINK_80G] = 80000, + [CGX_LINK_100G] = 100000, +}; /* Convert firmware lmac type encoding to string */ -static char *cgx_lmactype_string[LMAC_MODE_MAX]; +static const char *cgx_lmactype_string[LMAC_MODE_MAX] = { + [LMAC_MODE_SGMII] = "SGMII", + [LMAC_MODE_XAUI] = "XAUI", + [LMAC_MODE_RXAUI] = "RXAUI", + [LMAC_MODE_10G_R] = "10G_R", + [LMAC_MODE_40G_R] = "40G_R", + [LMAC_MODE_QSGMII] = "QSGMII", + [LMAC_MODE_25G_R] = "25G_R", + [LMAC_MODE_50G_R] = "50G_R", + [LMAC_MODE_100G_R] = "100G_R", + [LMAC_MODE_USXGMII] = "USXGMII", +}; /* CGX PHY management internal APIs */ static int cgx_fwi_link_change(struct cgx *cgx, int lmac_id, bool en); @@ -657,34 +682,6 @@ int cgx_fwi_cmd_generic(u64 req, u64 *resp, struct cgx *cgx, int lmac_id) return err; } -static inline void cgx_link_usertable_init(void) -{ - cgx_speed_mbps[CGX_LINK_NONE] = 0; - cgx_speed_mbps[CGX_LINK_10M] = 10; - cgx_speed_mbps[CGX_LINK_100M] = 100; - cgx_speed_mbps[CGX_LINK_1G] = 1000; - cgx_speed_mbps[CGX_LINK_2HG] = 2500; - cgx_speed_mbps[CGX_LINK_5G] = 5000; - cgx_speed_mbps[CGX_LINK_10G] = 10000; - cgx_speed_mbps[CGX_LINK_20G] = 20000; - cgx_speed_mbps[CGX_LINK_25G] = 25000; - cgx_speed_mbps[CGX_LINK_40G] = 40000; - cgx_speed_mbps[CGX_LINK_50G] = 50000; - cgx_speed_mbps[CGX_LINK_80G] = 80000; - cgx_speed_mbps[CGX_LINK_100G] = 100000; - - cgx_lmactype_string[LMAC_MODE_SGMII] = "SGMII"; - cgx_lmactype_string[LMAC_MODE_XAUI] = "XAUI"; - cgx_lmactype_string[LMAC_MODE_RXAUI] = "RXAUI"; - cgx_lmactype_string[LMAC_MODE_10G_R] = "10G_R"; - cgx_lmactype_string[LMAC_MODE_40G_R] = "40G_R"; - cgx_lmactype_string[LMAC_MODE_QSGMII] = "QSGMII"; - cgx_lmactype_string[LMAC_MODE_25G_R] = "25G_R"; - cgx_lmactype_string[LMAC_MODE_50G_R] = "50G_R"; - cgx_lmactype_string[LMAC_MODE_100G_R] = "100G_R"; - cgx_lmactype_string[LMAC_MODE_USXGMII] = "USXGMII"; -} - static int cgx_link_usertable_index_map(int speed) { switch (speed) { @@ -826,7 +823,7 @@ static inline void link_status_user_format(u64 lstat, struct cgx_link_user_info *linfo, struct cgx *cgx, u8 lmac_id) { - char *lmac_string; + const char *lmac_string; linfo->link_up = FIELD_GET(RESP_LINKSTAT_UP, lstat); linfo->full_duplex = FIELD_GET(RESP_LINKSTAT_FDUPLEX, lstat); @@ -1375,7 +1372,6 @@ static int cgx_probe(struct pci_dev *pdev, const struct pci_device_id *id) list_add(&cgx->cgx_list, &cgx_list); - cgx_link_usertable_init(); cgx_populate_features(cgx);