Return 0 to indicate failure and return "len" to indicate success. It was hard to distinguish success or failure if "len" equals the error code after the implicit cast. Moreover, eliminating implicit cast is a better practice. Fixes: acaefc25d21f ("[PATCH] libfs: add simple attribute files") Signed-off-by: Jiasheng Jiang <jiashengjiangcool@xxxxxxxxxxx> --- fs/libfs.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index b635ee5adbcc..637451f0d53e 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -1348,24 +1348,27 @@ static ssize_t simple_attr_write_xsigned(struct file *file, const char __user *b attr = file->private_data; if (!attr->set) - return -EACCES; + return 0; ret = mutex_lock_interruptible(&attr->mutex); if (ret) - return ret; + return 0; - ret = -EFAULT; size = min(sizeof(attr->set_buf) - 1, len); - if (copy_from_user(attr->set_buf, buf, size)) + if (copy_from_user(attr->set_buf, buf, size)) { + ret = 0; goto out; + } attr->set_buf[size] = '\0'; if (is_signed) - ret = kstrtoll(attr->set_buf, 0, &val); + ret = (size_t)kstrtoll(attr->set_buf, 0, &val); else - ret = kstrtoull(attr->set_buf, 0, &val); - if (ret) + ret = (size_t)kstrtoull(attr->set_buf, 0, &val); + if (ret) { + ret = 0; goto out; + } ret = attr->set(attr->data, val); if (ret == 0) ret = len; /* on success, claim we got the whole input */ -- 2.25.1