Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755393AbbESHpn (ORCPT ); Tue, 19 May 2015 03:45:43 -0400 Received: from metis.ext.pengutronix.de ([92.198.50.35]:38921 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752221AbbESHpk (ORCPT ); Tue, 19 May 2015 03:45:40 -0400 Date: Tue, 19 May 2015 09:45:35 +0200 From: Sascha Hauer To: Daniel Kurtz Cc: "linux-arm-kernel@lists.infradead.org" , "open list:OPEN FIRMWARE AND..." , Kevin Hilman , "linux-kernel@vger.kernel.org" , linux-mediatek@lists.infradead.org, Sasha Hauer , Matthias Brugger Subject: Re: [PATCH 1/5] soc: mediatek: Add infracfg misc driver support Message-ID: <20150519074535.GY6325@pengutronix.de> References: <1431372206-1237-1-git-send-email-s.hauer@pengutronix.de> <1431372206-1237-2-git-send-email-s.hauer@pengutronix.de> <20150518081625.GO6325@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-IRC: #ptxdist @freenode X-Accept-Language: de,en X-Accept-Content-Type: text/plain X-Uptime: 09:06:32 up 63 days, 18:58, 104 users, load average: 0.24, 0.20, 0.16 User-Agent: Mutt/1.5.21 (2010-09-15) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c0 X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2807 Lines: 85 On Tue, May 19, 2015 at 02:54:41PM +0800, Daniel Kurtz wrote: > >> > + while (1) { > >> > + ret = regmap_read(infracfg, INFRA_TOPAXI_PROTECTSTA1, &val); > >> > + if (ret) > >> > + return ret; > >> > + > >> > + if ((val & mask) == mask) > >> > + break; > >> > + > >> > + cpu_relax(); > >> > + if (time_after(jiffies, expired)) > >> > + return -EIO; > >> > >> I think we should check for timeout first, and then cpu_relax() if > >> there is still time left (here and in > >> mtk_infracfg_clear_bus_protection()). Otherwise we end up doing one > >> final cpu_relax() without rechecking the register we are polling > >> (again, I have the same comment for the timeout loops in mtk-scpsys). > > > > I think cpu_relax() delays execution in the order of microseconds (I > > don't actually know, just a guess), so if the timeout is a second the > > order doesn't really matter. What can happen though is an interrupt > > after the (val & mask) test but before the timeout check. So to be > > truly correct we have to repeat the (val & mask) test after the > > time_after() check. Is that what you want? > > I'm not following, why would you need to repeat (val & mask) test > after time_after? > What does an interrupt have to do with it? > Can you show a code snippet with what exactly you are proposing? Consider you have this timeout loop: while (1) { if (success()) break; if (time_after(jiffies, expired)) return -ETIMEDOUT; } Now when an interupt comes in between success() and time_after() then it can happen that the delay caused by the interrupt makes the code timeout even though success() might have become true in the meantime. So to be correct you have to: while (1) { if (success()) break; if (time_after(jiffies, expired)) { if (success()) break; return -ETIMEDOUT; } Or, if you don't want to repeat the termination condition: bool timeout = false; while (1) { if (success()) break; if (timeout) return -ETIMEDOUT; if (time_after(jiffies, expired)) timeout = true; } Anyway, with the timeout of one second used here this is all academic. Sascha -- Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/