Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp769866ybc; Sat, 16 Nov 2019 08:22:45 -0800 (PST) X-Google-Smtp-Source: APXvYqxigPWrtU0Nd42B3AXK//b/2vllUtYU0n3YdnJOdpJeJxm3kYoiExvuzlzK6fRWI90lohNY X-Received: by 2002:adf:e80d:: with SMTP id o13mr12306625wrm.73.1573921365076; Sat, 16 Nov 2019 08:22:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573921365; cv=none; d=google.com; s=arc-20160816; b=EhoGNqbXa84tsJIZsI7BbZ3LjtOmpI0TI5kuA87sX8UMTUp7xUNrqpZn5x91UYv+Xx OgAxYEtMqWxucMOtZewcbx9oKWM6MRn740q00KuuuA6I7ubfb2HPAoS1zm2QzjIeRZwd q02beGxKgqadO3DCVcCIKNw+L6V/4L/471lq8waNLjtjTWM9ahOhvMepfX8tVjcxz23e PxWjgjQkTwEFdjjW4G3R7fWgPgnI8p06/1u74vL0JmxcwT6RYdij1eL4olDF2rOOXa/E vJQQN8wCRyBbo6FxCDd678vAhk+21DYAUZsombg9WSnU29AKb3EuHkQEqEFDGY9LwyZo 0UoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YwiZlxBfZLxMan90JTPpesdueRM4db1XfdoJzj9+3zM=; b=ZaopOzeHlVbWFpmWJETgi/TwDMn1wdn8oZqPDOl2Z9f8OPrv46dqP3CmDgelSr4t7m wKvWHX0pgShXcwd+twAVLwakNe3/UhTg+OZH/Q+wjwrUpp/wYlR0843DJ3+W3Lo5hcN2 6ucABxBMStmTfHZfaRjlwX5xZifKF09FbZ9bn/5/7R1hu3aupznSzhJaCwkzy7GS/Mif JKhMZWlqNZNb/kPT2UYw1ha7KHNyEh27qQ7oVCMbNJD6HjqDVyy3U3BJ9rQyXl2Icu6U QWxeQ2gZRyOJKSk3Rnkpq7Lqtxuerc+TCqY3TpG1LKuaW+6IIVF2eoXSWopngOoA7z8C TW9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LlUBYgEe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ce3si10440989edb.441.2019.11.16.08.22.20; Sat, 16 Nov 2019 08:22:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LlUBYgEe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729298AbfKPPqI (ORCPT + 99 others); Sat, 16 Nov 2019 10:46:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:52120 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729271AbfKPPqC (ORCPT ); Sat, 16 Nov 2019 10:46:02 -0500 Received: from sasha-vm.mshome.net (unknown [50.234.116.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B63EE207FA; Sat, 16 Nov 2019 15:46:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573919162; bh=2Luct6aeUchWiuAqbQk8IOpLZN3/QWd0Ogx29N2hSO4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LlUBYgEeOXCtKO5CzykNtpRewz3OGoFKeNqp84A/2hRKeI2rbbe4oygBOzo1F8sqZ bJfisXzb3GZ4apRM/UrRScQR8Z+JthNhWFuN70UtDU/jgBnEJUBWgkYkdMspVE3Bqy sfNFf/HULlvXk3YQSVY+S2Q2KR3M2ckdojKfbZqM= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Huazhong Tan , "David S . Miller" , Sasha Levin , netdev@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 170/237] net: hns3: bugfix for is_valid_csq_clean_head() Date: Sat, 16 Nov 2019 10:40:05 -0500 Message-Id: <20191116154113.7417-170-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191116154113.7417-1-sashal@kernel.org> References: <20191116154113.7417-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Huazhong Tan [ Upstream commit 6d71ec6cbf74ac9c2823ef751b1baa5b889bb3ac ] The HEAD pointer of the hardware command queue maybe equal to the command queue's next_to_use in the driver, so that does not belong to the invalid HEAD pointer, since the hardware may not process the command in time, causing the HEAD pointer to be too late to update. The variables' name in this function is unreadable, so give them a more readable one. Fixes: 3ff504908f95 ("net: hns3: fix a dead loop in hclge_cmd_csq_clean") Signed-off-by: Huazhong Tan Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c index 68026a5ad7e77..690f62ed87dca 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c @@ -24,15 +24,15 @@ static int hclge_ring_space(struct hclge_cmq_ring *ring) return ring->desc_num - used - 1; } -static int is_valid_csq_clean_head(struct hclge_cmq_ring *ring, int h) +static int is_valid_csq_clean_head(struct hclge_cmq_ring *ring, int head) { - int u = ring->next_to_use; - int c = ring->next_to_clean; + int ntu = ring->next_to_use; + int ntc = ring->next_to_clean; - if (unlikely(h >= ring->desc_num)) - return 0; + if (ntu > ntc) + return head >= ntc && head <= ntu; - return u > c ? (h > c && h <= u) : (h > c || h <= u); + return head >= ntc || head <= ntu; } static int hclge_alloc_cmd_desc(struct hclge_cmq_ring *ring) -- 2.20.1