Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: bnxt_ptp: fix compilation error

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: <stable@vger.kernel.org>
Fixes: 9e518f25802c ("bnxt_en: 1PPS functions to configure TSIO pins")
Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Reviewed-by: Michael Chan <michael.chan@broadcom.com>
Link: https://lore.kernel.org/r/20220328062708.207079-1-damien.lemoal@opensource.wdc.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Damien Le Moal and committed by
Jakub Kicinski
dcf50006 d9142e1c

+6 -2
+5 -1
drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c
··· 382 382 struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg, 383 383 ptp_info); 384 384 struct bnxt *bp = ptp->bp; 385 - u8 pin_id; 385 + int pin_id; 386 386 int rc; 387 387 388 388 switch (rq->type) { ··· 390 390 /* Configure an External PPS IN */ 391 391 pin_id = ptp_find_pin(ptp->ptp_clock, PTP_PF_EXTTS, 392 392 rq->extts.index); 393 + if (!TSIO_PIN_VALID(pin_id)) 394 + return -EOPNOTSUPP; 393 395 if (!on) 394 396 break; 395 397 rc = bnxt_ptp_cfg_pin(bp, pin_id, BNXT_PPS_PIN_PPS_IN); ··· 405 403 /* Configure a Periodic PPS OUT */ 406 404 pin_id = ptp_find_pin(ptp->ptp_clock, PTP_PF_PEROUT, 407 405 rq->perout.index); 406 + if (!TSIO_PIN_VALID(pin_id)) 407 + return -EOPNOTSUPP; 408 408 if (!on) 409 409 break; 410 410
+1 -1
drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.h
··· 31 31 u8 state; 32 32 }; 33 33 34 - #define TSIO_PIN_VALID(pin) ((pin) < (BNXT_MAX_TSIO_PINS)) 34 + #define TSIO_PIN_VALID(pin) ((pin) >= 0 && (pin) < (BNXT_MAX_TSIO_PINS)) 35 35 36 36 #define EVENT_DATA2_PPS_EVENT_TYPE(data2) \ 37 37 ((data2) & ASYNC_EVENT_CMPL_PPS_TIMESTAMP_EVENT_DATA2_EVENT_TYPE)