#include <linux/module.h>
#include <linux/slab.h>
#include <linux/list.h>
+#include <linux/spinlock.h>
struct sspt_feature {
void *data;
};
-static LIST_HEAD(feature_list);
+static DEFINE_SPINLOCK(feature_img_lock);
+static LIST_HEAD(feature_img_list);
static struct sspt_feature_data *create_feature_data(struct sspt_feature_img *img)
{
f = kmalloc(sizeof(*f), GFP_ATOMIC);
if (f) {
- INIT_LIST_HEAD(&f->feature_list);
-
struct sspt_feature_data *fd;
struct sspt_feature_img *fi;
+ unsigned long flags;
+
+ INIT_LIST_HEAD(&f->feature_list);
- list_for_each_entry(fi, &feature_list, list) {
+ spin_lock_irqsave(&feature_img_lock, flags);
+ list_for_each_entry(fi, &feature_img_list, list) {
fd = create_feature_data(fi);
/* add to list */
list_add(&fd->list, &f->feature_list);
}
+ spin_unlock_irqrestore(&feature_img_lock, flags);
}
return f;
kfree(f);
}
+static void add_feature_img_to_list(struct sspt_feature_img *fi)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&feature_img_lock, flags);
+ list_add(&fi->list, &feature_img_list);
+ spin_unlock_irqrestore(&feature_img_lock, flags);
+}
+
+static void del_feature_img_from_list(struct sspt_feature_img *fi)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&feature_img_lock, flags);
+ list_del(&fi->list);
+ spin_unlock_irqrestore(&feature_img_lock, flags);
+}
+
static struct sspt_feature_img *create_feature_img(void *(*alloc)(void),
void (*free)(void *data))
{
fi->alloc = alloc;
fi->free = free;
- /* add to list */
- list_add(&fi->list, &feature_list);
+ add_feature_img_to_list(fi);
}
return fi;
static void destroy_feature_img(struct sspt_feature_img *fi)
{
- /* delete from list */
- list_del(&fi->list);
+ del_feature_img_from_list(fi);
kfree(fi);
}