-Wformat fixes
Subsystems (6)
cover -Wformat fixes
Hi,
This is a collection of some -Wformat fixes found during build, nothing critical, but nice to have for people turning on more warnings with their builds.
Florian Fainelli (4):
mlxsw: spectrum: Avoid -Wformat-truncation warnings
net: dsa: mv88e6xxx: Fix -Wformat-security warnings
e1000e: Fix -Wformat-truncation warnings
veth: Fix -Wformat-truncation
drivers/net/dsa/mv88e6xxx/chip.c | 2 +- drivers/net/dsa/mv88e6xxx/ptp.c | 2 +- drivers/net/ethernet/intel/e1000e/netdev.c | 4 ++-- drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 4 ++-- drivers/net/veth.c | 3 ++- 5 files changed, 8 insertions(+), 7 deletions(-)
Signature · 1 line
2.19.1
PATCH 1/4 mlxsw: spectrum: Avoid -Wformat-truncation warnings
Give precision identifiers to the two snprintf() formatting the priority and TC strings to avoid producing these two warnings:
drivers/net/ethernet/mellanox/mlxsw/spectrum.c: In function 'mlxsw_sp_port_get_prio_strings':drivers/net/ethernet/mellanox/mlxsw/spectrum.c:2132:37: warning: '%d' directive output may be truncated writing between 1 and 3 bytes into a region of size between 0 and 31 [-Wformat-truncation=]
snprintf(*p, ETH_GSTRING_LEN, "%s_%d",
^~
drivers/net/ethernet/mellanox/mlxsw/spectrum.c:2132:3: note: 'snprintf' output between 3 and 36 bytes into a destination of size 32
snprintf(*p, ETH_GSTRING_LEN, "%s_%d", ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mlxsw_sp_port_hw_prio_stats[i].str, prio);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~drivers/net/ethernet/mellanox/mlxsw/spectrum.c: In function 'mlxsw_sp_port_get_tc_strings':drivers/net/ethernet/mellanox/mlxsw/spectrum.c:2143:37: warning: '%d' directive output may be truncated writing between 1 and 11 bytes into a region of size between 0 and 31 [-Wformat-truncation=]
snprintf(*p, ETH_GSTRING_LEN, "%s_%d",
^~
drivers/net/ethernet/mellanox/mlxsw/spectrum.c:2143:3: note: 'snprintf' output between 3 and 44 bytes into a destination of size 32
snprintf(*p, ETH_GSTRING_LEN, "%s_%d", ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mlxsw_sp_port_hw_tc_stats[i].str, tc);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--- drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum.c +2 -2
@@ -2129,7 +2129,7 @@ static void mlxsw_sp_port_get_prio_strings(u8 **p, int prio)int i;for (i =0 ; i <MLXSW_SP_PORT_HW_PRIO_STATS_LEN ; i++) { -snprintf (*p,ETH_GSTRING_LEN ,"%s_%d" , +snprintf (*p,ETH_GSTRING_LEN ,"%.29s_%.1d" , mlxsw_sp_port_hw_prio_stats[i].str, prio); *p +=ETH_GSTRING_LEN ; }
@@ -2140,7 +2140,7 @@ static void mlxsw_sp_port_get_tc_strings(u8 **p, int tc)int i;for (i =0 ; i <MLXSW_SP_PORT_HW_TC_STATS_LEN ; i++) { -snprintf (*p,ETH_GSTRING_LEN ,"%s_%d" , +snprintf (*p,ETH_GSTRING_LEN ,"%.29s_%.1d" , mlxsw_sp_port_hw_tc_stats[i].str, tc); *p +=ETH_GSTRING_LEN ; }
Signature · 1 line
2.19.1
Re: [PATCH net-next 1/4] mlxsw: spectrum: Avoid -Wformat-truncation warnings
Quoted 23 lines · Florian Fainelli
Give precision identifiers to the two
snprintf()formatting the priority and TC strings to avoid producing these two warnings:
drivers/net/ethernet/mellanox/mlxsw/spectrum.c: In function 'mlxsw_sp_port_get_prio_strings':drivers/net/ethernet/mellanox/mlxsw/spectrum.c:2132:37: warning: '%d' directive output may be truncated writing between 1 and 3 bytes into a region of size between 0 and 31 [-Wformat-truncation=]
snprintf(*p,ETH_GSTRING_LEN, "%s_%d",^~
drivers/net/ethernet/mellanox/mlxsw/spectrum.c:2132:3: note: 'snprintf' output between 3 and 36 bytes into a destination of size 32
snprintf(*p,ETH_GSTRING_LEN, "%s_%d", ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~mlxsw_sp_port_hw_prio_stats[i].str, prio); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/mellanox/mlxsw/spectrum.c: In function 'mlxsw_sp_port_get_tc_strings':drivers/net/ethernet/mellanox/mlxsw/spectrum.c:2143:37: warning: '%d' directive output may be truncated writing between 1 and 11 bytes into a region of size between 0 and 31 [-Wformat-truncation=]
snprintf(*p,ETH_GSTRING_LEN, "%s_%d",^~
Quoted 8 lines
drivers/net/ethernet/mellanox/mlxsw/spectrum.c:2143:3: note: 'snprintf' output between 3 and 44 bytes into a destination of size 32
snprintf(*p,ETH_GSTRING_LEN, "%s_%d", ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~mlxsw_sp_port_hw_tc_stats[i].str, tc); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Signed-off-by Florian Fainelli <[email protected]>
PATCH 2/4 net: dsa: mv88e6xxx: Fix -Wformat-security warnings
In reply to Florian FainelliWe are not specifying an explicit format argument but instead passing a string litteral which causes these two warnings to show up:
drivers/net/dsa/mv88e6xxx/chip.c: In function 'mv88e6xxx_irq_poll_setup':drivers/net/dsa/mv88e6xxx/chip.c:483:2: warning: format not a string literal and no format arguments [-Wformat-security]
chip->kworker = kthread_create_worker(0, dev_name(chip->dev)); ^~~~drivers/net/dsa/mv88e6xxx/ptp.c: In function 'mv88e6xxx_ptp_setup':drivers/net/dsa/mv88e6xxx/ptp.c:403:4: warning: format not a string literal and no format arguments [-Wformat-security]
dev_name(chip->dev));
^~~~~~~~ LD [M] drivers/net/dsa/mv88e6xxx/mv88e6xxx.o
--- drivers/net/dsa/mv88e6xxx/chip.c | 2 +- drivers/net/dsa/mv88e6xxx/ptp.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/dsa/mv88e6xxx/chip.c +1 -1
@@ -480,7 +480,7 @@ static int mv88e6xxx_irq_poll_setup(struct mv88e6xxx_chip *chip)kthread_init_delayed_work (&chip->irq_poll_work, mv88e6xxx_irq_poll); - chip->kworker =kthread_create_worker (0 ,dev_name (chip->dev)); + chip->kworker =kthread_create_worker (0 ,"%s" ,dev_name (chip->dev));if (IS_ERR (chip->kworker))return PTR_ERR (chip->kworker);
drivers/net/dsa/mv88e6xxx/ptp.c +1 -1
@@ -400,7 +400,7 @@ int mv88e6xxx_ptp_setup(struct mv88e6xxx_chip *chip) chip->ptp_clock_info.owner =THIS_MODULE ;snprintf (chip->ptp_clock_info.name,sizeof (chip->ptp_clock_info.name), -dev_name (chip->dev)); +"%s" ,dev_name (chip->dev)); chip->ptp_clock_info.max_adj =1000000 ; chip->ptp_clock_info.n_ext_ts = ptp_ops->n_ext_ts;
Signature · 1 line
2.19.1
Re: [PATCH net-next 2/4] net: dsa: mv88e6xxx: Fix -Wformat-security warnings
Quoted 12 lines · Florian Fainelli
We are not specifying an explicit format argument but instead passing a string litteral which causes these two warnings to show up:
drivers/net/dsa/mv88e6xxx/chip.c: In function 'mv88e6xxx_irq_poll_setup':drivers/net/dsa/mv88e6xxx/chip.c:483:2: warning: format not a string literal and no format arguments [-Wformat-security]
chip->kworker=kthread_create_worker(0, dev_name(chip->dev)); ^~~~drivers/net/dsa/mv88e6xxx/ptp.c: In function 'mv88e6xxx_ptp_setup':drivers/net/dsa/mv88e6xxx/ptp.c:403:4: warning: format not a string literal and no format arguments [-Wformat-security]
Quoted 5 lines
dev_name(chip->dev)); ^~~~~~~~LD [M]
drivers/net/dsa/mv88e6xxx/mv88e6xxx.oSigned-off-by Florian Fainelli <[email protected]>
Hi Florian
Andrew
PATCH 3/4 e1000e: Fix -Wformat-truncation warnings
In reply to Florian FainelliProvide precision hints to snprintf() since we know the destination buffer size of the RX/TX ring names are IFNAMSIZ + 5 - 1. This fixes the following warnings:
drivers/net/ethernet/intel/e1000e/netdev.c: In function 'e1000_request_msix':drivers/net/ethernet/intel/e1000e/netdev.c:2109:13: warning: 'snprintf' output may be truncated before the last format character [-Wformat-truncation=]
"%s-rx-0", netdev->name);
^drivers/net/ethernet/intel/e1000e/netdev.c:2107:3: note: 'snprintf' output between 6 and 21 bytes into a destination of size 20
snprintf(adapter->rx_ring->name, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sizeof(adapter->rx_ring->name) - 1,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"%s-rx-0", netdev->name);
~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/intel/e1000e/netdev.c:2125:13: warning: 'snprintf'
output may be truncated before the last format character
[-Wformat-truncation=]
"%s-tx-0", netdev->name);
^drivers/net/ethernet/intel/e1000e/netdev.c:2123:3: note: 'snprintf' output between 6 and 21 bytes into a destination of size 20
snprintf(adapter->tx_ring->name, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sizeof(adapter->tx_ring->name) - 1,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"%s-tx-0", netdev->name);
~~~~~~~~~~~~~~~~~~~~~~~~--- drivers/net/ethernet/intel/e1000e/netdev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/e1000e/netdev.c +2 -2
@@ -2106,7 +2106,7 @@ static int e1000_request_msix(struct e1000_adapter *adapter)if (strlen (netdev->name) < (IFNAMSIZ -5 ))snprintf (adapter->rx_ring->name,sizeof (adapter->rx_ring->name) -1 , -"%s-rx-0" , netdev->name); +"%.14s-rx-0" , netdev->name);else memcpy (adapter->rx_ring->name, netdev->name,IFNAMSIZ ); err = request_irq(adapter->msix_entries[vector].vector,
@@ -2122,7 +2122,7 @@ static int e1000_request_msix(struct e1000_adapter *adapter)if (strlen (netdev->name) < (IFNAMSIZ -5 ))snprintf (adapter->tx_ring->name,sizeof (adapter->tx_ring->name) -1 , -"%s-tx-0" , netdev->name); +"%.14s-tx-0" , netdev->name);else memcpy (adapter->tx_ring->name, netdev->name,IFNAMSIZ ); err = request_irq(adapter->msix_entries[vector].vector,
Signature · 1 line
2.19.1
Re: [Intel-wired-lan] [PATCH net-next 3/4] e1000e: Fix -Wformat-truncation warnings
Quoted 53 lines · Florian Fainelli
Provide precision hints to
snprintf()since we know the destination buffer size of the RX/TX ring names are IFNAMSIZ + 5 - 1. This fixes the following warnings:
drivers/net/ethernet/intel/e1000e/netdev.c: In function 'e1000_request_msix':drivers/net/ethernet/intel/e1000e/netdev.c:2109:13: warning: 'snprintf' output may be truncated before the last format character [-Wformat-truncation=]"%s-rx-0", netdev->name); ^ drivers/net/ethernet/intel/e1000e/netdev.c:2107:3: note: 'snprintf' output between 6 and 21 bytes into a destination of size 20 snprintf(adapter->rx_ring->name, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sizeof(adapter->rx_ring->name) - 1, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "%s-rx-0", netdev->name); ~~~~~~~~~~~~~~~~~~~~~~~~ drivers/net/ethernet/intel/e1000e/netdev.c:2125:13: warning: 'snprintf' output may be truncated before the last format character [-Wformat-truncation=] "%s-tx-0", netdev->name); ^ drivers/net/ethernet/intel/e1000e/netdev.c:2123:3: note: 'snprintf' output between 6 and 21 bytes into a destination of size 20 snprintf(adapter->tx_ring->name, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sizeof(adapter->tx_ring->name) - 1, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "%s-tx-0", netdev->name); ~~~~~~~~~~~~~~~~~~~~~~~~Signed-off-by Florian Fainelli <[email protected]>--- drivers/net/ethernet/intel/e1000e/netdev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/ethernet/intel/e1000e/netdev.c +1
-1@@ -2106,7 +2106,7 @@ static int e1000_request_msix(struct e1000_adapter *adapter)if (strlen (netdev->name) < (IFNAMSIZ -5 ))snprintf (adapter->rx_ring->name,sizeof (adapter->rx_ring->name) -1 , -"%s-rx-0" , netdev->name); +"%.14s-rx-0" , netdev->name);else memcpy (adapter->rx_ring->name, netdev->name,IFNAMSIZ ); err = request_irq(adapter->msix_entries[vector].vector,
drivers/net/ethernet/intel/e1000e/netdev.c static int e1000_request_msix(struct e1000_adapter *adapter) · line 2128
Quoted 8 lines
drivers/net/ethernet/intel/e1000e/netdev.c +1
-1@@ -2122,7 +2122,7 @@ static int e1000_request_msix(struct e1000_adapter *adapter)if (strlen (netdev->name) < (IFNAMSIZ -5 ))snprintf (adapter->tx_ring->name,sizeof (adapter->tx_ring->name) -1 , -"%s-tx-0" , netdev->name); +"%.14s-tx-0" , netdev->name);else memcpy (adapter->tx_ring->name, netdev->name,IFNAMSIZ ); err = request_irq(adapter->msix_entries[vector].vector,
PATCH 4/4 veth: Fix -Wformat-truncation
In reply to Florian FainelliProvide a precision hint to snprintf() in order to eliminate a -Wformat-truncation warning provided below. A maximum of 11 characters is allowed to reach a maximum of 32 - 1 characters given a possible maximum value of queues using up to UINT_MAX which occupies 10 characters. Incidentally 11 is the number of characters for "xdp_packets" which is the largest string we append.
drivers/net/veth.c: In function 'veth_get_strings':drivers/net/veth.c:118:47: warning: '%s' directive output may be truncated writing up to 31 bytes into a region of size between 12 and 21 [-Wformat-truncation=]
snprintf(p, ETH_GSTRING_LEN, "rx_queue_%u_%s",
^~
drivers/net/veth.c:118:5: note: 'snprintf' output between 12 and 52
bytes into a destination of size 32
snprintf(p, ETH_GSTRING_LEN, "rx_queue_%u_%s",
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
i, veth_rq_stats_desc[j].desc);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--- drivers/net/veth.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/veth.c +2 -1
@@ -115,7 +115,8 @@ static void veth_get_strings(struct net_device *dev, u32 stringset, u8 *buf) p +=sizeof (ethtool_stats_keys);for (i =0 ; i < dev->real_num_rx_queues; i++) {for (j =0 ; j <VETH_RQ_STATS_LEN ; j++) { -snprintf (p,ETH_GSTRING_LEN ,"rx_queue_%u_%s" , +snprintf (p,ETH_GSTRING_LEN , +"rx_queue_%u_%.11s" , i, veth_rq_stats_desc[j].desc); p +=ETH_GSTRING_LEN ; }
Signature · 1 line
2.19.1
From: Florian Fainelli <[email protected]>
Date: Thu, 21 Feb 2019 20:09:25 -0800
Quoted 3 lines
This is a collection of some -Wformat fixes found during build, nothing critical, but nice to have for people turning on more warnings with their builds.
Applied, thanks Florian.