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 B4221C43334 for ; Sat, 4 Jun 2022 13:10:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236257AbiFDNKh (ORCPT ); Sat, 4 Jun 2022 09:10:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236189AbiFDNKg (ORCPT ); Sat, 4 Jun 2022 09:10:36 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8ED2831909 for ; Sat, 4 Jun 2022 06:10:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 292CBB803F5 for ; Sat, 4 Jun 2022 13:10:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51E8DC385B8; Sat, 4 Jun 2022 13:10:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654348231; bh=/bIFr/y8xS7t/EmL20/mJPG7N0RsP5HSwGlRbjw2Hxg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=c7vcw5vR7LhqHDfvqrCJqWGURLhritoP7nBetuhoFpj2CU88e9B7a2I+VY1WOrEYQ JJ34kVHq3s6O8jLWIZRR9ZEfQGHIiSdFPO+wFmfxsJHs9rG48PeUqC7zhR8/TbNq00 KRo5wdMNHWsGrBVVqcxz8uiY+W/PWdFMSkm3T2LrLFqdxvSHf7IVajDke60KOQKnqD AyZ+sYwtz62xDTI2M+YDBf9wT5D3yP2RLBvb8keBLccpGsh6aVn82gSqohNrixWNae qnm8mxomTlHYT2x8G5e10kzXXcXSIN9c2JYrWtAC0CEDICXXkhxqFmIbPcigUJ6/Bg 354VueR62kayA== Date: Sat, 4 Jun 2022 14:19:25 +0100 From: Jonathan Cameron To: Nuno =?UTF-8?B?U8Oh?= Cc: Andy Shevchenko , Nuno =?UTF-8?B?U8Oh?= , linux-iio , Matthias Brugger , Tomer Maimon , Fabrice Gasnier , Lorenzo Bianconi , Michael Hennerich , NXP Linux Team , Benson Leung , Lars-Peter Clausen , Pengutronix Kernel Team , Claudiu Beznea , Tali Perry , Alexandre Belloni , Nicolas Ferre , Sascha Hauer , Wan Jiabing , Linus Walleij , Alexandre Torgue , Gwendal Grignou , Amit Kucheria , Andy Gross , Bjorn Andersson , Cai Huoqing , Saravanan Sekar , Avi Fishman , Nancy Yuen , Guenter Roeck , Maxime Coquelin , Eugen Hristev , Lad Prabhakar , Olivier Moysan , Patrick Venture , Haibo Chen , Fabio Estevam , Benjamin Fair , Thara Gopinath , Paul Cercueil , Shawn Guo , Baryshkov Subject: Re: [RFC PATCH 1/6] iio: inkern: fix return value in devm_of_iio_channel_get_by_name() Message-ID: <20220604141925.129f0ffe@jic23-huawei> In-Reply-To: <1e5b07dfa4d703ba1faff319be047fbd8b211f56.camel@gmail.com> References: <20220602140400.213449-1-nuno.sa@analog.com> <20220602140400.213449-2-nuno.sa@analog.com> <1e5b07dfa4d703ba1faff319be047fbd8b211f56.camel@gmail.com> X-Mailer: Claws Mail 4.1.0 (GTK 3.24.34; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org On Fri, 03 Jun 2022 14:36:15 +0200 Nuno S=C3=A1 wrote: > On Fri, 2022-06-03 at 13:16 +0200, Andy Shevchenko wrote: > > On Thu, Jun 2, 2022 at 4:04 PM Nuno S=C3=A1 wrote:= =20 > > >=20 > > > of_iio_channel_get_by_name() can either return NULL or an error > > > pointer > > > so that only doing IS_ERR() is not enough. Fix it by checking the > > > NULL > > > pointer case and return -ENODEV in that case. Note this is done > > > like this > > > so that users of the function (which only check for error pointers) > > > do > > > not need to be changed. This is not ideal since we are losing error > > > codes > > > and as such, in a follow up change, things will be unified so that > > > of_iio_channel_get_by_name() only returns error codes. =20 > >=20 > > ... > > =20 > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 channel =3D of_iio_channel= _get_by_name(np, channel_name); > > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (IS_ERR(channel)) > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (IS_ERR_OR_NULL(channel)) { > > > +=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 if (!channel) > > > +=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 return E= RR_PTR(-ENODEV); > > > =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 return channel; > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } =20 > >=20 > > Why not make it not nested, i.e. just adding two lines after the > > existing check? > > if (!channel) > > =C2=A0 return -ENODEV; > >=20 > > =20 >=20 > I see, well yeah I guess I can do it so the diff is even smaller... I'd prefer the way Andy suggested as well due to the slightly simpler contr= ol flow. Thanks, Jonathan >=20 > - Nuno S=C3=A1 >=20