Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2503904imw; Wed, 6 Jul 2022 07:05:17 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u6j0rWm2K/Xn6MWvi8mvH1vRbBcNBegnuIDF+zJhDMWYz3H7TCf8IIZaibqjbRpdu7FTLI X-Received: by 2002:a05:6a00:a0c:b0:528:5233:f119 with SMTP id p12-20020a056a000a0c00b005285233f119mr23132264pfh.69.1657116316511; Wed, 06 Jul 2022 07:05:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657116316; cv=none; d=google.com; s=arc-20160816; b=eGmsD4Tgsl19HPpEg47hBrwXGk6B6B0SjrOz/86xe61WfTG7ZFyVbDWdQtIQUfeSgf JLuE3z7qXZ+QRhv3UG0m86bvm9s8Hbs+V+4GnxnG1sJoWyawPYtOqkj/87z03zt3an5l Z2fVdcgYTFAZ3slCeSIeeVH+UyQubOYWmKzbKsC7UEk6CkZW03gyIy5D2p724JniulrK DkQ83jBCRzbHt/MmFgvip4+x3ihhf5SMiaoIVhEFIGVKvsj/fYbAFXwMSYr9Dc5uJ/+a ZJ/1Q7satHm2Kt3Xr3kEnCuPDjQ8si2jBfVwkIeOlDvlWL0rV912jXuw8iyxnNSv/AKk YsEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=pNEUfwqlplOIfsxU8BPJxwIb+d3FuNgNfWoTeCpOydg=; b=w20pP9UgzgmFGOCbg3i+ES6jgkYurXSloVsLmf1ruEeyrZNfwW+8V4XQLVBmXRiP1H 2/Bhq1uVUbEelCs12Tt4rXIYFAp9uW4ggATzNtl50uFTV9D6COawhUsTpSA9QPYxGn4S U8q3kIzi73yIxrCDOVloYW+Hl4OE3UaXhilxQqykpXPHhodQ/Sz4RrulHglPFdiaOCZS H7vT6Zvgd69/WjnBXaVLNY9fpnC/Z6iAqKP94GgrTZL1fusfP3AqE8zcChBka95wzWTm HHMpQlz2k094sNavHQf3Rc6SsZ0YdnizCe/1Rn3HgyTY3qYaWMGaG3Q3yt1LAFnyZPvE CQDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PmNCrbN7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oe5-20020a17090b394500b001efb8e43855si1633101pjb.117.2022.07.06.07.05.01; Wed, 06 Jul 2022 07:05:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PmNCrbN7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233824AbiGFN24 (ORCPT + 99 others); Wed, 6 Jul 2022 09:28:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233813AbiGFN2x (ORCPT ); Wed, 6 Jul 2022 09:28:53 -0400 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FCF81D324; Wed, 6 Jul 2022 06:28:52 -0700 (PDT) Received: by mail-lj1-x229.google.com with SMTP id y18so7604883ljj.6; Wed, 06 Jul 2022 06:28:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=pNEUfwqlplOIfsxU8BPJxwIb+d3FuNgNfWoTeCpOydg=; b=PmNCrbN7c8HPxMFp+CQbVyc5YHM5VjvUmmJnN+UDExiG0SnTmUuE19ch1Bnauk6crH d2UADWJGRS0PhutnignyTGUtDKIzgLb2RqM0scFcV8jQUl9w7reI25ti5yipwvjqNPg2 P4NBnDwqtIB8g10MlQQzOSe0zgbioSzVBjKSS4vOpUv5piYYxs0gZ2atgciXTmLRPuG6 CNCemWzNZ5+NCvTLH8cB02kXwCaBawgrp9BaaLvDWkPpBj0ruMGz7ml4O2vK2s5ho7C1 HtwLlnpMOmJqyWk/NhVDBYmMxu598k3j+Qj0goC5MQyBWTcQbta51KCb9OtQzNmuIdy/ kdmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=pNEUfwqlplOIfsxU8BPJxwIb+d3FuNgNfWoTeCpOydg=; b=X4C1X5FD1tWgfXKxsCGbeYpc8B+FVyn/CFsIo9OXYoXZ7hAjm/lqp8OS57ZMQ82VAO noPAuvtPg3mjZEqwdVCN5UcHCfKRJ43LVu0zlzjd3MUQ14t2AAenzXOpvZMHjs0A1aJ3 2bPPRY9jZsQFfBw7uc/Uh7PBOIuploFv+K5l0+05UGfni22inm3qlFVADbT7uXMPmU6x tdFwG6cfgbH0V2rr6L8Kj1O9NPLUkfjma79KK2xmrGHyemP+xV70KRjeKvC90yqa3wrZ I3kiuNYCeWtAaMaBrvA0+wmtpAcsQkgDn1wOjsQqCGxy4qA9M42pgd5PQ84P0F7KKsCk eNTQ== X-Gm-Message-State: AJIora8v1iBHmI328CyeeBZ9NVWOr1voZM/j8mB6dUBoq72qyCaiEEFu h8VS90awGZMkx30z4/2Zabs= X-Received: by 2002:a2e:b8c2:0:b0:25b:6b0c:34e with SMTP id s2-20020a2eb8c2000000b0025b6b0c034emr14212226ljp.397.1657114130193; Wed, 06 Jul 2022 06:28:50 -0700 (PDT) Received: from fedora.. ([46.235.67.63]) by smtp.gmail.com with ESMTPSA id b17-20020a196711000000b004875a37b7b7sm105941lfc.159.2022.07.06.06.28.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 06:28:49 -0700 (PDT) From: Pavel Skripkin To: vladimir.oltean@nxp.com, claudiu.manoil@nxp.com, alexandre.belloni@bootlin.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: clement.leger@bootlin.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Pavel Skripkin , Andrew Lunn Subject: [PATCH v4] net: ocelot: fix wrong time_after usage Date: Wed, 6 Jul 2022 16:28:45 +0300 Message-Id: <20220706132845.27968-1-paskripkin@gmail.com> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Accidentally noticed, that this driver is the only user of while (time_after(jiffies...)). It looks like typo, because likely this while loop will finish after 1st iteration, because time_after() returns true when 1st argument _is after_ 2nd one. There is one possible problem with this poll loop: the scheduler could put the thread to sleep, and it does not get woken up for OCELOT_FDMA_CH_SAFE_TIMEOUT_US. During that time, the hardware has done its thing, but you exit the while loop and return -ETIMEDOUT. Fix it by using sane poll API that avoids all problems described above Fixes: 753a026cfec1 ("net: ocelot: add FDMA support") Suggested-by: Andrew Lunn Signed-off-by: Pavel Skripkin --- Changes since v3: - Aligned the arguments to the open bracket Changes since v2: - Use _atomic variant of readx_poll_timeout Changes since v1: - Fixed typos in title and commit message - Remove while loop and use readx_poll_timeout as suggested by Andrew --- drivers/net/ethernet/mscc/ocelot_fdma.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot_fdma.c b/drivers/net/ethernet/mscc/ocelot_fdma.c index 083fddd263ec..8e3894cf5f7c 100644 --- a/drivers/net/ethernet/mscc/ocelot_fdma.c +++ b/drivers/net/ethernet/mscc/ocelot_fdma.c @@ -94,19 +94,18 @@ static void ocelot_fdma_activate_chan(struct ocelot *ocelot, dma_addr_t dma, ocelot_fdma_writel(ocelot, MSCC_FDMA_CH_ACTIVATE, BIT(chan)); } +static u32 ocelot_fdma_read_ch_safe(struct ocelot *ocelot) +{ + return ocelot_fdma_readl(ocelot, MSCC_FDMA_CH_SAFE); +} + static int ocelot_fdma_wait_chan_safe(struct ocelot *ocelot, int chan) { - unsigned long timeout; u32 safe; - timeout = jiffies + usecs_to_jiffies(OCELOT_FDMA_CH_SAFE_TIMEOUT_US); - do { - safe = ocelot_fdma_readl(ocelot, MSCC_FDMA_CH_SAFE); - if (safe & BIT(chan)) - return 0; - } while (time_after(jiffies, timeout)); - - return -ETIMEDOUT; + return readx_poll_timeout_atomic(ocelot_fdma_read_ch_safe, ocelot, safe, + safe & BIT(chan), 0, + OCELOT_FDMA_CH_SAFE_TIMEOUT_US); } static void ocelot_fdma_dcb_set_data(struct ocelot_fdma_dcb *dcb, -- 2.36.1