Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp71184ioo; Fri, 20 May 2022 14:17:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQQz7YxdMKds5FeSM/L8f1xvrHQEGvCeZctnpd6p8yPMdrxn01IdOE0BFVmrbmJ3m91ySv X-Received: by 2002:a17:907:7e99:b0:6fd:c2a2:9620 with SMTP id qb25-20020a1709077e9900b006fdc2a29620mr10877891ejc.554.1653081457020; Fri, 20 May 2022 14:17:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653081457; cv=none; d=google.com; s=arc-20160816; b=pBxda6DRM1pOwSyOhB67QJX5kJ6IbtCEURJD7FHFeLMGhp2Z8eaSyR/s7hLt/zIzur FJ/LKj5f1ThrbupH+735Ef9aQdPKfy3/EOTkyUWlk94IHbPnMa9eY4/9EvHQoyCntLbi A6b2e3gYBYBDFJQl1Qf8rQO0g+HR+GkuvKeoDCyN4t+ZIH9A+2aQXq2D/o7T3cTCbsnx RaSdjPvUAonxwRADd6trA/NP8QXFnNSCH741NPNdh6aw3Xwza691twvJb2FHT2yAuhfc jOmH21BBLCQGWopjvXioatDgb6YIVyR26fwVqqkFFFSFs1RWjyCS8IBJD/yZSlkhrEn7 2nJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=y5yue5StjMLDz9Stw8tyOk8WJH/+6r8jlx/4Qmd/Q5c=; b=XVZh1uxY48SyJod4uEaNARd/EvvncOpeGERVcPZW+Z1eNTFjP/9zahYJsXJJWy/wlR UCrpSkw8xsRL7HQkCb4aXxWpP1pj1RXqn5pDyZpRwQFpqeLmZfiNxIUyJW4vuiqaMepm 0jC02R0WCJ5PbuZ2H9ek5LW1vd/IpQviOXaUbDjtot9mUjstVsxNELsZLurURlrVhK0j l8ryM0ChAKh2LmTuilj+yQkjLX8+ikvwZs27sMiWUmkcHinUG45LGtC2uB5jGWEUZQfX PqbHDWBmijBWdN0CwBbAMdIHpLLParSbvrKdcscb4ZD84wJPnqDIujNKmoBgxaAbztG0 L+KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b=40SWpeZS; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f8-20020a0564021e8800b0042abe1736e7si3582533edf.316.2022.05.20.14.17.11; Fri, 20 May 2022 14:17:37 -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=@lunn.ch header.s=20171124 header.b=40SWpeZS; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349398AbiETMlx (ORCPT + 99 others); Fri, 20 May 2022 08:41:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349541AbiETMlU (ORCPT ); Fri, 20 May 2022 08:41:20 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [185.16.172.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 363AE12D09; Fri, 20 May 2022 05:41:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Disposition:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:From:Sender:Reply-To:Subject: Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=y5yue5StjMLDz9Stw8tyOk8WJH/+6r8jlx/4Qmd/Q5c=; b=40SWpeZS1e9hHYXISSNDgAETMz fg0iOwPHdtVGaZDTPcOxP774uLKK3RHuX5jcE4qrYsikW4cnM776o07+TQqgZwxtsW+m6DT0zRKt3 1rFIDgLmHCxmY7Ydx0WhKf5o7ze+Udsh5JY7kAzAE1F8e79/jwIS+BL3YzMg56Q/cf3o=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1ns1wB-003co2-Au; Fri, 20 May 2022 14:40:59 +0200 Date: Fri, 20 May 2022 14:40:59 +0200 From: Andrew Lunn To: Pavel Skripkin Cc: vladimir.oltean@nxp.com, claudiu.manoil@nxp.com, alexandre.belloni@bootlin.com, UNGLinuxDriver@microchip.com, davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, dan.carpenter@oracle.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] net: ocelot: fix wront time_after usage Message-ID: References: <20220519204017.15586-1-paskripkin@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220519204017.15586-1-paskripkin@gmail.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,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 On Thu, May 19, 2022 at 11:40:17PM +0300, Pavel Skripkin wrote: > Accidentally noticed, that this driver is the only user of > while (timer_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. > > Fix it by negating time_after return value inside while loops statement A better fix would be to use one of the helpers in linux/iopoll.h. There is a second bug in the current code: 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; } 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. linux/iopoll.h handles this correctly by testing the state one more time after the timeout has expired. Andrew