#include "util.h"
#include "fs.h"
#include "handle.h"
+#include "match.h"
#include "metadata.h"
#include "node.h"
if (!kdbus_dir)
return -ENOMEM;
+ ret = kdbus_init_cache_create();
+ if (ret < 0)
+ goto exit_dir;
+
ret = kdbus_fs_init();
if (ret < 0) {
pr_err("cannot register filesystem: %d\n", ret);
- goto exit_dir;
+ goto exit_cache;
}
pr_info("initialized\n");
return 0;
+exit_cache:
+ kdbus_init_cache_destroy();
exit_dir:
kobject_put(kdbus_dir);
return ret;
static void __exit kdbus_exit(void)
{
kdbus_fs_exit();
+ kdbus_init_cache_destroy();
kobject_put(kdbus_dir);
ida_destroy(&kdbus_node_ida);
}
struct list_head rules_entry;
};
+struct kmem_cache *kdbus_match_entry_cachep, *kdbus_match_rule_cachep;
+
+int kdbus_init_cache_create(void)
+{
+ kdbus_match_entry_cachep = kmem_cache_create("kdbus_match_entry_cache",
+ sizeof(struct kdbus_match_entry), 0, 0, NULL);
+ if (!kdbus_match_entry_cachep)
+ return -ENOMEM;
+ kdbus_match_rule_cachep = kmem_cache_create("kdbus_match_rule_cache",
+ sizeof(struct kdbus_match_rule), 0, 0, NULL);
+ if (!kdbus_match_rule_cachep) {
+ kmem_cache_destroy(kdbus_match_entry_cachep);
+ return -ENOMEM;
+ }
+ return 0;
+}
+
+void kdbus_init_cache_destroy(void)
+{
+ if (kdbus_match_entry_cachep) {
+ kmem_cache_destroy(kdbus_match_entry_cachep);
+ kdbus_match_entry_cachep = NULL;
+ }
+ if (kdbus_match_rule_cachep) {
+ kmem_cache_destroy(kdbus_match_rule_cachep);
+ kdbus_match_rule_cachep = NULL;
+ }
+}
+
static void kdbus_match_rule_free(struct kdbus_match_rule *rule)
{
if (!rule)
}
list_del(&rule->rules_entry);
- kfree(rule);
+ kmem_cache_free(kdbus_match_rule_cachep, rule);
}
static void kdbus_match_entry_free(struct kdbus_match_entry *entry)
kdbus_match_rule_free(r);
list_del(&entry->list_entry);
- kfree(entry);
+ kmem_cache_free(kdbus_match_entry_cachep, entry);
}
/**
if (ret != 0)
return ret;
- entry = kzalloc(sizeof(*entry), GFP_KERNEL);
+ entry = kmem_cache_zalloc(kdbus_match_entry_cachep, GFP_KERNEL);
if (!entry) {
ret = -ENOMEM;
goto exit;
struct kdbus_match_rule *rule;
size_t size = item->size - offsetof(struct kdbus_item, data);
- rule = kzalloc(sizeof(*rule), GFP_KERNEL);
+ rule = kmem_cache_zalloc(kdbus_match_rule_cachep, GFP_KERNEL);
if (!rule) {
ret = -ENOMEM;
goto exit;