Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp4476241imd; Tue, 30 Oct 2018 02:34:25 -0700 (PDT) X-Google-Smtp-Source: AJdET5cM3kSEa1fMjp1XXx+BR/+rsZQkGlhCBL4KdMGVwbSsvDGc/Wym8arOaMQCKu93RluNvli2 X-Received: by 2002:a17:902:7d98:: with SMTP id a24-v6mr17950670plm.271.1540892065468; Tue, 30 Oct 2018 02:34:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540892065; cv=none; d=google.com; s=arc-20160816; b=hr4pTEOBbjbdsRTgTeKNKKyucE90oeZCKg1DXXSOsAl8deVcYlmgynXzRz66+hDenv T9waVYYvuNCwYxPNL4/KBroyw16ibpJq6v9jT1ujo90nk+UWfkL+YBAhsQoxfyr6AgSf XqILX+Lj7DcyT1zxLuopHng/U7BOqlq64P6163CWR5FNFsl+/B/KFS7aeT2nyPR2Ni8M jU0CyRrpZFB5LS/VrH60qWqTv9rrbBVPb7OY7jPnMMUeqdVUkObpjJGcf0K45G1y7Fzf 4fqi66Ga4TIlqGPZnSWKLCqoUyi06N8XFQ034gF0VPs6jvysVIevgCHicfduBBab/rJ6 qqeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=K8VQVdK5zUxbqOB4FoFiKGz7Kct7JLFS1TqE0+kXXsw=; b=wSOv644zeSJQHhUwaEglvC9/XDpXyfpbBA3iL4/5M7EDzi6Se4oX7C+W5+8eTdZhTB y0bBU1opJVRsu7G8dVOfTOns+aUFdc7Vxf2Kmq0d782hIZTC9UgOqynsgu0/NuKioweT hKABDCb0VhJXiFbVbSbiflCSpuyK602t0mbtM01EED0HQsKJZWl2bZit73eOOfAEZ+Gs fHyBtOVmjambV9T9qHpGbtzSHJIvHHz5h2Eo3zHuQZgrwhBGEHnAie7+p2vSyxY1Wvc+ ho1gjy6DXWJgsyRzB9YYlp8cK+7U/MvGVlMjcav3LIgscQv+eFdrolj6afmrZS8eyMtk yqLA== ARC-Authentication-Results: i=1; mx.google.com; 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 o13-v6si9696515pfd.46.2018.10.30.02.34.09; Tue, 30 Oct 2018 02:34:25 -0700 (PDT) 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; 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 S1726969AbeJ3SYc (ORCPT + 99 others); Tue, 30 Oct 2018 14:24:32 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:53430 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726212AbeJ3SYc (ORCPT ); Tue, 30 Oct 2018 14:24:32 -0400 Received: from hsi-kbw-5-158-153-52.hsi19.kabel-badenwuerttemberg.de ([5.158.153.52] helo=kurt.tec.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1gHQNB-0003Lk-Dn; Tue, 30 Oct 2018 10:31:41 +0100 From: Kurt Kanzenbach To: Anirudha Sarangi , John Linn , "David S. Miller" Cc: Michal Simek , Radhey Shyam Pandey , Andrew Lunn , YueHaibing , netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Kurt Kanzenbach Subject: [PATCH 1/2] net: axienet: recheck condition after timeout in mdio_wait() Date: Tue, 30 Oct 2018 10:31:38 +0100 Message-Id: <20181030093139.10226-2-kurt@linutronix.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181030093139.10226-1-kurt@linutronix.de> References: <20181030093139.10226-1-kurt@linutronix.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The function could report a false positive if it gets preempted between reading the XAE_MDIO_MCR_OFFSET register and checking for the timeout. In such a case, the condition has to be rechecked to avoid false positives. Therefore, check for expected condition even after the timeout occurred. Signed-off-by: Kurt Kanzenbach --- drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c b/drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c index 757a3b37ae8a..4f13125e4942 100644 --- a/drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_mdio.c @@ -21,15 +21,26 @@ int axienet_mdio_wait_until_ready(struct axienet_local *lp) { unsigned long end = jiffies + 2; - while (!(axienet_ior(lp, XAE_MDIO_MCR_OFFSET) & - XAE_MDIO_MCR_READY_MASK)) { + u32 val; + + while (1) { + val = axienet_ior(lp, XAE_MDIO_MCR_OFFSET); + + if (val & XAE_MDIO_MCR_READY_MASK) + return 0; + if (time_before_eq(end, jiffies)) { - WARN_ON(1); - return -ETIMEDOUT; + val = axienet_ior(lp, XAE_MDIO_MCR_OFFSET); + break; } + udelay(1); } - return 0; + if (val & XAE_MDIO_MCR_READY_MASK) + return 0; + + WARN_ON(1); + return -ETIMEDOUT; } /** -- 2.11.0