On an ext4 partition, Running echo -a /mnt/disk0.0/file test will crash barebox because fsdrv->truncate in __write is NULL. Don't let it come to this and verify earlier that the FS implements ->write. While at it, explicitly compare with O_RDONLY (== 0) for clarity. Fixes: b3fbfad7aeaf ("fs: dentry cache implementation") Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx> --- fs/fs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/fs.c b/fs/fs.c index a023324913c4..881dc2fca0ce 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -321,13 +321,13 @@ static ssize_t __write(FILE *f, const void *buf, size_t count) struct fs_driver_d *fsdrv; int ret; - if (!(f->flags & O_ACCMODE)) { + fsdrv = f->fsdev->driver; + + if ((f->flags & O_ACCMODE) == O_RDONLY || !fsdrv->write) { ret = -EBADF; goto out; } - fsdrv = f->fsdev->driver; - if (fsdrv != ramfs_driver) assert_command_context(); -- 2.29.2 _______________________________________________ barebox mailing list barebox@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/barebox