* [PATCH 1/2] fs: make dpath always panic on OOM
@ 2025-10-15 8:16 Ahmad Fatoum
2025-10-15 8:16 ` [PATCH 2/2] fs: add filepath helper Ahmad Fatoum
2025-10-20 11:14 ` [PATCH 1/2] fs: make dpath always panic on OOM Sascha Hauer
0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2025-10-15 8:16 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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@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
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] fs: add filepath helper
2025-10-15 8:16 [PATCH 1/2] fs: make dpath always panic on OOM Ahmad Fatoum
@ 2025-10-15 8:16 ` Ahmad Fatoum
2025-10-20 11:14 ` [PATCH 1/2] fs: make dpath always panic on OOM Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2025-10-15 8:16 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
This helper can be useful for debugging code, so export it in a header
and make first use of it.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
fs/legacy.c | 8 ++++----
include/fs.h | 5 +++++
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/fs/legacy.c b/fs/legacy.c
index c2170f52a40b..dce14706ca20 100644
--- a/fs/legacy.c
+++ b/fs/legacy.c
@@ -16,8 +16,7 @@ static struct inode *legacy_get_inode(struct super_block *sb, const struct inode
static int legacy_iterate(struct file *file, struct dir_context *ctx)
{
- struct dentry *dentry = file->f_path.dentry;
- struct inode *dir = d_inode(dentry);
+ struct inode *dir = d_inode(file->f_path.dentry);
struct super_block *sb = dir->i_sb;
struct fs_device *fsdev = container_of(sb, struct fs_device, sb);
const struct fs_legacy_ops *legacy_ops = fsdev->driver->legacy_ops;
@@ -27,7 +26,7 @@ static int legacy_iterate(struct file *file, struct dir_context *ctx)
dir_emit_dots(file, ctx);
- pathname = dpath(dentry, fsdev->vfsmount.mnt_root);
+ pathname = filepath(file);
d = legacy_ops->opendir(&fsdev->dev, pathname);
if (!d)
@@ -87,7 +86,8 @@ static int legacy_open(struct inode *inode, struct file *file)
if (!legacy_ops->open)
return 0;
- pathname = dpath(file->f_path.dentry, fsdev->vfsmount.mnt_root);
+ pathname = filepath(file);
+
error = legacy_ops->open(&file->fsdev->dev, file, pathname);
free(pathname);
diff --git a/include/fs.h b/include/fs.h
index 86442eacddf9..98c482bbf2a9 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -172,4 +172,9 @@ static inline const char *devpath_to_name(const char *devpath)
const char *fs_detect(const char *filename, const char *fsoptions);
+static inline char *filepath(struct file *f)
+{
+ return dpath(f->f_path.dentry, f->fsdev->vfsmount.mnt_root);
+}
+
#endif /* __FS_H */
--
2.47.3
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] fs: make dpath always panic on OOM
2025-10-15 8:16 [PATCH 1/2] fs: make dpath always panic on OOM Ahmad Fatoum
2025-10-15 8:16 ` [PATCH 2/2] fs: add filepath helper Ahmad Fatoum
@ 2025-10-20 11:14 ` Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2025-10-20 11:14 UTC (permalink / raw)
To: barebox, Ahmad Fatoum
On Wed, 15 Oct 2025 10:16:45 +0200, Ahmad Fatoum wrote:
> 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.
>
> [...]
Applied, thanks!
[1/2] fs: make dpath always panic on OOM
https://git.pengutronix.de/cgit/barebox/commit/?id=d8b66050032b (link may not be stable)
[2/2] fs: add filepath helper
https://git.pengutronix.de/cgit/barebox/commit/?id=60dd427b634d (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-10-20 12:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-15 8:16 [PATCH 1/2] fs: make dpath always panic on OOM Ahmad Fatoum
2025-10-15 8:16 ` [PATCH 2/2] fs: add filepath helper Ahmad Fatoum
2025-10-20 11:14 ` [PATCH 1/2] fs: make dpath always panic on OOM Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox