[PATCH 1/2] fs: make dpath always panic on OOM
Ahmad Fatoum
a.fatoum at barebox.org
Wed Oct 15 01:16:45 PDT 2025
This is effectively already the case since basprintf was changed to be
equivalent to xasprintf. Replace basprintf with xasprintf to make this
clearer and use xstrdup instead of strdup for the root node.
All users, except one, didn't bother to check dpath return value for NULL
anyway.
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
fs/fs.c | 6 +++---
fs/legacy.c | 2 --
2 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/fs/fs.c b/fs/fs.c
index 529c328f26fc..528299e039d2 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -3022,9 +3022,9 @@ static char *__dpath(struct dentry *dentry, struct dentry *root)
ppath = __dpath(dentry->d_parent, root);
if (ppath)
- res = basprintf("%s/%s", ppath, dentry->d_name.name);
+ res = xasprintf("%s/%s", ppath, dentry->d_name.name);
else
- res = basprintf("/%s", dentry->d_name.name);
+ res = xasprintf("/%s", dentry->d_name.name);
free(ppath);
return res;
@@ -3058,7 +3058,7 @@ char *dpath(struct dentry *dentry, struct dentry *root)
char *res;
if (dentry == root)
- return strdup("/");
+ return xstrdup("/");
res = __dpath(dentry, root);
diff --git a/fs/legacy.c b/fs/legacy.c
index 7c73ad7c41e4..c2170f52a40b 100644
--- a/fs/legacy.c
+++ b/fs/legacy.c
@@ -60,8 +60,6 @@ static struct dentry *legacy_lookup(struct inode *dir, struct dentry *dentry,
int ret;
pathname = dpath(dentry, fsdev->vfsmount.mnt_root);
- if (!pathname)
- return NULL;
ret = legacy_ops->stat(&fsdev->dev, pathname, &s);
if (!ret) {
--
2.47.3
More information about the barebox
mailing list