]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
docs: driver-api pinctrl cleanup
authorAlex Tran <alex.t.tran@gmail.com>
Wed, 27 Aug 2025 07:45:25 +0000 (00:45 -0700)
committerJonathan Corbet <corbet@lwn.net>
Fri, 29 Aug 2025 21:49:18 +0000 (15:49 -0600)
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

Signed-off-by: Alex Tran <alex.t.tran@gmail.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Link: https://lore.kernel.org/r/20250827074525.685863-1-alex.t.tran@gmail.com
Documentation/driver-api/pin-control.rst

index 27ea1236307e84965598c69d5e687055153823d1..281533c339142aa313257a9d1d8428232ef13bff 100644 (file)
@@ -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;
                }
        }