From patchwork Tue Nov 10 02:32:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 11892955 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 059E7C2D0A3 for ; Tue, 10 Nov 2020 02:33:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AA4DE205CB for ; Tue, 10 Nov 2020 02:33:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731300AbgKJCdL (ORCPT ); Mon, 9 Nov 2020 21:33:11 -0500 Received: from vps0.lunn.ch ([185.16.172.187]:44812 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730450AbgKJCdL (ORCPT ); Mon, 9 Nov 2020 21:33:11 -0500 Received: from andrew by vps0.lunn.ch with local (Exim 4.94) (envelope-from ) id 1kcJT2-006CsX-4N; Tue, 10 Nov 2020 03:33:08 +0100 From: Andrew Lunn To: Jakub Kicinski Cc: netdev , Mirko Lindner , Andrew Lunn , Stephen Hemminger Subject: [PATCH net-next v2] drivers: net: sky2: Fix -Wstringop-truncation with W=1 Date: Tue, 10 Nov 2020 03:32:22 +0100 Message-Id: <20201110023222.1479398-1-andrew@lunn.ch> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org In function ‘strncpy’, inlined from ‘sky2_name’ at drivers/net/ethernet/marvell/sky2.c:4903:3, inlined from ‘sky2_probe’ at drivers/net/ethernet/marvell/sky2.c:5049:2: ./include/linux/string.h:297:30: warning: ‘__builtin_strncpy’ specified bound 16 equals destination size [-Wstringop-truncation] None of the device names are 16 characters long, so it was never an issue. But replace the strncpy with an snprintf() to prevent the theoretical overflow. Suggested-by: Stephen Hemminger Signed-off-by: Andrew Lunn Acked-by: Stephen Hemminger --- drivers/net/ethernet/marvell/sky2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/marvell/sky2.c b/drivers/net/ethernet/marvell/sky2.c index 25981a7a43b5..ebe1406c6e64 100644 --- a/drivers/net/ethernet/marvell/sky2.c +++ b/drivers/net/ethernet/marvell/sky2.c @@ -4900,7 +4900,7 @@ static const char *sky2_name(u8 chipid, char *buf, int sz) }; if (chipid >= CHIP_ID_YUKON_XL && chipid <= CHIP_ID_YUKON_OP_2) - strncpy(buf, name[chipid - CHIP_ID_YUKON_XL], sz); + snprintf(buf, sz, "%s", name[chipid - CHIP_ID_YUKON_XL]); else snprintf(buf, sz, "(chip %#x)", chipid); return buf;