[MIPS] Remove unused system type name for DDB5074 and DDB5476.
[linux-2.6/linux-mips.git] / fs / jffs2 / malloc.c
blob036cbd11c00449d6755481b8a51e53bbf0f7fb4f
1 /*
2 * JFFS2 -- Journalling Flash File System, Version 2.
4 * Copyright (C) 2001-2003 Red Hat, Inc.
6 * Created by David Woodhouse <dwmw2@infradead.org>
8 * For licensing information, see the file 'LICENCE' in this directory.
10 * $Id: malloc.c,v 1.31 2005/11/07 11:14:40 gleixner Exp $
14 #include <linux/kernel.h>
15 #include <linux/slab.h>
16 #include <linux/init.h>
17 #include <linux/jffs2.h>
18 #include "nodelist.h"
20 /* These are initialised to NULL in the kernel startup code.
21 If you're porting to other operating systems, beware */
22 static kmem_cache_t *full_dnode_slab;
23 static kmem_cache_t *raw_dirent_slab;
24 static kmem_cache_t *raw_inode_slab;
25 static kmem_cache_t *tmp_dnode_info_slab;
26 static kmem_cache_t *raw_node_ref_slab;
27 static kmem_cache_t *node_frag_slab;
28 static kmem_cache_t *inode_cache_slab;
30 int __init jffs2_create_slab_caches(void)
32 full_dnode_slab = kmem_cache_create("jffs2_full_dnode",
33 sizeof(struct jffs2_full_dnode),
34 0, 0, NULL, NULL);
35 if (!full_dnode_slab)
36 goto err;
38 raw_dirent_slab = kmem_cache_create("jffs2_raw_dirent",
39 sizeof(struct jffs2_raw_dirent),
40 0, 0, NULL, NULL);
41 if (!raw_dirent_slab)
42 goto err;
44 raw_inode_slab = kmem_cache_create("jffs2_raw_inode",
45 sizeof(struct jffs2_raw_inode),
46 0, 0, NULL, NULL);
47 if (!raw_inode_slab)
48 goto err;
50 tmp_dnode_info_slab = kmem_cache_create("jffs2_tmp_dnode",
51 sizeof(struct jffs2_tmp_dnode_info),
52 0, 0, NULL, NULL);
53 if (!tmp_dnode_info_slab)
54 goto err;
56 raw_node_ref_slab = kmem_cache_create("jffs2_raw_node_ref",
57 sizeof(struct jffs2_raw_node_ref),
58 0, 0, NULL, NULL);
59 if (!raw_node_ref_slab)
60 goto err;
62 node_frag_slab = kmem_cache_create("jffs2_node_frag",
63 sizeof(struct jffs2_node_frag),
64 0, 0, NULL, NULL);
65 if (!node_frag_slab)
66 goto err;
68 inode_cache_slab = kmem_cache_create("jffs2_inode_cache",
69 sizeof(struct jffs2_inode_cache),
70 0, 0, NULL, NULL);
71 if (inode_cache_slab)
72 return 0;
73 err:
74 jffs2_destroy_slab_caches();
75 return -ENOMEM;
78 void jffs2_destroy_slab_caches(void)
80 if(full_dnode_slab)
81 kmem_cache_destroy(full_dnode_slab);
82 if(raw_dirent_slab)
83 kmem_cache_destroy(raw_dirent_slab);
84 if(raw_inode_slab)
85 kmem_cache_destroy(raw_inode_slab);
86 if(tmp_dnode_info_slab)
87 kmem_cache_destroy(tmp_dnode_info_slab);
88 if(raw_node_ref_slab)
89 kmem_cache_destroy(raw_node_ref_slab);
90 if(node_frag_slab)
91 kmem_cache_destroy(node_frag_slab);
92 if(inode_cache_slab)
93 kmem_cache_destroy(inode_cache_slab);
96 struct jffs2_full_dirent *jffs2_alloc_full_dirent(int namesize)
98 struct jffs2_full_dirent *ret;
99 ret = kmalloc(sizeof(struct jffs2_full_dirent) + namesize, GFP_KERNEL);
100 dbg_memalloc("%p\n", ret);
101 return ret;
104 void jffs2_free_full_dirent(struct jffs2_full_dirent *x)
106 dbg_memalloc("%p\n", x);
107 kfree(x);
110 struct jffs2_full_dnode *jffs2_alloc_full_dnode(void)
112 struct jffs2_full_dnode *ret;
113 ret = kmem_cache_alloc(full_dnode_slab, GFP_KERNEL);
114 dbg_memalloc("%p\n", ret);
115 return ret;
118 void jffs2_free_full_dnode(struct jffs2_full_dnode *x)
120 dbg_memalloc("%p\n", x);
121 kmem_cache_free(full_dnode_slab, x);
124 struct jffs2_raw_dirent *jffs2_alloc_raw_dirent(void)
126 struct jffs2_raw_dirent *ret;
127 ret = kmem_cache_alloc(raw_dirent_slab, GFP_KERNEL);
128 dbg_memalloc("%p\n", ret);
129 return ret;
132 void jffs2_free_raw_dirent(struct jffs2_raw_dirent *x)
134 dbg_memalloc("%p\n", x);
135 kmem_cache_free(raw_dirent_slab, x);
138 struct jffs2_raw_inode *jffs2_alloc_raw_inode(void)
140 struct jffs2_raw_inode *ret;
141 ret = kmem_cache_alloc(raw_inode_slab, GFP_KERNEL);
142 dbg_memalloc("%p\n", ret);
143 return ret;
146 void jffs2_free_raw_inode(struct jffs2_raw_inode *x)
148 dbg_memalloc("%p\n", x);
149 kmem_cache_free(raw_inode_slab, x);
152 struct jffs2_tmp_dnode_info *jffs2_alloc_tmp_dnode_info(void)
154 struct jffs2_tmp_dnode_info *ret;
155 ret = kmem_cache_alloc(tmp_dnode_info_slab, GFP_KERNEL);
156 dbg_memalloc("%p\n",
157 ret);
158 return ret;
161 void jffs2_free_tmp_dnode_info(struct jffs2_tmp_dnode_info *x)
163 dbg_memalloc("%p\n", x);
164 kmem_cache_free(tmp_dnode_info_slab, x);
167 struct jffs2_raw_node_ref *jffs2_alloc_raw_node_ref(void)
169 struct jffs2_raw_node_ref *ret;
170 ret = kmem_cache_alloc(raw_node_ref_slab, GFP_KERNEL);
171 dbg_memalloc("%p\n", ret);
172 return ret;
175 void jffs2_free_raw_node_ref(struct jffs2_raw_node_ref *x)
177 dbg_memalloc("%p\n", x);
178 kmem_cache_free(raw_node_ref_slab, x);
181 struct jffs2_node_frag *jffs2_alloc_node_frag(void)
183 struct jffs2_node_frag *ret;
184 ret = kmem_cache_alloc(node_frag_slab, GFP_KERNEL);
185 dbg_memalloc("%p\n", ret);
186 return ret;
189 void jffs2_free_node_frag(struct jffs2_node_frag *x)
191 dbg_memalloc("%p\n", x);
192 kmem_cache_free(node_frag_slab, x);
195 struct jffs2_inode_cache *jffs2_alloc_inode_cache(void)
197 struct jffs2_inode_cache *ret;
198 ret = kmem_cache_alloc(inode_cache_slab, GFP_KERNEL);
199 dbg_memalloc("%p\n", ret);
200 return ret;
203 void jffs2_free_inode_cache(struct jffs2_inode_cache *x)
205 dbg_memalloc("%p\n", x);
206 kmem_cache_free(inode_cache_slab, x);