[PATCH 6/7] commands: findmnt: use cdev_open_by_name()

Sascha Hauer s.hauer at pengutronix.de
Thu May 16 00:08:21 PDT 2024


cdev_by_name() returns a cdev without increasing its reference count. In
order to maintain a proper reference counting use cdev_open_by_name()
instead and make sure it's closed afterwards when no longer needed.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 commands/findmnt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/commands/findmnt.c b/commands/findmnt.c
index da8f58835f..3c9a520b85 100644
--- a/commands/findmnt.c
+++ b/commands/findmnt.c
@@ -71,7 +71,7 @@ static int do_findmnt(int argc, char *argv[])
 			const char *backingstore;
 			struct cdev *cdev;
 
-			cdev = cdev_by_name(devpath_to_name(device));
+			cdev = cdev_open_by_name(devpath_to_name(device), O_RDONLY);
 			if (!cdev)
 				continue;
 
@@ -82,6 +82,7 @@ static int do_findmnt(int argc, char *argv[])
 				print_header(&header_printed);
 				report_findmnt(target);
 			}
+			cdev_close(cdev);
 		}
 	}
 
-- 
2.39.2




More information about the barebox mailing list