Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dcf5000

Browse files
Damien Le Moalkuba-moo
authored andcommitted
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: <[email protected]> Fixes: 9e518f2 ("bnxt_en: 1PPS functions to configure TSIO pins") Signed-off-by: Damien Le Moal <[email protected]> Reviewed-by: Michael Chan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent d9142e1 commit dcf5000

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,14 +382,16 @@ static int bnxt_ptp_enable(struct ptp_clock_info *ptp_info,
382382
struct bnxt_ptp_cfg *ptp = container_of(ptp_info, struct bnxt_ptp_cfg,
383383
ptp_info);
384384
struct bnxt *bp = ptp->bp;
385-
u8 pin_id;
385+
int pin_id;
386386
int rc;
387387

388388
switch (rq->type) {
389389
case PTP_CLK_REQ_EXTTS:
390390
/* Configure an External PPS IN */
391391
pin_id = ptp_find_pin(ptp->ptp_clock, PTP_PF_EXTTS,
392392
rq->extts.index);
393+
if (!TSIO_PIN_VALID(pin_id))
394+
return -EOPNOTSUPP;
393395
if (!on)
394396
break;
395397
rc = bnxt_ptp_cfg_pin(bp, pin_id, BNXT_PPS_PIN_PPS_IN);
@@ -403,6 +405,8 @@ static int bnxt_ptp_enable(struct ptp_clock_info *ptp_info,
403405
/* Configure a Periodic PPS OUT */
404406
pin_id = ptp_find_pin(ptp->ptp_clock, PTP_PF_PEROUT,
405407
rq->perout.index);
408+
if (!TSIO_PIN_VALID(pin_id))
409+
return -EOPNOTSUPP;
406410
if (!on)
407411
break;
408412

drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct pps_pin {
3131
u8 state;
3232
};
3333

34-
#define TSIO_PIN_VALID(pin) ((pin) < (BNXT_MAX_TSIO_PINS))
34+
#define TSIO_PIN_VALID(pin) ((pin) >= 0 && (pin) < (BNXT_MAX_TSIO_PINS))
3535

3636
#define EVENT_DATA2_PPS_EVENT_TYPE(data2) \
3737
((data2) & ASYNC_EVENT_CMPL_PPS_TIMESTAMP_EVENT_DATA2_EVENT_TYPE)

0 commit comments

Comments
 (0)