From patchwork Tue Oct 30 09:31:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kurt Kanzenbach X-Patchwork-Id: 10661225 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 00C8F14BD for ; Tue, 30 Oct 2018 16:09:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF6E72A833 for ; Tue, 30 Oct 2018 16:09:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D33132A837; Tue, 30 Oct 2018 16:09:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 874962A833 for ; Tue, 30 Oct 2018 16:09:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=43w91bp0Mm/B2ndUNFYaJ6QSqSNf6M555u/rnmaFQvI=; b=mRFYGmlm8x3kA3HPsbz0nEA2Xf e3g7IDU68Z8RyUXzz6c9cs2RxhGtvu17q+Ipn2Gsl5mTSi330wUkwwaOHwxtqO9Bpi2L9ntxzAGBT K5Sdp0f/Nytc9qjO1Rt2r+wiFBh1ImofgxDQP0lmgx6ADxnfXdcUBPyBp39/tA0O0/sQhiqTH/OAZ +4HKjlbXR7qR9cw8j2U76GCBuyGSsAasLf0ej58nEI0vYbQgiWsu+n3GFl1Zbm8mGpNPvrxF2UCr2 FMKSz8IrO5tzxT2+nCM3kAP5S7m4xpxBUFdPedtxTaa+WHhvfxtdHGew1TAITWkyiLXwYANhV7Ts9 uktzVgEQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gHWa4-0000FU-5J; Tue, 30 Oct 2018 16:09:24 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gHVsG-0002Rf-26 for linux-arm-kernel@bombadil.infradead.org; Tue, 30 Oct 2018 15:24:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=a3pHKPztoUnZAYgBJ+/6JWaoWcdfqtsWj2jPXnlLX2s=; b=S4FCrgLTWmBlyvpkp1KfdBYPm 85uAWytmVAzkYzOivHZnEwlsUwr5H7ZlwRjY/uvg89ERemjpI9jjzh3gXeoeWEavsXINLiMDMi/Bn 2A0rz2raaMcH76SR9x3/DPw8EpNNmVmpt5dcgNv+eubCA8nHhWrI7ZxjHIKfwimRAv0FNbIr5oT6m nRazztCUB9ScHc2NaJeyh8UC9hItMfbq7GsFgsKuCpoi/SYLl51irv9JczcVQONpQze5uXy8LcxCT +eaWzEfeo2GYnfbq6lX118XWrf4nDSUglNycY4tyRR9rjG8KeFdJbCFY3gC64DP65F+/nqr9qSJo2 TIYjHjisw==; Received: from galois.linutronix.de ([2a01:7a0:2:106d:700::1]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gHQP9-0005bW-J5 for linux-arm-kernel@lists.infradead.org; Tue, 30 Oct 2018 09:33:44 +0000 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-UV; Tue, 30 Oct 2018 10:31:42 +0100 From: Kurt Kanzenbach To: Anirudha Sarangi , John Linn , "David S. Miller" Subject: [PATCH 2/2] net: xilinx_emaclite: recheck condition after timeout in mdio_wait() Date: Tue, 30 Oct 2018 10:31:39 +0100 Message-Id: <20181030093139.10226-3-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181030_093343_640657_A4944521 X-CRM114-Status: GOOD ( 14.30 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Lunn , Kurt Kanzenbach , netdev@vger.kernel.org, Radhey Shyam Pandey , YueHaibing , Michal Simek , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The function could report a false positive if it gets preempted between reading the XEL_MDIOCTRL_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_emaclite.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/xilinx/xilinx_emaclite.c b/drivers/net/ethernet/xilinx/xilinx_emaclite.c index 639e3e99af46..957d03085bd0 100644 --- a/drivers/net/ethernet/xilinx/xilinx_emaclite.c +++ b/drivers/net/ethernet/xilinx/xilinx_emaclite.c @@ -714,19 +714,29 @@ static irqreturn_t xemaclite_interrupt(int irq, void *dev_id) static int xemaclite_mdio_wait(struct net_local *lp) { unsigned long end = jiffies + 2; + u32 val; /* wait for the MDIO interface to not be busy or timeout * after some time. */ - while (xemaclite_readl(lp->base_addr + XEL_MDIOCTRL_OFFSET) & - XEL_MDIOCTRL_MDIOSTS_MASK) { + while (1) { + val = xemaclite_readl(lp->base_addr + XEL_MDIOCTRL_OFFSET); + + if (!(val & XEL_MDIOCTRL_MDIOSTS_MASK)) + return 0; + if (time_before_eq(end, jiffies)) { - WARN_ON(1); - return -ETIMEDOUT; + val = xemaclite_readl(lp->base_addr + XEL_MDIOCTRL_OFFSET); + break; } + msleep(1); } - return 0; + if (!(val & XEL_MDIOCTRL_MDIOSTS_MASK)) + return 0; + + WARN_ON(1); + return -ETIMEDOUT; } /**