Skip to content

Commit 0bb17fd

Browse files
Yttrium-32gregkh
authored andcommitted
tty: sunsu: Simplify device_node cleanup by using __free
Add `__free` function attribute to `ap` and `match` pointer initialisations which ensure that the pointers are freed as soon as they go out of scope, thus removing the need to manually free them using `of_node_put`. This also removes the need for the `goto` statement and the `rc` variable. Suggested-by: Julia Lawall <[email protected]> Signed-off-by: Shresth Prasad <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c3f38fa commit 0bb17fd

File tree

1 file changed

+11
-26
lines changed

1 file changed

+11
-26
lines changed

drivers/tty/serial/sunsu.c

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,44 +1382,29 @@ static inline struct console *SUNSU_CONSOLE(void)
13821382

13831383
static enum su_type su_get_type(struct device_node *dp)
13841384
{
1385-
struct device_node *ap = of_find_node_by_path("/aliases");
1386-
enum su_type rc = SU_PORT_PORT;
1385+
struct device_node *ap __free(device_node) =
1386+
of_find_node_by_path("/aliases");
13871387

13881388
if (ap) {
13891389
const char *keyb = of_get_property(ap, "keyboard", NULL);
13901390
const char *ms = of_get_property(ap, "mouse", NULL);
1391-
struct device_node *match;
13921391

13931392
if (keyb) {
1394-
match = of_find_node_by_path(keyb);
1393+
struct device_node *match __free(device_node) =
1394+
of_find_node_by_path(keyb);
13951395

1396-
/*
1397-
* The pointer is used as an identifier not
1398-
* as a pointer, we can drop the refcount on
1399-
* the of__node immediately after getting it.
1400-
*/
1401-
of_node_put(match);
1402-
1403-
if (dp == match) {
1404-
rc = SU_PORT_KBD;
1405-
goto out;
1406-
}
1396+
if (dp == match)
1397+
return SU_PORT_KBD;
14071398
}
14081399
if (ms) {
1409-
match = of_find_node_by_path(ms);
1400+
struct device_node *match __free(device_node) =
1401+
of_find_node_by_path(ms);
14101402

1411-
of_node_put(match);
1412-
1413-
if (dp == match) {
1414-
rc = SU_PORT_MS;
1415-
goto out;
1416-
}
1403+
if (dp == match)
1404+
return SU_PORT_MS;
14171405
}
14181406
}
1419-
1420-
out:
1421-
of_node_put(ap);
1422-
return rc;
1407+
return SU_PORT_PORT;
14231408
}
14241409

14251410
static int su_probe(struct platform_device *op)

0 commit comments

Comments
 (0)