Skip to content

Commit f57a33b

Browse files
David LaightKernel Patches Daemon
authored andcommitted
net: use min() instead of min_t()
min_t(unsigned int, a, b) casts an 'unsigned long' to 'unsigned int'. Use min(a, b) instead as it promotes any 'unsigned int' to 'unsigned long' and so cannot discard significant bits. In this case the 'unsigned long' value is small enough that the result is ok. Detected by an extra check added to min_t(). Signed-off-by: David Laight <[email protected]>
1 parent 4c10477 commit f57a33b

File tree

9 files changed

+17
-20
lines changed

9 files changed

+17
-20
lines changed

net/core/net-sysfs.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -985,8 +985,7 @@ static int netdev_rx_queue_set_rps_mask(struct netdev_rx_queue *queue,
985985
struct rps_map *old_map, *map;
986986
int cpu, i;
987987

988-
map = kzalloc(max_t(unsigned int,
989-
RPS_MAP_SIZE(cpumask_weight(mask)), L1_CACHE_BYTES),
988+
map = kzalloc(max(RPS_MAP_SIZE(cpumask_weight(mask)), L1_CACHE_BYTES),
990989
GFP_KERNEL);
991990
if (!map)
992991
return -ENOMEM;

net/ipv4/fib_trie.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ static unsigned char update_suffix(struct key_vector *tn)
710710
* tn->pos + tn->bits, the second highest node will have a suffix
711711
* length at most of tn->pos + tn->bits - 1
712712
*/
713-
slen_max = min_t(unsigned char, tn->pos + tn->bits - 1, tn->slen);
713+
slen_max = min(tn->pos + tn->bits - 1, tn->slen);
714714

715715
/* search though the list of children looking for nodes that might
716716
* have a suffix greater than the one we currently have. This is

net/ipv4/tcp_input.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2870,7 +2870,7 @@ static void tcp_mtup_probe_success(struct sock *sk)
28702870
val = (u64)tcp_snd_cwnd(tp) * tcp_mss_to_mtu(sk, tp->mss_cache);
28712871
do_div(val, icsk->icsk_mtup.probe_size);
28722872
DEBUG_NET_WARN_ON_ONCE((u32)val != val);
2873-
tcp_snd_cwnd_set(tp, max_t(u32, 1U, val));
2873+
tcp_snd_cwnd_set(tp, max(1, val));
28742874

28752875
tp->snd_cwnd_cnt = 0;
28762876
tp->snd_cwnd_stamp = tcp_jiffies32;
@@ -3323,7 +3323,7 @@ void tcp_rearm_rto(struct sock *sk)
33233323
/* delta_us may not be positive if the socket is locked
33243324
* when the retrans timer fires and is rescheduled.
33253325
*/
3326-
rto = usecs_to_jiffies(max_t(int, delta_us, 1));
3326+
rto = usecs_to_jiffies(max(delta_us, 1));
33273327
}
33283328
tcp_reset_xmit_timer(sk, ICSK_TIME_RETRANS, rto, true);
33293329
}

net/ipv4/tcp_output.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3076,7 +3076,7 @@ bool tcp_schedule_loss_probe(struct sock *sk, bool advancing_rto)
30763076
jiffies_to_usecs(inet_csk(sk)->icsk_rto) :
30773077
tcp_rto_delta_us(sk); /* How far in future is RTO? */
30783078
if (rto_delta_us > 0)
3079-
timeout = min_t(u32, timeout, usecs_to_jiffies(rto_delta_us));
3079+
timeout = min(timeout, usecs_to_jiffies(rto_delta_us));
30803080

30813081
tcp_reset_xmit_timer(sk, ICSK_TIME_LOSS_PROBE, timeout, true);
30823082
return true;
@@ -4382,8 +4382,7 @@ void tcp_send_delayed_ack(struct sock *sk)
43824382
* directly.
43834383
*/
43844384
if (tp->srtt_us) {
4385-
int rtt = max_t(int, usecs_to_jiffies(tp->srtt_us >> 3),
4386-
TCP_DELACK_MIN);
4385+
int rtt = max(usecs_to_jiffies(tp->srtt_us >> 3), TCP_DELACK_MIN);
43874386

43884387
if (rtt < max_ato)
43894388
max_ato = rtt;

net/ipv4/tcp_timer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static u32 tcp_clamp_rto_to_user_timeout(const struct sock *sk)
4343
if (remaining <= 0)
4444
return 1; /* user timeout has passed; fire ASAP */
4545

46-
return min_t(u32, icsk->icsk_rto, msecs_to_jiffies(remaining));
46+
return min(icsk->icsk_rto, msecs_to_jiffies(remaining));
4747
}
4848

