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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EFCDEC433EF for ; Fri, 10 Jun 2022 19:48:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348291AbiFJTsb (ORCPT ); Fri, 10 Jun 2022 15:48:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233646AbiFJTs1 (ORCPT ); Fri, 10 Jun 2022 15:48:27 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BA121F5ACE; Fri, 10 Jun 2022 12:48:26 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id o8so9962835wro.3; Fri, 10 Jun 2022 12:48:26 -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 :user-agent:mime-version:content-transfer-encoding; bh=Uw42AgxCz2OX29JjZrfK1zeziXwl4MAn7te6Qnb21ik=; b=VnmBwWKvliqZ17mqAO3YFUhuijHFVCA0X/6JoDEeNmtQ5fuB2ME76Abp7kguBl57K7 M9/alivbnhSTovq/B//wCei53pyxQ+HtrJaffG1iGtF9Ndaudu7kcr9ovspAlwBkBSrl Qk8wAlB8QCS5xW3y97CMGT7D89Ky4udjBupXK19Q8pH4R+6TZMpKLOBEkE6ub91Xaf7Y S7oL2lI6/EzqlSBNis27lv8/Z8dTYnHGhUC0YHRirC4Dqxm1vVmg/6fapPeKzP00VvFU tNNMy6jrpva6Bk+UcwypSwoLQSKLiQbVV7FbXXq9G/VEvyzMlVefQmke6B2XscRqIWLl voDA== 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:user-agent:mime-version:content-transfer-encoding; bh=Uw42AgxCz2OX29JjZrfK1zeziXwl4MAn7te6Qnb21ik=; b=viRo3WeJy74s7+9G4goKaz4xU7SIC/gnAlJfz/aL2I3JmaVBDaXHkPhW5Jk9QA6xTM Ul+gvPTO98PLjwGrHRPcSyZZUsz6yP6TWC1lk3cAX42DV/sKK6yMdBUd2m70XuV3r3B3 6GRp2rWNGLEkwdOa1ZV15yhuLRDz9K3NARb/g13isY0jsv1Z0umOGH45+c+8q8GB0J3I iMUDEYi/OvDzCEXbz+1mWD9jEibjP+aDX8qHFLkTl9q5o9N/pDKNdGDz/0+zG9ZR3tEE 1hq+ebtYKlwcWoAaEKuNxQpsfisBMtu1MAhHribarnFBqRMZFJbBeoDXkRd+FSFV2Xb5 tyFg== X-Gm-Message-State: AOAM530TFki8uH5pJTgc2rGLT2DQZU7A0AgcZa+kUmnV4jZDZuq8WcPz GC+2RVgy3rqOiEQiqrpmqR6s04wOIplw1gGZ X-Google-Smtp-Source: ABdhPJy5G62/5XmSgGYkKL4gT5Hd/Ethb/qClZrbwW5M3Zb4SLtoP92M/h2fB9W3tywpi7sFv5O92A== X-Received: by 2002:a5d:5983:0:b0:218:519e:78a5 with SMTP id n3-20020a5d5983000000b00218519e78a5mr20645990wri.718.1654890504947; Fri, 10 Jun 2022 12:48:24 -0700 (PDT) Received: from ?IPv6:2001:a61:136e:3c01:8bd4:cf6f:76f1:a861? ([2001:a61:136e:3c01:8bd4:cf6f:76f1:a861]) by smtp.gmail.com with ESMTPSA id x3-20020a5d6503000000b002103136623esm257905wru.85.2022.06.10.12.48.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jun 2022 12:48:24 -0700 (PDT) Message-ID: <25e286370d34419c3fc32a75896d5bfebc4128ea.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: Andy Shevchenko , Nuno =?ISO-8859-1?Q?S=E1?= Cc: dl-linux-imx , Linux-Renesas , "open list:BROADCOM NVRAM DRIVER" , linux-arm Mailing List , chrome-platform@lists.linux.dev, Lad Prabhakar , "moderated list:ARM/Mediatek SoC support" , linux-stm32@st-md-mailman.stormreply.com, linux-arm-msm , linux-iio , OpenBMC Maillist , 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 , Fabrice Gasnier , Matthias Brugger , Tomer Maimon , Bjorn Andersson , Nicolas Ferre , Jonathan Cameron , Zhang Rui , Shawn Guo , Guenter Roeck , Fabio Estevam , Olivier Moysan , Eugen Hristev , Miquel Raynal Date: Fri, 10 Jun 2022 21:48:22 +0200 In-Reply-To: References: <20220610084545.547700-1-nuno.sa@analog.com> <20220610084545.547700-23-nuno.sa@analog.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 (3.42.4-2.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org On Fri, 2022-06-10 at 17:05 +0200, Andy Shevchenko wrote: > On Fri, Jun 10, 2022 at 10:48 AM Nuno Sá wrote: > > > > 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 > > "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 != NULL) return > > channel' > > were being used where channel could actually be an error code which > > makes the code hard to read. > > ... > > >                 np = np->parent; > >                 if (np && !of_get_property(np, "io-channel-ranges", > > NULL)) > > -                       return NULL; > > +                       return chan; > > Shouldn't it return a dedicated error code and not some arbitrary > one? > It may be I missed something and chan has a correct error code in > this > case... > Since in this case we won't look for channels in the parent device, I'm just honoring the code returned by 'of_iio_channel_get()'. > ... > > > +       if (nummaps == 0)       /* return -ENODEV to search map > > table */ > > Comment is superfluous, the next line is self-explaining. > Well, I agree. I just kept as it was on the original code. Can hapilly remove it if no one objects against it. > > +               return ERR_PTR(-ENODEV); > > ... > > > -               if (channel != NULL) > > +               if (!IS_ERR(channel) || PTR_ERR(channel) == - > > EPROBE_DEFER) > > Btw, in the GPIO library we have a macro or inliner (don't remember) > that represents such a conditional. > Perhaps make it (if it's a macro) global, or introduce an inline in > IIO? > > Okay, it's here: > https://elixir.bootlin.com/linux/v5.19-rc1/source/drivers/gpio/gpiolib.h#L179 > > It's similar, but not the same, so just play with an idea to > introduce > something in this file, maybe it's worth doing this, maybe not. > I would also argue that could be something done after this series gets applied... - Nuno Sá