Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <julia.lawall@inria.fr>
Signed-off-by: Shresth Prasad <shresthprasad7@gmail.com>
Link: https://lore.kernel.org/r/20240518114051.18125-3-shresthprasad7@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Shresth Prasad and committed by
Greg Kroah-Hartman
0bb17fdc c3f38fa6

+11 -26
+11 -26
drivers/tty/serial/sunsu.c
··· 1382 1382 1383 1383 static enum su_type su_get_type(struct device_node *dp) 1384 1384 { 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"); 1387 1387 1388 1388 if (ap) { 1389 1389 const char *keyb = of_get_property(ap, "keyboard", NULL); 1390 1390 const char *ms = of_get_property(ap, "mouse", NULL); 1391 - struct device_node *match; 1392 1391 1393 1392 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); 1395 1395 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; 1407 1398 } 1408 1399 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); 1410 1402 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; 1417 1405 } 1418 1406 } 1419 - 1420 - out: 1421 - of_node_put(ap); 1422 - return rc; 1407 + return SU_PORT_PORT; 1423 1408 } 1424 1409 1425 1410 static int su_probe(struct platform_device *op)