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 1077BC71132 for ; Fri, 18 Aug 2023 01:54:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353068AbjHRByX (ORCPT ); Thu, 17 Aug 2023 21:54:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351230AbjHRBxy (ORCPT ); Thu, 17 Aug 2023 21:53:54 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BB25100; Thu, 17 Aug 2023 18:53:53 -0700 (PDT) Received: from kwepemi500008.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4RRlGk5XHtzVk4T; Fri, 18 Aug 2023 09:51:42 +0800 (CST) Received: from [10.67.109.254] (10.67.109.254) by kwepemi500008.china.huawei.com (7.221.188.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Fri, 18 Aug 2023 09:53:49 +0800 Message-ID: Date: Fri, 18 Aug 2023 09:53:49 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.2.0 Subject: Re: [PATCH -next v2] I2C: Fix return value check for devm_pinctrl_get() Content-Language: en-US To: Yann Sionneau , Leo Li , Codrin Ciubotariu , Andi Shyti , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Oleksij Rempel , Pengutronix Kernel Team , Shawn Guo , Sascha Hauer , Fabio Estevam , dl-linux-imx , Wolfram Sang , Linus Walleij , =?UTF-8?Q?Uwe_Kleine-K=c3=b6nig?= , CC: , "linux-i2c@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" References: <20230817022018.3527570-1-ruanjinjie@huawei.com> <6b508343-7b7f-0fd5-d83f-92dc88a9510d@sionneau.net> From: Ruan Jinjie In-Reply-To: <6b508343-7b7f-0fd5-d83f-92dc88a9510d@sionneau.net> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.109.254] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemi500008.china.huawei.com (7.221.188.139) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org On 2023/8/18 7:07, Yann Sionneau wrote: > Hi, > > Le 17/08/2023 à 19:30, Leo Li a écrit : > >>> The devm_pinctrl_get() function returns error pointers and never returns >>> NULL. Update the checks accordingly. >> Not exactly.  It can return NULL when CONFIG_PINCTRL is not defined.  >> We probably should fix that API too. >> >> include/linux/pinctrl/consumer.h: >> static inline struct pinctrl * __must_check devm_pinctrl_get(struct >> device *dev) >> { >>          return NULL; >> } > > So, as Leo pointed out it seems devm_pinctrl_get() can in fact return > NULL, when CONFIG_PINCTRL is not defined. > > What do we do about this? > > Proposals: > > 1/ make sure all call sites of devm_pinctrl_get() do check for error > with IS_ERR *and* check for NULL => therefore using IS_ERR_OR_NULL I think it's the best. > > 2/ change the fallback implementation in > include/linux/pinctrl/consumer.h to return ERR_PTR(-Esomething) (which > errno?) It seems a convention to return NULL if the related macro is not defined. > > 3/ another solution? Make I2C_IMX and I2C_AT91 config depends on PINCTRL config is another option. However it seems that the function call devm_pinctrl_get() has an optional recovery feature from the following notes and dev_info(). So this dependency is not necessary. 1378 /* 1379 * We switch SCL and SDA to their GPIO function and do some bitbanging 1380 * for bus recovery. These alternative pinmux settings can be 1381 * described in the device tree by a separate pinctrl state "gpio". If 1382 * this is missing this is not a big problem, the only implication is 1383 * that we can't do bus recovery. 1384 */ 1385 static int i2c_imx_init_recovery_info(struct imx_i2c_struct *i2c_imx, 1386 struct platform_device *pdev) 1387 { 1388 struct i2c_bus_recovery_info *rinfo = &i2c_imx->rinfo; 1389 1390 i2c_imx->pinctrl = devm_pinctrl_get(&pdev->dev); 828 static int at91_init_twi_recovery_gpio(struct platform_device *pdev, 829 struct at91_twi_dev *dev) 830 { 831 struct i2c_bus_recovery_info *rinfo = &dev->rinfo; 832 833 rinfo->pinctrl = devm_pinctrl_get(&pdev->dev); 834 if (!rinfo->pinctrl || IS_ERR(rinfo->pinctrl)) { 835 dev_info(dev->dev, "can't get pinctrl, bus recovery not supported\n"); 836 return PTR_ERR(rinfo->pinctrl); 837 } > > Regards, >