From 84e33a138dc9faf2b1b154df5eaed910aa236eeb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20Wei=C3=9Fschuh?= Date: Wed, 12 Jun 2024 23:30:28 +0200 Subject: [PATCH] lib/sysfs: abort device hierarchy walk at root of sysfs MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit It does not make sense to leave the sysfs hierarchy during the walk of the parent directories. Signed-off-by: Thomas Weißschuh --- lib/sysfs.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/sysfs.c b/lib/sysfs.c index dfacf4a4a7..e7294e6b1a 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -467,6 +467,10 @@ static int sysfs_devchain_is_removable(char *chain) /* append "/removable" to the path */ memcpy(chain + len, REMOVABLE_FILENAME, sizeof(REMOVABLE_FILENAME)); + /* root of device hierarchy */ + if (strcmp(chain, "/sys/dev/block" REMOVABLE_FILENAME) == 0) + break; + /* try to read it */ fd = open(chain, O_RDONLY); if (fd != -1) { -- 2.47.3