From: Dan Carpenter <dan.carpenter@oracle.com>
To: Namjae Jeon <linkinjeon@kernel.org>
Cc: Steve French <sfrench@samba.org>,
Hyunchul Lee <hyc.lee@gmail.com>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
linux-cifs@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] ksmbd: clean up a type in ksmbd_vfs_stream_write()
Date: Fri, 3 Jun 2022 10:36:52 +0300 [thread overview]
Message-ID: <20220603073651.GM2168@kadam> (raw)
In-Reply-To: <CAKYAXd9zSCd5d9K2h9EvTbbXea1zMBcDU5Ryi6o5=GRGFQ97ag@mail.gmail.com>
On Fri, Jun 03, 2022 at 09:45:21AM +0900, Namjae Jeon wrote:
> 2022-06-03 9:10 GMT+09:00, Dan Carpenter <dan.carpenter@oracle.com>:
> > On Fri, Jun 03, 2022 at 08:18:19AM +0900, Namjae Jeon wrote:
> >> 2022-06-02 19:51 GMT+09:00, Dan Carpenter <dan.carpenter@oracle.com>:
> >> > @@ -428,9 +429,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;
> >> Data type of ssize_t is long. Wouldn't some static checker warn us
> >> that this is a problem?
> >
> > None that I know of.
> >
> > To a human reader, the cast isn't needed because when a function returns
> > ssize_t the negatives can only be error codes in the (-4095)-(-1) range.
> > No other negative sizes make sense.
> >
> > On the other hand, the "if ((int)v_len < 0) {" line really should
> > trigger a static checker because there are times when sizes could be
> > over 2GB. I will write down that I need to create that checker.
> Okay, And there is a similar type casting in ksmbd_vfs_stream_read().
> Is it not necessary to change together?
The motivation for this change was that I was looking for places which
save negative error codes in a positive value. Since the ksmbd_vfs_stream_read()
is using ssize_t then it didn't trigger that warning. But
ksmbd_vfs_stream_read() has some minor issues.
if ((int)v_len <= 0)
This cast is "buggy". Harmless though.
return (int)v_len;
This is fine, but unnecessary.
if (v_len <= *pos) {
count = -EINVAL;
I feel like this should return 0 bytes instead of -EINVAL; It probably
doesn't matter.
I am going to try write a static checker that complains specifically
about casting size_t (not long) to int. I will make it complain about
ssize_t as well, but that's kind of unusual because ssize_t can already
store negatives.
regards,
dan carpenter
prev parent reply other threads:[~2022-06-03 7:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-02 10:51 [PATCH] ksmbd: clean up a type in ksmbd_vfs_stream_write() Dan Carpenter
2022-06-02 23:18 ` Namjae Jeon
2022-06-03 0:10 ` Dan Carpenter
2022-06-03 0:45 ` Namjae Jeon
2022-06-03 7:36 ` Dan Carpenter [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220603073651.GM2168@kadam \
--to=dan.carpenter@oracle.com \
--cc=hyc.lee@gmail.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linkinjeon@kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=senozhatsky@chromium.org \
--cc=sfrench@samba.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox