Skip to content

Commit 4c10477

Browse files
David LaightKernel Patches Daemon
authored andcommitted
net/core: Change loop conditions so min() can be used
Loops like: int copied = ...; ... while (copied) { use = min_t(type, copied, PAGE_SIZE - offset); ... copied -= 0; } can be converted to a plain min() if the comparison is changed to: while (copied > 0) { This removes any chance of high bits being discded by min_t(). (In the case above PAGE_SIZE is 64bits so the 'int' cast is safe, but there are plenty of cases where the check shows up bugs.) Signed-off-by: David Laight <[email protected]>
1 parent 54c5a7a commit 4c10477

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

net/core/datagram.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,8 @@ int zerocopy_fill_skb_from_iter(struct sk_buff *skb,
664664
head = compound_head(pages[n]);
665665
order = compound_order(head);
666666

667-
for (refs = 0; copied != 0; start = 0) {
668-
int size = min_t(int, copied, PAGE_SIZE - start);
667+
for (refs = 0; copied > 0; start = 0) {
668+
int size = min(copied, PAGE_SIZE - start);
669669

670670
if (pages[n] - head > (1UL << order) - 1) {
671671
head = compound_head(pages[n]);
@@ -783,7 +783,7 @@ EXPORT_SYMBOL(__zerocopy_sg_from_iter);
783783
*/
784784
int zerocopy_sg_from_iter(struct sk_buff *skb, struct iov_iter *from)
785785
{
786-
int copy = min_t(int, skb_headlen(skb), iov_iter_count(from));
786+
int copy = min(skb_headlen(skb), iov_iter_count(from));
787787

788788
/* copy up to skb headlen */
789789
if (skb_copy_datagram_from_iter(skb, 0, from, copy))

net/core/skmsg.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,8 @@ int sk_msg_zerocopy_from_iter(struct sock *sk, struct iov_iter *from,
335335
bytes -= copied;
336336
msg->sg.size += copied;
337337

338-
while (copied) {
339-
use = min_t(int, copied, PAGE_SIZE - offset);
338+
while (copied > 0) {
339+
use = min(copied, PAGE_SIZE - offset);
340340
sg_set_page(&msg->sg.data[msg->sg.end],
341341
pages[i], use, offset);
342342
sg_unmark_end(&msg->sg.data[msg->sg.end]);

0 commit comments

Comments
 (0)