The protect() function previously masked errors for out-of-bounds requests. It would either return success for offsets already beyond file/partition size or clamp the count for ranges extending beyond the boundary. This behavior was introduced by commit 6815e0d05480 ("fs: limit flash erase and protect to the partiton boundary") to address SPI flash wrap-around issues.
This masking prevented shell commands from reporting failures for invalid ranges, which could mislead users and scripts. For example, underlying driver errors like -EINVAL from NVMEM were not propagated. This patch modifies protect() to return appropriate error codes (-ENXIO or -EINVAL) for such out-of-bounds conditions, instead of silently succeeding or clamping. Fixes: 6815e0d05480 ("fs: limit flash erase and protect to the partiton boundary") Signed-off-by: Oleksij Rempel <o.rem...@pengutronix.de> --- fs/fs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/fs.c b/fs/fs.c index 465fd617c2ba..6d60a1ae918b 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -652,9 +652,9 @@ int protect(int fd, size_t count, loff_t offset, int prot) if (IS_ERR(f)) return -errno; if (offset >= f->f_size) - return 0; - if (count > f->f_size - offset) - count = f->f_size - offset; + return errno_set(-ENXIO); + if (!count || count > f->f_size - offset) + return errno_set(-EINVAL); fsdrv = f->fsdev->driver; -- 2.39.5