Skip to contentSkip to conversation

reset: core: honour optional resets when the GPIO fallback is unusable

PATCH RESEND Superseded Yang Siyuan 2 participants 7 messages Nov 17

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 reset: core: honour optional resets when the GPIO fallback is unusable

__fwnode_reset_control_get() honours RESET_CONTROL_FLAGS_BIT_OPTIONAL for every failure source except the reset-gpio fallback: when __reset_add_reset_gpio_device() fails, the error is returned even for an optional reset.

This is reachable on Allwinner SoCs, whose pinctrl uses three-cell GPIO specifiers. The reset-gpio fallback only supports two cells, so it returns -ENOENT and a consumer asking for an optional reset fails to probe instead of falling back to its own GPIO handling. mmc-pwrseq-simple on the Anbernic RG35XX family hits this: its wifi_pwrseq node has reset-gpios but no resets, so the SDIO WiFi adapter never probes.

Keep propagating -EPROBE_DEFER, since the GPIO provider may be available later, but treat any other failure as "no reset" when the request is optional.

Fixes c721f189e89c ("reset: Instantiate reset GPIO controller for shared reset-gpios")
---
 drivers/reset/core.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/reset/core.c +11 -1
index 38e189d04..f2375dd17 100644
@@ -1181,7 +1181,17 @@ __fwnode_reset_control_get(struct fwnode_handle *fwnode, const char *id, int ind
 		ret = __reset_add_reset_gpio_device(fwnode, &args);
 		if (ret) {
 			fwnode_handle_put(args.fwnode);
-			return ERR_PTR(ret);
+
+			/*
+			 * The GPIO provider may just not be available yet, so
+			 * EPROBE_DEFER must always be propagated. Any other
+			 * failure means that the fallback cannot be used,
+			 * which is not an error for an optional reset.
+			 */
+			if (ret == -EPROBE_DEFER || !optional)
+				return ERR_PTR(ret);
+
+			return NULL;
 		}
 	}
 

base-commit: 091b06388b117fefdcb63336ac09956a4914b961

Signature · 1 line
2.56.0
maintainer
#1 lore raw
Quoted 4 lines · Yang Siyuan

__fwnode_reset_control_get() honours RESET_CONTROL_FLAGS_BIT_OPTIONAL for every failure source except the reset-gpio fallback: when __reset_add_reset_gpio_device() fails, the error is returned even for an optional reset.

RESET_CONTROL_FLAGS_BIT_OPTIONAL is only meant to replace -ENOENT with NULL, not other error codes. See the kerneldoc of reset_control_get_optional_exclusive():

"If the requested reset is not specified in the device tree, this
function returns NULL instead of an error."

Quoted 23 lines

This is reachable on Allwinner SoCs, whose pinctrl uses three-cell GPIO specifiers. The reset-gpio fallback only supports two cells, so it returns -ENOENT and a consumer asking for an optional reset fails to probe instead of falling back to its own GPIO handling. mmc-pwrseq-simple on the Anbernic RG35XX family hits this: its wifi_pwrseq node has reset-gpios but no resets, so the SDIO WiFi adapter never probes.

Keep propagating -EPROBE_DEFER, since the GPIO provider may be available later, but treat any other failure as "no reset" when the request is optional.

Fixes c721f189e89c ("reset: Instantiate reset GPIO controller for shared reset-gpios")
---
 drivers/reset/core.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/reset/core.c +0 -0
index 38e189d04..f2375dd17 100644

