diff mbox series

[v1] fs:smb:Fix unsigned expression compared with zero

Message ID 20230701055556.23632-1-machel@vivo.com
State New
Headers show
Series [v1] fs:smb:Fix unsigned expression compared with zero | expand

Commit Message

王明-软件底层技术部 July 1, 2023, 5:55 a.m. UTC
The return value of the ksmbd_vfs_getcasexattr() is long.
However, the return value is being assigned to an unsignef
long variable 'v_len',so making 'v_len' to long. Also, when
comparing to zero in the following code, no type conversion
is required.

silence the warning:
./fs/smb/server/vfs.c:WARNING: Unsigned expression compared
with zero: v_len > 0

Signed-off-by: Wang Ming <machel@vivo.com>
---
 fs/smb/server/vfs.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

--
2.25.1

Comments

Tom Talpey July 1, 2023, 2:43 p.m. UTC | #1
On 7/1/2023 1:55 AM, Wang Ming wrote:
> The return value of the ksmbd_vfs_getcasexattr() is long.
> However, the return value is being assigned to an unsignef
> long variable 'v_len',so making 'v_len' to long. Also, when
> comparing to zero in the following code, no type conversion
> is required.

I agree with the fix, but this commit message is confusing.
The type is strictly speaking not "long", it's ssize_t. And
the final sentence seems unnecessary.

"The return value of the ksmbd_vfs_getcasexattr() is signed.
  However, the return value is being assigned to an unsigned
  variable and subsequently recasted, causing warnings. Use
  a signed type."

or similar.

With this clarified...
Acked-by: Tom Talpey <tom@talpey.com>


