Message ID | 20210421134743.3260921-1-arnd@kernel.org (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [net-next] net: stmmac: fix gcc-10 -Wrestrict warning | expand |
Context | Check | Description |
---|---|---|
netdev/cover_letter | success | Link |
netdev/fixes_present | success | Link |
netdev/patch_count | success | Link |
netdev/tree_selection | success | Clearly marked for net-next |
netdev/subject_prefix | success | Link |
netdev/cc_maintainers | success | CCed 11 of 11 maintainers |
netdev/source_inline | success | Was 0 now: 0 |
netdev/verify_signedoff | success | Link |
netdev/module_param | success | Was 0 now: 0 |
netdev/build_32bit | success | Errors and warnings before: 0 this patch: 0 |
netdev/kdoc | success | Errors and warnings before: 0 this patch: 0 |
netdev/verify_fixes | success | Link |
netdev/checkpatch | success | total: 0 errors, 0 warnings, 0 checks, 16 lines checked |
netdev/build_allmodconfig_warn | success | Errors and warnings before: 0 this patch: 0 |
netdev/header_inline | success | Link |
From: Arnd Bergmann > Sent: 21 April 2021 14:47 > > From: Arnd Bergmann <arnd@arndb.de> > > gcc-10 and later warn about a theoretical array overrun when > accessing priv->int_name_rx_irq[i] with an out of bounds value > of 'i': > > drivers/net/ethernet/stmicro/stmmac/stmmac_main.c: In function 'stmmac_request_irq_multi_msi': > drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:3528:17: error: 'snprintf' argument 4 may overlap > destination object 'dev' [-Werror=restrict] > 3528 | snprintf(int_name, int_name_len, "%s:%s-%d", dev->name, "tx", i); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:3404:60: note: destination object referenced by > 'restrict'-qualified argument 1 was declared here > 3404 | static int stmmac_request_irq_multi_msi(struct net_device *dev) > | ~~~~~~~~~~~~~~~~~~~^~~ > > The warning is a bit strange since it's not actually about the array > bounds but rather about possible string operations with overlapping > arguments, but it's not technically wrong. > > Avoid the warning by adding an extra bounds check. > > Fixes: 8532f613bc78 ("net: stmmac: introduce MSI Interrupt routines for mac, safety, RX & TX") > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > --- > drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > index d1ca07c846e6..aadac783687b 100644 > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > @@ -3498,6 +3498,8 @@ static int stmmac_request_irq_multi_msi(struct net_device *dev) > > /* Request Rx MSI irq */ > for (i = 0; i < priv->plat->rx_queues_to_use; i++) { > + if (i > MTL_MAX_RX_QUEUES) > + break; > if (priv->rx_irq[i] == 0) > continue; It might be best to do: num_queues = min(priv->plat->rx_queues_to_use, MTL_MAX_RX_QUEUES); if (i = 0; i < num_queues; i++) { ... Or just give up - if rx_queues_to_use is too big it's all gone horribly wrong already. The compile must be smoking weed again. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Hi Arnd, url: https://github.com/0day-ci/linux/commits/Arnd-Bergmann/net-stmmac-fix-gcc-10-Wrestrict-warning/20210421-215015 base: b74523885a715463203d4ccc3cf8c85952d3701a config: x86_64-randconfig-m001-20210421 (attached as .config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <lkp@intel.com> Reported-by: Dan Carpenter <dan.carpenter@oracle.com> New smatch warnings: drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:3503 stmmac_request_irq_multi_msi() error: buffer overflow 'priv->rx_irq' 8 <= 8 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:3506 stmmac_request_irq_multi_msi() error: buffer overflow 'priv->int_name_rx_irq' 8 <= 8 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:3528 stmmac_request_irq_multi_msi() error: buffer overflow 'priv->tx_irq' 8 <= 8 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:3531 stmmac_request_irq_multi_msi() error: buffer overflow 'priv->int_name_tx_irq' 8 <= 8 Old smatch warnings: drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:1708 init_dma_rx_desc_rings() warn: always true condition '(queue >= 0) => (0-u32max >= 0)' drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:1708 init_dma_rx_desc_rings() warn: always true condition '(queue >= 0) => (0-u32max >= 0)' drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:3508 stmmac_request_irq_multi_msi() error: buffer overflow 'priv->rx_irq' 8 <= 8 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:3514 stmmac_request_irq_multi_msi() error: buffer overflow 'priv->rx_irq' 8 <= 8 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:3521 stmmac_request_irq_multi_msi() error: buffer overflow 'priv->rx_irq' 8 <= 8 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:3533 stmmac_request_irq_multi_msi() error: buffer overflow 'priv->tx_irq' 8 <= 8 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:3539 stmmac_request_irq_multi_msi() error: buffer overflow 'priv->tx_irq' 8 <= 8 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:3546 stmmac_request_irq_multi_msi() error: buffer overflow 'priv->tx_irq' 8 <= 8 vim +3503 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c 8532f613bc78b6 Ong Boon Leong 2021-03-26 3404 static int stmmac_request_irq_multi_msi(struct net_device *dev) 8532f613bc78b6 Ong Boon Leong 2021-03-26 3405 { 8532f613bc78b6 Ong Boon Leong 2021-03-26 3406 enum request_irq_err irq_err = REQ_IRQ_ERR_NO; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3407 struct stmmac_priv *priv = netdev_priv(dev); 8deec94c6040bb Ong Boon Leong 2021-04-01 3408 cpumask_t cpu_mask; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3409 int irq_idx = 0; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3410 char *int_name; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3411 int ret; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3412 int i; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3413 8532f613bc78b6 Ong Boon Leong 2021-03-26 3414 /* For common interrupt */ 8532f613bc78b6 Ong Boon Leong 2021-03-26 3415 int_name = priv->int_name_mac; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3416 sprintf(int_name, "%s:%s", dev->name, "mac"); 8532f613bc78b6 Ong Boon Leong 2021-03-26 3417 ret = request_irq(dev->irq, stmmac_mac_interrupt, 8532f613bc78b6 Ong Boon Leong 2021-03-26 3418 0, int_name, dev); 8532f613bc78b6 Ong Boon Leong 2021-03-26 3419 if (unlikely(ret < 0)) { 8532f613bc78b6 Ong Boon Leong 2021-03-26 3420 netdev_err(priv->dev, 8532f613bc78b6 Ong Boon Leong 2021-03-26 3421 "%s: alloc mac MSI %d (error: %d)\n", 8532f613bc78b6 Ong Boon Leong 2021-03-26 3422 __func__, dev->irq, ret); 8532f613bc78b6 Ong Boon Leong 2021-03-26 3423 irq_err = REQ_IRQ_ERR_MAC; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3424 goto irq_error; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3425 } 8532f613bc78b6 Ong Boon Leong 2021-03-26 3426 8532f613bc78b6 Ong Boon Leong 2021-03-26 3427 /* Request the Wake IRQ in case of another line 8532f613bc78b6 Ong Boon Leong 2021-03-26 3428 * is used for WoL 8532f613bc78b6 Ong Boon Leong 2021-03-26 3429 */ 8532f613bc78b6 Ong Boon Leong 2021-03-26 3430 if (priv->wol_irq > 0 && priv->wol_irq != dev->irq) { 8532f613bc78b6 Ong Boon Leong 2021-03-26 3431 int_name = priv->int_name_wol; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3432 sprintf(int_name, "%s:%s", dev->name, "wol"); 8532f613bc78b6 Ong Boon Leong 2021-03-26 3433 ret = request_irq(priv->wol_irq, 8532f613bc78b6 Ong Boon Leong 2021-03-26 3434 stmmac_mac_interrupt, 8532f613bc78b6 Ong Boon Leong 2021-03-26 3435 0, int_name, dev); 8532f613bc78b6 Ong Boon Leong 2021-03-26 3436 if (unlikely(ret < 0)) { 8532f613bc78b6 Ong Boon Leong 2021-03-26 3437 netdev_err(priv->dev, 8532f613bc78b6 Ong Boon Leong 2021-03-26 3438 "%s: alloc wol MSI %d (error: %d)\n", 8532f613bc78b6 Ong Boon Leong 2021-03-26 3439 __func__, priv->wol_irq, ret); 8532f613bc78b6 Ong Boon Leong 2021-03-26 3440 irq_err = REQ_IRQ_ERR_WOL; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3441 goto irq_error; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3442 } 8532f613bc78b6 Ong Boon Leong 2021-03-26 3443 } 8532f613bc78b6 Ong Boon Leong 2021-03-26 3444 8532f613bc78b6 Ong Boon Leong 2021-03-26 3445 /* Request the LPI IRQ in case of another line 8532f613bc78b6 Ong Boon Leong 2021-03-26 3446 * is used for LPI 8532f613bc78b6 Ong Boon Leong 2021-03-26 3447 */ 8532f613bc78b6 Ong Boon Leong 2021-03-26 3448 if (priv->lpi_irq > 0 && priv->lpi_irq != dev->irq) { 8532f613bc78b6 Ong Boon Leong 2021-03-26 3449 int_name = priv->int_name_lpi; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3450 sprintf(int_name, "%s:%s", dev->name, "lpi"); 8532f613bc78b6 Ong Boon Leong 2021-03-26 3451 ret = request_irq(priv->lpi_irq, 8532f613bc78b6 Ong Boon Leong 2021-03-26 3452 stmmac_mac_interrupt, 8532f613bc78b6 Ong Boon Leong 2021-03-26 3453 0, int_name, dev); 8532f613bc78b6 Ong Boon Leong 2021-03-26 3454 if (unlikely(ret < 0)) { 8532f613bc78b6 Ong Boon Leong 2021-03-26 3455 netdev_err(priv->dev, 8532f613bc78b6 Ong Boon Leong 2021-03-26 3456 "%s: alloc lpi MSI %d (error: %d)\n", 8532f613bc78b6 Ong Boon Leong 2021-03-26 3457 __func__, priv->lpi_irq, ret); 8532f613bc78b6 Ong Boon Leong 2021-03-26 3458 irq_err = REQ_IRQ_ERR_LPI; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3459 goto irq_error; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3460 } 8532f613bc78b6 Ong Boon Leong 2021-03-26 3461 } 8532f613bc78b6 Ong Boon Leong 2021-03-26 3462 8532f613bc78b6 Ong Boon Leong 2021-03-26 3463 /* Request the Safety Feature Correctible Error line in 8532f613bc78b6 Ong Boon Leong 2021-03-26 3464 * case of another line is used 8532f613bc78b6 Ong Boon Leong 2021-03-26 3465 */ 8532f613bc78b6 Ong Boon Leong 2021-03-26 3466 if (priv->sfty_ce_irq > 0 && priv->sfty_ce_irq != dev->irq) { 8532f613bc78b6 Ong Boon Leong 2021-03-26 3467 int_name = priv->int_name_sfty_ce; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3468 sprintf(int_name, "%s:%s", dev->name, "safety-ce"); 8532f613bc78b6 Ong Boon Leong 2021-03-26 3469 ret = request_irq(priv->sfty_ce_irq, 8532f613bc78b6 Ong Boon Leong 2021-03-26 3470 stmmac_safety_interrupt, 8532f613bc78b6 Ong Boon Leong 2021-03-26 3471 0, int_name, dev); 8532f613bc78b6 Ong Boon Leong 2021-03-26 3472 if (unlikely(ret < 0)) { 8532f613bc78b6 Ong Boon Leong 2021-03-26 3473 netdev_err(priv->dev, 8532f613bc78b6 Ong Boon Leong 2021-03-26 3474 "%s: alloc sfty ce MSI %d (error: %d)\n", 8532f613bc78b6 Ong Boon Leong 2021-03-26 3475 __func__, priv->sfty_ce_irq, ret); 8532f613bc78b6 Ong Boon Leong 2021-03-26 3476 irq_err = REQ_IRQ_ERR_SFTY_CE; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3477 goto irq_error; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3478 } 8532f613bc78b6 Ong Boon Leong 2021-03-26 3479 } 8532f613bc78b6 Ong Boon Leong 2021-03-26 3480 8532f613bc78b6 Ong Boon Leong 2021-03-26 3481 /* Request the Safety Feature Uncorrectible Error line in 8532f613bc78b6 Ong Boon Leong 2021-03-26 3482 * case of another line is used 8532f613bc78b6 Ong Boon Leong 2021-03-26 3483 */ 8532f613bc78b6 Ong Boon Leong 2021-03-26 3484 if (priv->sfty_ue_irq > 0 && priv->sfty_ue_irq != dev->irq) { 8532f613bc78b6 Ong Boon Leong 2021-03-26 3485 int_name = priv->int_name_sfty_ue; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3486 sprintf(int_name, "%s:%s", dev->name, "safety-ue"); 8532f613bc78b6 Ong Boon Leong 2021-03-26 3487 ret = request_irq(priv->sfty_ue_irq, 8532f613bc78b6 Ong Boon Leong 2021-03-26 3488 stmmac_safety_interrupt, 8532f613bc78b6 Ong Boon Leong 2021-03-26 3489 0, int_name, dev); 8532f613bc78b6 Ong Boon Leong 2021-03-26 3490 if (unlikely(ret < 0)) { 8532f613bc78b6 Ong Boon Leong 2021-03-26 3491 netdev_err(priv->dev, 8532f613bc78b6 Ong Boon Leong 2021-03-26 3492 "%s: alloc sfty ue MSI %d (error: %d)\n", 8532f613bc78b6 Ong Boon Leong 2021-03-26 3493 __func__, priv->sfty_ue_irq, ret); 8532f613bc78b6 Ong Boon Leong 2021-03-26 3494 irq_err = REQ_IRQ_ERR_SFTY_UE; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3495 goto irq_error; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3496 } 8532f613bc78b6 Ong Boon Leong 2021-03-26 3497 } 8532f613bc78b6 Ong Boon Leong 2021-03-26 3498 8532f613bc78b6 Ong Boon Leong 2021-03-26 3499 /* Request Rx MSI irq */ 8532f613bc78b6 Ong Boon Leong 2021-03-26 3500 for (i = 0; i < priv->plat->rx_queues_to_use; i++) { e4af3ad54243da Arnd Bergmann 2021-04-21 3501 if (i > MTL_MAX_RX_QUEUES) ^^^^^^^^^^^^^^^^^^^^^ Off by one. e4af3ad54243da Arnd Bergmann 2021-04-21 3502 break; 8532f613bc78b6 Ong Boon Leong 2021-03-26 @3503 if (priv->rx_irq[i] == 0) ^^^^^^^^^ 8532f613bc78b6 Ong Boon Leong 2021-03-26 3504 continue; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3505 8532f613bc78b6 Ong Boon Leong 2021-03-26 @3506 int_name = priv->int_name_rx_irq[i]; ^^^^^^^^^^^^^^^^^^^^ 8532f613bc78b6 Ong Boon Leong 2021-03-26 3507 sprintf(int_name, "%s:%s-%d", dev->name, "rx", i); 8532f613bc78b6 Ong Boon Leong 2021-03-26 3508 ret = request_irq(priv->rx_irq[i], 8532f613bc78b6 Ong Boon Leong 2021-03-26 3509 stmmac_msi_intr_rx, 8532f613bc78b6 Ong Boon Leong 2021-03-26 3510 0, int_name, &priv->rx_queue[i]); 8532f613bc78b6 Ong Boon Leong 2021-03-26 3511 if (unlikely(ret < 0)) { 8532f613bc78b6 Ong Boon Leong 2021-03-26 3512 netdev_err(priv->dev, 8532f613bc78b6 Ong Boon Leong 2021-03-26 3513 "%s: alloc rx-%d MSI %d (error: %d)\n", 8532f613bc78b6 Ong Boon Leong 2021-03-26 3514 __func__, i, priv->rx_irq[i], ret); 8532f613bc78b6 Ong Boon Leong 2021-03-26 3515 irq_err = REQ_IRQ_ERR_RX; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3516 irq_idx = i; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3517 goto irq_error; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3518 } 8deec94c6040bb Ong Boon Leong 2021-04-01 3519 cpumask_clear(&cpu_mask); 8deec94c6040bb Ong Boon Leong 2021-04-01 3520 cpumask_set_cpu(i % num_online_cpus(), &cpu_mask); 8deec94c6040bb Ong Boon Leong 2021-04-01 3521 irq_set_affinity_hint(priv->rx_irq[i], &cpu_mask); 8532f613bc78b6 Ong Boon Leong 2021-03-26 3522 } 8532f613bc78b6 Ong Boon Leong 2021-03-26 3523 8532f613bc78b6 Ong Boon Leong 2021-03-26 3524 /* Request Tx MSI irq */ 8532f613bc78b6 Ong Boon Leong 2021-03-26 3525 for (i = 0; i < priv->plat->tx_queues_to_use; i++) { e4af3ad54243da Arnd Bergmann 2021-04-21 3526 if (i > MTL_MAX_TX_QUEUES) ^^^^^^^^^^^^^^^^^^^^^ e4af3ad54243da Arnd Bergmann 2021-04-21 3527 break; 8532f613bc78b6 Ong Boon Leong 2021-03-26 @3528 if (priv->tx_irq[i] == 0) 8532f613bc78b6 Ong Boon Leong 2021-03-26 3529 continue; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3530 8532f613bc78b6 Ong Boon Leong 2021-03-26 @3531 int_name = priv->int_name_tx_irq[i]; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3532 sprintf(int_name, "%s:%s-%d", dev->name, "tx", i); 8532f613bc78b6 Ong Boon Leong 2021-03-26 3533 ret = request_irq(priv->tx_irq[i], 8532f613bc78b6 Ong Boon Leong 2021-03-26 3534 stmmac_msi_intr_tx, 8532f613bc78b6 Ong Boon Leong 2021-03-26 3535 0, int_name, &priv->tx_queue[i]); 8532f613bc78b6 Ong Boon Leong 2021-03-26 3536 if (unlikely(ret < 0)) { 8532f613bc78b6 Ong Boon Leong 2021-03-26 3537 netdev_err(priv->dev, 8532f613bc78b6 Ong Boon Leong 2021-03-26 3538 "%s: alloc tx-%d MSI %d (error: %d)\n", 8532f613bc78b6 Ong Boon Leong 2021-03-26 3539 __func__, i, priv->tx_irq[i], ret); 8532f613bc78b6 Ong Boon Leong 2021-03-26 3540 irq_err = REQ_IRQ_ERR_TX; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3541 irq_idx = i; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3542 goto irq_error; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3543 } 8deec94c6040bb Ong Boon Leong 2021-04-01 3544 cpumask_clear(&cpu_mask); 8deec94c6040bb Ong Boon Leong 2021-04-01 3545 cpumask_set_cpu(i % num_online_cpus(), &cpu_mask); 8deec94c6040bb Ong Boon Leong 2021-04-01 3546 irq_set_affinity_hint(priv->tx_irq[i], &cpu_mask); 8532f613bc78b6 Ong Boon Leong 2021-03-26 3547 } 8532f613bc78b6 Ong Boon Leong 2021-03-26 3548 8532f613bc78b6 Ong Boon Leong 2021-03-26 3549 return 0; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3550 8532f613bc78b6 Ong Boon Leong 2021-03-26 3551 irq_error: 8532f613bc78b6 Ong Boon Leong 2021-03-26 3552 stmmac_free_irq(dev, irq_err, irq_idx); 8532f613bc78b6 Ong Boon Leong 2021-03-26 3553 return ret; 8532f613bc78b6 Ong Boon Leong 2021-03-26 3554 } --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index d1ca07c846e6..aadac783687b 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -3498,6 +3498,8 @@ static int stmmac_request_irq_multi_msi(struct net_device *dev) /* Request Rx MSI irq */ for (i = 0; i < priv->plat->rx_queues_to_use; i++) { + if (i > MTL_MAX_RX_QUEUES) + break; if (priv->rx_irq[i] == 0) continue; @@ -3521,6 +3523,8 @@ static int stmmac_request_irq_multi_msi(struct net_device *dev) /* Request Tx MSI irq */ for (i = 0; i < priv->plat->tx_queues_to_use; i++) { + if (i > MTL_MAX_TX_QUEUES) + break; if (priv->tx_irq[i] == 0) continue;