Skip to contentSkip to conversation

net: ethernet: adi: adin1110: Check return value of devm_gpiod_get_optional() in adin1110_check_spi()

PATCH Applied Chen Ni 4 participants 4 messages Feb 2 – Feb 4

Subsystems (2)
lore
Share & tools
lore

Chen Ni

author
#0 lore raw

PATCH 1/1 net: ethernet: adi: adin1110: Check return value of devm_gpiod_get_optional() in adin1110_check_spi()

The devm_gpiod_get_optional() function may return an ERR_PTR in case of genuine GPIO acquisition errors, not just NULL which indicates the legitimate absence of an optional GPIO.

Add an IS_ERR() check after the call in adin1110_check_spi(). On error, return the error code to ensure proper failure handling rather than proceeding with invalid pointers.

Fixes 36934cac7aaf ("net: ethernet: adi: adin1110: add reset GPIO")
---
 drivers/net/ethernet/adi/adin1110.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/ethernet/adi/adin1110.c +3 -0
index 30f9d271e595..71a2397edf2b 100644
@@ -1089,6 +1089,9 @@ static int adin1110_check_spi(struct adin1110_priv *priv)
 
 	reset_gpio = devm_gpiod_get_optional(&priv->spidev->dev, "reset",
 					     GPIOD_OUT_LOW);
+	if (IS_ERR(reset_gpio))
+		return dev_err_probe(&priv->spidev->dev, PTR_ERR(reset_gpio),
+				     "failed to get reset gpio\n");
 	if (reset_gpio) {
 		/* MISO pin is used for internal configuration, can't have
 		 * anyone else disturbing the SDO line.
Signature · 1 line
2.25.1
#1 lore raw
Quoted 9 lines · Chen Ni

The devm_gpiod_get_optional() function may return an ERR_PTR in case of genuine GPIO acquisition errors, not just NULL which indicates the legitimate absence of an optional GPIO.

Add an IS_ERR() check after the call in adin1110_check_spi(). On error, return the error code to ensure proper failure handling rather than proceeding with invalid pointers.

Fixes 36934cac7aaf ("net: ethernet: adi: adin1110: add reset GPIO")

This patch is a bugfix, so it should be sent to net, not net-next.

Quoted 19 lines
---
  drivers/net/ethernet/adi/adin1110.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/net/ethernet/adi/adin1110.c +3 -0
index 30f9d271e595..71a2397edf2b 100644
@@ -1089,6 +1089,9 @@ static int adin1110_check_spi(struct adin1110_priv *priv)
 
  	reset_gpio = devm_gpiod_get_optional(&priv->spidev->dev, "reset",
  					     GPIOD_OUT_LOW);
+	if (IS_ERR(reset_gpio))
+		return dev_err_probe(&priv->spidev->dev, PTR_ERR(reset_gpio),
+				     "failed to get reset gpio\n");
  	if (reset_gpio) {
  		/* MISO pin is used for internal configuration, can't have
  		 * anyone else disturbing the SDO line.
Reviewed-by on v1 1/1
#2 lore raw
In reply to Chen Ni
Quoted 11 lines · Chen Ni

The devm_gpiod_get_optional() function may return an ERR_PTR in case of genuine GPIO acquisition errors, not just NULL which indicates the legitimate absence of an optional GPIO.

Add an IS_ERR() check after the call in adin1110_check_spi(). On error, return the error code to ensure proper failure handling rather than proceeding with invalid pointers.

Fixes 36934cac7aaf ("net: ethernet: adi: adin1110: add reset GPIO")

---

For the change itself:

Quoted 17 lines

 drivers/net/ethernet/adi/adin1110.c | 3 +++

 1 file changed, 3 insertions(+)
drivers/net/ethernet/adi/adin1110.c +0 -0
index 30f9d271e595..71a2397edf2b 100644
@@ -1089,6 +1089,9 @@ static int adin1110_check_spi(struct adin1110_priv *priv)


  reset_gpio = devm_gpiod_get_optional(&priv->spidev->dev, "reset", GPIOD_OUT_LOW);

drivers/net/ethernet/adi/adin1110.c +3 -0
+	if (IS_ERR(reset_gpio))
+		return dev_err_probe(&priv->spidev->dev, PTR_ERR(reset_gpio),
+				     "failed to get reset gpio\n");

  if (reset_gpio) {
  /* MISO pin is used for internal configuration, can't have
  * anyone else disturbing the SDO line.

#3 lore raw
In reply to Chen Ni
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Mon, 2 Feb 2026 12:02:28 +0800 you wrote:

The devm_gpiod_get_optional() function may return an ERR_PTR in case of genuine GPIO acquisition errors, not just NULL which indicates the legitimate absence of an optional GPIO.

Add an IS_ERR() check after the call in adin1110_check_spi(). On error, return the error code to ensure proper failure handling rather than proceeding with invalid pointers.

[...]

Here is the summary with links:
- [net-next] net: ethernet: adi: adin1110: Check return value of devm_gpiod_get_optional() in adin1110_check_spi()

    https://git.kernel.org/netdev/net/c/78211543d2e4

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html