i2c: gpio: fault-injector: refactor incomplete transfer
[linux/fpc-iii.git] / drivers / net / wireless / quantenna / qtnfmac / util.c
blobe745733ba417ad8eee3ff78d3c5e81f05dc51510
1 /*
2 * Copyright (c) 2015-2016 Quantenna Communications, Inc.
3 * All rights reserved.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
17 #include "util.h"
19 void qtnf_sta_list_init(struct qtnf_sta_list *list)
21 if (unlikely(!list))
22 return;
24 INIT_LIST_HEAD(&list->head);
25 atomic_set(&list->size, 0);
28 struct qtnf_sta_node *qtnf_sta_list_lookup(struct qtnf_sta_list *list,
29 const u8 *mac)
31 struct qtnf_sta_node *node;
33 if (unlikely(!mac))
34 return NULL;
36 list_for_each_entry(node, &list->head, list) {
37 if (ether_addr_equal(node->mac_addr, mac))
38 return node;
41 return NULL;
44 struct qtnf_sta_node *qtnf_sta_list_lookup_index(struct qtnf_sta_list *list,
45 size_t index)
47 struct qtnf_sta_node *node;
49 if (qtnf_sta_list_size(list) <= index)
50 return NULL;
52 list_for_each_entry(node, &list->head, list) {
53 if (index-- == 0)
54 return node;
57 return NULL;
60 struct qtnf_sta_node *qtnf_sta_list_add(struct qtnf_vif *vif,
61 const u8 *mac)
63 struct qtnf_sta_list *list = &vif->sta_list;
64 struct qtnf_sta_node *node;
66 if (unlikely(!mac))
67 return NULL;
69 node = qtnf_sta_list_lookup(list, mac);
71 if (node)
72 goto done;
74 node = kzalloc(sizeof(*node), GFP_KERNEL);
75 if (unlikely(!node))
76 goto done;
78 ether_addr_copy(node->mac_addr, mac);
79 list_add_tail(&node->list, &list->head);
80 atomic_inc(&list->size);
81 ++vif->generation;
83 done:
84 return node;
87 bool qtnf_sta_list_del(struct qtnf_vif *vif, const u8 *mac)
89 struct qtnf_sta_list *list = &vif->sta_list;
90 struct qtnf_sta_node *node;
91 bool ret = false;
93 node = qtnf_sta_list_lookup(list, mac);
95 if (node) {
96 list_del(&node->list);
97 atomic_dec(&list->size);
98 kfree(node);
99 ++vif->generation;
100 ret = true;
103 return ret;
106 void qtnf_sta_list_free(struct qtnf_sta_list *list)
108 struct qtnf_sta_node *node, *tmp;
110 atomic_set(&list->size, 0);
112 list_for_each_entry_safe(node, tmp, &list->head, list) {
113 list_del(&node->list);
114 kfree(node);
117 INIT_LIST_HEAD(&list->head);