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
|
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2018 Samsung Electronics Co., Ltd.
*/
#include "ksmbd_ida.h"
struct ksmbd_ida *ksmbd_ida_alloc(void)
{
struct ksmbd_ida *ida;
ida = kmalloc(sizeof(struct ksmbd_ida), GFP_KERNEL);
if (!ida)
return NULL;
ida_init(&ida->map);
return ida;
}
void ksmbd_ida_free(struct ksmbd_ida *ida)
{
if (!ida)
return;
ida_destroy(&ida->map);
kfree(ida);
}
static inline int __acquire_id(struct ksmbd_ida *ida, int from, int to)
{
return ida_simple_get(&ida->map, from, to, GFP_KERNEL);
}
int ksmbd_acquire_smb2_tid(struct ksmbd_ida *ida)
{
int id;
do {
id = __acquire_id(ida, 0, 0);
} while (id == 0xFFFF);
return id;
}
int ksmbd_acquire_smb2_uid(struct ksmbd_ida *ida)
{
int id;
do {
id = __acquire_id(ida, 1, 0);
} while (id == 0xFFFE);
return id;
}
int ksmbd_acquire_async_msg_id(struct ksmbd_ida *ida)
{
return __acquire_id(ida, 1, 0);
}
int ksmbd_acquire_id(struct ksmbd_ida *ida)
{
return __acquire_id(ida, 0, 0);
}
void ksmbd_release_id(struct ksmbd_ida *ida, int id)
{
ida_simple_remove(&ida->map, id);
}
|