From: Jacob Keller <jacob.e.keller@intel.com>
To: Li Zetao <lizetao1@huawei.com>,
"Dr. David Alan Gilbert" <linux@treblig.org>
Cc: <davem@davemloft.net>, <edumazet@google.com>, <kuba@kernel.org>,
<pabeni@redhat.com>, <marcel@holtmann.org>,
<johan.hedberg@gmail.com>, <luiz.dentz@gmail.com>,
<idryomov@gmail.com>, <xiubli@redhat.com>, <dsahern@kernel.org>,
<trondmy@kernel.org>, <anna@kernel.org>, <chuck.lever@oracle.com>,
<jlayton@kernel.org>, <neilb@suse.de>, <okorniev@redhat.com>,
<Dai.Ngo@oracle.com>, <tom@talpey.com>, <jmaloy@redhat.com>,
<ying.xue@windriver.com>, <willemb@google.com>,
<kuniyu@amazon.com>, <wuyun.abel@bytedance.com>,
<quic_abchauha@quicinc.com>, <gouhao@uniontech.com>,
<netdev@vger.kernel.org>, <linux-bluetooth@vger.kernel.org>,
<ceph-devel@vger.kernel.org>, <linux-nfs@vger.kernel.org>,
<tipc-discussion@lists.sourceforge.net>
Subject: Re: [PATCH net-next 1/8] atm: use min() to simplify the code
Date: Thu, 22 Aug 2024 13:20:17 -0700 [thread overview]
Message-ID: <469c7954-9a50-4822-a862-21decb1e8850@intel.com> (raw)
In-Reply-To: <01f3dd36-e4b6-4769-ba10-cdd0856a1076@huawei.com>
On 8/22/2024 6:50 AM, Li Zetao wrote:
> Hi,
>
> 在 2024/8/22 21:39, Dr. David Alan Gilbert 写道:
>> * Li Zetao (lizetao1@huawei.com) wrote:
>>> When copying data to user, it needs to determine the copy length.
>>> It is easier to understand using min() here.
>>>
>>> Signed-off-by: Li Zetao <lizetao1@huawei.com>
>>> ---
>>> net/atm/addr.c | 4 ++--
>>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/net/atm/addr.c b/net/atm/addr.c
>>> index 0530b63f509a..6c4c942b2cb9 100644
>>> --- a/net/atm/addr.c
>>> +++ b/net/atm/addr.c
>>> @@ -136,7 +136,7 @@ int atm_get_addr(struct atm_dev *dev, struct sockaddr_atmsvc __user * buf,
>>> unsigned long flags;
>>> struct atm_dev_addr *this;
>>> struct list_head *head;
>>> - int total = 0, error;
>>> + size_t total = 0, error;
>>
>> Aren't you accidentally changing the type of 'error' there, and the function
>> returns 'int'.
> This is intentionally modified because the input parameter size is of
> type size_t. If total is of type int, the compiler will report an error
> when the min() is called.
>>
Yea, but what you're missing is that error was an int before and is now
a size_t which can't be negative.
I think this either needs to be:
size_t total = 0;
int error
or better yet....
>> Dav
>>
>>
>>> struct sockaddr_atmsvc *tmp_buf, *tmp_bufp;
>>>
>>> spin_lock_irqsave(&dev->lock, flags);
>>> @@ -155,7 +155,7 @@ int atm_get_addr(struct atm_dev *dev, struct sockaddr_atmsvc __user * buf,
>>> memcpy(tmp_bufp++, &this->addr, sizeof(struct sockaddr_atmsvc));
>>> spin_unlock_irqrestore(&dev->lock, flags);
>>> error = total > size ? -E2BIG : total;
>>> - if (copy_to_user(buf, tmp_buf, total < size ? total : size))
>>> + if (copy_to_user(buf, tmp_buf, min(total, size)))
>>> error = -EFAULT;
Couldn't you just use min_t here instead of changing the variable sizes?
Thanks,
Jake
next prev parent reply other threads:[~2024-08-22 20:20 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-22 13:39 [PATCH net-next 0/8] Some modifications to optimize code readability Li Zetao
2024-08-22 13:39 ` [PATCH net-next 1/8] atm: use min() to simplify the code Li Zetao
2024-08-22 13:39 ` Dr. David Alan Gilbert
2024-08-22 13:50 ` Li Zetao
2024-08-22 20:20 ` Jacob Keller [this message]
2024-08-22 13:39 ` [PATCH net-next 2/8] Bluetooth: " Li Zetao
2024-08-24 18:15 ` Simon Horman
2024-08-22 13:39 ` [PATCH net-next 3/8] net: caif: use max() " Li Zetao
2024-08-24 17:37 ` Simon Horman
2024-08-22 13:39 ` [PATCH net-next 4/8] libceph: use min() " Li Zetao
2024-08-24 18:12 ` Simon Horman
2024-08-25 16:21 ` Ilya Dryomov
2024-08-27 7:31 ` Ilya Dryomov
2024-08-22 13:39 ` [PATCH net-next 5/8] net: remove redundant judgments " Li Zetao
2024-08-24 18:16 ` Simon Horman
2024-08-22 13:39 ` [PATCH net-next 6/8] ipv6: mcast: use min() " Li Zetao
2024-08-24 17:57 ` Simon Horman
2024-08-22 13:39 ` [PATCH net-next 7/8] tipc: " Li Zetao
2024-08-24 18:03 ` Simon Horman
2024-08-22 13:39 ` [PATCH net-next 8/8] SUNRPC: " Li Zetao
2024-08-24 18:07 ` Simon Horman
2024-08-24 18:21 ` Chuck Lever
2024-08-24 18:33 ` Trond Myklebust
2024-08-26 17:00 ` [PATCH net-next 0/8] Some modifications to optimize code readability patchwork-bot+netdevbpf
2024-09-12 16:33 ` patchwork-bot+bluetooth
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=469c7954-9a50-4822-a862-21decb1e8850@intel.com \
--to=jacob.e.keller@intel.com \
--cc=Dai.Ngo@oracle.com \
--cc=anna@kernel.org \
--cc=ceph-devel@vger.kernel.org \
--cc=chuck.lever@oracle.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=gouhao@uniontech.com \
--cc=idryomov@gmail.com \
--cc=jlayton@kernel.org \
--cc=jmaloy@redhat.com \
--cc=johan.hedberg@gmail.com \
--cc=kuba@kernel.org \
--cc=kuniyu@amazon.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=linux@treblig.org \
--cc=lizetao1@huawei.com \
--cc=luiz.dentz@gmail.com \
--cc=marcel@holtmann.org \
--cc=neilb@suse.de \
--cc=netdev@vger.kernel.org \
--cc=okorniev@redhat.com \
--cc=pabeni@redhat.com \
--cc=quic_abchauha@quicinc.com \
--cc=tipc-discussion@lists.sourceforge.net \
--cc=tom@talpey.com \
--cc=trondmy@kernel.org \
--cc=willemb@google.com \
--cc=wuyun.abel@bytedance.com \
--cc=xiubli@redhat.com \
--cc=ying.xue@windriver.com \
/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;
as well as URLs for NNTP newsgroup(s).