Skip to content
/ linux Public

Commit 14fc2a0

Browse files
arndbSasha Levin
authored andcommitted
myri10ge: avoid uninitialized variable use
[ Upstream commit fd24173 ] While compile testing on less common architectures, I noticed that gcc-10 on s390 finds a bug that all other configurations seem to miss: drivers/net/ethernet/myricom/myri10ge/myri10ge.c: In function 'myri10ge_set_multicast_list': drivers/net/ethernet/myricom/myri10ge/myri10ge.c:391:25: error: 'cmd.data0' is used uninitialized in this function [-Werror=uninitialized] 391 | buf->data0 = htonl(data->data0); | ^~ drivers/net/ethernet/myricom/myri10ge/myri10ge.c:392:25: error: '*((void *)&cmd+4)' is used uninitialized in this function [-Werror=uninitialized] 392 | buf->data1 = htonl(data->data1); | ^~ drivers/net/ethernet/myricom/myri10ge/myri10ge.c: In function 'myri10ge_allocate_rings': drivers/net/ethernet/myricom/myri10ge/myri10ge.c:392:13: error: 'cmd.data1' is used uninitialized in this function [-Werror=uninitialized] 392 | buf->data1 = htonl(data->data1); drivers/net/ethernet/myricom/myri10ge/myri10ge.c:1939:22: note: 'cmd.data1' was declared here 1939 | struct myri10ge_cmd cmd; | ^~~ drivers/net/ethernet/myricom/myri10ge/myri10ge.c:393:13: error: 'cmd.data2' is used uninitialized in this function [-Werror=uninitialized] 393 | buf->data2 = htonl(data->data2); drivers/net/ethernet/myricom/myri10ge/myri10ge.c:1939:22: note: 'cmd.data2' was declared here 1939 | struct myri10ge_cmd cmd; It would be nice to understand how to make other compilers catch this as well, but for the moment I'll just shut up the warning by fixing the undefined behavior in this driver. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Link: https://patch.msgid.link/20260205162935.2126442-1-arnd@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent cf39060 commit 14fc2a0

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

drivers/net/ethernet/myricom/myri10ge/myri10ge.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,9 @@ static int myri10ge_get_firmware_capabilities(struct myri10ge_priv *mgp)
688688

