Skip to content

Commit

Permalink
virtio_net: Fix error code in __virtnet_get_hw_stats()
Browse files Browse the repository at this point in the history
The virtnet_send_command_reply() function returns true on success or
false on failure.  The "ok" variable is true/false depending on whether
it succeeds or not.  It's up to the caller to translate the true/false
into -EINVAL on failure or zero for success.

The bug is that __virtnet_get_hw_stats() returns false for both
errors and success.  It's not a bug, but it is confusing that the caller
virtnet_get_hw_stats() uses an "ok" variable to store negative error
codes.

Fix the bug and clean things up so that it's clear that
__virtnet_get_hw_stats() returns zero on success or negative error codes
on failure.

Fixes: 941168f ("virtio_net: support device stats")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Simon Horman <horms@kernel.org>
Reviewed-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Signed-off-by: NipaLocal <nipa@local>
  • Loading branch information
Dan Carpenter authored and NipaLocal committed May 13, 2024
1 parent bd00e9d commit c13d302
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions drivers/net/virtio_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -4015,7 +4015,7 @@ static int __virtnet_get_hw_stats(struct virtnet_info *vi,
&sgs_out, &sgs_in);

if (!ok)
return ok;
return -EINVAL;

for (p = reply; p - reply < res_size; p += le16_to_cpu(hdr->size)) {
hdr = p;
Expand Down Expand Up @@ -4052,7 +4052,7 @@ static int virtnet_get_hw_stats(struct virtnet_info *vi,
struct virtio_net_ctrl_queue_stats *req;
bool enable_cvq;
void *reply;
int ok;
int err;

if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_DEVICE_STATS))
return 0;
Expand Down Expand Up @@ -4099,12 +4099,12 @@ static int virtnet_get_hw_stats(struct virtnet_info *vi,
if (enable_cvq)
virtnet_make_stat_req(vi, ctx, req, vi->max_queue_pairs * 2, &j);

ok = __virtnet_get_hw_stats(vi, ctx, req, sizeof(*req) * j, reply, res_size);
err = __virtnet_get_hw_stats(vi, ctx, req, sizeof(*req) * j, reply, res_size);

kfree(req);
kfree(reply);

return ok;
return err;
}

static void virtnet_get_strings(struct net_device *dev, u32 stringset, u8 *data)
Expand Down

0 comments on commit c13d302

Please sign in to comment.