Message ID | BYAPR03MB41685A92DCDD499A2B1369F0ADEC2@BYAPR03MB4168.namprd03.prod.outlook.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | libfs: fix implicitly cast in simple_attr_write_xsigned() | expand |
On Wed, May 15, 2024 at 03:17:25PM +0000, Jiasheng Jiang wrote: > 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. According to whom? Merits of your ex cathedra claims aside, you do realize that functions have calling conventions because they are, well, called, right? And changing the value returned in such and such case should be accompanied with the corresponding change in the _callers_. Al, wondering if somebody had decided to play with LLM...
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 */
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@outlook.com> --- fs/libfs.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)