libdect: don't reseed PRNG on dect_open_handle()
Move seeding to an __init function to avoid reseeding the PRNG multiple times with the same seed when opening multiple handles in a short amount of time. While at it, switch from rand() to random() since it uses a better PRNG in old libcs and non-Linux systems. Signed-off-by: Patrick McHardy <kaber@trash.net>
This commit is contained in:
parent
305e9be660
commit
4e04c104d1
|
@ -1550,7 +1550,7 @@ static void dect_pp_set_default_pmid(struct dect_handle *dh)
|
|||
{
|
||||
dect_assert(!(dh->flags & DECT_PP_TPUI));
|
||||
dh->pmid = DECT_PMID_DEFAULT_ID +
|
||||
(rand() & DECT_PMID_DEFAULT_NUM_MASK);
|
||||
(random() & DECT_PMID_DEFAULT_NUM_MASK);
|
||||
lce_debug("set default pmid %05x\n", dh->pmid);
|
||||
}
|
||||
|
||||
|
|
|
@ -57,8 +57,6 @@ struct dect_handle *dect_open_handle(struct dect_ops *ops, const char *cluster)
|
|||
if (cluster == NULL)
|
||||
cluster = "cluster0";
|
||||
|
||||
srand(time(NULL));
|
||||
|
||||
dh = dect_alloc_handle(ops);
|
||||
if (dh == NULL)
|
||||
goto err1;
|
||||
|
@ -98,4 +96,9 @@ void *dect_handle_priv(struct dect_handle *dh)
|
|||
}
|
||||
EXPORT_SYMBOL(dect_handle_priv);
|
||||
|
||||
static void __init libdect_init(void)
|
||||
{
|
||||
srandom(time(NULL));
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
|
Reference in New Issue