From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3853FED2 for ; Mon, 13 Jun 2022 07:06:02 +0000 (UTC) Received: by mail-qt1-f180.google.com with SMTP id f13so3307714qtb.5 for ; Mon, 13 Jun 2022 00:06:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:subject:from:to:cc:date:in-reply-to:references :content-transfer-encoding:user-agent:mime-version; bh=yv1ygT3I3cNrjiki9LWaI9usnmiwYkji5v0xZWzW+js=; b=BeUQU7At5w8QXnQumv31sTGFNuryglGKvde6SoIxLoHOJ5t/WGMn1AXz3Eknm6h5AI kNL4PEd0uMir3gUr1z6XGSGK1rVD3INLVDD+LZJQYc8d9+62lYvyaguTm78kNak/rSak T3okK5/4ndABoNywbeazmrsJmzecZtZstWGrOW2kSrrZPWoL+4bF34YazBYZMgWZX4Tb Bt9W4HzigonIOzfvWB+W869hPSh+dfOJ4Kquh0y9Dsp8gm71SNYKkMAx9kDUk/JCp9Zv 0D3K88QtgS+P4vXBJD6FFG3yQbdUH3SbzIbxx14i72EO5NKMHtU9uCEpi/JGyYCXjqA1 +OOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:content-transfer-encoding:user-agent:mime-version; bh=yv1ygT3I3cNrjiki9LWaI9usnmiwYkji5v0xZWzW+js=; b=Fh/sxwrf5h5JJ7/hSNyfweC9Cl1DBBuda1fDT8JOaKGe5t7DJFsyOJM6n7djwJdsyO a+QBW3twB55FQNVUmQPE5cor0quuheevoNIPdLnMMtZ9EsSO4PRf98l0Du1k5oGy5C8z aLpLxmb/ippu/J5lhRDnqGso7jjvKVumHlpqz1b9d0m9NdYJJNwWNJ6aboaGY+TUE0LM oAHo5tC+eEtHilJpLwv4rQ8pHp+p+31Bz8XBh2u7AXHe0KoQfyb32tb/RiHY9j+qxcOM ZUTmsAZpGs0fkHMYTHIhK5Y/ewEOCYImlLU6hDA4wusy10EkYNAcmgeRUyZklX8zcnMB RLFQ== X-Gm-Message-State: AOAM533avGRayjzQ0WRgbtPDWO9DMKozn1HDq1IZgabYFn24LC7dbhbl JjKfic1/zuagFiMyR69BobY= X-Google-Smtp-Source: ABdhPJx1ATSZFfuRWjaAT70y9WnEKuNuBqF1XmR5jBeGYYoq9SJ4nRAMyKQM1AWqPTp0l7HO6v7YKg== X-Received: by 2002:a05:622a:311:b0:2f3:ddb0:4ae6 with SMTP id q17-20020a05622a031100b002f3ddb04ae6mr46319206qtw.140.1655103961023; Mon, 13 Jun 2022 00:06:01 -0700 (PDT) Received: from p200300f6ef062c0090c03b551078f99d.dip0.t-ipconnect.de (p200300f6ef062c0090c03b551078f99d.dip0.t-ipconnect.de. [2003:f6:ef06:2c00:90c0:3b55:1078:f99d]) by smtp.gmail.com with ESMTPSA id d3-20020a05620a240300b006a6a1e4aec2sm6086602qkn.49.2022.06.13.00.05.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jun 2022 00:06:00 -0700 (PDT) Message-ID: <35e7c36c9ecbdc67698b413cf867cf19442ccfa9.camel@gmail.com> Subject: Re: [PATCH 22/34] iio: inkern: only return error codes in iio_channel_get_*() APIs From: Nuno =?ISO-8859-1?Q?S=E1?= To: Jonathan Cameron , Nuno =?ISO-8859-1?Q?S=E1?= Cc: linux-imx@nxp.com, linux-renesas-soc@vger.kernel.org, linux-mips@vger.kernel.org, linux-arm-kernel@lists.infradead.org, chrome-platform@lists.linux.dev, Lad Prabhakar , linux-mediatek@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-msm@vger.kernel.org, linux-iio@vger.kernel.org, openbmc@lists.ozlabs.org, Cai Huoqing , Benjamin Fair , Jishnu Prakash , Linus Walleij , Lars-Peter Clausen , Alexandre Torgue , Amit Kucheria , Andy Gross , Michael Hennerich , Haibo Chen , Benson Leung , "Rafael J. Wysocki" , Alexandre Belloni , Christophe Branchereau , Patrick Venture , Arnd Bergmann , Nancy Yuen , Sascha Hauer , Daniel Lezcano , Gwendal Grignou , Saravanan Sekar , Tali Perry , Maxime Coquelin , Paul Cercueil , Thara Gopinath , Avi Fishman , Lorenzo Bianconi , Claudiu Beznea , Pengutronix Kernel Team , Andy Shevchenko , Fabrice Gasnier , Matthias Brugger , Tomer Maimon , Bjorn Andersson , Nicolas Ferre , Zhang Rui , Shawn Guo , Guenter Roeck , Fabio Estevam , Olivier Moysan , Eugen Hristev , Miquel Raynal Date: Mon, 13 Jun 2022 09:06:49 +0200 In-Reply-To: <20220611161701.46a68837@jic23-huawei> References: <20220610084545.547700-1-nuno.sa@analog.com> <20220610084545.547700-23-nuno.sa@analog.com> <20220611161701.46a68837@jic23-huawei> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.2 Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Sat, 2022-06-11 at 16:17 +0100, Jonathan Cameron wrote: > On Fri, 10 Jun 2022 10:45:33 +0200 > Nuno S=C3=A1 wrote: >=20 > > APIs like of_iio_channel_get_by_name() and of_iio_channel_get_all() > > were > > returning a mix of NULL and error pointers being NULL the way to >=20 > pointers with NULL being the way to... >=20 > > "notify" that we should do a "system" lookup for channels. This > > make > > it very confusing and prone to errors as commit dbbccf7c20bf > > ("iio: inkern: fix return value in > > devm_of_iio_channel_get_by_name()") > > proves. On top of this, patterns like 'if (channel !=3D NULL) return > > channel' > > were being used where channel could actually be an error code which > > makes the code hard to read. > >=20 > > Signed-off-by: Nuno S=C3=A1 > > --- > > =C2=A0drivers/iio/inkern.c | 24 +++++++++++------------- > > =C2=A01 file changed, 11 insertions(+), 13 deletions(-) > >=20 > > diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c > > index 87fd2a0d44f2..31d9c122199a 100644 > > --- a/drivers/iio/inkern.c > > +++ b/drivers/iio/inkern.c > > @@ -214,7 +214,7 @@ static struct iio_channel > > *of_iio_channel_get(struct device_node *np, int index) > > =C2=A0struct iio_channel *of_iio_channel_get_by_name(struct device_node > > *np, > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 const char *name) > > =C2=A0{ > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0struct iio_channel *chan =3D= NULL; > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0struct iio_channel *chan; > > =C2=A0 > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0/* Walk up the tree of = devices looking for a matching iio > > channel */ > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0while (np) { > > @@ -231,11 +231,11 @@ struct iio_channel > > *of_iio_channel_get_by_name(struct device_node *np, > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 name); > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0chan =3D of_iio_channel_get(np, index); > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0if (!IS_ERR(chan) || PTR_ERR(chan) =3D=3D - > > EPROBE_DEFER) > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0break; >=20 > This original behaviour is 'interesting'. If we get a error like - > ENOMEM > we should return it rather than carry on.=C2=A0 Do we have enough > knowledge > of possible errors here to be more explicit on when we keep looking > up > the tree?=C2=A0 I think we can get -ENOENT from > of_parse_phandle_with_args() >=20 > That raises an interesting question on whether -ENODEV is the right > response > for the previously NULL case or is -ENOENT more consistent with other > of_ functions?=C2=A0 No device could be thought of as being the case that > needs > to defer (in hope it turns up later) whereas no entry means it will > never > succeed. >From what I could see, of_parse_phandle_with_args() either returns=C2=A0 -EINVAL or -ENOENT. We also have the internal of_iio_channel_get() which can return -ENOMEM. So I guess we should only continue looking if we get -ENOENT? To be clear, do you still prefer to explicitly return -ENODEV in the previous NULL cases or should we honor the return code from=20 of_parse_phandle_with_args() and just return chans (and thus ENOENT)? - Nuno S=C3=A1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1A790C433EF for ; Mon, 13 Jun 2022 07:06:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Date:Cc:To:From:Subject:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=kAPri0EFUKHN6hPuYViroL/AirI5V0tDKzxe6pqgRUw=; b=bUO2k8PphNPwa4 puXg1/BrqUCCOYgD5lQw+i5J4OIw1ElD2zrlbylRHhCD41OuJ3AiIo+wbABqKjebG7fMxm71HbAhj oLEocMi4qPp8jvzy9+6EVvj+JgvtlI9C8H/q0ywdi8TPi0Mxz9lAGtduyMXyDftVzNyrJRsZIdhrP r/IGPHGErRZYDw+RR8/+G4lvLTdXuNoXW0JGriWo1/v8Z0iMk2Pd4nstjKpASloUe4gxkNfEXhYI0 Ac9b5/CPWiJAXFUP1E2R4nQFAhHZ3x2v4J0E/awz9QzoKyyU7OALQAJxm5BhqjxaLPW7YFGZjUdjC 0yPirZo1No4aCRqjO2eQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o0e9H-001sdP-JN; Mon, 13 Jun 2022 07:06:07 +0000 Received: from mail-qt1-x836.google.com ([2607:f8b0:4864:20::836]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o0e9E-001scK-3w; Mon, 13 Jun 2022 07:06:05 +0000 Received: by mail-qt1-x836.google.com with SMTP id k4so3299008qth.8; Mon, 13 Jun 2022 00:06:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:subject:from:to:cc:date:in-reply-to:references :content-transfer-encoding:user-agent:mime-version; bh=yv1ygT3I3cNrjiki9LWaI9usnmiwYkji5v0xZWzW+js=; b=BeUQU7At5w8QXnQumv31sTGFNuryglGKvde6SoIxLoHOJ5t/WGMn1AXz3Eknm6h5AI kNL4PEd0uMir3gUr1z6XGSGK1rVD3INLVDD+LZJQYc8d9+62lYvyaguTm78kNak/rSak T3okK5/4ndABoNywbeazmrsJmzecZtZstWGrOW2kSrrZPWoL+4bF34YazBYZMgWZX4Tb Bt9W4HzigonIOzfvWB+W869hPSh+dfOJ4Kquh0y9Dsp8gm71SNYKkMAx9kDUk/JCp9Zv 0D3K88QtgS+P4vXBJD6FFG3yQbdUH3SbzIbxx14i72EO5NKMHtU9uCEpi/JGyYCXjqA1 +OOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:content-transfer-encoding:user-agent:mime-version; bh=yv1ygT3I3cNrjiki9LWaI9usnmiwYkji5v0xZWzW+js=; b=6QYaFtdcW1HVO+2MvnGVyldCXxTPDfp0A1WpzcSXtGtaiFxS5BfYVphwS/XXjfwUfX j3xATTDl052CvltxqeK7cssh6+arxeQBGNIIyyAYX//D+VRdlIDGPiZAvA/AAqzTfel7 tYowHZBr0ONjDG4cvsQyFttqmY8+NbhAnjxo2fCSPGu4coS+aY/oJBCRv+MIpxIgtWoB M9rWy85hu8gWEj2l8fLgb0BoRGD10YyqOGw4NACJ9CpcyvD4E3QoF1iIbeRyk1SkbmAl xKCERA4wiU88hdT4xWXQX3R7eP6FxnZlaBFTcqS2raXMiLOzOCiDnuABasR6ZwC79U4r YHRQ== X-Gm-Message-State: AOAM532t3xjr1MAUOwyMd7NREZ2tIwt5+oWKd3LQuGlea5wM8Otf1PBj rWhwBpRzFDuf+BYsnfrEwoA= X-Google-Smtp-Source: ABdhPJx1ATSZFfuRWjaAT70y9WnEKuNuBqF1XmR5jBeGYYoq9SJ4nRAMyKQM1AWqPTp0l7HO6v7YKg== X-Received: by 2002:a05:622a:311:b0:2f3:ddb0:4ae6 with SMTP id q17-20020a05622a031100b002f3ddb04ae6mr46319206qtw.140.1655103961023; Mon, 13 Jun 2022 00:06:01 -0700 (PDT) Received: from p200300f6ef062c0090c03b551078f99d.dip0.t-ipconnect.de (p200300f6ef062c0090c03b551078f99d.dip0.t-ipconnect.de. [2003:f6:ef06:2c00:90c0:3b55:1078:f99d]) by smtp.gmail.com with ESMTPSA id d3-20020a05620a240300b006a6a1e4aec2sm6086602qkn.49.2022.06.13.00.05.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jun 2022 00:06:00 -0700 (PDT) Message-ID: <35e7c36c9ecbdc67698b413cf867cf19442ccfa9.camel@gmail.com> Subject: Re: [PATCH 22/34] iio: inkern: only return error codes in iio_channel_get_*() APIs From: Nuno =?ISO-8859-1?Q?S=E1?= To: Jonathan Cameron , Nuno =?ISO-8859-1?Q?S=E1?= Cc: linux-imx@nxp.com, linux-renesas-soc@vger.kernel.org, linux-mips@vger.kernel.org, linux-arm-kernel@lists.infradead.org, chrome-platform@lists.linux.dev, Lad Prabhakar , linux-mediatek@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-msm@vger.kernel.org, linux-iio@vger.kernel.org, openbmc@lists.ozlabs.org, Cai Huoqing , Benjamin Fair , Jishnu Prakash , Linus Walleij , Lars-Peter Clausen , Alexandre Torgue , Amit Kucheria , Andy Gross , Michael Hennerich , Haibo Chen , Benson Leung , "Rafael J. Wysocki" , Alexandre Belloni , Christophe Branchereau , Patrick Venture , Arnd Bergmann , Nancy Yuen , Sascha Hauer , Daniel Lezcano , Gwendal Grignou , Saravanan Sekar , Tali Perry , Maxime Coquelin , Paul Cercueil , Thara Gopinath , Avi Fishman , Lorenzo Bianconi , Claudiu Beznea , Pengutronix Kernel Team , Andy Shevchenko , Fabrice Gasnier , Matthias Brugger , Tomer Maimon , Bjorn Andersson , Nicolas Ferre , Zhang Rui , Shawn Guo , Guenter Roeck , Fabio Estevam , Olivier Moysan , Eugen Hristev , Miquel Raynal Date: Mon, 13 Jun 2022 09:06:49 +0200 In-Reply-To: <20220611161701.46a68837@jic23-huawei> References: <20220610084545.547700-1-nuno.sa@analog.com> <20220610084545.547700-23-nuno.sa@analog.com> <20220611161701.46a68837@jic23-huawei> User-Agent: Evolution 3.44.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220613_000604_230135_D1670530 X-CRM114-Status: GOOD ( 28.74 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: base64 Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org T24gU2F0LCAyMDIyLTA2LTExIGF0IDE2OjE3ICswMTAwLCBKb25hdGhhbiBDYW1lcm9uIHdyb3Rl Ogo+IE9uIEZyaSwgMTAgSnVuIDIwMjIgMTA6NDU6MzMgKzAyMDAKPiBOdW5vIFPDoSA8bnVuby5z YUBhbmFsb2cuY29tPiB3cm90ZToKPiAKPiA+IEFQSXMgbGlrZSBvZl9paW9fY2hhbm5lbF9nZXRf YnlfbmFtZSgpIGFuZCBvZl9paW9fY2hhbm5lbF9nZXRfYWxsKCkKPiA+IHdlcmUKPiA+IHJldHVy bmluZyBhIG1peCBvZiBOVUxMIGFuZCBlcnJvciBwb2ludGVycyBiZWluZyBOVUxMIH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mVlZHMKPiB0byBkZWZlciAoaW4gaG9wZSBpdCB0dXJucyB1cCBsYXRlcikgd2hlcmVhcyBu byBlbnRyeSBtZWFucyBpdCB3aWxsCj4gbmV2ZXIKPiBzdWNjZWVkLgoKRnJvbSB3aGF0IEkgY291 bGQgc2VlLCBvZl9wYXJzZV9waGFuZGxlX3dpdGhfYXJncygpIGVpdGhlciByZXR1cm5zwqAKLUVJ TlZBTCBvciAtRU5PRU5ULiBXZSBhbHNvIGhhdmUgdGhlIGludGVybmFsIG9mX2lpb19jaGFubmVs X2dldCgpCndoaWNoIGNhbiByZXR1cm4gLUVOT01FTS4gU28gSSBndWVzcyB3ZSBzaG91bGQgb25s eSBjb250aW51ZSBsb29raW5nIGlmCndlIGdldCAtRU5PRU5UPwoKVG8gYmUgY2xlYXIsIGRvIHlv dSBzdGlsbCBwcmVmZXIgdG8gZXhwbGljaXRseSByZXR1cm4gLUVOT0RFViBpbiB0aGUKcHJldmlv dXMgTlVMTCBjYXNlcyBvciBzaG91bGQgd2UgaG9ub3IgdGhlIHJldHVybiBjb2RlIGZyb20gCm9m X3BhcnNlX3BoYW5kbGVfd2l0aF9hcmdzKCkgYW5kIGp1c3QgcmV0dXJuIGNoYW5zIChhbmQgdGh1 cyBFTk9FTlQpPwoKLSBOdW5vIFPDoQoKX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX18KTGludXgtbWVkaWF0ZWsgbWFpbGluZyBsaXN0CkxpbnV4LW1lZGlhdGVr QGxpc3RzLmluZnJhZGVhZC5vcmcKaHR0cDovL2xpc3RzLmluZnJhZGVhZC5vcmcvbWFpbG1hbi9s aXN0aW5mby9saW51eC1tZWRpYXRlawo= From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 36D07C43334 for ; Thu, 16 Jun 2022 02:41:55 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4LNmf96dX8z3fTw for ; Thu, 16 Jun 2022 12:41:53 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=BeUQU7At; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::82e; helo=mail-qt1-x82e.google.com; envelope-from=noname.nuno@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=BeUQU7At; dkim-atps=neutral Received: from mail-qt1-x82e.google.com (mail-qt1-x82e.google.com [IPv6:2607:f8b0:4864:20::82e]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4LM2fP3PDpz3bk8 for ; Mon, 13 Jun 2022 17:06:04 +1000 (AEST) Received: by mail-qt1-x82e.google.com with SMTP id k18so3296216qtm.9 for ; Mon, 13 Jun 2022 00:06:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:subject:from:to:cc:date:in-reply-to:references :content-transfer-encoding:user-agent:mime-version; bh=yv1ygT3I3cNrjiki9LWaI9usnmiwYkji5v0xZWzW+js=; b=BeUQU7At5w8QXnQumv31sTGFNuryglGKvde6SoIxLoHOJ5t/WGMn1AXz3Eknm6h5AI kNL4PEd0uMir3gUr1z6XGSGK1rVD3INLVDD+LZJQYc8d9+62lYvyaguTm78kNak/rSak T3okK5/4ndABoNywbeazmrsJmzecZtZstWGrOW2kSrrZPWoL+4bF34YazBYZMgWZX4Tb Bt9W4HzigonIOzfvWB+W869hPSh+dfOJ4Kquh0y9Dsp8gm71SNYKkMAx9kDUk/JCp9Zv 0D3K88QtgS+P4vXBJD6FFG3yQbdUH3SbzIbxx14i72EO5NKMHtU9uCEpi/JGyYCXjqA1 +OOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:content-transfer-encoding:user-agent:mime-version; bh=yv1ygT3I3cNrjiki9LWaI9usnmiwYkji5v0xZWzW+js=; b=jl7mTZL17gludQMSHRdNbhgAOPoD1sAHGcPHHjNG6qZB4Ok47NFDsDMZRGlBa5nU87 yjz2JRKZtWmdc+qCJgPalFgJbNPdpxH4U05TkErE66XczqrTfL/uqR35sKfB12BjL6LZ bN+/Vvdo+1xLP13WOwHunuxJUQqr01g17MzZq9cq9uBWcAAEqN1nes3hX2todZA9osBc RHDYC6cKIpkJsssPBNq630qwYjWRoCuPXzrEGeaReWssYZYHh59GC3gUHuDfacClT4DT Ix6FF2KyMGO9nUwaD2ELo73bdc0Y55SGYTn4tkl7VG/BOBW6Ktp6JwJbaCzlcUHZa68r TE/A== X-Gm-Message-State: AOAM532MlvAMv/sHFCOQI29aAZ4YNjYEdA1KSL8wvlPWJoLcjddI+CUB jhq8P7VIN6QdgeuLO2Q/UEU= X-Google-Smtp-Source: ABdhPJx1ATSZFfuRWjaAT70y9WnEKuNuBqF1XmR5jBeGYYoq9SJ4nRAMyKQM1AWqPTp0l7HO6v7YKg== X-Received: by 2002:a05:622a:311:b0:2f3:ddb0:4ae6 with SMTP id q17-20020a05622a031100b002f3ddb04ae6mr46319206qtw.140.1655103961023; Mon, 13 Jun 2022 00:06:01 -0700 (PDT) Received: from p200300f6ef062c0090c03b551078f99d.dip0.t-ipconnect.de (p200300f6ef062c0090c03b551078f99d.dip0.t-ipconnect.de. [2003:f6:ef06:2c00:90c0:3b55:1078:f99d]) by smtp.gmail.com with ESMTPSA id d3-20020a05620a240300b006a6a1e4aec2sm6086602qkn.49.2022.06.13.00.05.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jun 2022 00:06:00 -0700 (PDT) Message-ID: <35e7c36c9ecbdc67698b413cf867cf19442ccfa9.camel@gmail.com> Subject: Re: [PATCH 22/34] iio: inkern: only return error codes in iio_channel_get_*() APIs From: Nuno =?ISO-8859-1?Q?S=E1?= To: Jonathan Cameron , Nuno =?ISO-8859-1?Q?S=E1?= Date: Mon, 13 Jun 2022 09:06:49 +0200 In-Reply-To: <20220611161701.46a68837@jic23-huawei> References: <20220610084545.547700-1-nuno.sa@analog.com> <20220610084545.547700-23-nuno.sa@analog.com> <20220611161701.46a68837@jic23-huawei> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.2 MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 16 Jun 2022 12:05:36 +1000 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Belloni , Daniel Lezcano , Tomer Maimon , "Rafael J. Wysocki" , linux-iio@vger.kernel.org, Linus Walleij , Amit Kucheria , Alexandre Torgue , Tali Perry , Paul Cercueil , Miquel Raynal , Guenter Roeck , Fabio Estevam , linux-stm32@st-md-mailman.stormreply.com, chrome-platform@lists.linux.dev, Lars-Peter Clausen , Benjamin Fair , openbmc@lists.ozlabs.org, Jishnu Prakash , Haibo Chen , Andy Shevchenko , Andy Gross , linux-imx@nxp.com, Olivier Moysan , Zhang Rui , Christophe Branchereau , Saravanan Sekar , Michael Hennerich , linux-arm-msm@vger.kernel.org, Sascha Hauer , Nicolas Ferre , Lad Prabhakar , Fabrice Gasnier , linux-mediatek@lists.infradead.org, Eugen Hristev , Matthias Brugger , Gwendal Grignou , Bjorn Andersson , Benson Leung , Pengutronix Kernel Team , linux-arm-kernel@lists.infradead.org, Lorenzo Bianconi , Avi Fishman , Patrick Venture , linux-mips@vger.kernel.org, Thara Gopinath , linux-renesas-soc@vger.kernel.org, Arnd Bergmann , Maxime Coquelin , Cai Huoqing , Shawn Guo , Claudiu Beznea Errors-To: openbmc-bounces+openbmc=archiver.kernel.org@lists.ozlabs.org Sender: "openbmc" On Sat, 2022-06-11 at 16:17 +0100, Jonathan Cameron wrote: > On Fri, 10 Jun 2022 10:45:33 +0200 > Nuno S=C3=A1 wrote: >=20 > > APIs like of_iio_channel_get_by_name() and of_iio_channel_get_all() > > were > > returning a mix of NULL and error pointers being NULL the way to >=20 > pointers with NULL being the way to... >=20 > > "notify" that we should do a "system" lookup for channels. This > > make > > it very confusing and prone to errors as commit dbbccf7c20bf > > ("iio: inkern: fix return value in > > devm_of_iio_channel_get_by_name()") > > proves. On top of this, patterns like 'if (channel !=3D NULL) return > > channel' > > were being used where channel could actually be an error code which > > makes the code hard to read. > >=20 > > Signed-off-by: Nuno S=C3=A1 > > --- > > =C2=A0drivers/iio/inkern.c | 24 +++++++++++------------- > > =C2=A01 file changed, 11 insertions(+), 13 deletions(-) > >=20 > > diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c > > index 87fd2a0d44f2..31d9c122199a 100644 > > --- a/drivers/iio/inkern.c > > +++ b/drivers/iio/inkern.c > > @@ -214,7 +214,7 @@ static struct iio_channel > > *of_iio_channel_get(struct device_node *np, int index) > > =C2=A0struct iio_channel *of_iio_channel_get_by_name(struct device_node > > *np, > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 const char *name) > > =C2=A0{ > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0struct iio_channel *chan =3D= NULL; > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0struct iio_channel *chan; > > =C2=A0 > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0/* Walk up the tree of = devices looking for a matching iio > > channel */ > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0while (np) { > > @@ -231,11 +231,11 @@ struct iio_channel > > *of_iio_channel_get_by_name(struct device_node *np, > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 name); > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0chan =3D of_iio_channel_get(np, index); > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0if (!IS_ERR(chan) || PTR_ERR(chan) =3D=3D - > > EPROBE_DEFER) > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0break; >=20 > This original behaviour is 'interesting'. If we get a error like - > ENOMEM > we should return it rather than carry on.=C2=A0 Do we have enough > knowledge > of possible errors here to be more explicit on when we keep looking > up > the tree?=C2=A0 I think we can get -ENOENT from > of_parse_phandle_with_args() >=20 > That raises an interesting question on whether -ENODEV is the right > response > for the previously NULL case or is -ENOENT more consistent with other > of_ functions?=C2=A0 No device could be thought of as being the case that > needs > to defer (in hope it turns up later) whereas no entry means it will > never > succeed. >From what I could see, of_parse_phandle_with_args() either returns=C2=A0 -EINVAL or -ENOENT. We also have the internal of_iio_channel_get() which can return -ENOMEM. So I guess we should only continue looking if we get -ENOENT? To be clear, do you still prefer to explicitly return -ENODEV in the previous NULL cases or should we honor the return code from=20 of_parse_phandle_with_args() and just return chans (and thus ENOENT)? - Nuno S=C3=A1