Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp5997300ybc; Wed, 27 Nov 2019 13:07:49 -0800 (PST) X-Google-Smtp-Source: APXvYqzvN9pqWBjTdUcgGT3eUjgDtDoZWE98ip46/t/O/NcGiQHNBhfrk3kI8zQI54V3KypF5cTN X-Received: by 2002:a17:906:6847:: with SMTP id a7mr25329506ejs.95.1574888869758; Wed, 27 Nov 2019 13:07:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574888869; cv=none; d=google.com; s=arc-20160816; b=DOr9PEtPayGnaA2n+G5WHCP2Jd1gTtJbCYgr4RWk3D86ozJVbWSqfSnxEdZ89G4L/m H4kLn38y/5v3IzPkrkNtnLdfcnC9x8hAlHqFORd1yF4a6DTpyqBsVIlNLqlcuwXsiaWN HkBdfFWKcnmDp4XW/C1kzZPr5hRuvuFZwhBJt0yApP6vnzVL2v+UNZoY0psRy7gSNkwZ ZDA2DPDzx8JetqJ+wGBhxDiayt5jz6zCS6ZRR3yMXK4zsTWvlKUwEyCywpx7L2i5mHMi TkF2Or3SZLnCz9Owhs4G5fnC6oWi49gaGeSl0B9vmQxrJ0Gs9xs/GyzSj1F3WT3mmHi4 v4ZA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YwiZlxBfZLxMan90JTPpesdueRM4db1XfdoJzj9+3zM=; b=RjBi+QkacDgZnlTTLs6p/FHWyjaAAQOg5cohQEC52/RGyDxwQqfnz3EpGNY9Z3MJFO LDIAvGk9eI9oWUa+wYH9LtuO8ThUcgeDRkKaRCn2iCIleYdrXKshOaTzFohBmLNu89fz tytxX+ByJbQEPUDQa3BIri2CWr7VkTRV+SvY4P83qmojgA1NWekh730f7T1jNCYQksd9 B3FjMbMLIu8WC+ucQYlQMzq+PhclgtSx0gLKarf4VBEGsYrdyUn0poOeVWs7FJT0x6eV XcKRuWvElhYW924YaSIz+upJaV9UEPXlgT8c8DvOCbDDc65EK9IjUCiAtLTiGMOTcYrg 3Luw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Eaet1Upa; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t30si12433422edi.207.2019.11.27.13.07.26; Wed, 27 Nov 2019 13:07:49 -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=Eaet1Upa; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732259AbfK0VFO (ORCPT + 99 others); Wed, 27 Nov 2019 16:05:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:58884 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731672AbfK0VFM (ORCPT ); Wed, 27 Nov 2019 16:05:12 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4AE6920637; Wed, 27 Nov 2019 21:05:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574888711; bh=2Luct6aeUchWiuAqbQk8IOpLZN3/QWd0Ogx29N2hSO4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Eaet1UpaG4YLiimeUvXzBgUP9dnkbz2GTLMfl44OTmD5mtz06/qzexaL8upyp213E P/ItXIyP4fL/jGWIHgKEH8qE7VKSlaGhRIteS02kfX7U6E1jBiH2Krc7zgS126wN3J vYDnBryBzu1G10O9UG1+yiinntdM5DPLWC9TiTyQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Huazhong Tan , "David S. Miller" , Sasha Levin Subject: [PATCH 4.19 187/306] net: hns3: bugfix for is_valid_csq_clean_head() Date: Wed, 27 Nov 2019 21:30:37 +0100 Message-Id: <20191127203128.927710566@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203114.766709977@linuxfoundation.org> References: <20191127203114.766709977@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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