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

Configure Feed

Select the types of activity you want to include in your feed.

octeontx2-pf: Treat truncation of IRQ name as an error

According to GCC, the constriction of irq_name in otx2_open()
may, theoretically, be truncated.

This patch takes the approach of treating such a situation as an error
which it detects by making use of the return value of snprintf, which is
the total number of bytes, excluding the trailing '\0', that would have
been written.

Based on the approach taken to a similar problem in
commit 54b909436ede ("rtc: fix snprintf() checking in is_rtc_hctosys()")

Flagged by gcc-13 W=1 builds as:

.../otx2_pf.c:1933:58: warning: 'snprintf' output may be truncated before the last format character [-Wformat-truncation=]
1933 | snprintf(irq_name, NAME_SIZE, "%s-rxtx-%d", pf->netdev->name,
| ^
.../otx2_pf.c:1933:17: note: 'snprintf' output between 8 and 33 bytes into a destination of size 32
1933 | snprintf(irq_name, NAME_SIZE, "%s-rxtx-%d", pf->netdev->name,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1934 | qidx);
| ~~~~~

Compile tested only.

Tested-by: Geetha sowjanya <gakula@marvell.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Simon Horman <horms@kernel.org>
Link: https://lore.kernel.org/r/20240503-octeon2-pf-irq_name-truncation-v2-1-91099177b942@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Simon Horman and committed by
Jakub Kicinski
6bee6942 ad3c9f0e

+10 -2
+10 -2
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
··· 1886 1886 vec = pf->hw.nix_msixoff + NIX_LF_CINT_VEC_START; 1887 1887 for (qidx = 0; qidx < pf->hw.cint_cnt; qidx++) { 1888 1888 irq_name = &pf->hw.irq_name[vec * NAME_SIZE]; 1889 + int name_len; 1889 1890 1890 - snprintf(irq_name, NAME_SIZE, "%s-rxtx-%d", pf->netdev->name, 1891 - qidx); 1891 + name_len = snprintf(irq_name, NAME_SIZE, "%s-rxtx-%d", 1892 + pf->netdev->name, qidx); 1893 + if (name_len >= NAME_SIZE) { 1894 + dev_err(pf->dev, 1895 + "RVUPF%d: IRQ registration failed for CQ%d, irq name is too long\n", 1896 + rvu_get_pf(pf->pcifunc), qidx); 1897 + err = -EINVAL; 1898 + goto err_free_cints; 1899 + } 1892 1900 1893 1901 err = request_irq(pci_irq_vector(pf->pdev, vec), 1894 1902 otx2_cq_intr_handler, 0, irq_name,