Skip to content

Commit 63862b5

Browse files
Aruna-Hewapathiranedavem330
authored andcommitted
net: replace macros net_random and net_srandom with direct calls to prandom
This patch removes the net_random and net_srandom macros and replaces them with direct calls to the prandom ones. As new commits only seem to use prandom_u32 there is no use to keep them around. This change makes it easier to grep for users of prandom_u32. Signed-off-by: Aruna-Hewapathirane <[email protected]> Suggested-by: Hannes Frederic Sowa <[email protected]> Acked-by: Hannes Frederic Sowa <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 825edac commit 63862b5

File tree

30 files changed

+50
-51
lines changed

30 files changed

+50
-51
lines changed

drivers/infiniband/core/cma.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2310,7 +2310,7 @@ static int cma_alloc_any_port(struct idr *ps, struct rdma_id_private *id_priv)
23102310

23112311
inet_get_local_port_range(&init_net, &low, &high);
23122312
remaining = (high - low) + 1;
2313-
rover = net_random() % remaining + low;
2313+
rover = prandom_u32() % remaining + low;
23142314
retry:
23152315
if (last_used_port != rover &&
23162316
!idr_find(ps, (unsigned short) rover)) {

include/linux/net.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,6 @@ do { \
245245
#define net_dbg_ratelimited(fmt, ...) \
246246
net_ratelimited_function(pr_debug, fmt, ##__VA_ARGS__)
247247

248-
#define net_random() prandom_u32()
249-
#define net_srandom(seed) prandom_seed((__force u32)(seed))
250-
251248
bool __net_get_random_once(void *buf, int nbytes, bool *done,
252249
struct static_key *done_key);
253250

include/net/red.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ static inline unsigned long red_calc_qavg(const struct red_parms *p,
303303

304304
static inline u32 red_random(const struct red_parms *p)
305305
{
306-
return reciprocal_divide(net_random(), p->max_P_reciprocal);
306+
return reciprocal_divide(prandom_u32(), p->max_P_reciprocal);
307307
}
308308

309309
static inline int red_mark_probability(const struct red_parms *p,

net/802/garp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ static void garp_join_timer_arm(struct garp_applicant *app)
397397
{
398398
unsigned long delay;
399399

400-
delay = (u64)msecs_to_jiffies(garp_join_time) * net_random() >> 32;
400+
delay = (u64)msecs_to_jiffies(garp_join_time) * prandom_u32() >> 32;
401401
mod_timer(&app->join_timer, jiffies + delay);
402402
}
403403

net/802/mrp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ static void mrp_join_timer_arm(struct mrp_applicant *app)
583583
{
584584
unsigned long delay;
585585

586-
delay = (u64)msecs_to_jiffies(mrp_join_time) * net_random() >> 32;
586+
delay = (u64)msecs_to_jiffies(mrp_join_time) * prandom_u32() >> 32;
587587
mod_timer(&app->join_timer, jiffies + delay);
588588
}
589589

net/core/neighbour.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ static void neigh_cleanup_and_release(struct neighbour *neigh)
117117

118118
unsigned long neigh_rand_reach_time(unsigned long base)
119119
{
120-
return base ? (net_random() % base) + (base >> 1) : 0;
120+
return base ? (prandom_u32() % base) + (base >> 1) : 0;
121121
}
122122
EXPORT_SYMBOL(neigh_rand_reach_time);
123123

@@ -1415,7 +1415,8 @@ void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p,
14151415
struct sk_buff *skb)
14161416
{
14171417
unsigned long now = jiffies;
1418-
unsigned long sched_next = now + (net_random() %
1418+
1419+
unsigned long sched_next = now + (prandom_u32() %
14191420
NEIGH_VAR(p, PROXY_DELAY));
14201421

14211422
if (tbl->proxy_queue.qlen > NEIGH_VAR(p, PROXY_QLEN)) {

net/core/stream.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ int sk_stream_wait_memory(struct sock *sk, long *timeo_p)
122122
DEFINE_WAIT(wait);
123123

124124
if (sk_stream_memory_free(sk))
125-
current_timeo = vm_wait = (net_random() % (HZ / 5)) + 2;
125+
current_timeo = vm_wait = (prandom_u32() % (HZ / 5)) + 2;
126126

127127
while (1) {
128128
set_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags);

net/ipv4/devinet.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ static int __inet_insert_ifa(struct in_ifaddr *ifa, struct nlmsghdr *nlh,
464464
}
465465

466466
if (!(ifa->ifa_flags & IFA_F_SECONDARY)) {
467-
net_srandom(ifa->ifa_local);
467+
prandom_seed((__force u32) ifa->ifa_local);
468468
ifap = last_primary;
469469
}
470470

net/ipv4/igmp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ static void igmp_stop_timer(struct ip_mc_list *im)
211211
/* It must be called with locked im->lock */
212212
static void igmp_start_timer(struct ip_mc_list *im, int max_delay)
213213
{
214-
int tv = net_random() % max_delay;
214+
int tv = prandom_u32() % max_delay;
215215

216216
im->tm_running = 1;
217217
if (!mod_timer(&im->timer, jiffies+tv+2))
@@ -220,7 +220,7 @@ static void igmp_start_timer(struct ip_mc_list *im, int max_delay)
220220

221221
static void igmp_gq_start_timer(struct in_device *in_dev)
222222
{
223-
int tv = net_random() % in_dev->mr_maxdelay;
223+
int tv = prandom_u32() % in_dev->mr_maxdelay;
224224

225225
in_dev->mr_gq_running = 1;
226226
if (!mod_timer(&in_dev->mr_gq_timer, jiffies+tv+2))
@@ -229,7 +229,7 @@ static void igmp_gq_start_timer(struct in_device *in_dev)
229229

230230
static void igmp_ifc_start_timer(struct in_device *in_dev, int delay)
231231
{
232-
int tv = net_random() % delay;
232+
int tv = prandom_u32() % delay;
233233

234234
if (!mod_timer(&in_dev->mr_ifc_timer, jiffies+tv+2))
235235
in_dev_hold(in_dev);

net/ipv4/inet_connection_sock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ int inet_csk_get_port(struct sock *sk, unsigned short snum)
109109
again:
110110
inet_get_local_port_range(net, &low, &high);
111111
remaining = (high - low) + 1;
112-
smallest_rover = rover = net_random() % remaining + low;
112+
smallest_rover = rover = prandom_u32() % remaining + low;
113113

114114
smallest_size = -1;
115115
do {

net/ipv4/udp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum,
223223
inet_get_local_port_range(net, &low, &high);
224224
remaining = (high - low) + 1;
225225

226-
rand = net_random();
226+
rand = prandom_u32();
227227
first = (((u64)rand * remaining) >> 32) + low;
228228
/*
229229
* force rand to be an odd multiple of UDP_HTABLE_SIZE

net/ipv6/addrconf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3104,7 +3104,7 @@ static void addrconf_dad_kick(struct inet6_ifaddr *ifp)
31043104
if (ifp->flags & IFA_F_OPTIMISTIC)
31053105
rand_num = 0;
31063106
else
3107-
rand_num = net_random() % (idev->cnf.rtr_solicit_delay ? : 1);
3107+
rand_num = prandom_u32() % (idev->cnf.rtr_solicit_delay ? : 1);
31083108

31093109
ifp->dad_probes = idev->cnf.dad_transmits;
31103110
addrconf_mod_dad_timer(ifp, rand_num);
@@ -3117,7 +3117,7 @@ static void addrconf_dad_start(struct inet6_ifaddr *ifp)
31173117

31183118
addrconf_join_solict(dev, &ifp->addr);
31193119

3120-
net_srandom(ifp->addr.s6_addr32[3]);
3120+
prandom_seed((__force u32) ifp->addr.s6_addr32[3]);
31213121

31223122
read_lock_bh(&idev->lock);
31233123
spin_lock(&ifp->lock);

net/ipv6/ip6_flowlabel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ static struct ip6_flowlabel *fl_intern(struct net *net,
210210
spin_lock_bh(&ip6_fl_lock);
211211
if (label == 0) {
212212
for (;;) {
213-
fl->label = htonl(net_random())&IPV6_FLOWLABEL_MASK;
213+
fl->label = htonl(prandom_u32())&IPV6_FLOWLABEL_MASK;
214214
if (fl->label) {
215215
lfl = __fl_lookup(net, fl->label);
216216
if (lfl == NULL)

net/ipv6/mcast.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ bool ipv6_chk_mcast_addr(struct net_device *dev, const struct in6_addr *group,
999999

10001000
static void mld_gq_start_timer(struct inet6_dev *idev)
10011001
{
1002-
unsigned long tv = net_random() % idev->mc_maxdelay;
1002+
unsigned long tv = prandom_u32() % idev->mc_maxdelay;
10031003

10041004
idev->mc_gq_running = 1;
10051005
if (!mod_timer(&idev->mc_gq_timer, jiffies+tv+2))
@@ -1015,7 +1015,7 @@ static void mld_gq_stop_timer(struct inet6_dev *idev)
10151015

10161016
static void mld_ifc_start_timer(struct inet6_dev *idev, unsigned long delay)
10171017
{
1018-
unsigned long tv = net_random() % delay;
1018+
unsigned long tv = prandom_u32() % delay;
10191019

10201020
if (!mod_timer(&idev->mc_ifc_timer, jiffies+tv+2))
10211021
in6_dev_hold(idev);
@@ -1030,7 +1030,7 @@ static void mld_ifc_stop_timer(struct inet6_dev *idev)
10301030

10311031
static void mld_dad_start_timer(struct inet6_dev *idev, unsigned long delay)
10321032
{
1033-
unsigned long tv = net_random() % delay;
1033+
unsigned long tv = prandom_u32() % delay;
10341034

10351035
if (!mod_timer(&idev->mc_dad_timer, jiffies+tv+2))
10361036
in6_dev_hold(idev);
@@ -1061,7 +1061,7 @@ static void igmp6_group_queried(struct ifmcaddr6 *ma, unsigned long resptime)
10611061
}
10621062

10631063
if (delay >= resptime)
1064-
delay = net_random() % resptime;
1064+
delay = prandom_u32() % resptime;
10651065

10661066
ma->mca_timer.expires = jiffies + delay;
10671067
if (!mod_timer(&ma->mca_timer, jiffies + delay))
@@ -2328,7 +2328,7 @@ static void igmp6_join_group(struct ifmcaddr6 *ma)
23282328

23292329
igmp6_send(&ma->mca_addr, ma->idev->dev, ICMPV6_MGM_REPORT);
23302330

2331-
delay = net_random() % unsolicited_report_interval(ma->idev);
2331+
delay = prandom_u32() % unsolicited_report_interval(ma->idev);
23322332

23332333
spin_lock_bh(&ma->mca_lock);
23342334
if (del_timer(&ma->mca_timer)) {

net/netfilter/ipvs/ip_vs_conn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ void ip_vs_random_dropentry(struct net *net)
12091209
* Randomly scan 1/32 of the whole table every second
12101210
*/
12111211
for (idx = 0; idx < (ip_vs_conn_tab_size>>5); idx++) {
1212-
unsigned int hash = net_random() & ip_vs_conn_tab_mask;
1212+
unsigned int hash = prandom_u32() & ip_vs_conn_tab_mask;
12131213

12141214
hlist_for_each_entry_rcu(cp, &ip_vs_conn_tab[hash], c_list) {
12151215
if (cp->flags & IP_VS_CONN_F_TEMPLATE)

net/netfilter/xt_statistic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
3737

3838
switch (info->mode) {
3939
case XT_STATISTIC_MODE_RANDOM:
40-
if ((net_random() & 0x7FFFFFFF) < info->u.random.probability)
40+
if ((prandom_u32() & 0x7FFFFFFF) < info->u.random.probability)
4141
ret = !ret;
4242
break;
4343
case XT_STATISTIC_MODE_NTH:

net/openvswitch/actions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ static int sample(struct datapath *dp, struct sk_buff *skb,
445445
a = nla_next(a, &rem)) {
446446
switch (nla_type(a)) {
447447
case OVS_SAMPLE_ATTR_PROBABILITY:
448-
if (net_random() >= nla_get_u32(a))
448+
if (prandom_u32() >= nla_get_u32(a))
449449
return 0;
450450
break;
451451

net/rds/bind.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ static int rds_add_bound(struct rds_sock *rs, __be32 addr, __be16 *port)
117117
rover = be16_to_cpu(*port);
118118
last = rover;
119119
} else {
120-
rover = max_t(u16, net_random(), 2);
120+
rover = max_t(u16, prandom_u32(), 2);
121121
last = rover - 1;
122122
}
123123

net/sched/act_gact.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static struct tcf_hashinfo gact_hash_info;
2929
#ifdef CONFIG_GACT_PROB
3030
static int gact_net_rand(struct tcf_gact *gact)
3131
{
32-
if (!gact->tcfg_pval || net_random() % gact->tcfg_pval)
32+
if (!gact->tcfg_pval || prandom_u32() % gact->tcfg_pval)
3333
return gact->tcf_action;
3434
return gact->tcfg_paction;
3535
}

net/sched/sch_fq_codel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ static int fq_codel_init(struct Qdisc *sch, struct nlattr *opt)
390390
sch->limit = 10*1024;
391391
q->flows_cnt = 1024;
392392
q->quantum = psched_mtu(qdisc_dev(sch));
393-
q->perturbation = net_random();
393+
q->perturbation = prandom_u32();
394394
INIT_LIST_HEAD(&q->new_flows);
395395
INIT_LIST_HEAD(&q->old_flows);
396396
codel_params_init(&q->cparams);

net/sched/sch_hhf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ static int hhf_init(struct Qdisc *sch, struct nlattr *opt)
607607

608608
sch->limit = 1000;
609609
q->quantum = psched_mtu(qdisc_dev(sch));
610-
q->perturbation = net_random();
610+
q->perturbation = prandom_u32();
611611
INIT_LIST_HEAD(&q->new_buckets);
612612
INIT_LIST_HEAD(&q->old_buckets);
613613

net/sched/sch_netem.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ static inline struct netem_skb_cb *netem_skb_cb(struct sk_buff *skb)
169169
static void init_crandom(struct crndstate *state, unsigned long rho)
170170
{
171171
state->rho = rho;
172-
state->last = net_random();
172+
state->last = prandom_u32();
173173
}
174174

175175
/* get_crandom - correlated random number generator
@@ -182,9 +182,9 @@ static u32 get_crandom(struct crndstate *state)
182182
unsigned long answer;
183183

184184
if (state->rho == 0) /* no correlation */
185-
return net_random();
185+
return prandom_u32();
186186

187-
value = net_random();
187+
value = prandom_u32();
188188
rho = (u64)state->rho + 1;
189189
answer = (value * ((1ull<<32) - rho) + state->last * rho) >> 32;
190190
state->last = answer;
@@ -198,7 +198,7 @@ static u32 get_crandom(struct crndstate *state)
198198
static bool loss_4state(struct netem_sched_data *q)
199199
{
200200
struct clgstate *clg = &q->clg;
201-
u32 rnd = net_random();
201+
u32 rnd = prandom_u32();
202202

203203
/*
204204
* Makes a comparison between rnd and the transition
@@ -264,15 +264,15 @@ static bool loss_gilb_ell(struct netem_sched_data *q)
264264

265265
switch (clg->state) {
266266
case 1:
267-
if (net_random() < clg->a1)
267+
if (prandom_u32() < clg->a1)
268268
clg->state = 2;
269-
if (net_random() < clg->a4)
269+
if (prandom_u32() < clg->a4)
270270
return true;
271271
break;
272272
case 2:
273-
if (net_random() < clg->a2)
273+
if (prandom_u32() < clg->a2)
274274
clg->state = 1;
275-
if (net_random() > clg->a3)
275+
if (prandom_u32() > clg->a3)
276276
return true;
277277
}
278278

@@ -457,7 +457,8 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch)
457457
skb_checksum_help(skb)))
458458
return qdisc_drop(skb, sch);
459459

460-
skb->data[net_random() % skb_headlen(skb)] ^= 1<<(net_random() % 8);
460+
skb->data[prandom_u32() % skb_headlen(skb)] ^=
461+
1<<(prandom_u32() % 8);
461462
}
462463

463464
if (unlikely(skb_queue_len(&sch->q) >= sch->limit))

net/sched/sch_pie.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static bool drop_early(struct Qdisc *sch, u32 packet_size)
122122
else
123123
local_prob = q->vars.prob;
124124

125-
rnd = net_random();
125+
rnd = prandom_u32();
126126
if (rnd < local_prob)
127127
return true;
128128

net/sched/sch_sfb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ static u32 sfb_compute_qlen(u32 *prob_r, u32 *avgpm_r, const struct sfb_sched_da
220220

221221
static void sfb_init_perturbation(u32 slot, struct sfb_sched_data *q)
222222
{
223-
q->bins[slot].perturbation = net_random();
223+
q->bins[slot].perturbation = prandom_u32();
224224
}
225225

226226
static void sfb_swap_slot(struct sfb_sched_data *q)
@@ -381,7 +381,7 @@ static int sfb_enqueue(struct sk_buff *skb, struct Qdisc *sch)
381381
goto enqueue;
382382
}
383383

384-
r = net_random() & SFB_MAX_PROB;
384+
r = prandom_u32() & SFB_MAX_PROB;
385385

386386
if (unlikely(r < p_min)) {
387387
if (unlikely(p_min > SFB_MAX_PROB / 2)) {

net/sched/sch_sfq.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ static void sfq_perturbation(unsigned long arg)
629629
spinlock_t *root_lock = qdisc_lock(qdisc_root_sleeping(sch));
630630

631631
spin_lock(root_lock);
632-
q->perturbation = net_random();
632+
q->perturbation = prandom_u32();
633633
if (!q->filter_list && q->tail)
634634
sfq_rehash(sch);
635635
spin_unlock(root_lock);
@@ -698,7 +698,7 @@ static int sfq_change(struct Qdisc *sch, struct nlattr *opt)
698698
del_timer(&q->perturb_timer);
699699
if (q->perturb_period) {
700700
mod_timer(&q->perturb_timer, jiffies + q->perturb_period);
701-
q->perturbation = net_random();
701+
q->perturbation = prandom_u32();
702702
}
703703
sch_tree_unlock(sch);
704704
kfree(p);
@@ -759,7 +759,7 @@ static int sfq_init(struct Qdisc *sch, struct nlattr *opt)
759759
q->quantum = psched_mtu(qdisc_dev(sch));
760760
q->scaled_quantum = SFQ_ALLOT_SIZE(q->quantum);
761761
q->perturb_period = 0;
762-
q->perturbation = net_random();
762+
q->perturbation = prandom_u32();
763763

764764
if (opt) {
765765
int err = sfq_change(sch, opt);

net/sctp/socket.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5926,7 +5926,7 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
59265926

59275927
inet_get_local_port_range(sock_net(sk), &low, &high);
59285928
remaining = (high - low) + 1;
5929-
rover = net_random() % remaining + low;
5929+
rover = prandom_u32() % remaining + low;
59305930

59315931
do {
59325932
rover++;

net/sunrpc/cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ static void cache_limit_defers(void)
619619

620620
/* Consider removing either the first or the last */
621621
if (cache_defer_cnt > DFR_MAX) {
622-
if (net_random() & 1)
622+
if (prandom_u32() & 1)
623623
discard = list_entry(cache_defer_list.next,
624624
struct cache_deferred_req, recent);
625625
else

0 commit comments

Comments
 (0)