-
Notifications
You must be signed in to change notification settings - Fork 11
/
al_list.c
74 lines (63 loc) · 1.58 KB
/
al_list.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* al_list.c
*
* Copyright (C) 2016, Allegro DVT (www.allegrodvt.com)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "al_list.h"
#include <linux/slab.h>
void al5_list_init(struct al5_list **l)
{
*l = NULL;
}
int al5_list_empty(const struct al5_list *l)
{
return l == NULL;
}
void al5_list_push(struct al5_list **l, struct al5_mail *mail)
{
struct al5_list *first_pos = *l;
if (*l == NULL) {
*l = kmalloc(sizeof(**l), GFP_KERNEL);
(*l)->mail = mail;
(*l)->next = NULL;
return;
}
while ((*l)->next != NULL)
*l = (*l)->next;
(*l)->next = kmalloc(sizeof(*((*l)->next)), GFP_KERNEL);
(*l)->next->mail = mail;
(*l)->next->next = NULL;
*l = first_pos;
}
struct al5_mail *al5_list_pop(struct al5_list **l)
{
struct al5_mail *mail;
struct al5_list *next;
if (*l == NULL)
return NULL;
mail = (*l)->mail;
next = (*l)->next;
kfree(*l);
*l = next;
return mail;
}
void al5_list_empty_and_destroy(struct al5_list **l)
{
while (!al5_list_empty(*l)) {
struct al5_mail *mail = al5_list_pop(l);
al5_free_mail(mail);
}
kfree(*l);
}