drivers/reset/core.c __fwnode_reset_control_get(struct fwnode_handle *fwnode, const char *id, int ind · line 1189

Quoted 10 lines
drivers/reset/core.c +6 -1
@@ -1181,7 +1181,17 @@ __fwnode_reset_control_get(struct fwnode_handle *fwnode, const char *id, int ind
 		ret = __reset_add_reset_gpio_device(fwnode, &args);
 		if (ret) {
 			fwnode_handle_put(args.fwnode);
-			return ERR_PTR(ret);
+
+			/*
+			 * The GPIO provider may just not be available yet, so
+			 * EPROBE_DEFER must always be propagated. Any other
+			 * failure means that the fallback cannot be used,
+			 * which is not an error for an optional reset.

No, it is very much an error if an optional reset is specified in the device tree but can't be used.

The /*TODO*/-marked -ENOENT return in __reset_add_reset_gpio_device() is already papering over the issue.

drivers/reset/core.c __fwnode_reset_control_get(struct fwnode_handle *fwnode, const char *id, int ind · line 1194

Quoted 5 lines
drivers/reset/core.c +5 -0
+			 */
+			if (ret == -EPROBE_DEFER || !optional)
+				return ERR_PTR(ret);
+
+			return NULL;

I think instead this could be replaced with:

if (ret) {
fwnode_handle_put(args.fwnode);
+ if (ret == -ENOENT && optional)

+				return NULL;
			return ERR_PTR(ret);

regards
Philipp

#2 lore raw

PATCH v2 1/1 reset: core: honour optional resets when the GPIO fallback returns -ENOENT

In reply to Yang Siyuan

__fwnode_reset_control_get() honours RESET_CONTROL_FLAGS_BIT_OPTIONAL by returning NULL when the requested reset is not described in the device tree. The reset-gpio fallback breaks this: when __reset_add_reset_gpio_device() fails with -ENOENT, the error is returned even for an optional reset.

This is reachable on Allwinner SoCs, whose pinctrl uses three-cell GPIO specifiers. The reset-gpio fallback only supports two cells, so it returns -ENOENT and a consumer asking for an optional reset fails to probe instead of falling back to its own GPIO handling. mmc-pwrseq-simple on the Anbernic RG35XX family hits this: its wifi_pwrseq node has reset-gpios but no resets, so the SDIO WiFi adapter never probes.

Return NULL only for -ENOENT when the reset was requested as optional. A reset that is described but cannot be used is still an error, so -EPROBE_DEFER and all other failures are propagated.

Fixes c721f189e89c ("reset: Instantiate reset GPIO controller for shared reset-gpios")

---
Changes in v2:
- Only translate -ENOENT to NULL for an optional reset; propagate all other errors, as suggested by Philipp Zabel.

 drivers/reset/core.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/reset/core.c +2 -0
index 38e189d..daa4038 100644
@@ -1181,6 +1181,8 @@ __fwnode_reset_control_get(struct fwnode_handle *fwnode, const char *id, int ind
 		ret = __reset_add_reset_gpio_device(fwnode, &args);
 		if (ret) {
 			fwnode_handle_put(args.fwnode);
+			if (ret == -ENOENT && optional)
+				return NULL;
 			return ERR_PTR(ret);
 		}
 	}

base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3

Signature · 1 line
2.56.1
maintainer
#3 lore raw

Re: [PATCH v2] reset: core: honour optional resets when the GPIO fallback returns -ENOENT

Quoted 13 lines · Yang Siyuan

__fwnode_reset_control_get() honours RESET_CONTROL_FLAGS_BIT_OPTIONAL by returning NULL when the requested reset is not described in the device tree. The reset-gpio fallback breaks this: when __reset_add_reset_gpio_device() fails with -ENOENT, the error is returned even for an optional reset.

This is reachable on Allwinner SoCs, whose pinctrl uses three-cell GPIO specifiers. The reset-gpio fallback only supports two cells, so it returns -ENOENT and a consumer asking for an optional reset fails to probe instead of falling back to its own GPIO handling. mmc-pwrseq-simple on the Anbernic RG35XX family hits this: its wifi_pwrseq node has reset-gpios but no resets, so the SDIO WiFi adapter never probes.

Quoted 6 lines

Return NULL only for -ENOENT when the reset was requested as optional. A reset that is described but cannot be used is still an error, so -EPROBE_DEFER and all other failures are propagated.

Fixes c721f189e89c ("reset: Instantiate reset GPIO controller for shared reset-gpios")

This won't apply on top of c721f189e89c. The surroundings have most recently been touched by commits 1f10008aff71 ("reset: use lock guards in reset core") and 9035073d0ef1 ("reset: convert reset core to using firmware nodes"). I suggest you drop the Fixes: and Cc:stable tags. You can provide a backport if you need this on v7.0 or older.

regards
Philipp

#4 lore raw

PATCH v3 1/1 reset: core: honour optional resets when the GPIO fallback returns -ENOENT

In reply to Yang Siyuan

__fwnode_reset_control_get() honours RESET_CONTROL_FLAGS_BIT_OPTIONAL by returning NULL when the requested reset is not described in the device tree. The reset-gpio fallback breaks this: when __reset_add_reset_gpio_device() fails with -ENOENT, the error is returned even for an optional reset.

This is reachable on Allwinner SoCs, whose pinctrl uses three-cell GPIO specifiers. The reset-gpio fallback only supports two cells, so it returns -ENOENT and a consumer asking for an optional reset fails to probe instead of falling back to its own GPIO handling. mmc-pwrseq-simple on the Anbernic RG35XX family hits this: its wifi_pwrseq node has reset-gpios but no resets, so the SDIO WiFi adapter never probes.

Return NULL only for -ENOENT when the reset was requested as optional. A reset that is described but cannot be used is still an error, so -EPROBE_DEFER and all other failures are propagated.

---
Changes in v3:
- Drop the Fixes and Cc: stable tags. The patch does not apply on top of c721f189e89c because the surrounding code was changed by 1f10008aff71 ("reset: use lock guards in reset core") and 9035073d0ef1 ("reset: convert reset core to using firmware nodes"). It is a mainline fix only; older stable trees need a separate backport.

Changes in v2:
- Only translate -ENOENT to NULL for an optional reset; propagate all other errors, as suggested by Philipp Zabel.

 drivers/reset/core.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/reset/core.c +2 -0
index 38e189d..daa4038 100644
@@ -1181,6 +1181,8 @@ __fwnode_reset_control_get(struct fwnode_handle *fwnode, const char *id, int ind
 		ret = __reset_add_reset_gpio_device(fwnode, &args);
 		if (ret) {
 			fwnode_handle_put(args.fwnode);
+			if (ret == -ENOENT && optional)
+				return NULL;
 			return ERR_PTR(ret);
 		}
 	}

base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3

Signature · 1 line
2.56.1
maintainer Reviewed-by on v3 1/1
#5 lore raw

Re: [PATCH v3] reset: core: honour optional resets when the GPIO fallback returns -ENOENT

Quoted 13 lines · Yang Siyuan

__fwnode_reset_control_get() honours RESET_CONTROL_FLAGS_BIT_OPTIONAL by returning NULL when the requested reset is not described in the device tree. The reset-gpio fallback breaks this: when __reset_add_reset_gpio_device() fails with -ENOENT, the error is returned even for an optional reset.

This is reachable on Allwinner SoCs, whose pinctrl uses three-cell GPIO specifiers. The reset-gpio fallback only supports two cells, so it returns -ENOENT and a consumer asking for an optional reset fails to probe instead of falling back to its own GPIO handling. mmc-pwrseq-simple on the Anbernic RG35XX family hits this: its wifi_pwrseq node has reset-gpios but no resets, so the SDIO WiFi adapter never probes.

Quoted 5 lines

Return NULL only for -ENOENT when the reset was requested as optional. A reset that is described but cannot be used is still an error, so -EPROBE_DEFER and all other failures are propagated.

regards
Philipp

maintainer Applied
#6 lore raw

Re: [PATCH v3] reset: core: honour optional resets when the GPIO fallback returns -ENOENT

In reply to Yang Siyuan
Quoted 7 lines · Yang Siyuan

__fwnode_reset_control_get() honours RESET_CONTROL_FLAGS_BIT_OPTIONAL by returning NULL when the requested reset is not described in the device tree. The reset-gpio fallback breaks this: when __reset_add_reset_gpio_device() fails with -ENOENT, the error is returned even for an optional reset.

[...]

Applied to reset/fixes, thanks!

[1/1] reset: core: honour optional resets when the GPIO fallback returns -ENOENT

      https://git.kernel.org/pub/scm/linux/kernel/git/pza/linux.git/commit/?id=586a87701101

regards
Philipp