summaryrefslogtreecommitdiffstats
path: root/crypto/userspace/ncr.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/userspace/ncr.c')
-rw-r--r--crypto/userspace/ncr.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/crypto/userspace/ncr.c b/crypto/userspace/ncr.c
index e643fe139a0..6cae7167c9d 100644
--- a/crypto/userspace/ncr.c
+++ b/crypto/userspace/ncr.c
@@ -26,6 +26,7 @@
#include <linux/crypto.h>
#include <linux/ioctl.h>
#include <linux/mm.h>
+#include <linux/mutex.h>
#include <linux/highmem.h>
#include <linux/random.h>
#include <linux/uaccess.h>
@@ -42,6 +43,9 @@
*/
struct key_item_st master_key;
+static struct mutex lists_ida_mutex;
+static DEFINE_IDA(lists_ida);
+
void* ncr_init_lists(void)
{
struct ncr_lists *lst;
@@ -54,6 +58,19 @@ void* ncr_init_lists(void)
memset(lst, 0, sizeof(*lst));
+ mutex_init(&lists_ida_mutex);
+ mutex_lock(&lists_ida_mutex);
+ /* ida_pre_get() should preallocate enough, and, due to lists_ida_mutex,
+ nobody else can use the preallocated data. Therefore the loop
+ recommended in idr_get_new() documentation is not necessary. */
+ if (ida_pre_get(&lists_ida, GFP_KERNEL) == 0 ||
+ ida_get_new(&lists_ida, &lst->id) != 0) {
+ mutex_unlock(&lists_ida_mutex);
+ kfree(lst);
+ return NULL;
+ }
+ mutex_unlock(&lists_ida_mutex);
+
mutex_init(&lst->key_idr_mutex);
idr_init(&lst->key_idr);
@@ -68,6 +85,11 @@ void ncr_deinit_lists(struct ncr_lists *lst)
if(lst) {
ncr_key_list_deinit(lst);
ncr_sessions_list_deinit(lst);
+
+ mutex_lock(&lists_ida_mutex);
+ ida_remove(&lists_ida, lst->id);
+ mutex_unlock(&lists_ida_mutex);
+
kfree(lst);
}
}