Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp471983lqo; Fri, 10 May 2024 05:51:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWhcYl+nqbl0VfxKXjkJz1jZJ4MsxeTGUxTy/DGVDqJOYCwGiPMlVoSt0Psn6k8r23An+yI0lYgptozj4yz3bBxt027RmMrpndvkR40vg== X-Google-Smtp-Source: AGHT+IEyJl3bfniMSwMvKdrB/bU7ZU7sVKgOGw9gdimjK8n/ierzpjnIkMGtuJ17845VpPYvy7H/ X-Received: by 2002:a17:906:3512:b0:a59:a282:5dbd with SMTP id a640c23a62f3a-a5a2d676474mr234476566b.66.1715345469324; Fri, 10 May 2024 05:51:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715345469; cv=pass; d=google.com; s=arc-20160816; b=vCa4rFs7OSrBRLMVhAtANWRB81EC+XEwuQlTvwIPZsJB4xh7z6E9AjbY6AM1thHiMr qZNNJSjplFNmOffMoexVco26pJC5TdoH6gEJkjmNFR5CGDYu9OS02J1j0atEQt2Oofrv xj0lIRbp73KI/NUITFiszXTVx3k28woANH47JHaxr0ZeUawadIQZYcs+kkCVcKlUHSdQ VShNOJENrP2O9lkeTYJVbtNMSLCjSSVTiVPy2O3H6L0+AyIZJdWDHSseCWmC08e+2qHA idBfPYqKPIum9vioIcxj8EDw5kCCCNYn0BduRHhbcBVaOpP236eg2jx1PRC6y9aIGbAB Rjiw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:subject:cc:to:from:date :dkim-signature; bh=LM/odI6j/fMx3udtCezmjdbmQwQqNuohmtxS/7GVXYY=; fh=X3f4ABW9U43vPM/4Mv986bYpt/yY9g/RAaVs+M7BdTE=; b=YYXwm62WhHvf99fCiiYHuBCLSRwzxBGFUpePlXDGIb7v4u4IHI/cud3DE/blWCaIXT 6VLlmrF1kikicAbQzuIZogrZsxTcZVigC2TueHpxw2GjHtekYcGpWvWKD71OHS+9HO3f 0YOQc1MdK1rHSPJAsZM8YdYtivUltBuNJfBHTXg4trGfof2jB9Anm+Joi1/F256AnpgC ObBZj6Wx67Yai5VFWmSO8I9DZzZRWotp9BGhVbTMmLwM2h74SHsLCg9PM+xYCFh7+n2e O4r8jaDOBQ2iF3pIlUb+wa93ITBBqfCmwSdNUffsKG1UBKORZcj+saDy59LGvwTz45re uL4A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RjoqKFIb; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-175792-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175792-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17be6afesi194992366b.802.2024.05.10.05.51.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 05:51:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-175792-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RjoqKFIb; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-175792-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175792-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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 CC6981F25C7D for ; Fri, 10 May 2024 12:51:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8A81212839E; Fri, 10 May 2024 12:50:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="RjoqKFIb" Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8FC823FB87 for ; Fri, 10 May 2024 12:50:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715345454; cv=none; b=I30gdK0sKsCWCkDHaAGUtgySweoFq3NxhvCGdIyeq+2nXvRoWGfHEjlUwcJUdFvmT2jTSGF6y24XEZIjyG86tmfU5pkvORam55ktOST1OfTN6S4y5aHiqzGFvoVhpvRdNrbbfZvgBT9IhmY7LFK0yCRWaIeNzI2+tBUvcV39lJk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715345454; c=relaxed/simple; bh=ko3uVA6VJm1NSJB8YRJHTV6RnbG8NXS2brijGf7c8Do=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=aPT0G9IcELCl0B86XRCmmUDG1apYVh0cBFGGDAzk0EcMOYN6LI5Uv//U2rsnjFvXv2KI3fkxW4omww9kgXOXZPLZANNabnI+8w0FHoiN0Q9vzgoJUHlhAQjq3DKRW6pAGocWi1umEVLoEyGA/o1SZzJnl2blRHfqP9PdhLIG5r8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=RjoqKFIb; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a59ab4f60a6so442288166b.0 for ; Fri, 10 May 2024 05:50:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715345451; x=1715950251; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=LM/odI6j/fMx3udtCezmjdbmQwQqNuohmtxS/7GVXYY=; b=RjoqKFIb+ypWZs2vOOmjq96n9WZETO0/+s0paF0ALSnhdSQP5YIoBBD9DMHq3rVMzK YUOQt6icneD0DJEuZahSncPsHK23mjb9wE2HX5lAOLW/j/BzU45zfNqo3iayjdUHWisN 3zeLVJsL/Ygoe0HnzyMnLdpPC81KdFjJwEK3P+1KXBBwxsFr3kYsGwFzvNARdngyW7NZ OpWLR6BgvlmWK+yy9276m3gF+DVXALevXZgxzflub3WQoe66hPEMKdib5FTerCMKzu8G jnwPY10VMnqJKGcxRbffly7ajd8quzynBu8kOq5HdgSfdmKTmE/wMIi/hiDPMwNbIGEh zd7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715345451; x=1715950251; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LM/odI6j/fMx3udtCezmjdbmQwQqNuohmtxS/7GVXYY=; b=YPLFGPItvH694V/QQGzF03KWLcS4cXAjnUVyD6sajzTfuynhtdtx4gYDMq7hieHpuC u4H6xueVkTNStcZyUsxiOOsDu413ojSb0Ymj0q1EWgbHREsdheEJcBGVVBVvyETxS4KT nL88U76WbSKX0MDDxkwT0HW9QOV/NpOGCMahpr0ChlvSJ8f4gS8dVjUhzZdbZBsDDl4k 3SK0PIt9cYa5Ih0+8V0z4PhCVS790qKxA278i117cWpT/2cM1PI7bojzE7Koqicgi/i6 dM+uWwqkR+/mkmtOsljrV0b4xaqAheWzd86o2mjub82GFOlTv/KRpqG6EyzGOZWQBdBD MBKw== X-Forwarded-Encrypted: i=1; AJvYcCUx8qJUwRhVJj94CSKhdtJEDSVis3+aD3HL9TqcSD/9c7XIhfcn6W9xKBJOrrZ0qYaN/VERMygOKrEFRrI+m0xC745GXjPEB4jlNBNG X-Gm-Message-State: AOJu0YwexVA2jafwgYdxXpKU6Td31Ap8fPh3tkdO4qxkMGalb0huvDAK 13kTiVzO3CrS9gvpMRJ8tabsoW26YE5M8q48U6tZvvv8TWYm0PXRxsfGjMT5T579+1YJUK3OrfJ C X-Received: by 2002:a17:906:80a:b0:a59:b784:ced3 with SMTP id a640c23a62f3a-a5a2d676b2emr194516266b.77.1715345450478; Fri, 10 May 2024 05:50:50 -0700 (PDT) Received: from localhost ([102.222.70.76]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5a179c814dsm180050666b.118.2024.05.10.05.50.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 05:50:50 -0700 (PDT) Date: Fri, 10 May 2024 15:50:45 +0300 From: Dan Carpenter To: Xuan Zhuo 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 Subject: [PATCH net-next] virtio_net: Fix error code in __virtnet_get_hw_stats() Message-ID: <3762ac53-5911-4792-b277-1f1ead2e90a3@moroto.mountain> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Mailer: git-send-email haha only kidding 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 --- 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)