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 498A8C43334 for ; Mon, 11 Jul 2022 14:06:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230447AbiGKOF7 (ORCPT ); Mon, 11 Jul 2022 10:05:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230425AbiGKOFw (ORCPT ); Mon, 11 Jul 2022 10:05:52 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2374619C18; Mon, 11 Jul 2022 07:05:51 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id bk26so7137321wrb.11; Mon, 11 Jul 2022 07:05:51 -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=OpuAbJzOZmkFVUVRYRfhJb2EZ79ErPrcazI4dJRRIZw=; b=AxqKn1jFCUvR9r8eF6G9LQNJai0j26cooZSTaW/y5LjqtvcEM/8McIf/+yQzlzaUFd LwcEnbV3x0T98SP3+BJlr0dZ/4NoEFEHYkvinYuvlXRJ/rScOUvz84TzCH0CqciB5xr3 70JCY+zxyG19vqUL7fnu7cTlKI0FIx088QGgbn+DUglz7JpgcVQ5PpQGbQcOhaZFlPbl Sj/1dCgEulNZFTYu6gtOT+azXEODMFcBsZXMw1Holn5VdIjBppSACDRDbXOOwlKV+GrT gUqBD8ESK3VZeUfDigHKr2IQSaYpAIV6HBehOLe57cJG8VwM+8e6vaZ86/RiS+6W3xCR PgeQ== 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=OpuAbJzOZmkFVUVRYRfhJb2EZ79ErPrcazI4dJRRIZw=; b=ZMKjKFUhvDxJG9iP/+hczR7gvSLbX0J95VEG/AdojdXnC197ssMwdL8875JcdedDt3 ITGxVW4ToaLXe0B7dwaCFsd9h3yz3uB9PTnVQzoVBmqeyk9bfqji8kYhPWAA01ZID38K nAjOfa6CzjXHFGQ17mpzMEtyorG0trZcdq6bjH4AP5Vpz0GCFt2QE/H5s5ntMnFL3idM VdV5MZazC1B+jl5niOKPmLTBrRETwFprh29D2vvnRmZUeBUSlaSd/1ktHSpjWVs0hZAo hhrLvDAkbs6eutuV1IuafU4RD8iVRap1rWWk1KnWbynlbayFvRYXbvAFayHTdaMcUbuL +NcQ== X-Gm-Message-State: AJIora+TRv2ABGcHFbpqHyzbky85zLSK3KzJLzxkLe3bgfmGpLuNI+ID uiR/z/QO2ohcIFqmls8vSI8= X-Google-Smtp-Source: AGRyM1vjxZ3LaYt2iroYaYC6yqBPM5QdYtXuGkJjk8H9N1njA0MUYRP5ggIbz4O4J7Zmd/vjCEw/YA== X-Received: by 2002:adf:f581:0:b0:21d:1e01:e9b7 with SMTP id f1-20020adff581000000b0021d1e01e9b7mr16555540wro.529.1657548349537; Mon, 11 Jul 2022 07:05:49 -0700 (PDT) Received: from p200300f6ef036f005de6a4d0d791ed01.dip0.t-ipconnect.de (p200300f6ef036f005de6a4d0d791ed01.dip0.t-ipconnect.de. [2003:f6:ef03:6f00:5de6:a4d0:d791:ed01]) by smtp.gmail.com with ESMTPSA id g1-20020a05600c000100b00397623ff335sm6700494wmc.10.2022.07.11.07.05.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Jul 2022 07:05:49 -0700 (PDT) Message-ID: Subject: Re: [PATCH v2 03/15] 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: linux-arm-msm , OpenBMC Maillist , Linux-Renesas , "moderated list:ARM/Mediatek SoC support" , dl-linux-imx , "open list:BROADCOM NVRAM DRIVER" , Lad Prabhakar , linux-iio , chrome-platform@lists.linux.dev, linux-arm Mailing List , linux-stm32@st-md-mailman.stormreply.com, Andy Gross , Nicolas Ferre , Benson Leung , Matthias Brugger , Tomer Maimon , Zhang Rui , "Rafael J. Wysocki" , Eugen Hristev , Sascha Hauer , Alexandre Belloni , Benjamin Fair , Nancy Yuen , Fabrice Gasnier , Jishnu Prakash , Christophe Branchereau , Avi Fishman , Tali Perry , Michael Hennerich , Miquel Raynal , Claudiu Beznea , Lars-Peter Clausen , Thara Gopinath , Cai Huoqing , Fabio Estevam , Olivier Moysan , Shawn Guo , Haibo Chen , Arnd Bergmann , Daniel Lezcano , Patrick Venture , Amit Kucheria , Maxime Coquelin , Lorenzo Bianconi , Paul Cercueil , Alexandre Torgue , Gwendal Grignou , Bjorn Andersson , Saravanan Sekar , Guenter Roeck , Jonathan Cameron , Pengutronix Kernel Team , Linus Walleij Date: Mon, 11 Jul 2022 16:06:50 +0200 In-Reply-To: References: <20220711123835.811358-1-nuno.sa@analog.com> <20220711123835.811358-4-nuno.sa@analog.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.3 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org On Mon, 2022-07-11 at 15:29 +0200, Andy Shevchenko wrote: > On Mon, Jul 11, 2022 at 2:38 PM 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 pointers with NULL being the way to > > "notify" that we should do a "system" lookup for channels. This > > make > > it very confusing and prone to errors as commit 9f63cc0921ec > > ("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 > > This change also makes some functional changes on how errors were > > being > > handled. In the original behavior, even if we get an error like '- > > ENOMEM', > > we still continue with the search. We should only continue to > > lookup for > > the channel when it makes sense to do so. Hence, the main error > > handling > > in 'of_iio_channel_get_by_name()' is changed to the following > > logic: > >=20 > > =C2=A0* If a channel 'name' is provided and we do find it via > > 'io-channel-names', we should be able to get it. If we get any > > error, > > we should not proceed with the lookup. Moreover, we should return > > an error > > so that callers won't proceed with a system lookup. > > =C2=A0* If a channel 'name' is provided and we cannot find it ('index < > > 0'), > > 'of_parse_phandle_with_args()' is expected to fail with '-EINVAL'. > > Hence, > > we should only continue if we get that error. > > =C2=A0* If a channel 'name' is not provided we should only carry on wit= h > > the > > search if 'of_parse_phandle_with_args()' returns '-ENOENT'. > >=20 > > Also note that a system channel lookup is only done if the returned > > error code (from 'of_iio_channel_get_by_name()' or > > 'of_iio_channel_get_all()' is -ENODEV. >=20 > LGTM (but I might miss something, it's a bit too many conditionals), > Reviewed-by: Andy Shevchenko >=20 Agreed. It ended up being more complicated than I thought... - Nuno S=C3=A1