Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp6525415rwl; Wed, 22 Mar 2023 11:44:07 -0700 (PDT) X-Google-Smtp-Source: AK7set+BcrdWj9Xkn0yFFcasodp9XSgLRegr9aa5aG8F7c28tiGKhFdhAXcjt59cZ8Aa//jI4yaW X-Received: by 2002:a17:902:e405:b0:19f:1c64:c9ca with SMTP id m5-20020a170902e40500b0019f1c64c9camr3254581ple.49.1679510647373; Wed, 22 Mar 2023 11:44:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679510647; cv=none; d=google.com; s=arc-20160816; b=NF7iyT/48vYkeZn/pj44aDvm7UfQinHJwGiWx/qJvgGSGpPI1fjuDn1qfYeClcj0LZ 5uw0PpnAH8gC2tinKK2vwB7wJWWT9z/hMbH3GJypWGJOtBxaC+DTTf8Emg1RIVo6qMgt ac/6zpuCWvo1Dq33DUgnN2Bf36QBT6hPYU/k3DciJUPgvF/AcaO8Au6/9wRrp53nCcd7 M8qqFFHPl+8waado0kpV7QgtEHFtxngTedLT4gNxS6/XAeil+fBNwbh67WI6/6HC3wj2 YkbGxhPAjHXTH1bS2My6n7wkhfCfAMgEgIekiG3lWUSMw8GQNtbClzlxofIH4BILH7Nz pirg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:subject:from:cc:to :in-reply-to:content-language:user-agent:mime-version:date :message-id:dkim-signature; bh=2jI7XF69xGSYc6uWoXcTewsdZMSwsHV3zIs6n8EvIlc=; b=WQ0FoqX4zHu9YiVJELrBR7WOhwqYMbCpKCFRAKB7ya2wr+jLmCT9PBej1Jdz6BjKKa rPXCqfhOLP/XEAy7jUE4Ywe4zSAM9i9RyGMgOkZX9Wiqjgm7fCkEwOxzXq7i4PtYx2Z7 nssq4WtF+juUuSY2dZI3UIMhmfmWlKVA02d9pw9X+qzPGZynnYC+3Mjk/++TbxodWzuK p+CwI8ehdmAaeayUPGM1NQNO4KYATw/O0n27o+qa4VxRpYhIyuCAjAINutW5SOFv3A6m +D5McUGenVlW6lGw50JWAKRv6jM7Iu7dAD9z8GyCzqevPOTAMcOXCChSmd135iK+eUJ4 lt3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=SZpMU2qE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q192-20020a632ac9000000b004fb2685a0d4si16557507pgq.621.2023.03.22.11.43.55; Wed, 22 Mar 2023 11:44:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=SZpMU2qE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229980AbjCVSji (ORCPT + 99 others); Wed, 22 Mar 2023 14:39:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229513AbjCVSjh (ORCPT ); Wed, 22 Mar 2023 14:39:37 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CFD810F8; Wed, 22 Mar 2023 11:39:36 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 87DC25FD3E; Wed, 22 Mar 2023 21:39:34 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1679510374; bh=2jI7XF69xGSYc6uWoXcTewsdZMSwsHV3zIs6n8EvIlc=; h=Message-ID:Date:MIME-Version:To:From:Subject:Content-Type; b=SZpMU2qEABc12peDtdbirDKGuboITfiDWAirBrD6tS8q1573+ddUDcT40cjQtEPvE v8HUT2EfMlxnzHn3hHhbAjZdf+/roRZcTrSNAdD9hyD9wcfnt1Cqao5CDZ5DRs6BXO tc7mbOPAyo+dj/qBRGCDaPDBdjHfjC8J8vQ2Dbptf3NnUPnN64vdair/N5WgweZ35y eoU+gRWNdp0YKRN5KX0ku2QRugtBV37cSBWkEMUgfBEhkFTD6ApMiyTR09B3Zs+JwI 4uhdPb2Qyg0NPKhwQv3QXLKhBwthB0cvfQtfyb7IQxpFm+YrrJiTJsl7eJB5/OooTg dB9e3N1t8nvCg== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Wed, 22 Mar 2023 21:39:34 +0300 (MSK) Message-ID: <50bb0210-1ed7-42fb-b5f6-8d97247209b5@sberdevices.ru> Date: Wed, 22 Mar 2023 21:36:24 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Content-Language: en-US In-Reply-To: To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Bobby Eshleman CC: , , , , , , From: Arseniy Krasnov Subject: [RFC PATCH v5 2/2] virtio/vsock: check argument to avoid no effect call Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH01.sberdevices.ru (172.16.1.4) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/03/22 14:20:00 #20991698 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Both of these functions have no effect when input argument is 0, so to avoid useless spinlock access, check argument before it. Signed-off-by: Arseniy Krasnov --- net/vmw_vsock/virtio_transport_common.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c index 9e87c7d4d7cf..312658c176bd 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -302,6 +302,9 @@ u32 virtio_transport_get_credit(struct virtio_vsock_sock *vvs, u32 credit) { u32 ret; + if (!credit) + return 0; + spin_lock_bh(&vvs->tx_lock); ret = vvs->peer_buf_alloc - (vvs->tx_cnt - vvs->peer_fwd_cnt); if (ret > credit) @@ -315,6 +318,9 @@ EXPORT_SYMBOL_GPL(virtio_transport_get_credit); void virtio_transport_put_credit(struct virtio_vsock_sock *vvs, u32 credit) { + if (!credit) + return; + spin_lock_bh(&vvs->tx_lock); vvs->tx_cnt -= credit; spin_unlock_bh(&vvs->tx_lock); -- 2.25.1