[1/4] nvmem: core: return EFBIG on out-of-range write

Message ID 20170911090014.16806-2-srinivas.kandagatla@linaro.org
State New
Headers show
  • nvmem: set2 patches for v4.14
Related show

Commit Message

Srinivas Kandagatla Sept. 11, 2017, 9 a.m.
From: Guy Shapiro <guy.shapiro@mobi-wize.com>

When writing data that exceeds the nvmem size to a nvmem sysfs file
using the sh redirection operator >, the shell hangs, trying to
write the out-of-range bytes endlessly.

Fix the problem by returning EFBIG described in man 2 write.

Similar change was done for binary sysfs files on commit

Signed-off-by: Guy Shapiro <guy.shapiro@mobi-wize.com>

Cc: linux-api@vger.kernel.org
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>

 drivers/nvmem/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)



diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index de54c7f..3866117 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -135,7 +135,7 @@  static ssize_t bin_attr_nvmem_write(struct file *filp, struct kobject *kobj,
 	/* Stop the user from writing */
 	if (pos >= nvmem->size)
-		return 0;
+		return -EFBIG;
 	if (count < nvmem->word_size)
 		return -EINVAL;