Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp4474647imd; Tue, 30 Oct 2018 02:32:38 -0700 (PDT) X-Google-Smtp-Source: AJdET5dTuUyWmF5L32+CFgLvWOD8m6ZFphi+eptAC8jhRQdGoJl6doGf5GrxvZR0+OIQcZL+3Ns1 X-Received: by 2002:a62:1552:: with SMTP id 79-v6mr2143958pfv.120.1540891958369; Tue, 30 Oct 2018 02:32:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540891958; cv=none; d=google.com; s=arc-20160816; b=KCpxcjT5MRJMSFRlmv19VjczOsArGuBUAFxpvatSZWzdRlL2fEYDbZIYnIPCuIup01 5suEkIKUbVcWsxGlIurF7y++JNeMjB3saxx89Gh077jsp7Y20UzPWxyAWF8c6hmNEoY6 35omgU/XiEorp9aT8MczSrGcUofbbKw1nvBVhsrB0uLRh/qRvqXfDlxYMz3HbGd2nyzp ziz8Etr+ODnX1sOeFIMUrYGVqD36Ki5HQTpHNXh9M40LFWCPepBuFuOmJYW1JSjFHwjA 0AfqsQ/xxYIP59/tL+6tie41jfptf0MnH+yYDZPA5BwDPWkSsd8NRNN0ifn3A7asVAFb 7CJQ== 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=a3pHKPztoUnZAYgBJ+/6JWaoWcdfqtsWj2jPXnlLX2s=; b=bsdu+g2YFuOK7YOJiAxheEvvZpYK9bo1fpo/HexIFvjf6HQes2L0gvRI66NSpiJmf8 f/cJLF5ndBURfk5gGPXz4u3NZwEvf9pdHsRLh7mFPk10efsVw8jlBbodGY0Dp6GTVdtV G294V5ya97/POil/whxNANSA3nFhTnz3W2+lJfXBpgPQD6Vm6R73cLuU0hrFAMzEYcY0 51NSvdOMb+KiiEKEG61W29uEls6wWY8WcTqk3ycTUho3VlVul7yocapBPn1XYPzvFtFU xFcyqVhtn6ypUgl0bqUDdkHYWvEQucCJbUI5tYMz5VcGescbtIJ+TRoFy7eHZQNF5kAc I0FA== 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 x1-v6si23588371plb.132.2018.10.30.02.32.23; Tue, 30 Oct 2018 02:32:38 -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 S1727381AbeJ3SYh (ORCPT + 99 others); Tue, 30 Oct 2018 14:24:37 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:53435 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726212AbeJ3SYh (ORCPT ); Tue, 30 Oct 2018 14:24:37 -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-UV; Tue, 30 Oct 2018 10:31:42 +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 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> 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 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; } /** -- 2.11.0