4949
u32 tcp_clamp_probe0_to_user_timeout(const struct sock *sk, u32 when)
@@ -504,7 +504,7 @@ static bool tcp_rtx_probe0_timed_out(const struct sock *sk,
504504
*/
505505
if (rtx_delta > user_timeout)
506506
return true;
507-
timeout = min_t(u32, timeout, msecs_to_jiffies(user_timeout));
507+
timeout = umin(timeout, msecs_to_jiffies(user_timeout));
508508
}
509509
/* Note: timer interrupt might have been delayed by at least one jiffy,
510510
* and tp->rcv_tstamp might very well have been written recently.

net/ipv6/addrconf.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,11 +1422,11 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, bool block)
14221422
if_public_preferred_lft = ifp->prefered_lft;
14231423

14241424
memset(&cfg, 0, sizeof(cfg));
1425-
cfg.valid_lft = min_t(__u32, ifp->valid_lft,
1426-
READ_ONCE(idev->cnf.temp_valid_lft) + age);
1425+
cfg.valid_lft = min(ifp->valid_lft,
1426+
READ_ONCE(idev->cnf.temp_valid_lft) + age);
14271427
cfg.preferred_lft = cnf_temp_preferred_lft + age - idev->desync_factor;
1428-
cfg.preferred_lft = min_t(__u32, if_public_preferred_lft, cfg.preferred_lft);
1429-
cfg.preferred_lft = min_t(__u32, cfg.valid_lft, cfg.preferred_lft);
1428+
cfg.preferred_lft = min(if_public_preferred_lft, cfg.preferred_lft);
1429+
cfg.preferred_lft = min(cfg.valid_lft, cfg.preferred_lft);
14301430

14311431
cfg.plen = ifp->prefix_len;
14321432
tmp_tstamp = ifp->tstamp;

net/ipv6/ndisc.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,9 +1731,8 @@ void ndisc_send_redirect(struct sk_buff *skb, const struct in6_addr *target)
17311731
neigh_release(neigh);
17321732
}
17331733

1734-
rd_len = min_t(unsigned int,
1735-
IPV6_MIN_MTU - sizeof(struct ipv6hdr) - sizeof(*msg) - optlen,
1736-
skb->len + 8);
1734+
rd_len = min(IPV6_MIN_MTU - sizeof(struct ipv6hdr) - sizeof(*msg) - optlen,
1735+
skb->len + 8);
17371736
rd_len &= ~0x7;
17381737
optlen += rd_len;
17391738

net/packet/af_packet.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3015,7 +3015,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
30153015
hlen = LL_RESERVED_SPACE(dev);
30163016
tlen = dev->needed_tailroom;
30173017
linear = __virtio16_to_cpu(vio_le(), vnet_hdr.hdr_len);
3018-
linear = max(linear, min_t(int, len, dev->hard_header_len));
3018+
linear = max(linear, min(len, dev->hard_header_len));
30193019
skb = packet_alloc_skb(sk, hlen + tlen, hlen, len, linear,
30203020
msg->msg_flags & MSG_DONTWAIT, &err);
30213021
if (skb == NULL)

net/unix/af_unix.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2448,7 +2448,7 @@ static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,
24482448
/* allow fallback to order-0 allocations */
24492449
size = min_t(int, size, SKB_MAX_HEAD(0) + UNIX_SKB_FRAGS_SZ);
24502450

2451-
data_len = max_t(int, 0, size - SKB_MAX_HEAD(0));
2451+
data_len = max(0, size - (int)SKB_MAX_HEAD(0));
24522452

24532453
data_len = min_t(size_t, size, PAGE_ALIGN(data_len));
24542454

@@ -3054,7 +3054,7 @@ static int unix_stream_read_generic(struct unix_stream_read_state *state,
30543054
sunaddr = NULL;
30553055
}
30563056

3057-
chunk = min_t(unsigned int, unix_skb_len(skb) - skip, size);
3057+
chunk = min(unix_skb_len(skb) - skip, size);
30583058
chunk = state->recv_actor(skb, skip, chunk, state);
30593059
if (chunk < 0) {
30603060
if (copied == 0)

0 commit comments

Comments
 (0)