platform/mellanox: Add BlueField-3 support in the tmfifo driver
Hello Liming Sun,
The patch bc05ea63b394: "platform/mellanox: Add BlueField-3 support in the tmfifo driver" from Oct 18, 2022 (linux-next), leads to the following Smatch static checker warning:
drivers/platform/mellanox/mlxbf-tmfifo.c:634 mlxbf_tmfifo_rxtx_word()
error: uninitialized symbol 'data'.
drivers/platform/mellanox/mlxbf-tmfifo.c
592 static void mlxbf_tmfifo_rxtx_word(struct mlxbf_tmfifo_vring *vring,
593 struct vring_desc *desc,
594 bool is_rx, int len)
595 {
596 struct virtio_device *vdev = vring->vq->vdev;
597 struct mlxbf_tmfifo *fifo = vring->fifo;
598 void *addr;
599 u64 data;
600
601 /* Get the buffer address of this desc. */
602 addr = phys_to_virt(virtio64_to_cpu(vdev, desc->addr));
603
604 /* Read a word from FIFO for Rx. */
605 if (is_rx)
606 data = readq(fifo->rx.data);
607
608 if (vring->cur_len + sizeof(u64) <= len) {
609 /* The whole word. */
610 if (!IS_VRING_DROP(vring)) {
611 if (is_rx)
612 memcpy(addr + vring->cur_len, &data,
613 sizeof(u64));
614 else
615 memcpy(&data, addr + vring->cur_len,
616 sizeof(u64));
617 }if IS_VRING_DROP() is true then data isn't intialized.
618 vring->cur_len += sizeof(u64);
619 } else {
620 /* Leftover bytes. */
621 if (!IS_VRING_DROP(vring)) {
622 if (is_rx)
623 memcpy(addr + vring->cur_len, &data,
624 len - vring->cur_len);
625 else
626 memcpy(&data, addr + vring->cur_len,
627 len - vring->cur_len);
628 }Same here.
629 vring->cur_len = len;
630 }
631
632 /* Write the word into FIFO for Tx. */
633 if (!is_rx)
--> 634 writeq(data, fifo->tx.data);
^^^^Unitialized if IS_VRING_DROP() is true.
635 }
regards,
dan carpenter
+Cc Vadim, David.
Quoted 8 lines · Dan Carpenter
Hello Liming Sun,
The patch
bc05ea63b394: "platform/mellanox: Add BlueField-3 support in the tmfifo driver" from Oct 18, 2022 (linux-next), leads to the following Smatch static checker warning:
drivers/platform/mellanox/mlxbf-tmfifo.c:634mlxbf_tmfifo_rxtx_word()
error: uninitialized symbol 'data'.
Dan as always thank you for reporting this.
Liming, David, Vadim,
Can one of you take a look at this please ?
Regards,
Hans
Quoted 59 lines
drivers/platform/mellanox/mlxbf-tmfifo.c592 static void mlxbf_tmfifo_rxtx_word(struct mlxbf_tmfifo_vring *vring, 593 struct vring_desc *desc, 594 bool is_rx, int len) 595 { 596 struct virtio_device *vdev = vring->vq->vdev; 597 struct mlxbf_tmfifo *fifo = vring->fifo; 598 void *addr; 599 u64 data; 600 601 /* Get the buffer address of this desc. */ 602 addr = phys_to_virt(virtio64_to_cpu(vdev, desc->addr)); 603 604 /* Read a word from FIFO for Rx. */ 605 if (is_rx) 606 data = readq(fifo->rx.data); 607 608 if (vring->cur_len + sizeof(u64) <= len) { 609 /* The whole word. */ 610 if (!IS_VRING_DROP(vring)) { 611 if (is_rx) 612 memcpy(addr + vring->cur_len, &data, 613 sizeof(u64)); 614 else 615 memcpy(&data, addr + vring->cur_len, 616 sizeof(u64)); 617 }if
IS_VRING_DROP()is true then data isn't intialized.618 vring->cur_len += sizeof(u64); 619 } else { 620 /* Leftover bytes. */ 621 if (!IS_VRING_DROP(vring)) { 622 if (is_rx) 623 memcpy(addr + vring->cur_len, &data, 624 len - vring->cur_len); 625 else 626 memcpy(&data, addr + vring->cur_len, 627 len - vring->cur_len); 628 }Same here.
629 vring->cur_len = len; 630 } 631 632 /* Write the word into FIFO for Tx. */ 633 if (!is_rx) --> 634 writeq(data, fifo->tx.data); ^^^^Unitialized if
IS_VRING_DROP()is true.635 }regards,
dan carpenter
Quoted 27 lines
-----Original Message-----
From: Hans de Goede <[email protected]>
Sent: Wednesday, 4 October 2023 12:38
To: Dan Carpenter <[email protected]>; Liming Sun <[email protected]>; Vadim Pasternak <[email protected]>; David Thompson <[email protected]>
Cc: [email protected]
Subject: Re: [bug report] platform/mellanox: Add BlueField-3 support in the tmfifo driver+Cc Vadim, David.
Quoted 7 lines · Dan Carpenter
Hello Liming Sun,
The patch
bc05ea63b394: "platform/mellanox: Add BlueField-3 support in the tmfifo driver" from Oct 18, 2022 (linux-next), leads to the following Smatch static checker warning:
drivers/platform/mellanox/mlxbf-tmfifo.c:634
mlxbf_tmfifo_rxtx_word()Quoted 1 line
error: uninitialized symbol 'data'.
Dan as always thank you for reporting this.
Quoted 8 lines
Liming, David, Vadim,
Can one of you take a look at this please ?
Regards,
Hans
Hi Hans,
Sure. We'll handle it.
Thanks,
Vadim.
Quoted 61 lines
Quoted 61 lines
drivers/platform/mellanox/mlxbf-tmfifo.c592 static void mlxbf_tmfifo_rxtx_word(struct mlxbf_tmfifo_vring *vring, 593 struct vring_desc *desc, 594 bool is_rx, int len) 595 { 596 struct virtio_device *vdev = vring->vq->vdev; 597 struct mlxbf_tmfifo *fifo = vring->fifo; 598 void *addr; 599 u64 data; 600 601 /* Get the buffer address of this desc. */ 602 addr = phys_to_virt(virtio64_to_cpu(vdev, desc->addr)); 603 604 /* Read a word from FIFO for Rx. */ 605 if (is_rx) 606 data = readq(fifo->rx.data); 607 608 if (vring->cur_len + sizeof(u64) <= len) { 609 /* The whole word. */ 610 if (!IS_VRING_DROP(vring)) { 611 if (is_rx) 612 memcpy(addr + vring->cur_len, &data, 613 sizeof(u64)); 614 else 615 memcpy(&data, addr + vring->cur_len, 616 sizeof(u64)); 617 }if
IS_VRING_DROP()is true then data isn't intialized.618 vring->cur_len += sizeof(u64); 619 } else { 620 /* Leftover bytes. */ 621 if (!IS_VRING_DROP(vring)) { 622 if (is_rx) 623 memcpy(addr + vring->cur_len, &data, 624 len - vring->cur_len); 625 else 626 memcpy(&data, addr + vring->cur_len, 627 len - vring->cur_len); 628 }Same here.
629 vring->cur_len = len; 630 } 631 632 /* Write the word into FIFO for Tx. */ 633 if (!is_rx) --> 634 writeq(data, fifo->tx.data); ^^^^Unitialized if
IS_VRING_DROP()is true.635 }regards,
dan carpenter
Thanks!
There is no functionality issue. IS_VRING_DROP is only set for Rx. Line 634 is for Tx. So there is no case for line 634 to be used when IS_VRING_DROP() is TRUE.
But I'll submit a patch today to eliminate the warning.
Thanks,
Liming
Quoted 75 lines
-----Original Message-----
From: Dan Carpenter <[email protected]>
Sent: Thursday, September 28, 2023 8:23 AM
To: Liming Sun <[email protected]>
Cc: [email protected]
Subject: [bug report] platform/mellanox: Add BlueField-3 support in the tmfifo driverHello Liming Sun,
The patch
bc05ea63b394: "platform/mellanox: Add BlueField-3 support in the tmfifo driver" from Oct 18, 2022 (linux-next), leads to the following Smatch static checker warning:
drivers/platform/mellanox/mlxbf-tmfifo.c:634mlxbf_tmfifo_rxtx_word()
error: uninitialized symbol 'data'.
drivers/platform/mellanox/mlxbf-tmfifo.c592 static void mlxbf_tmfifo_rxtx_word(struct mlxbf_tmfifo_vring *vring, 593 struct vring_desc *desc, 594 bool is_rx, int len) 595 { 596 struct virtio_device *vdev = vring->vq->vdev; 597 struct mlxbf_tmfifo *fifo = vring->fifo; 598 void *addr; 599 u64 data; 600 601 /* Get the buffer address of this desc. */ 602 addr = phys_to_virt(virtio64_to_cpu(vdev, desc->addr)); 603 604 /* Read a word from FIFO for Rx. */ 605 if (is_rx) 606 data = readq(fifo->rx.data); 607 608 if (vring->cur_len + sizeof(u64) <= len) { 609 /* The whole word. */ 610 if (!IS_VRING_DROP(vring)) { 611 if (is_rx) 612 memcpy(addr + vring->cur_len, &data, 613 sizeof(u64)); 614 else 615 memcpy(&data, addr + vring->cur_len, 616 sizeof(u64)); 617 }if
IS_VRING_DROP()is true then data isn't intialized.618 vring->cur_len += sizeof(u64); 619 } else { 620 /* Leftover bytes. */ 621 if (!IS_VRING_DROP(vring)) { 622 if (is_rx) 623 memcpy(addr + vring->cur_len, &data, 624 len - vring->cur_len); 625 else 626 memcpy(&data, addr + vring->cur_len, 627 len - vring->cur_len); 628 }Same here.
629 vring->cur_len = len; 630 } 631 632 /* Write the word into FIFO for Tx. */ 633 if (!is_rx) --> 634 writeq(data, fifo->tx.data); ^^^^Unitialized if
IS_VRING_DROP()is true.635 }regards,
dan carpenter