treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / net / wireguard / queueing.c
blob5c964fcb994ec5f44e69d5fa987369af99afe40f
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
4 */
6 #include "queueing.h"
8 struct multicore_worker __percpu *
9 wg_packet_percpu_multicore_worker_alloc(work_func_t function, void *ptr)
11 int cpu;
12 struct multicore_worker __percpu *worker =
13 alloc_percpu(struct multicore_worker);
15 if (!worker)
16 return NULL;
18 for_each_possible_cpu(cpu) {
19 per_cpu_ptr(worker, cpu)->ptr = ptr;
20 INIT_WORK(&per_cpu_ptr(worker, cpu)->work, function);
22 return worker;
25 int wg_packet_queue_init(struct crypt_queue *queue, work_func_t function,
26 bool multicore, unsigned int len)
28 int ret;
30 memset(queue, 0, sizeof(*queue));
31 ret = ptr_ring_init(&queue->ring, len, GFP_KERNEL);
32 if (ret)
33 return ret;
34 if (function) {
35 if (multicore) {
36 queue->worker = wg_packet_percpu_multicore_worker_alloc(
37 function, queue);
38 if (!queue->worker)
39 return -ENOMEM;
40 } else {
41 INIT_WORK(&queue->work, function);
44 return 0;
47 void wg_packet_queue_free(struct crypt_queue *queue, bool multicore)
49 if (multicore)
50 free_percpu(queue->worker);
51 WARN_ON(!__ptr_ring_empty(&queue->ring));
52 ptr_ring_cleanup(&queue->ring, NULL);