Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: use get_random_u{16,32,64}() where appropriate

Use the typed random integer helpers instead of
get_random_bytes() when filling a single integer variable.
The helpers return the value directly, require no pointer
or size argument, and better express intent.

Skipped sites writing into __be16 (netdevsim) and __le64
(ceph) fields where a direct assignment would trigger
sparse endianness warnings.

Signed-off-by: David Carlier <devnexen@gmail.com>
Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20260407150758.5889-1-devnexen@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

David Carlier and committed by
Jakub Kicinski
9addea5d 581d2860

+10 -10
+2 -2
drivers/net/netdevsim/psample.c
··· 94 94 if (psample->out_tc_occ_max) { 95 95 u64 out_tc_occ; 96 96 97 - get_random_bytes(&out_tc_occ, sizeof(u64)); 97 + out_tc_occ = get_random_u64(); 98 98 md->out_tc_occ = out_tc_occ & (psample->out_tc_occ_max - 1); 99 99 md->out_tc_occ_valid = 1; 100 100 } ··· 102 102 if (psample->latency_max) { 103 103 u64 latency; 104 104 105 - get_random_bytes(&latency, sizeof(u64)); 105 + latency = get_random_u64(); 106 106 md->latency = latency & (psample->latency_max - 1); 107 107 md->latency_valid = 1; 108 108 }
+1 -1
net/core/net_namespace.c
··· 411 411 ref_tracker_dir_init(&net->refcnt_tracker, 128, "net_refcnt"); 412 412 ref_tracker_dir_init(&net->notrefcnt_tracker, 128, "net_notrefcnt"); 413 413 414 - get_random_bytes(&net->hash_mix, sizeof(u32)); 414 + net->hash_mix = get_random_u32(); 415 415 net->dev_base_seq = 1; 416 416 net->user_ns = user_ns; 417 417
+1 -1
net/mac80211/mesh_plink.c
··· 712 712 "Mesh plink for %pM (retry, timeout): %d %d\n", 713 713 sta->sta.addr, sta->mesh->plink_retries, 714 714 sta->mesh->plink_timeout); 715 - get_random_bytes(&rand, sizeof(u32)); 715 + rand = get_random_u32(); 716 716 sta->mesh->plink_timeout = sta->mesh->plink_timeout + 717 717 rand % sta->mesh->plink_timeout; 718 718 ++sta->mesh->plink_retries;
+2 -2
net/mptcp/subflow.c
··· 72 72 struct mptcp_sock *msk = subflow_req->msk; 73 73 u8 hmac[SHA256_DIGEST_SIZE]; 74 74 75 - get_random_bytes(&subflow_req->local_nonce, sizeof(u32)); 75 + subflow_req->local_nonce = get_random_u32(); 76 76 77 77 subflow_generate_hmac(READ_ONCE(msk->local_key), 78 78 READ_ONCE(msk->remote_key), ··· 1639 1639 ssk = sf->sk; 1640 1640 subflow = mptcp_subflow_ctx(ssk); 1641 1641 do { 1642 - get_random_bytes(&subflow->local_nonce, sizeof(u32)); 1642 + subflow->local_nonce = get_random_u32(); 1643 1643 } while (!subflow->local_nonce); 1644 1644 1645 1645 /* if 'IPADDRANY', the ID will be set later, after the routing */
+1 -1
net/openvswitch/flow_table.c
··· 167 167 168 168 ti->n_buckets = new_size; 169 169 ti->node_ver = 0; 170 - get_random_bytes(&ti->hash_seed, sizeof(u32)); 170 + ti->hash_seed = get_random_u32(); 171 171 172 172 return ti; 173 173 }
+2 -2
net/sctp/sm_make_chunk.c
··· 2727 2727 __u32 x; 2728 2728 2729 2729 do { 2730 - get_random_bytes(&x, sizeof(__u32)); 2730 + x = get_random_u32(); 2731 2731 } while (x == 0); 2732 2732 2733 2733 return x; ··· 2738 2738 { 2739 2739 __u32 retval; 2740 2740 2741 - get_random_bytes(&retval, sizeof(__u32)); 2741 + retval = get_random_u32(); 2742 2742 return retval; 2743 2743 } 2744 2744
+1 -1
net/tipc/node.c
··· 1275 1275 goto exit; 1276 1276 1277 1277 if_name = strchr(b->name, ':') + 1; 1278 - get_random_bytes(&session, sizeof(u16)); 1278 + session = get_random_u16(); 1279 1279 if (!tipc_link_create(net, if_name, b->identity, b->tolerance, 1280 1280 b->net_plane, b->mtu, b->priority, 1281 1281 b->min_win, b->max_win, session,