689689
/* probe for IPv6 TSO support */
690690
mgp->features = NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_TSO;
691+
cmd.data0 = 0,
692+
cmd.data1 = 0,
693+
cmd.data2 = 0,
691694
status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_MAX_TSO6_HDR_SIZE,
692695
&cmd, 0);
693696
if (status == 0) {
@@ -806,6 +809,7 @@ static int myri10ge_update_mac_address(struct myri10ge_priv *mgp,
806809
| (addr[2] << 8) | addr[3]);
807810

808811
cmd.data1 = ((addr[4] << 8) | (addr[5]));
812+
cmd.data2 = 0;
809813

810814
status = myri10ge_send_cmd(mgp, MXGEFW_SET_MAC_ADDRESS, &cmd, 0);
811815
return status;
@@ -817,6 +821,9 @@ static int myri10ge_change_pause(struct myri10ge_priv *mgp, int pause)
817821
int status, ctl;
818822

819823
ctl = pause ? MXGEFW_ENABLE_FLOW_CONTROL : MXGEFW_DISABLE_FLOW_CONTROL;
824+
cmd.data0 = 0,
825+
cmd.data1 = 0,
826+
cmd.data2 = 0,
820827
status = myri10ge_send_cmd(mgp, ctl, &cmd, 0);
821828

822829
if (status) {
@@ -834,6 +841,9 @@ myri10ge_change_promisc(struct myri10ge_priv *mgp, int promisc, int atomic)
834841
int status, ctl;
835842

836843
ctl = promisc ? MXGEFW_ENABLE_PROMISC : MXGEFW_DISABLE_PROMISC;
844+
cmd.data0 = 0;
845+
cmd.data1 = 0;
846+
cmd.data2 = 0;
837847
status = myri10ge_send_cmd(mgp, ctl, &cmd, atomic);
838848
if (status)
839849
netdev_err(mgp->dev, "Failed to set promisc mode\n");
@@ -1946,6 +1956,8 @@ static int myri10ge_allocate_rings(struct myri10ge_slice_state *ss)
19461956
/* get ring sizes */
19471957
slice = ss - mgp->ss;
19481958
cmd.data0 = slice;
1959+
cmd.data1 = 0;
1960+
cmd.data2 = 0;
19491961
status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_SEND_RING_SIZE, &cmd, 0);
19501962
tx_ring_size = cmd.data0;
19511963
cmd.data0 = slice;
@@ -2238,12 +2250,16 @@ static int myri10ge_get_txrx(struct myri10ge_priv *mgp, int slice)
22382250
status = 0;
22392251
if (slice == 0 || (mgp->dev->real_num_tx_queues > 1)) {
22402252
cmd.data0 = slice;
2253+
cmd.data1 = 0;
2254+
cmd.data2 = 0;
22412255
status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_SEND_OFFSET,
22422256
&cmd, 0);
22432257
ss->tx.lanai = (struct mcp_kreq_ether_send __iomem *)
22442258
(mgp->sram + cmd.data0);
22452259
}
22462260
cmd.data0 = slice;
2261+
cmd.data1 = 0;
2262+
cmd.data2 = 0;
22472263
status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_SMALL_RX_OFFSET,
22482264
&cmd, 0);
22492265
ss->rx_small.lanai = (struct mcp_kreq_ether_recv __iomem *)
@@ -2312,6 +2328,7 @@ static int myri10ge_open(struct net_device *dev)
23122328
if (mgp->num_slices > 1) {
23132329
cmd.data0 = mgp->num_slices;
23142330
cmd.data1 = MXGEFW_SLICE_INTR_MODE_ONE_PER_SLICE;
2331+
cmd.data2 = 0;
23152332
if (mgp->dev->real_num_tx_queues > 1)
23162333
cmd.data1 |= MXGEFW_SLICE_ENABLE_MULTIPLE_TX_QUEUES;
23172334
status = myri10ge_send_cmd(mgp, MXGEFW_CMD_ENABLE_RSS_QUEUES,
@@ -2414,6 +2431,8 @@ static int myri10ge_open(struct net_device *dev)
24142431

24152432
/* now give firmware buffers sizes, and MTU */
24162433
cmd.data0 = dev->mtu + ETH_HLEN + VLAN_HLEN;
2434+
cmd.data1 = 0;
2435+
cmd.data2 = 0;
24172436
status = myri10ge_send_cmd(mgp, MXGEFW_CMD_SET_MTU, &cmd, 0);
24182437
cmd.data0 = mgp->small_bytes;
24192438
status |=
@@ -2472,7 +2491,6 @@ static int myri10ge_open(struct net_device *dev)
24722491
static int myri10ge_close(struct net_device *dev)
24732492
{
24742493
struct myri10ge_priv *mgp = netdev_priv(dev);
2475-
struct myri10ge_cmd cmd;
24762494
int status, old_down_cnt;
24772495
int i;
24782496

@@ -2491,8 +2509,13 @@ static int myri10ge_close(struct net_device *dev)
24912509

24922510
netif_tx_stop_all_queues(dev);
24932511
if (mgp->rebooted == 0) {
2512+
struct myri10ge_cmd cmd;
2513+
24942514
old_down_cnt = mgp->down_cnt;
24952515
mb();
2516+
cmd.data0 = 0;
2517+
cmd.data1 = 0;
2518+
cmd.data2 = 0;
24962519
status =
24972520
myri10ge_send_cmd(mgp, MXGEFW_CMD_ETHERNET_DOWN, &cmd, 0);
24982521
if (status)
@@ -2956,6 +2979,9 @@ static void myri10ge_set_multicast_list(struct net_device *dev)
29562979

29572980
/* Disable multicast filtering */
29582981

2982+
cmd.data0 = 0;
2983+
cmd.data1 = 0;
2984+
cmd.data2 = 0;
29592985
err = myri10ge_send_cmd(mgp, MXGEFW_ENABLE_ALLMULTI, &cmd, 1);
29602986
if (err != 0) {
29612987
netdev_err(dev, "Failed MXGEFW_ENABLE_ALLMULTI, error status: %d\n",

0 commit comments

Comments
 (0)