Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp1781076lqo; Sun, 12 May 2024 19:20:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU0NOIsZM4ywtj3OWH0KAIcf8rulKXFaM0pypuYvaLTNoJl72JpNxGLFHf4UoZsrgVEFALtZxm09Z7FRg6Mz2eftaDOqYQzLFke4VHUDg== X-Google-Smtp-Source: AGHT+IFx0P87HJmy8Zb+BZS+zcUpWE3dvwmxoqnIO18zSPm9eczhNOIQcjBynaKM9abVN9j1nmVe X-Received: by 2002:a17:906:594d:b0:a59:bb1f:6ffc with SMTP id a640c23a62f3a-a5a2d54c13fmr525359666b.8.1715566811204; Sun, 12 May 2024 19:20:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715566811; cv=pass; d=google.com; s=arc-20160816; b=BfaL8pJe9snVmYQueJO6HKb+q86QItcXeNXFY52ANYXDjFACfoTNNCbQGH1AnKwtC/ LKoVaWp8Rv2lwRRwfRwybBLQXvXlwq1rL8qOse2WGBZmLFdNJghQ9W7p+EMJSXNBo7th fN9xmqYdlPBZ3hkWhRfangTCnFqMaCp4UbG+Wt4RmPLKCGLlhfFv6lCA1cGNoqJZpkDM EMuBLAxBqTjgnUliImV4u06Bth8aNdr3z3pnIYdrdl2g7trDqVxsuxI3gkSg1jqMfuJk Cpheu6q4QxF/KTiO8cdwsohnKnquOe8ZNMMfDekis6S1MYlmCGuz3Zl6YkWooXs/3oo5 Fq7A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to :references:cc:to:from:date:subject:message-id:dkim-signature; bh=+Ibcgk1wyvyT1sLlBJMhxYkwNZUy81Vb4Yk6knvBeK0=; fh=NBEXpnT1xvU23J2ooHMJk0MFbEZ8ZsRSPauwjnRzkLA=; b=E8ODu3tLgX8S5anOaiH93OFL8fuLZZNGEqpE7m+iihy76Hc0NRQr8e+eP01FEPIb8D +mJ6TCdHx9iqZcpLpbG1dPcPnOLF5OguwafiJZhxwPKkRQwXvpSczghcr0Vorsx5Nbvy Kcdy0H00EwRWKPkPuBWHLEkkUhU2AsTn76xZdPFJH0/kOZuYpuM6PzHad7xFOYTT0TL7 D6kQayj+fkGrRnmWJ9tb9YaNeW6jUiNh1a8IY9KNfcoo/+MwPzWvs508xDSVbkFrmyoQ g8ErFQwMcV++nQiIentYqIDnvXv2E8bY1DZfSrBFQsR9/I1v3O49UqLvXPTfLgNqEfVW OGnA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=hSYrJAIc; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-177104-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177104-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17b22062si459305466b.486.2024.05.12.19.20.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 May 2024 19:20:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-177104-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=hSYrJAIc; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-177104-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177104-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id EA9EB1F211E8 for ; Mon, 13 May 2024 02:20:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8E650134426; Mon, 13 May 2024 02:19:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="hSYrJAIc" Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B736F7483; Mon, 13 May 2024 02:19:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.111 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715566797; cv=none; b=LnKfAwimnOV0WS/MmEdiKAyXQ5o+3577zVuJqGARDZs44tSo1yfNdEKLzoZd8nbX3qTmkjc6FlC65VBXGvKaI0A8dDSakN/ClOOj0LR9417aUepshGRYblrBlMVb/s2G4LxoZFM1sciImdifH/JyqZjt1WbUgIajj4eVlBcPRAk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715566797; c=relaxed/simple; bh=nLF3UxM7MjtqZfnysVw+O3InSkNqMGsxV6LviZSaZnY=; h=Message-ID:Subject:Date:From:To:Cc:References:In-Reply-To; b=hy1MxmZEeb1Vk8yuwYK6PPkq8TiljBCJPdscXZzypw7edqONTBleeBDSxYsTj60HQyGLPhe+tuJxu/VyO3TgPe9cy8qRXBnt4W4sQw2gLQo//LjitADE9IQZz9SRDlSGmzuQ84KDTfNAqlcFx8DAMfi8YsW7ujYH7YWo/f9Wfxg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=hSYrJAIc; arc=none smtp.client-ip=115.124.30.111 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1715566786; h=Message-ID:Subject:Date:From:To; bh=+Ibcgk1wyvyT1sLlBJMhxYkwNZUy81Vb4Yk6knvBeK0=; b=hSYrJAIch7ALWRr6LJwU9cKteYSF4qkbwNW4QOfTU/jmKS1wlcmAGQUuWzJwdtKTrlCrBe3XPB+VckXTmNOVPtkre9/MBwej6CMjO6iN6ezVS2Hao820MTDwHjLE7rscF/kYDQR5SRCPYNs8T2lR6XHUwdLH672RyzVc7vc+hQ0= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045046011;MF=xuanzhuo@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0W6Gqhnu_1715566783; Received: from localhost(mailfrom:xuanzhuo@linux.alibaba.com fp:SMTPD_---0W6Gqhnu_1715566783) by smtp.aliyun-inc.com; Mon, 13 May 2024 10:19:45 +0800 Message-ID: <1715566739.6868987-1-xuanzhuo@linux.alibaba.com> Subject: Re: [PATCH net-next] virtio_net: Fix error code in __virtnet_get_hw_stats() Date: Mon, 13 May 2024 10:18:59 +0800 From: Xuan Zhuo To: Dan Carpenter Cc: "Michael S. Tsirkin" , Jason Wang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org References: <3762ac53-5911-4792-b277-1f1ead2e90a3@moroto.mountain> In-Reply-To: <3762ac53-5911-4792-b277-1f1ead2e90a3@moroto.mountain> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: On Fri, 10 May 2024 15:50:45 +0300, Dan Carpenter wrote: > 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: 941168f8b40e ("virtio_net: support device stats") > Signed-off-by: Dan Carpenter That confused me too. Reviewed-by: Xuan Zhuo Thanks. > --- > drivers/net/virtio_net.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > index 218a446c4c27..4fc0fcdad259 100644 > --- a/drivers/net/virtio_net.c > +++ b/drivers/net/virtio_net.c > @@ -4016,7 +4016,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; > @@ -4053,7 +4053,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; > @@ -4100,12 +4100,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) >