> 
> silence the warning:
> ./fs/smb/server/vfs.c:WARNING: Unsigned expression compared
> with zero: v_len > 0
> 
> Signed-off-by: Wang Ming <machel@vivo.com>
> ---
>   fs/smb/server/vfs.c | 7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/smb/server/vfs.c b/fs/smb/server/vfs.c
> index e35914457..e605ee96b 100644
> --- a/fs/smb/server/vfs.c
> +++ b/fs/smb/server/vfs.c
> @@ -412,7 +412,8 @@ static int ksmbd_vfs_stream_write(struct ksmbd_file *fp, char *buf, loff_t *pos,
>   {
>          char *stream_buf = NULL, *wbuf;
>          struct mnt_idmap *idmap = file_mnt_idmap(fp->filp);
> -       size_t size, v_len;
> +       size_t size;
> +       ssize_t v_len;
>          int err = 0;
> 
>          ksmbd_debug(VFS, "write stream data pos : %llu, count : %zd\n",
> @@ -429,9 +430,9 @@ static int ksmbd_vfs_stream_write(struct ksmbd_file *fp, char *buf, loff_t *pos,
>                                         fp->stream.name,
>                                         fp->stream.size,
>                                         &stream_buf);
> -       if ((int)v_len < 0) {
> +       if (v_len < 0) {
>                  pr_err("not found stream in xattr : %zd\n", v_len);
> -               err = (int)v_len;
> +               err = v_len;
>                  goto out;
>          }
> 
> --
> 2.25.1
> 
> 
> ________________________________
> 本邮件及其附件内容可能含有机密和/或隐私信息,仅供指定个人或机构使用。若您非发件人指定收件人或其代理人,请勿使用、传播、复制或存储此邮件之任何内容或其附件。如您误收本邮件,请即以回复或电话方式通知发件人,并将原始邮件、附件及其所有复本删除。谢谢。
> The contents of this message and any attachments may contain confidential and/or privileged information and are intended exclusively for the addressee(s). If you are not the intended recipient of this message or their agent, please note that any use, dissemination, copying, or storage of this message or its attachments is not allowed. If you receive this message in error, please notify the sender by reply the message or phone and delete this message, any attachments and any copies immediately.
> Thank you
>
Namjae Jeon July 2, 2023, 12:51 p.m. UTC | #2
2023-07-01 14:55 GMT+09:00, Wang Ming <machel@vivo.com>:
> The return value of the ksmbd_vfs_getcasexattr() is long.
> However, the return value is being assigned to an unsignef
> long variable 'v_len',so making 'v_len' to long. Also, when
> comparing to zero in the following code, no type conversion
> is required.
>
> silence the warning:
> ./fs/smb/server/vfs.c:WARNING: Unsigned expression compared
> with zero: v_len > 0
>
> Signed-off-by: Wang Ming <machel@vivo.com>
I have previously pointed out that we can not apply your patch.
It still has issues and can't apply. The patch sent by your
colleague(Lu Hongfei) applied without problems. Ask him for help on
what's wrong.

Please check the warnings from checkpatch.pl.

ERROR: patch seems to be corrupt (line wrapped?)
#114: FILE: fs/smb/server/vfs.c:411:
, char *buf, loff_t *pos,

WARNING: please, no spaces at the start of a line
#119: FILE: fs/smb/server/vfs.c:415:
+       size_t size;$

WARNING: please, no spaces at the start of a line
#120: FILE: fs/smb/server/vfs.c:416:
+       ssize_t v_len;$

WARNING: please, no spaces at the start of a line
#130: FILE: fs/smb/server/vfs.c:433:
+       if (v_len < 0) {$

WARNING: suspect code indent for conditional statements (7, 15)
#130: FILE: fs/smb/server/vfs.c:433:
+       if (v_len < 0) {
                pr_err("not found stream in xattr : %zd\n", v_len);

ERROR: code indent should use tabs where possible
#133: FILE: fs/smb/server/vfs.c:435:
+               err =3D v_len;$

WARNING: please, no spaces at the start of a line
#133: FILE: fs/smb/server/vfs.c:435:
+               err =3D v_len;$

ERROR: spaces required around that '=' (ctx:WxV)
#133: FILE: fs/smb/server/vfs.c:435:
+               err =3D v_len;
                    ^

total: 3 errors, 5 warnings, 22 lines checked

> ---
>  fs/smb/server/vfs.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/fs/smb/server/vfs.c b/fs/smb/server/vfs.c
> index e35914457..e605ee96b 100644
> --- a/fs/smb/server/vfs.c
> +++ b/fs/smb/server/vfs.c
> @@ -412,7 +412,8 @@ static int ksmbd_vfs_stream_write(struct ksmbd_file *fp,
> char *buf, loff_t *pos,
>  {
>         char *stream_buf = NULL, *wbuf;
>         struct mnt_idmap *idmap = file_mnt_idmap(fp->filp);
> -       size_t size, v_len;
> +       size_t size;
> +       ssize_t v_len;
>         int err = 0;
>
>         ksmbd_debug(VFS, "write stream data pos : %llu, count : %zd\n",
> @@ -429,9 +430,9 @@ static int ksmbd_vfs_stream_write(struct ksmbd_file *fp,
> char *buf, loff_t *pos,
>                                        fp->stream.name,
>                                        fp->stream.size,
>                                        &stream_buf);
> -       if ((int)v_len < 0) {
> +       if (v_len < 0) {
>                 pr_err("not found stream in xattr : %zd\n", v_len);
> -               err = (int)v_len;
> +               err = v_len;
>                 goto out;
>         }
>
> --
> 2.25.1
>
>
> ________________________________
> 本邮件及其附件内容可能含有机密和/或隐私信息,仅供指定个人或机构使用。若您非发件人指定收件人或其代理人,请勿使用、传播、复制或存储此邮件之任何内容或其附件。如您误收本邮件,请即以回复或电话方式通知发件人,并将原始邮件、附件及其所有复本删除。谢谢。
> The contents of this message and any attachments may contain confidential
> and/or privileged information and are intended exclusively for the
> addressee(s). If you are not the intended recipient of this message or their
> agent, please note that any use, dissemination, copying, or storage of this
> message or its attachments is not allowed. If you receive this message in
> error, please notify the sender by reply the message or phone and delete
> this message, any attachments and any copies immediately.
> Thank you
>
王明-软件底层技术部 July 6, 2023, 3:14 a.m. UTC | #3
Thank you. I will Modify it
-----邮件原件-----
发件人: Markus Elfring <Markus.Elfring@web.de> 
发送时间: 2023年7月6日 2:51
收件人: 王明-软件底层技术部 <machel@vivo.com>; linux-cifs@vger.kernel.org; kernel-janitors@vger.kernel.org; Namjae Jeon <linkinjeon@kernel.org>; Sergey Senozhatsky <senozhatsky@chromium.org>; Steve French <sfrench@samba.org>; Tom Talpey <tom@talpey.com>
抄送: opensource.kernel <opensource.kernel@vivo.com>; LKML <linux-kernel@vger.kernel.org>
主题: Re: [PATCH] fs: smb: Fix unsigned expression compared with zero in ksmbd_vfs_stream_write()

> The return value of the ksmbd_vfs_getcasexattr() is long.

The function “ksmbd_vfs_getcasexattr” is defined with the return type “long”.


> However, the return value is being assigned to an unsignef long 
> variable 'v_len',so making 'v_len' to long. …

Please avoid further typos for an improved change description.

Regards,
Markus
王明-软件底层技术部 July 6, 2023, 3:24 a.m. UTC | #4
Hi, Markus
I already submitted the new version. It has been reviewed by Namjae Jeon.
Thank you. :)
https://lore.kernel.org/all/20230704074057.1162-1-machel@vivo.com/

-----邮件原件-----
发件人: Markus Elfring <Markus.Elfring@web.de> 
发送时间: 2023年7月6日 2:51
收件人: 王明-软件底层技术部 <machel@vivo.com>; linux-cifs@vger.kernel.org; kernel-janitors@vger.kernel.org; Namjae Jeon <linkinjeon@kernel.org>; Sergey Senozhatsky <senozhatsky@chromium.org>; Steve French <sfrench@samba.org>; Tom Talpey <tom@talpey.com>
抄送: opensource.kernel <opensource.kernel@vivo.com>; LKML <linux-kernel@vger.kernel.org>
主题: Re: [PATCH] fs: smb: Fix unsigned expression compared with zero in ksmbd_vfs_stream_write()

> The return value of the ksmbd_vfs_getcasexattr() is long.

The function “ksmbd_vfs_getcasexattr” is defined with the return type “long”.


> However, the return value is being assigned to an unsignef long 
> variable 'v_len',so making 'v_len' to long. …

Please avoid further typos for an improved change description.

Regards,
Markus
diff mbox series

Patch

diff --git a/fs/smb/server/vfs.c b/fs/smb/server/vfs.c
index e35914457..e605ee96b 100644
--- a/fs/smb/server/vfs.c
+++ b/fs/smb/server/vfs.c
@@ -412,7 +412,8 @@  static int ksmbd_vfs_stream_write(struct ksmbd_file *fp, char *buf, loff_t *pos,
 {
        char *stream_buf = NULL, *wbuf;
        struct mnt_idmap *idmap = file_mnt_idmap(fp->filp);
-       size_t size, v_len;
+       size_t size;
+       ssize_t v_len;
        int err = 0;

        ksmbd_debug(VFS, "write stream data pos : %llu, count : %zd\n",
@@ -429,9 +430,9 @@  static int ksmbd_vfs_stream_write(struct ksmbd_file *fp, char *buf, loff_t *pos,
                                       fp->stream.name,
                                       fp->stream.size,
                                       &stream_buf);
-       if ((int)v_len < 0) {
+       if (v_len < 0) {
                pr_err("not found stream in xattr : %zd\n", v_len);
-               err = (int)v_len;
+               err = v_len;
                goto out;
        }