linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] pinctrl: eswin: Fix regulator error check and Kconfig dependency
@ 2025-09-03  9:19 Yulin Lu
  2025-09-04 19:29 ` Linus Walleij
  0 siblings, 1 reply; 2+ messages in thread
From: Yulin Lu @ 2025-09-03  9:19 UTC (permalink / raw)
  To: linus.walleij, linux-gpio, linux-kernel
  Cc: ningyu, zhengyu, linmin, huangyifeng, fenglin, lianghujun,
	Yulin Lu, Dan Carpenter

Smatch reported the following warning in eic7700_pinctrl_probe():

  drivers/pinctrl/pinctrl-eic7700.c:638 eic7700_pinctrl_probe()
  warn: passing zero to 'PTR_ERR'

The root cause is that devm_regulator_get() may return NULL when
CONFIG_REGULATOR is disabled. In such case, IS_ERR_OR_NULL() triggers
PTR_ERR(NULL) which evaluates to 0, leading to passing a success code
as an error.

However, this driver cannot work without a regulator. To fix this:

 - Change the check from IS_ERR_OR_NULL() to IS_ERR()
 - Update Kconfig to explicitly select REGULATOR and
   REGULATOR_FIXED_VOLTAGE, ensuring that the regulator framework is
   always available.

This resolves the Smatch warning and enforces the correct dependency.

Suggested-by: Dan Carpenter <dan.carpenter@linaro.org>
Fixes: 5b797bcc00ef ("pinctrl: eswin: Add EIC7700 pinctrl driver")
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/linux-gpio/aKRGiZ-fai0bv0tG@stanley.mountain/
Signed-off-by: Yulin Lu <luyulin@eswincomputing.com>
---
Changes in v2:
 - Add Reported-by with Closes in the commit message.
 - Link to v1:
   https://lore.kernel.org/linux-gpio/20250902094508.288-1-luyulin@eswincomputing.com/
---
 drivers/pinctrl/Kconfig           | 2 ++
 drivers/pinctrl/pinctrl-eic7700.c | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/pinctrl/Kconfig b/drivers/pinctrl/Kconfig
index be1ca8e85754..0402626c4b98 100644
--- a/drivers/pinctrl/Kconfig
+++ b/drivers/pinctrl/Kconfig
@@ -211,6 +211,8 @@ config PINCTRL_EIC7700
 	depends on ARCH_ESWIN || COMPILE_TEST
 	select PINMUX
 	select GENERIC_PINCONF
+	select REGULATOR
+	select REGULATOR_FIXED_VOLTAGE
 	help
 	  This driver support for the pin controller in ESWIN's EIC7700 SoC,
 	  which supports pin multiplexing, pin configuration,and rgmii voltage
diff --git a/drivers/pinctrl/pinctrl-eic7700.c b/drivers/pinctrl/pinctrl-eic7700.c
index 4874b5532343..ffcd0ec5c2dc 100644
--- a/drivers/pinctrl/pinctrl-eic7700.c
+++ b/drivers/pinctrl/pinctrl-eic7700.c
@@ -634,7 +634,7 @@ static int eic7700_pinctrl_probe(struct platform_device *pdev)
 		return PTR_ERR(pc->base);
 
 	regulator = devm_regulator_get(dev, "vrgmii");
-	if (IS_ERR_OR_NULL(regulator)) {
+	if (IS_ERR(regulator)) {
 		return dev_err_probe(dev, PTR_ERR(regulator),
 					 "failed to get vrgmii regulator\n");
 	}
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] pinctrl: eswin: Fix regulator error check and Kconfig dependency
  2025-09-03  9:19 [PATCH v2] pinctrl: eswin: Fix regulator error check and Kconfig dependency Yulin Lu
@ 2025-09-04 19:29 ` Linus Walleij
  0 siblings, 0 replies; 2+ messages in thread
From: Linus Walleij @ 2025-09-04 19:29 UTC (permalink / raw)
  To: Yulin Lu
  Cc: linux-gpio, linux-kernel, ningyu, zhengyu, linmin, huangyifeng,
	fenglin, lianghujun, Dan Carpenter

On Wed, Sep 3, 2025 at 11:19 AM Yulin Lu <luyulin@eswincomputing.com> wrote:

> Smatch reported the following warning in eic7700_pinctrl_probe():
>
>   drivers/pinctrl/pinctrl-eic7700.c:638 eic7700_pinctrl_probe()
>   warn: passing zero to 'PTR_ERR'
>
> The root cause is that devm_regulator_get() may return NULL when
> CONFIG_REGULATOR is disabled. In such case, IS_ERR_OR_NULL() triggers
> PTR_ERR(NULL) which evaluates to 0, leading to passing a success code
> as an error.
>
> However, this driver cannot work without a regulator. To fix this:
>
>  - Change the check from IS_ERR_OR_NULL() to IS_ERR()
>  - Update Kconfig to explicitly select REGULATOR and
>    REGULATOR_FIXED_VOLTAGE, ensuring that the regulator framework is
>    always available.
>
> This resolves the Smatch warning and enforces the correct dependency.
>
> Suggested-by: Dan Carpenter <dan.carpenter@linaro.org>
> Fixes: 5b797bcc00ef ("pinctrl: eswin: Add EIC7700 pinctrl driver")
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Closes: https://lore.kernel.org/linux-gpio/aKRGiZ-fai0bv0tG@stanley.mountain/
> Signed-off-by: Yulin Lu <luyulin@eswincomputing.com>

Patch applied!

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-09-04 19:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-03  9:19 [PATCH v2] pinctrl: eswin: Fix regulator error check and Kconfig dependency Yulin Lu
2025-09-04 19:29 ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).