netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] virtio_net: Fix duplicated return values in virtnet_get_hw_stats
@ 2025-05-14  5:44 Tang Longjun
  2025-05-15 14:10 ` Jakub Kicinski
  0 siblings, 1 reply; 3+ messages in thread
From: Tang Longjun @ 2025-05-14  5:44 UTC (permalink / raw)
  To: xuanzhuo, jasowang
  Cc: mst, davem, edumazet, netdev, virtualization, Tang Longjun

From: Tang Longjun <tanglongjun@kylinos.cn>

virtnet_get_hw_stats will return same value of 0 in the following three cases:
1. VIRTIO_NET_F_DEVICE_STATS feature is not configured on the device side.
2. success to obtain device stats.
3. fail to obtain device stats.
This would lead to case 1 and case 3 being unable to be recognized.

So, it's fixed by returning different values for the three cases.

Fixes: 941168f8b40e ("virtio_net: support device stats")
Signed-off-by: Tang Longjun <tanglongjun@kylinos.cn>
---
 drivers/net/virtio_net.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index e53ba600605a..c9a86f325619 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -4897,7 +4897,7 @@ static int __virtnet_get_hw_stats(struct virtnet_info *vi,
 					&sgs_out, &sgs_in);
 
 	if (!ok)
-		return ok;
+		return 1;
 
 	for (p = reply; p - reply < res_size; p += le16_to_cpu(hdr->size)) {
 		hdr = p;
@@ -4937,7 +4937,7 @@ static int virtnet_get_hw_stats(struct virtnet_info *vi,
 	int ok;
 
 	if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_DEVICE_STATS))
-		return 0;
+		return -EOPNOTSUPP;
 
 	if (qid == -1) {
 		last_vq = vi->curr_queue_pairs * 2 - 1;
@@ -5038,10 +5038,12 @@ static void virtnet_get_ethtool_stats(struct net_device *dev,
 	struct virtnet_stats_ctx ctx = {0};
 	unsigned int start, i;
 	const u8 *stats_base;
+	int ret;
 
 	virtnet_stats_ctx_init(vi, &ctx, data, false);
-	if (virtnet_get_hw_stats(vi, &ctx, -1))
-		dev_warn(&vi->dev->dev, "Failed to get hw stats.\n");
+	ret = virtnet_get_hw_stats(vi, &ctx, -1);
+	if (ret)
+		dev_warn(&vi->dev->dev, "Failed to get hw stats. err code:%d\n", ret);
 
 	for (i = 0; i < vi->curr_queue_pairs; i++) {
 		struct receive_queue *rq = &vi->rq[i];
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-05-16  7:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-14  5:44 [PATCH] virtio_net: Fix duplicated return values in virtnet_get_hw_stats Tang Longjun
2025-05-15 14:10 ` Jakub Kicinski
2025-05-16  7:36   ` Lange Tang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).