batman-adv: Utilize prandom_u32_max for random [0, max) values
The kernel provides a function to create random values from 0 - (max-1)
since commit f337db64af
("random32: add prandom_u32_max and convert open
coded users"). Simply use this function to replace code sections which use
prandom_u32 and a handcrafted method to map it to the correct range.
Signed-off-by: Sven Eckelmann <sven@narfation.org>
This commit is contained in:
Родитель
9204a4f876
Коммит
26893e7e92
|
@ -280,7 +280,7 @@ batadv_iv_ogm_emit_send_time(const struct batadv_priv *bat_priv)
|
||||||
unsigned int msecs;
|
unsigned int msecs;
|
||||||
|
|
||||||
msecs = atomic_read(&bat_priv->orig_interval) - BATADV_JITTER;
|
msecs = atomic_read(&bat_priv->orig_interval) - BATADV_JITTER;
|
||||||
msecs += prandom_u32() % (2 * BATADV_JITTER);
|
msecs += prandom_u32_max(2 * BATADV_JITTER);
|
||||||
|
|
||||||
return jiffies + msecs_to_jiffies(msecs);
|
return jiffies + msecs_to_jiffies(msecs);
|
||||||
}
|
}
|
||||||
|
@ -288,7 +288,7 @@ batadv_iv_ogm_emit_send_time(const struct batadv_priv *bat_priv)
|
||||||
/* when do we schedule a ogm packet to be sent */
|
/* when do we schedule a ogm packet to be sent */
|
||||||
static unsigned long batadv_iv_ogm_fwd_send_time(void)
|
static unsigned long batadv_iv_ogm_fwd_send_time(void)
|
||||||
{
|
{
|
||||||
return jiffies + msecs_to_jiffies(prandom_u32() % (BATADV_JITTER / 2));
|
return jiffies + msecs_to_jiffies(prandom_u32_max(BATADV_JITTER / 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* apply hop penalty for a normal link */
|
/* apply hop penalty for a normal link */
|
||||||
|
|
|
@ -49,7 +49,7 @@ static void batadv_v_elp_start_timer(struct batadv_hard_iface *hard_iface)
|
||||||
unsigned int msecs;
|
unsigned int msecs;
|
||||||
|
|
||||||
msecs = atomic_read(&hard_iface->bat_v.elp_interval) - BATADV_JITTER;
|
msecs = atomic_read(&hard_iface->bat_v.elp_interval) - BATADV_JITTER;
|
||||||
msecs += prandom_u32() % (2 * BATADV_JITTER);
|
msecs += prandom_u32_max(2 * BATADV_JITTER);
|
||||||
|
|
||||||
queue_delayed_work(batadv_event_workqueue, &hard_iface->bat_v.elp_wq,
|
queue_delayed_work(batadv_event_workqueue, &hard_iface->bat_v.elp_wq,
|
||||||
msecs_to_jiffies(msecs));
|
msecs_to_jiffies(msecs));
|
||||||
|
|
|
@ -88,7 +88,7 @@ static void batadv_v_ogm_start_queue_timer(struct batadv_hard_iface *hard_iface)
|
||||||
unsigned int msecs = BATADV_MAX_AGGREGATION_MS * 1000;
|
unsigned int msecs = BATADV_MAX_AGGREGATION_MS * 1000;
|
||||||
|
|
||||||
/* msecs * [0.9, 1.1] */
|
/* msecs * [0.9, 1.1] */
|
||||||
msecs += prandom_u32() % (msecs / 5) - (msecs / 10);
|
msecs += prandom_u32_max(msecs / 5) - (msecs / 10);
|
||||||
queue_delayed_work(batadv_event_workqueue, &hard_iface->bat_v.aggr_wq,
|
queue_delayed_work(batadv_event_workqueue, &hard_iface->bat_v.aggr_wq,
|
||||||
msecs_to_jiffies(msecs / 1000));
|
msecs_to_jiffies(msecs / 1000));
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ static void batadv_v_ogm_start_timer(struct batadv_priv *bat_priv)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
msecs = atomic_read(&bat_priv->orig_interval) - BATADV_JITTER;
|
msecs = atomic_read(&bat_priv->orig_interval) - BATADV_JITTER;
|
||||||
msecs += prandom_u32() % (2 * BATADV_JITTER);
|
msecs += prandom_u32_max(2 * BATADV_JITTER);
|
||||||
queue_delayed_work(batadv_event_workqueue, &bat_priv->bat_v.ogm_wq,
|
queue_delayed_work(batadv_event_workqueue, &bat_priv->bat_v.ogm_wq,
|
||||||
msecs_to_jiffies(msecs));
|
msecs_to_jiffies(msecs));
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче