Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions drivers/net/ethernet/realtek/r8169_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4238,8 +4238,7 @@ static unsigned int rtl8125_quirk_udp_padto(struct rtl8169_private *tp,
}

if (trans_data_len < sizeof(struct udphdr))
padto = max_t(unsigned int, padto,
len + sizeof(struct udphdr) - trans_data_len);
padto = max(padto, len + sizeof(struct udphdr) - trans_data_len);
}

return padto;
Expand Down
5 changes: 2 additions & 3 deletions include/net/tcp_ecn.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ static inline void tcp_accecn_opt_demand_min(struct sock *sk,
struct tcp_sock *tp = tcp_sk(sk);
u8 opt_demand;

opt_demand = max_t(u8, opt_demand_min, tp->accecn_opt_demand);
opt_demand = max(opt_demand_min, tp->accecn_opt_demand + 0);
tp->accecn_opt_demand = opt_demand;
}

Expand Down Expand Up @@ -303,8 +303,7 @@ static inline void tcp_ecn_received_counters(struct sock *sk,
u32 bytes_mask = GENMASK_U32(31, 22);

tp->received_ecn_bytes[ecnfield - 1] += len;
tp->accecn_minlen = max_t(u8, tp->accecn_minlen,
minlen);
tp->accecn_minlen = max(tp->accecn_minlen + 0, minlen);

/* Send AccECN option at least once per 2^22-byte
* increase in any ECN byte counter.
Expand Down
4 changes: 2 additions & 2 deletions kernel/bpf/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,
bpf_fill_ill_insns(hdr, size);

hdr->size = size;
hole = min_t(unsigned int, size - (proglen + sizeof(*hdr)),
hole = min(size - (proglen + sizeof(*hdr)),
PAGE_SIZE - sizeof(*hdr));
start = get_random_u32_below(hole) & ~(alignment - 1);

Expand Down Expand Up @@ -1142,7 +1142,7 @@ bpf_jit_binary_pack_alloc(unsigned int proglen, u8 **image_ptr,
bpf_fill_ill_insns(*rw_header, size);
(*rw_header)->size = size;

hole = min_t(unsigned int, size - (proglen + sizeof(*ro_header)),
hole = min(size - (proglen + sizeof(*ro_header)),
BPF_PROG_CHUNK_SIZE - sizeof(*ro_header));
start = get_random_u32_below(hole) & ~(alignment - 1);

Expand Down
2 changes: 1 addition & 1 deletion kernel/bpf/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void bpf_verifier_vlog(struct bpf_verifier_log *log, const char *fmt,
/* check if we have at least something to put into user buf */
new_n = 0;
if (log->end_pos < log->len_total) {
new_n = min_t(u32, log->len_total - log->end_pos, n);
new_n = min(log->len_total - log->end_pos, n);
log->kbuf[new_n - 1] = '\0';
}

Expand Down
29 changes: 11 additions & 18 deletions kernel/bpf/verifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -2346,24 +2346,24 @@ static void __update_reg32_bounds(struct bpf_reg_state *reg)
struct tnum var32_off = tnum_subreg(reg->var_off);

/* min signed is max(sign bit) | min(other bits) */
reg->s32_min_value = max_t(s32, reg->s32_min_value,
var32_off.value | (var32_off.mask & S32_MIN));
reg->s32_min_value = max(reg->s32_min_value,
(s32)(var32_off.value | (var32_off.mask & S32_MIN)));
/* max signed is min(sign bit) | max(other bits) */
reg->s32_max_value = min_t(s32, reg->s32_max_value,
var32_off.value | (var32_off.mask & S32_MAX));
reg->u32_min_value = max_t(u32, reg->u32_min_value, (u32)var32_off.value);
reg->s32_max_value = min(reg->s32_max_value,
(s32)(var32_off.value | (var32_off.mask & S32_MAX)));
reg->u32_min_value = max(reg->u32_min_value, (u32)var32_off.value);
reg->u32_max_value = min(reg->u32_max_value,
(u32)(var32_off.value | var32_off.mask));
}

