From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752772AbcEDMrr (ORCPT ); Wed, 4 May 2016 08:47:47 -0400 Received: from mout.kundenserver.de ([212.227.126.187]:56562 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750904AbcEDMrq (ORCPT ); Wed, 4 May 2016 08:47:46 -0400 From: Arnd Bergmann To: Philipp Zabel Cc: Masahiro Yamada , Linux Kernel Mailing List Subject: Re: [PATCH] reset: allow to pass NULL pointer to reset_control_put() Date: Wed, 04 May 2016 14:47:31 +0200 Message-ID: <4907878.9ttKQmtdM4@wuerfel> User-Agent: KMail/4.11.5 (Linux/3.16.0-10-generic; KDE/4.11.5; x86_64; ; ) In-Reply-To: <1462365283.3536.27.camel@pengutronix.de> References: <1462360671-13668-1-git-send-email-yamada.masahiro@socionext.com> <1462365283.3536.27.camel@pengutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Provags-ID: V03:K0:zp6AvjwHzsi5fZwCn3gtk1XbtaOZPuWWo6BXVnLHHv7FekUBlIE rfae3eLoAGXz7pLPIfo0RkuUSD/GJvqPGOSt3oEgfB/1XhKqzBcLo6FXybXooGhoVW5+fsC PMsb44hZ2ns5u3w3DSAi2vBhIA33BbIJ+zKGrO5c6rjrE51+6/Z0AF7a/YiKRiGTPga4n6K 9ToVlX+3hmc9CUGTlcMZA== X-UI-Out-Filterresults: notjunk:1;V01:K0:GpRQEkJxKfw=:fLY0mH4aB8/tRzJnLrSgjM q1U7MVBpmBU90fbbJLgoUPJu6E3c/lJYg4E1W9XVHQnUagjhDQPI8Ukb7uwHSdqKfhdNNMTQv x7bYdvpIcMal3gv9uwoj9j/f8Py41g+lAZBAOi3N+JBf5BfTlweoZNPQl+HUhTQq1tdRbQ3d7 Dsim7Uvl3Kq294/RhEN3d2gCLPDXwWYiJ/QQR9uWmplZOym8+zo48ir4lDLx4OtwXMMhGgbLj 5vgnt341O9w5TqTU2MCIAC7vSmlP57kJZ1dW8sbzCPC5L328++ywUgLZsOFcHADS3+V+nVau3 XRVFTCoQTYY3ues3gbOQmpuwOq7rzfs5gTKRiZKX+eGjIc2yIC/ZtEAHHqfpW8eDTz0Y0hi5o tqV+zcXgZulGFQ/cv7JiKT03rJrnvtet76yszFlySOkp6wgoigzI/UtcvMdPd8fppmlkYHAFO B1GhWbFSKrPCPOSM5Hl1SzFbeZnVEm2tq8B7v2lY7QE0CE9tjfK/AkIrxiRBWNH1HtQ6xb1kr Tlqo2BXso4VT74J+EyTcKDrSKNhlX0YRyAAcJWTi+jpRg3GWcO9h6M3j8maFsnpOQT68EW8og cjHDtIPo/fWGeNLeYgpQEYejWoqQgBz2c15xecDiaMc1mF00TN0VzCGCc7SVjcAxM3a//I4Vj aGZZERU7U81eRSSiYuwxWRrbHT2ChPUMsZMgfSCT54ascEAHKpfYqyVbfhg0+3TK8eDYFHLHE zNW2/aL+Fbzk9JRJ Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wednesday 04 May 2016 14:34:43 Philipp Zabel wrote: > Am Mittwoch, den 04.05.2016, 20:34 +0900 schrieb Masahiro Yamada: > > Hi Arnd, > > > > 2016-05-04 20:24 GMT+09:00 Arnd Bergmann : > > > On Wednesday 04 May 2016 20:17:51 Masahiro Yamada wrote: > > >> Currently, reset_control_put() just returns for error pointer, > > >> but not for NULL pointer. This is not reasonable. > > >> > > >> Passing NULL pointer should be allowed as well to make failure path > > >> handling easier. > > >> > > >> Signed-off-by: Masahiro Yamada > > >> --- > > >> > > >> drivers/reset/core.c | 2 +- > > >> 1 file changed, 1 insertion(+), 1 deletion(-) > > >> > > >> diff --git a/drivers/reset/core.c b/drivers/reset/core.c > > >> index 181b05d..7bb16d1 100644 > > >> --- a/drivers/reset/core.c > > >> +++ b/drivers/reset/core.c > > >> @@ -288,7 +288,7 @@ EXPORT_SYMBOL_GPL(reset_control_get); > > >> > > >> void reset_control_put(struct reset_control *rstc) > > >> { > > >> - if (IS_ERR(rstc)) > > >> + if (IS_ERR_OR_NULL(rstc)) > > >> return; > > >> > > >> module_put(rstc->rcdev->owner); > > > > > > Using IS_ERR_OR_NULL() normally indicates that there is something > > > wrong with the API, or with the caller. > > > > > > What exactly is the idea behind treating an error pointer as a valid > > > input to reset_control_put() here? Maybe it should just test for > > > NULL? > > The idea was that you could do > drvdata->rstc = reset_control_get(...) > in the probe() function and > reset_control_put(drvdata->rstc) > in remove() without having to check for IS_ERR(drvdata->rstc) again. > I'm not convinced this is necessarily a good idea though. To simplify > the teardown path we already have devm_reset_control_get(). > > > I thought about that a bit, > > but there might be some (not nice) drivers that rely on the current behavior. > > I did not want to break any boards with my patch. > > > > So, should it be > > > > if (!rstc) > > return; > > or, perhaps > > > > if (!rstc || WARN_ON_ONCE(IS_ERR(rstc))) > > return; > > > > ? > > NULL is not a valid input to reset_control, reset_control_get(_optional) > should never return NULL. > > I'd be in favor of turning this into > > if (WARN_ON(IS_ERR_OR_NULL(rstc))) > return; Sounds good to me too. We'd still have to think about whatever Masahiro was trying to do and how his caller should be written, but hopefully there is a good solution. > As far as I am aware, ehci-tegra is the only driver that currently makes > use of the IS_ERR(rstc) return in reset_control_put(): > > struct reset_control *usb1_reset; > > usb1_reset = of_reset_control_get(phy_np, "usb"); > if (IS_ERR(usb1_reset)) { > /* ... */ > } else { > reset_control_assert(usb1_reset); > udelay(1); > reset_control_deassert(usb1_reset); > } > reset_control_put(usb1_reset); > > That'd be trivial to fix. Ah, good. Could the above code just be converted into a variation of device_reset() that takes the name of a reset line? Arnd