diff options
Diffstat (limited to 'net/core/utils.c')
-rw-r--r-- | net/core/utils.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/net/core/utils.c b/net/core/utils.c index aa88e23fc87a..bf09371e19b1 100644 --- a/net/core/utils.c +++ b/net/core/utils.c | |||
@@ -338,3 +338,51 @@ void inet_proto_csum_replace16(__sum16 *sum, struct sk_buff *skb, | |||
338 | csum_unfold(*sum))); | 338 | csum_unfold(*sum))); |
339 | } | 339 | } |
340 | EXPORT_SYMBOL(inet_proto_csum_replace16); | 340 | EXPORT_SYMBOL(inet_proto_csum_replace16); |
341 | |||
342 | struct __net_random_once_work { | ||
343 | struct work_struct work; | ||
344 | struct static_key *key; | ||
345 | }; | ||
346 | |||
347 | static void __net_random_once_deferred(struct work_struct *w) | ||
348 | { | ||
349 | struct __net_random_once_work *work = | ||
350 | container_of(w, struct __net_random_once_work, work); | ||
351 | if (!static_key_enabled(work->key)) | ||
352 | static_key_slow_inc(work->key); | ||
353 | kfree(work); | ||
354 | } | ||
355 | |||
356 | static void __net_random_once_disable_jump(struct static_key *key) | ||
357 | { | ||
358 | struct __net_random_once_work *w; | ||
359 | |||
360 | w = kmalloc(sizeof(*w), GFP_ATOMIC); | ||
361 | if (!w) | ||
362 | return; | ||
363 | |||
364 | INIT_WORK(&w->work, __net_random_once_deferred); | ||
365 | w->key = key; | ||
366 | schedule_work(&w->work); | ||
367 | } | ||
368 | |||
369 | bool __net_get_random_once(void *buf, int nbytes, bool *done, | ||
370 | struct static_key *done_key) | ||
371 | { | ||
372 | static DEFINE_SPINLOCK(lock); | ||
373 | |||
374 | spin_lock_bh(&lock); | ||
375 | if (*done) { | ||
376 | spin_unlock_bh(&lock); | ||
377 | return false; | ||
378 | } | ||
379 | |||
380 | get_random_bytes(buf, nbytes); | ||
381 | *done = true; | ||
382 | spin_unlock_bh(&lock); | ||
383 | |||
384 | __net_random_once_disable_jump(done_key); | ||
385 | |||
386 | return true; | ||
387 | } | ||
388 | EXPORT_SYMBOL(__net_get_random_once); | ||