static void __update_reg64_bounds(struct bpf_reg_state *reg)
{
/* min signed is max(sign bit) | min(other bits) */
reg->smin_value = max_t(s64, reg->smin_value,
reg->var_off.value | (reg->var_off.mask & S64_MIN));
reg->smin_value = max(reg->smin_value,
(s64)(reg->var_off.value | (reg->var_off.mask & S64_MIN)));
/* max signed is min(sign bit) | max(other bits) */
reg->smax_value = min_t(s64, reg->smax_value,
reg->var_off.value | (reg->var_off.mask & S64_MAX));
reg->smax_value = min(reg->smax_value,
(s64)(reg->var_off.value | (reg->var_off.mask & S64_MAX)));
reg->umin_value = max(reg->umin_value, reg->var_off.value);
reg->umax_value = min(reg->umax_value,
reg->var_off.value | reg->var_off.mask);
Expand Down Expand Up @@ -6185,15 +6185,8 @@ static int check_packet_access(struct bpf_verifier_env *env, u32 regno, int off,
return err;
}

/* __check_mem_access has made sure "off + size - 1" is within u16.
* reg->umax_value can't be bigger than MAX_PACKET_OFF which is 0xffff,
* otherwise find_good_pkt_pointers would have refused to set range info
* that __check_mem_access would have rejected this pkt access.
* Therefore, "off + reg->umax_value + size - 1" won't overflow u32.
*/
env->prog->aux->max_pkt_offset =
max_t(u32, env->prog->aux->max_pkt_offset,
off + reg->umax_value + size - 1);
env->prog->aux->max_pkt_offset = max(env->prog->aux->max_pkt_offset,
off + reg->umax_value + size - 1);

return err;
}
Expand Down
2 changes: 1 addition & 1 deletion kernel/trace/bpf_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1515,7 +1515,7 @@ BPF_CALL_4(bpf_read_branch_records, struct bpf_perf_event_data_kern *, ctx,
if (!buf || (size % br_entry_size != 0))
return -EINVAL;

to_copy = min_t(u32, br_stack->nr * br_entry_size, size);
to_copy = min(br_stack->nr * br_entry_size, size);
memcpy(buf, br_stack->entries, to_copy);

return to_copy;
Expand Down
6 changes: 3 additions & 3 deletions net/core/datagram.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,8 @@ int zerocopy_fill_skb_from_iter(struct sk_buff *skb,
head = compound_head(pages[n]);
order = compound_order(head);

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

if (pages[n] - head > (1UL << order) - 1) {
head = compound_head(pages[n]);
Expand Down Expand Up @@ -783,7 +783,7 @@ EXPORT_SYMBOL(__zerocopy_sg_from_iter);
*/
int zerocopy_sg_from_iter(struct sk_buff *skb, struct iov_iter *from)
{
int copy = min_t(int, skb_headlen(skb), iov_iter_count(from));
int copy = min(skb_headlen(skb), iov_iter_count(from));

/* copy up to skb headlen */
if (skb_copy_datagram_from_iter(skb, 0, from, copy))
Expand Down
7 changes: 3 additions & 4 deletions net/core/flow_dissector.c
Original file line number Diff line number Diff line change
Expand Up @@ -1023,9 +1023,8 @@ u32 bpf_flow_dissect(struct bpf_prog *prog, struct bpf_flow_dissector *ctx,

result = bpf_prog_run_pin_on_cpu(prog, ctx);

flow_keys->nhoff = clamp_t(u16, flow_keys->nhoff, nhoff, hlen);
flow_keys->thoff = clamp_t(u16, flow_keys->thoff,
flow_keys->nhoff, hlen);
flow_keys->nhoff = clamp(flow_keys->nhoff, nhoff, hlen);
flow_keys->thoff = clamp(flow_keys->thoff, flow_keys->nhoff, hlen);

return result;
}
Expand Down Expand Up @@ -1687,7 +1686,7 @@ bool __skb_flow_dissect(const struct net *net,
ret = true;

out:
key_control->thoff = min_t(u16, nhoff, skb ? skb->len : hlen);
key_control->thoff = umin(nhoff, skb ? skb->len : hlen);
key_basic->n_proto = proto;
key_basic->ip_proto = ip_proto;

Expand Down
3 changes: 1 addition & 2 deletions net/core/net-sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -985,8 +985,7 @@ static int netdev_rx_queue_set_rps_mask(struct netdev_rx_queue *queue,
struct rps_map *old_map, *map;
int cpu, i;

map = kzalloc(max_t(unsigned int,
RPS_MAP_SIZE(cpumask_weight(mask)), L1_CACHE_BYTES),
map = kzalloc(max(RPS_MAP_SIZE(cpumask_weight(mask)), L1_CACHE_BYTES),
GFP_KERNEL);
if (!map)
return -ENOMEM;
Expand Down
4 changes: 2 additions & 2 deletions net/core/skmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ int sk_msg_zerocopy_from_iter(struct sock *sk, struct iov_iter *from,
bytes -= copied;
msg->sg.size += copied;

while (copied) {
use = min_t(int, copied, PAGE_SIZE - offset);
while (copied > 0) {
use = min(copied, PAGE_SIZE - offset);
sg_set_page(&msg->sg.data[msg->sg.end],
pages[i], use, offset);
sg_unmark_end(&msg->sg.data[msg->sg.end]);
Expand Down
7 changes: 3 additions & 4 deletions net/ethtool/cmis_cdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,12 +573,11 @@ ethtool_cmis_cdb_execute_epl_cmd(struct net_device *dev,
while (offset <= CMIS_CDB_EPL_FW_BLOCK_OFFSET_END &&
bytes_written < epl_len) {
u32 bytes_left = epl_len - bytes_written;
u16 space_left, bytes_to_write;
u32 space_left, bytes_to_write;

space_left = CMIS_CDB_EPL_FW_BLOCK_OFFSET_END - offset + 1;
bytes_to_write = min_t(u16, bytes_left,
min_t(u16, space_left,
args->read_write_len_ext));
bytes_to_write = min3(bytes_left, space_left,
args->read_write_len_ext);

err = __ethtool_cmis_cdb_execute_cmd(dev, page_data,
page, offset,
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/fib_trie.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ static unsigned char update_suffix(struct key_vector *tn)
* tn->pos + tn->bits, the second highest node will have a suffix
* length at most of tn->pos + tn->bits - 1
*/
slen_max = min_t(unsigned char, tn->pos + tn->bits - 1, tn->slen);
slen_max = min(tn->pos + tn->bits - 1, tn->slen);

/* search though the list of children looking for nodes that might
* have a suffix greater than the one we currently have. This is
Expand Down
4 changes: 2 additions & 2 deletions net/ipv4/tcp_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -2870,7 +2870,7 @@ static void tcp_mtup_probe_success(struct sock *sk)
val = (u64)tcp_snd_cwnd(tp) * tcp_mss_to_mtu(sk, tp->mss_cache);
do_div(val, icsk->icsk_mtup.probe_size);
DEBUG_NET_WARN_ON_ONCE((u32)val != val);
tcp_snd_cwnd_set(tp, max_t(u32, 1U, val));
tcp_snd_cwnd_set(tp, max(1, val));

tp->snd_cwnd_cnt = 0;
tp->snd_cwnd_stamp = tcp_jiffies32;
Expand Down Expand Up @@ -3323,7 +3323,7 @@ void tcp_rearm_rto(struct sock *sk)
/* delta_us may not be positive if the socket is locked
* when the retrans timer fires and is rescheduled.
*/
rto = usecs_to_jiffies(max_t(int, delta_us, 1));
rto = usecs_to_jiffies(max(delta_us, 1));
}
tcp_reset_xmit_timer(sk, ICSK_TIME_RETRANS, rto, true);
}
Expand Down
5 changes: 2 additions & 3 deletions net/ipv4/tcp_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -3076,7 +3076,7 @@ bool tcp_schedule_loss_probe(struct sock *sk, bool advancing_rto)
jiffies_to_usecs(inet_csk(sk)->icsk_rto) :
tcp_rto_delta_us(sk); /* How far in future is RTO? */
if (rto_delta_us > 0)
timeout = min_t(u32, timeout, usecs_to_jiffies(rto_delta_us));
timeout = min(timeout, usecs_to_jiffies(rto_delta_us));

tcp_reset_xmit_timer(sk, ICSK_TIME_LOSS_PROBE, timeout, true);
return true;
Expand Down Expand Up @@ -4382,8 +4382,7 @@ void tcp_send_delayed_ack(struct sock *sk)
* directly.
*/
if (tp->srtt_us) {
int rtt = max_t(int, usecs_to_jiffies(tp->srtt_us >> 3),
TCP_DELACK_MIN);
int rtt = max(usecs_to_jiffies(tp->srtt_us >> 3), TCP_DELACK_MIN);

if (rtt < max_ato)
max_ato = rtt;
Expand Down
4 changes: 2 additions & 2 deletions net/ipv4/tcp_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static u32 tcp_clamp_rto_to_user_timeout(const struct sock *sk)
if (remaining <= 0)
return 1; /* user timeout has passed; fire ASAP */

return min_t(u32, icsk->icsk_rto, msecs_to_jiffies(remaining));
return min(icsk->icsk_rto, msecs_to_jiffies(remaining));
}

u32 tcp_clamp_probe0_to_user_timeout(const struct sock *sk, u32 when)
Expand Down Expand Up @@ -504,7 +504,7 @@ static bool tcp_rtx_probe0_timed_out(const struct sock *sk,
*/
if (rtx_delta > user_timeout)
return true;
timeout = min_t(u32, timeout, msecs_to_jiffies(user_timeout));
timeout = umin(timeout, msecs_to_jiffies(user_timeout));
}
/* Note: timer interrupt might have been delayed by at least one jiffy,
* and tp->rcv_tstamp might very well have been written recently.
Expand Down
8 changes: 4 additions & 4 deletions net/ipv6/addrconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1422,11 +1422,11 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, bool block)
if_public_preferred_lft = ifp->prefered_lft;

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

cfg.plen = ifp->prefix_len;
tmp_tstamp = ifp->tstamp;
Expand Down
7 changes: 4 additions & 3 deletions net/ipv6/ip6_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,7 @@ static int __ip6_append_data(struct sock *sk,
struct sk_buff *skb, *skb_prev = NULL;
struct inet_cork *cork = &cork_full->base;
struct flowi6 *fl6 = &cork_full->fl.u.ip6;
unsigned int maxfraglen, fragheaderlen, mtu, orig_mtu, pmtu;
unsigned int maxfraglen, fragheaderlen, mtu, orig_mtu;
struct ubuf_info *uarg = NULL;
int exthdrlen = 0;
int dst_exthdrlen = 0;
Expand Down Expand Up @@ -1504,9 +1504,10 @@ static int __ip6_append_data(struct sock *sk,
maxnonfragsize = mtu;

if (cork->length + length > maxnonfragsize - headersize) {
int pmtu;
emsgsize:
pmtu = max_t(int, mtu - headersize + sizeof(struct ipv6hdr), 0);
ipv6_local_error(sk, EMSGSIZE, fl6, pmtu);
pmtu = mtu - headersize + (int)sizeof(struct ipv6hdr);
ipv6_local_error(sk, EMSGSIZE, fl6, max(pmtu, 0));
return -EMSGSIZE;
}

Expand Down
5 changes: 2 additions & 3 deletions net/ipv6/ndisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1731,9 +1731,8 @@ void ndisc_send_redirect(struct sk_buff *skb, const struct in6_addr *target)
neigh_release(neigh);
}

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

Expand Down
8 changes: 4 additions & 4 deletions net/mptcp/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -1125,8 +1125,8 @@ struct mptcp_sendmsg_info {
bool data_lock_held;
};

static int mptcp_check_allowed_size(const struct mptcp_sock *msk, struct sock *ssk,
u64 data_seq, int avail_size)
static size_t mptcp_check_allowed_size(const struct mptcp_sock *msk, struct sock *ssk,
u64 data_seq, size_t avail_size)
{
u64 window_end = mptcp_wnd_end(msk);
u64 mptcp_snd_wnd;
Expand All @@ -1135,7 +1135,7 @@ static int mptcp_check_allowed_size(const struct mptcp_sock *msk, struct sock *s
return avail_size;

mptcp_snd_wnd = window_end - data_seq;
avail_size = min_t(unsigned int, mptcp_snd_wnd, avail_size);
avail_size = min(mptcp_snd_wnd, avail_size);

if (unlikely(tcp_sk(ssk)->snd_wnd < mptcp_snd_wnd)) {
tcp_sk(ssk)->snd_wnd = min_t(u64, U32_MAX, mptcp_snd_wnd);
Expand Down Expand Up @@ -1479,7 +1479,7 @@ struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk)
if (!ssk || !sk_stream_memory_free(ssk))
return NULL;

burst = min_t(int, MPTCP_SEND_BURST_SIZE, mptcp_wnd_end(msk) - msk->snd_nxt);
burst = min(MPTCP_SEND_BURST_SIZE, mptcp_wnd_end(msk) - msk->snd_nxt);
wmem = READ_ONCE(ssk->sk_wmem_queued);
if (!burst)
return ssk;
Expand Down
9 changes: 4 additions & 5 deletions net/netlink/genetlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,11 @@ static unsigned int genl_op_iter_idx(struct genl_op_iter *iter)
return iter->cmd_idx;
}

static int genl_allocate_reserve_groups(int n_groups, int *first_id)
static noinline_for_stack int genl_allocate_reserve_groups(int n_groups, int *first_id)
{
unsigned long *new_groups;
int start = 0;
int limit;
int i;
int id;
bool fits;
Expand All @@ -414,10 +415,8 @@ static int genl_allocate_reserve_groups(int n_groups, int *first_id)
start);

fits = true;
for (i = id;
i < min_t(int, id + n_groups,
mc_groups_longs * BITS_PER_LONG);
i++) {
limit = umin(id + n_groups, mc_groups_longs * BITS_PER_LONG);
for (i = id; i < limit; i++) {
if (test_bit(i, mc_groups)) {
start = i;
fits = false;
Expand Down
2 changes: 1 addition & 1 deletion net/packet/af_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -3015,7 +3015,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
hlen = LL_RESERVED_SPACE(dev);
tlen = dev->needed_tailroom;
linear = __virtio16_to_cpu(vio_le(), vnet_hdr.hdr_len);
linear = max(linear, min_t(int, len, dev->hard_header_len));
linear = max(linear, min(len, dev->hard_header_len));
skb = packet_alloc_skb(sk, hlen + tlen, hlen, len, linear,
msg->msg_flags & MSG_DONTWAIT, &err);
if (skb == NULL)
Expand Down
4 changes: 2 additions & 2 deletions net/unix/af_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -2448,7 +2448,7 @@ static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,
/* allow fallback to order-0 allocations */
size = min_t(int, size, SKB_MAX_HEAD(0) + UNIX_SKB_FRAGS_SZ);

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

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

Expand Down Expand Up @@ -3054,7 +3054,7 @@ static int unix_stream_read_generic(struct unix_stream_read_state *state,
sunaddr = NULL;
}

chunk = min_t(unsigned int, unix_skb_len(skb) - skip, size);
chunk = min(unix_skb_len(skb) - skip, size);
chunk = state->recv_actor(skb, skip, chunk, state);
if (chunk < 0) {
if (copied == 0)
Expand Down
Loading