Skip to contentSkip to conversation

docs: driver-api pinctrl cleanup

PATCH Applied Alex Tran 3 participants 3 messages Aug 27, 2025 – Aug 29, 2025

Subsystems (3)
lore
Share & tools
lore

Alex Tran

author
#0 lore raw

PATCH v2 1/1 docs: driver-api pinctrl cleanup

changelog:
v2
Replace FIXME comments in the pinctrl documentation example with proper cleanup code:
- Add devm_pinctrl_put() calls in error paths (pinctrl_lookup_state, pinctrl_select_state)
after successful devm_pinctrl_get()
- Set foo->p to NULL when devm_pinctrl_get() fails
- Add ret variable for cleaner error handling
- provides proper example of pinctrl resource management on failure

---
 Documentation/driver-api/pin-control.rst | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
Documentation/driver-api/pin-control.rst +6 -4
index 27ea12363..281533c33 100644
@@ -1202,22 +1202,24 @@ default state like this:
 	{
 		/* Allocate a state holder named "foo" etc */
 		struct foo_state *foo = ...;
+		int ret;
 
 		foo->p = devm_pinctrl_get(&device);
 		if (IS_ERR(foo->p)) {
-			/* FIXME: clean up "foo" here */
-			return PTR_ERR(foo->p);
+			ret = PTR_ERR(foo->p);
+			foo->p = NULL;
+			return ret;
 		}
 
 		foo->s = pinctrl_lookup_state(foo->p, PINCTRL_STATE_DEFAULT);
 		if (IS_ERR(foo->s)) {
-			/* FIXME: clean up "foo" here */
+			devm_pinctrl_put(foo->p);
 			return PTR_ERR(foo->s);
 		}
 
 		ret = pinctrl_select_state(foo->p, foo->s);
 		if (ret < 0) {
-			/* FIXME: clean up "foo" here */
+			devm_pinctrl_put(foo->p);
 			return ret;
 		}
 	}
Signature · 1 line
2.51.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 2 lines · Alex Tran

changelog:
v2

I think Jonathan will trim these two lines when applying...

Quoted 10 lines

Replace FIXME comments in the pinctrl documentation example with proper cleanup code:
- Add devm_pinctrl_put() calls in error paths (pinctrl_lookup_state, pinctrl_select_state)
after successful devm_pinctrl_get()
- Set foo->p to NULL when devm_pinctrl_get() fails
- Add ret variable for cleaner error handling
- provides proper example of pinctrl resource management on failure

... but it looks good otherwise!

Yours,
Linus Walleij

maintainer Applied
#2 lore raw
In reply to Alex Tran
Quoted 2 lines · Alex Tran

changelog:
v2

It's best to keep this kind of stuff out of changelogs so the maintainer doesn't have to edit it out when applying the patch. I've taken care of it this time.

Quoted 9 lines

Replace FIXME comments in the pinctrl documentation example with proper cleanup code:
- Add devm_pinctrl_put() calls in error paths (pinctrl_lookup_state, pinctrl_select_state)
after successful devm_pinctrl_get()
- Set foo->p to NULL when devm_pinctrl_get() fails
- Add ret variable for cleaner error handling
- provides proper example of pinctrl resource management on failure

Quoted 4 lines
---
 Documentation/driver-api/pin-control.rst | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Applied, thanks.

jon