Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp672922pxb; Tue, 5 Apr 2022 18:11:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyjk1L4pUzeIVkS8V29gGzaEckuYaaKyFQpp+qfsbB48HiUwquLKW56QRimQgj570/iLOTg X-Received: by 2002:a17:907:9621:b0:6d7:355d:6da5 with SMTP id gb33-20020a170907962100b006d7355d6da5mr6069181ejc.195.1649207435854; Tue, 05 Apr 2022 18:10:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649207435; cv=none; d=google.com; s=arc-20160816; b=bhjOxis2SZoEfkwy2x4IztvR+oN3rQa2afg0R0ETkOGEp/pO2oKq8Sfx2ptuOEWdml AfKIMGQ+WWJxdSSydClRx1NFtLECx34xPeptCFnOTafXz26OopWfTfQ8vkUUysgdF4wh 97c21JUzluNY8K8JQD/dfpCoLZAyvzUot9OpWHUgl2/C8MBjiwb+Yp6xYCu8zVMtHuTF qJEvUUn/WsE257sAWXdiNs04Jjc9mIbE3BDBRrtc7rnSEe1881vjp1wMh8HhFTzW8LHM ZXaOn4nuwREJxfyG6/vCVnOpO1/d3fytVwYNhB+GqBU7YvnEva4IgzFPFocRXQ6vSUqm Fp9g== 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=3oEhMtV+FproEKNnklCo3z/Ql/Mklo3YQmuuDNvkBtQ=; b=VjRkpkCaCY7pXn9swywq04bsm+n568XwRYLVcy8S2gY1+Ace1UmE6uSMLLNmPpVjxc TU23wk/njCjfFd1rWvJoKYZ+FfJ/nG62Mrwd0jSzXqJ1wCzJ/TUPITS4hKv4kxsaRwP4 PiR6DjSh0sDIOPejEA7NcPKqW3oUYIzvTGNMyVyVplryToxqCeHxqA6RAsILN940wpvb FLi3yNJC8Fnapp3TeTKYniyrEl6/o/e8QIfN+OfCubj0TTC8sSVkFzyU77IQqibCAf8+ ssIWZWsbTfAzUCfKDWf4kFvEvKoR8e8XYqKsFU2Svgrl1ryXN5tbMv8jN+L60KfdYN1l +IDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FiiP4w0t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f14-20020a0564021e8e00b00418ea5ad78bsi11695768edf.85.2022.04.05.18.10.11; Tue, 05 Apr 2022 18:10:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FiiP4w0t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359826AbiDELU6 (ORCPT + 99 others); Tue, 5 Apr 2022 07:20:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240691AbiDEIrW (ORCPT ); Tue, 5 Apr 2022 04:47:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6CC125580; Tue, 5 Apr 2022 01:36:22 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 5A70561517; Tue, 5 Apr 2022 08:36:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67EBDC385A2; Tue, 5 Apr 2022 08:36:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649147772; bh=La9b5PkZMRTBVUZfxGXy8R1qZAliNvOQdKryZHSfOug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FiiP4w0t2sthEPy/jULQ5XFvw35EzeRHXKeXFuWasZAImq/862RMCilbghik6EpH2 hYOH6Xkh8813sZVljbfLbtx+J5jWXEOJXaZJQR7KhiS6p2gxYzegbrpedGSVlmSoAP q92Ie5I1iODfz+GeRqIDnMQ9ogSqNJl9QO/UWYDo= 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.16 0077/1017] net: bnxt_ptp: fix compilation error Date: Tue, 5 Apr 2022 09:16:30 +0200 Message-Id: <20220405070356.476374643@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@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=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 @@ -329,7 +329,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) { @@ -337,6 +337,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); @@ -350,6 +352,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 @@ -31,7 +31,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)