Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp605255pxb; Tue, 5 Apr 2022 15:42:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRr933B7+VVRPcbhY/63qG39t1CORbOOEBFqLJWTmBuH3dOMSeSgpzvRrXXdNxaOkwVWOw X-Received: by 2002:a17:902:c2d8:b0:154:2946:4ff with SMTP id c24-20020a170902c2d800b00154294604ffmr5636234pla.99.1649198563951; Tue, 05 Apr 2022 15:42:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649198563; cv=none; d=google.com; s=arc-20160816; b=L6wuYENHmbUfUPvQqt3RXnyth3j2q4iIOH/W7qvlEJeKgErGVOI6m0mKhLh7sodt+6 gnNokw8Z6myaOI3QNunFHCWmFD4GYCo6OxXm51Ccjjs8FEZ2pwx7t+C+39ryB7kf1Bip E2mJwJKFx5XBoy/Wj8kM4eO2If0jI564UzzuejWsOcY7h5A4FXbDVTrAIChnCfzPAIDj f810EApgSon0TpvPYriPxAcLMGa+Mvd25C5caHGTBnD5MPzMTyDmRFIrrAVXUWyr+huh ViAENDh3a7oFd+ER/ZoXLixiX+JGzkuqFhJDtZuIE9zBDlLjj25UAph8jeu6oMvF3Hxt thtw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/cp+TNfOAscXVZc4WZgJZSTYmQ29ek0pS9YmuJv7l7s=; b=oxbpy8PfTFdAXGGg5/3psQ3PwHJaJ2IpdvIKLk0d5VxU4aUQAXloNzqk46bVaF4fIc gbpaSw+j9fanY3fAO0K2VvY+tLQxySpg7T8L4c6to+x9eAlc+mLByEShGG9ToAIZZ8sS zjq0vHoZ2JQIV7FrpnnKgW5W0YFH+BW6SeLmcu2phsNhMvj41STV94aR7DvNAMrKNVNj XQHj2EqNh+zCBqWdmmRePhc7Mel+h3vtbXj1BetBBBSca0gAjN3AHJJmHwbbMCd6Z6X8 EyF71fm4oCe3VGbqTL6SWLMhmMfJndyt2dlNpLzgnAuvmUeKXuaYDAEVsnf/3AOPt5fN kHGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Rn+WaevP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id w2-20020a170902e88200b001544c9777e0si15556347plg.95.2022.04.05.15.42.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 15:42:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Rn+WaevP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B1FE54B855; Tue, 5 Apr 2022 15:23:24 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386857AbiDEO0J (ORCPT + 99 others); Tue, 5 Apr 2022 10:26:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239003AbiDEJdP (ORCPT ); Tue, 5 Apr 2022 05:33:15 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B51351B78C; Tue, 5 Apr 2022 02:21:35 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 61D57B81C77; Tue, 5 Apr 2022 09:21:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4EC7C385A0; Tue, 5 Apr 2022 09:21:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649150493; bh=oNJJptU9u/zceqK/D8gBY0xZZHowfss4cI6kI7VcPaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rn+WaevP5fWQ5v3vKr9oIpDFx+3kYjv3CJxt1k2DnBY6D1lGBb/Awg/cYuZaMUQw6 TooB/UjfIRjSzkBJflXOZG4QTmSCsJ4Qb/KILIhzxsXyavCrzU+XRz458uKkAMzDva JnswptBXg22k5q2fu+GRmDGtYDUIMceFE5lNtpvw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Damien Le Moal , Michael Chan , Jakub Kicinski Subject: [PATCH 5.15 074/913] net: bnxt_ptp: fix compilation error Date: Tue, 5 Apr 2022 09:18:56 +0200 Message-Id: <20220405070342.041921381@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Damien Le Moal commit dcf500065fabe27676dfe7b4ba521a4f1e0fc8ac upstream. The Broadcom bnxt_ptp driver does not compile with GCC 11.2.2 when CONFIG_WERROR is enabled. The following error is generated: drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c: In function ‘bnxt_ptp_enable’: drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c:400:43: error: array subscript 255 is above array bounds of ‘struct pps_pin[4]’ [-Werror=array-bounds] 400 | ptp->pps_info.pins[pin_id].event = BNXT_PPS_EVENT_EXTERNAL; | ~~~~~~~~~~~~~~~~~~^~~~~~~~ In file included from drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c:20: drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.h:75:24: note: while referencing ‘pins’ 75 | struct pps_pin pins[BNXT_MAX_TSIO_PINS]; | ^~~~ cc1: all warnings being treated as errors This is due to the function ptp_find_pin() returning a pin ID of -1 when a valid pin is not found and this error never being checked. Change the TSIO_PIN_VALID() function to also check that a pin ID is not negative and use this macro in bnxt_ptp_enable() to check the result of the calls to ptp_find_pin() to return an error early for invalid pins. This fixes the compilation error. Cc: Fixes: 9e518f25802c ("bnxt_en: 1PPS functions to configure TSIO pins") Signed-off-by: Damien Le Moal Reviewed-by: Michael Chan Link: https://lore.kernel.org/r/20220328062708.207079-1-damien.lemoal@opensource.wdc.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c | 6 +++++- drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.h | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c @@ -331,7 +331,7 @@ static int bnxt_ptp_enable(struct ptp_cl struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg, ptp_info); struct bnxt *bp = ptp->bp; - u8 pin_id; + int pin_id; int rc; switch (rq->type) { @@ -339,6 +339,8 @@ static int bnxt_ptp_enable(struct ptp_cl /* Configure an External PPS IN */ pin_id = ptp_find_pin(ptp->ptp_clock, PTP_PF_EXTTS, rq->extts.index); + if (!TSIO_PIN_VALID(pin_id)) + return -EOPNOTSUPP; if (!on) break; rc = bnxt_ptp_cfg_pin(bp, pin_id, BNXT_PPS_PIN_PPS_IN); @@ -352,6 +354,8 @@ static int bnxt_ptp_enable(struct ptp_cl /* Configure a Periodic PPS OUT */ pin_id = ptp_find_pin(ptp->ptp_clock, PTP_PF_PEROUT, rq->perout.index); + if (!TSIO_PIN_VALID(pin_id)) + return -EOPNOTSUPP; if (!on) break; --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.h +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.h @@ -28,7 +28,7 @@ struct pps_pin { u8 state; }; -#define TSIO_PIN_VALID(pin) ((pin) < (BNXT_MAX_TSIO_PINS)) +#define TSIO_PIN_VALID(pin) ((pin) >= 0 && (pin) < (BNXT_MAX_TSIO_PINS)) #define EVENT_DATA2_PPS_EVENT_TYPE(data2) \ ((data2) & ASYNC_EVENT_CMPL_PPS_TIMESTAMP_EVENT_DATA2_EVENT_TYPE)