blob: 40c8c2e32fa3e5617c818e782eed34ea61670d29 [file] [log] [blame]
Thomas Gleixner09c434b2019-05-19 13:08:20 +01001// SPDX-License-Identifier: GPL-2.0-only
David S. Miller3d824a42006-06-25 23:19:14 -07002/* inode.c: /proc/openprom handling routines
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Copyright (C) 1996-1999 Jakub Jelinek (jakub@redhat.com)
5 * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
6 */
7
8#include <linux/module.h>
9#include <linux/types.h>
10#include <linux/string.h>
11#include <linux/fs.h>
David Howells7ab2fa72019-03-25 16:38:30 +000012#include <linux/fs_context.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/init.h>
14#include <linux/slab.h>
David S. Miller3d824a42006-06-25 23:19:14 -070015#include <linux/seq_file.h>
Jeff Garzike18fa702006-09-24 11:13:19 -040016#include <linux/magic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18#include <asm/openprom.h>
19#include <asm/oplib.h>
David S. Miller3d824a42006-06-25 23:19:14 -070020#include <asm/prom.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080021#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
David S. Miller3d824a42006-06-25 23:19:14 -070023static DEFINE_MUTEX(op_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
David S. Miller3d824a42006-06-25 23:19:14 -070025#define OPENPROM_ROOT_INO 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
David S. Miller3d824a42006-06-25 23:19:14 -070027enum op_inode_type {
28 op_inode_node,
29 op_inode_prop,
30};
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
David S. Miller3d824a42006-06-25 23:19:14 -070032union op_inode_data {
33 struct device_node *node;
34 struct property *prop;
35};
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
David S. Miller3d824a42006-06-25 23:19:14 -070037struct op_inode_info {
38 struct inode vfs_inode;
39 enum op_inode_type type;
40 union op_inode_data u;
41};
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
David Howellsb88a27e2008-02-07 00:15:49 -080043static struct inode *openprom_iget(struct super_block *sb, ino_t ino);
44
David S. Miller3d824a42006-06-25 23:19:14 -070045static inline struct op_inode_info *OP_I(struct inode *inode)
Jan Engelhardta04ee142006-06-25 05:47:36 -070046{
David S. Miller3d824a42006-06-25 23:19:14 -070047 return container_of(inode, struct op_inode_info, vfs_inode);
Jan Engelhardta04ee142006-06-25 05:47:36 -070048}
49
David S. Miller3d824a42006-06-25 23:19:14 -070050static int is_string(unsigned char *p, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051{
David S. Miller3d824a42006-06-25 23:19:14 -070052 int i;
53
54 for (i = 0; i < len; i++) {
55 unsigned char val = p[i];
56
57 if ((i && !val) ||
58 (val >= ' ' && val <= '~'))
59 continue;
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 return 0;
David S. Miller3d824a42006-06-25 23:19:14 -070062 }
63
64 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065}
66
David S. Miller3d824a42006-06-25 23:19:14 -070067static int property_show(struct seq_file *f, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
David S. Miller3d824a42006-06-25 23:19:14 -070069 struct property *prop = f->private;
70 void *pval;
71 int len;
72
73 len = prop->length;
74 pval = prop->value;
75
76 if (is_string(pval, len)) {
77 while (len > 0) {
78 int n = strlen(pval);
79
80 seq_printf(f, "%s", (char *) pval);
81
82 /* Skip over the NULL byte too. */
83 pval += n + 1;
84 len -= n + 1;
85
86 if (len > 0)
87 seq_printf(f, " + ");
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 } else {
David S. Miller3d824a42006-06-25 23:19:14 -070090 if (len & 3) {
91 while (len) {
92 len--;
93 if (len)
94 seq_printf(f, "%02x.",
95 *(unsigned char *) pval);
96 else
97 seq_printf(f, "%02x",
98 *(unsigned char *) pval);
99 pval++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 }
101 } else {
David S. Miller3d824a42006-06-25 23:19:14 -0700102 while (len >= 4) {
103 len -= 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
David S. Miller3d824a42006-06-25 23:19:14 -0700105 if (len)
106 seq_printf(f, "%08x.",
107 *(unsigned int *) pval);
108 else
109 seq_printf(f, "%08x",
110 *(unsigned int *) pval);
111 pval += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 }
113 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 }
David S. Miller3d824a42006-06-25 23:19:14 -0700115 seq_printf(f, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 return 0;
118}
119
David S. Miller3d824a42006-06-25 23:19:14 -0700120static void *property_start(struct seq_file *f, loff_t *pos)
121{
122 if (*pos == 0)
123 return pos;
124 return NULL;
125}
126
127static void *property_next(struct seq_file *f, void *v, loff_t *pos)
128{
129 (*pos)++;
130 return NULL;
131}
132
133static void property_stop(struct seq_file *f, void *v)
134{
135 /* Nothing to do */
136}
137
Jan Engelhardt872e2be2008-01-22 18:29:20 -0800138static const struct seq_operations property_op = {
David S. Miller3d824a42006-06-25 23:19:14 -0700139 .start = property_start,
140 .next = property_next,
141 .stop = property_stop,
142 .show = property_show
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143};
144
David S. Miller3d824a42006-06-25 23:19:14 -0700145static int property_open(struct inode *inode, struct file *file)
146{
147 struct op_inode_info *oi = OP_I(inode);
148 int ret;
149
150 BUG_ON(oi->type != op_inode_prop);
151
152 ret = seq_open(file, &property_op);
153 if (!ret) {
154 struct seq_file *m = file->private_data;
155 m->private = oi->u.prop;
156 }
157 return ret;
158}
159
160static const struct file_operations openpromfs_prop_ops = {
161 .open = property_open,
162 .read = seq_read,
163 .llseek = seq_lseek,
164 .release = seq_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165};
166
Al Viro68c61472013-05-16 01:52:12 -0400167static int openpromfs_readdir(struct file *, struct dir_context *);
David S. Miller3d824a42006-06-25 23:19:14 -0700168
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800169static const struct file_operations openprom_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 .read = generic_read_dir,
Al Viroc51da202016-04-30 22:37:34 -0400171 .iterate_shared = openpromfs_readdir,
Christoph Hellwig3222a3e2008-09-03 21:53:01 +0200172 .llseek = generic_file_llseek,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173};
174
Al Viro00cd8dd2012-06-10 17:13:09 -0400175static struct dentry *openpromfs_lookup(struct inode *, struct dentry *, unsigned int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
Arjan van de Ven92e1d5b2007-02-12 00:55:39 -0800177static const struct inode_operations openprom_inode_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 .lookup = openpromfs_lookup,
179};
180
Al Viro00cd8dd2012-06-10 17:13:09 -0400181static struct dentry *openpromfs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182{
David S. Miller3d824a42006-06-25 23:19:14 -0700183 struct op_inode_info *ent_oi, *oi = OP_I(dir);
184 struct device_node *dp, *child;
185 struct property *prop;
186 enum op_inode_type ent_type;
187 union op_inode_data ent_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 const char *name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 struct inode *inode;
David S. Miller3d824a42006-06-25 23:19:14 -0700190 unsigned int ino;
191 int len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
David S. Miller3d824a42006-06-25 23:19:14 -0700193 BUG_ON(oi->type != op_inode_node);
194
195 dp = oi->u.node;
196
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 name = dentry->d_name.name;
198 len = dentry->d_name.len;
David S. Miller3d824a42006-06-25 23:19:14 -0700199
200 mutex_lock(&op_mutex);
201
202 child = dp->child;
203 while (child) {
Rob Herring105e9962018-11-16 15:06:52 -0600204 const char *node_name = kbasename(child->full_name);
205 int n = strlen(node_name);
David S. Miller3d824a42006-06-25 23:19:14 -0700206
207 if (len == n &&
Rob Herring105e9962018-11-16 15:06:52 -0600208 !strncmp(node_name, name, len)) {
David S. Miller3d824a42006-06-25 23:19:14 -0700209 ent_type = op_inode_node;
210 ent_data.node = child;
211 ino = child->unique_id;
212 goto found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 }
David S. Miller3d824a42006-06-25 23:19:14 -0700214 child = child->sibling;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 }
David S. Miller3d824a42006-06-25 23:19:14 -0700216
217 prop = dp->properties;
218 while (prop) {
219 int n = strlen(prop->name);
220
221 if (len == n && !strncmp(prop->name, name, len)) {
222 ent_type = op_inode_prop;
223 ent_data.prop = prop;
224 ino = prop->unique_id;
225 goto found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 }
David S. Miller3d824a42006-06-25 23:19:14 -0700227
228 prop = prop->next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 }
David S. Miller3d824a42006-06-25 23:19:14 -0700230
231 mutex_unlock(&op_mutex);
232 return ERR_PTR(-ENOENT);
233
234found:
David Howellsb88a27e2008-02-07 00:15:49 -0800235 inode = openprom_iget(dir->i_sb, ino);
David S. Miller3d824a42006-06-25 23:19:14 -0700236 mutex_unlock(&op_mutex);
David Howellsb88a27e2008-02-07 00:15:49 -0800237 if (IS_ERR(inode))
238 return ERR_CAST(inode);
David S. Miller3d824a42006-06-25 23:19:14 -0700239 ent_oi = OP_I(inode);
240 ent_oi->type = ent_type;
241 ent_oi->u = ent_data;
242
243 switch (ent_type) {
244 case op_inode_node:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO;
David S. Miller3d824a42006-06-25 23:19:14 -0700246 inode->i_op = &openprom_inode_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 inode->i_fop = &openprom_operations;
Miklos Szeredibfe86842011-10-28 14:13:29 +0200248 set_nlink(inode, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 break;
David S. Miller3d824a42006-06-25 23:19:14 -0700250 case op_inode_prop:
Rob Herringf3180e12018-11-16 15:06:53 -0600251 if (of_node_name_eq(dp, "options") && (len == 17) &&
David S. Miller3d824a42006-06-25 23:19:14 -0700252 !strncmp (name, "security-password", 17))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 inode->i_mode = S_IFREG | S_IRUSR | S_IWUSR;
David S. Miller3d824a42006-06-25 23:19:14 -0700254 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 inode->i_mode = S_IFREG | S_IRUGO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 inode->i_fop = &openpromfs_prop_ops;
Miklos Szeredibfe86842011-10-28 14:13:29 +0200257 set_nlink(inode, 1);
David S. Miller3d824a42006-06-25 23:19:14 -0700258 inode->i_size = ent_oi->u.prop->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 break;
260 }
261
Al Viro0ed883f2018-05-03 09:46:23 -0400262 return d_splice_alias(inode, dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263}
264
Al Viro68c61472013-05-16 01:52:12 -0400265static int openpromfs_readdir(struct file *file, struct dir_context *ctx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266{
Al Viro68c61472013-05-16 01:52:12 -0400267 struct inode *inode = file_inode(file);
David S. Miller3d824a42006-06-25 23:19:14 -0700268 struct op_inode_info *oi = OP_I(inode);
269 struct device_node *dp = oi->u.node;
270 struct device_node *child;
271 struct property *prop;
David S. Miller3d824a42006-06-25 23:19:14 -0700272 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
David S. Miller3d824a42006-06-25 23:19:14 -0700274 mutex_lock(&op_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
Al Viro68c61472013-05-16 01:52:12 -0400276 if (ctx->pos == 0) {
277 if (!dir_emit(ctx, ".", 1, inode->i_ino, DT_DIR))
David S. Miller3d824a42006-06-25 23:19:14 -0700278 goto out;
Al Viro68c61472013-05-16 01:52:12 -0400279 ctx->pos = 1;
280 }
281 if (ctx->pos == 1) {
282 if (!dir_emit(ctx, "..", 2,
David S. Miller3d824a42006-06-25 23:19:14 -0700283 (dp->parent == NULL ?
284 OPENPROM_ROOT_INO :
Al Viro68c61472013-05-16 01:52:12 -0400285 dp->parent->unique_id), DT_DIR))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 goto out;
Al Viro68c61472013-05-16 01:52:12 -0400287 ctx->pos = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 }
Al Viro68c61472013-05-16 01:52:12 -0400289 i = ctx->pos - 2;
290
291 /* First, the children nodes as directories. */
292 child = dp->child;
293 while (i && child) {
294 child = child->sibling;
295 i--;
296 }
297 while (child) {
298 if (!dir_emit(ctx,
Rob Herring105e9962018-11-16 15:06:52 -0600299 kbasename(child->full_name),
300 strlen(kbasename(child->full_name)),
Al Viro68c61472013-05-16 01:52:12 -0400301 child->unique_id, DT_DIR))
302 goto out;
303
304 ctx->pos++;
305 child = child->sibling;
306 }
307
308 /* Next, the properties as files. */
309 prop = dp->properties;
310 while (i && prop) {
311 prop = prop->next;
312 i--;
313 }
314 while (prop) {
315 if (!dir_emit(ctx, prop->name, strlen(prop->name),
316 prop->unique_id, DT_REG))
317 goto out;
318
319 ctx->pos++;
320 prop = prop->next;
321 }
322
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323out:
David S. Miller3d824a42006-06-25 23:19:14 -0700324 mutex_unlock(&op_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 return 0;
326}
327
Christoph Lametere18b8902006-12-06 20:33:20 -0800328static struct kmem_cache *op_inode_cachep;
David S. Miller3d824a42006-06-25 23:19:14 -0700329
330static struct inode *openprom_alloc_inode(struct super_block *sb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331{
David S. Miller3d824a42006-06-25 23:19:14 -0700332 struct op_inode_info *oi;
333
Christoph Lametere94b1762006-12-06 20:33:17 -0800334 oi = kmem_cache_alloc(op_inode_cachep, GFP_KERNEL);
David S. Miller3d824a42006-06-25 23:19:14 -0700335 if (!oi)
336 return NULL;
337
338 return &oi->vfs_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339}
340
Al Viro363db952019-04-15 20:27:27 -0400341static void openprom_free_inode(struct inode *inode)
Nick Pigginfa0d7e3d2011-01-07 17:49:49 +1100342{
Nick Pigginfa0d7e3d2011-01-07 17:49:49 +1100343 kmem_cache_free(op_inode_cachep, OP_I(inode));
344}
345
David Howellsb88a27e2008-02-07 00:15:49 -0800346static struct inode *openprom_iget(struct super_block *sb, ino_t ino)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347{
David Howellsb88a27e2008-02-07 00:15:49 -0800348 struct inode *inode;
349
350 inode = iget_locked(sb, ino);
351 if (!inode)
352 return ERR_PTR(-ENOMEM);
353 if (inode->i_state & I_NEW) {
Deepa Dinamani078cd822016-09-14 07:48:04 -0700354 inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
David Howellsb88a27e2008-02-07 00:15:49 -0800355 if (inode->i_ino == OPENPROM_ROOT_INO) {
356 inode->i_op = &openprom_inode_operations;
357 inode->i_fop = &openprom_operations;
358 inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO;
359 }
360 unlock_new_inode(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 }
David Howellsb88a27e2008-02-07 00:15:49 -0800362 return inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363}
364
365static int openprom_remount(struct super_block *sb, int *flags, char *data)
366{
Theodore Ts'o02b99842014-03-13 10:14:33 -0400367 sync_filesystem(sb);
Linus Torvalds1751e8a2017-11-27 13:05:09 -0800368 *flags |= SB_NOATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 return 0;
370}
371
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800372static const struct super_operations openprom_sops = {
David S. Miller3d824a42006-06-25 23:19:14 -0700373 .alloc_inode = openprom_alloc_inode,
Al Viro363db952019-04-15 20:27:27 -0400374 .free_inode = openprom_free_inode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 .statfs = simple_statfs,
376 .remount_fs = openprom_remount,
377};
378
David Howells7ab2fa72019-03-25 16:38:30 +0000379static int openprom_fill_super(struct super_block *s, struct fs_context *fc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380{
David S. Miller3d824a42006-06-25 23:19:14 -0700381 struct inode *root_inode;
382 struct op_inode_info *oi;
David Howellsb88a27e2008-02-07 00:15:49 -0800383 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
Linus Torvalds1751e8a2017-11-27 13:05:09 -0800385 s->s_flags |= SB_NOATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 s->s_blocksize = 1024;
387 s->s_blocksize_bits = 10;
388 s->s_magic = OPENPROM_SUPER_MAGIC;
389 s->s_op = &openprom_sops;
390 s->s_time_gran = 1;
David Howellsb88a27e2008-02-07 00:15:49 -0800391 root_inode = openprom_iget(s, OPENPROM_ROOT_INO);
392 if (IS_ERR(root_inode)) {
393 ret = PTR_ERR(root_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 goto out_no_root;
David Howellsb88a27e2008-02-07 00:15:49 -0800395 }
David S. Miller3d824a42006-06-25 23:19:14 -0700396
397 oi = OP_I(root_inode);
398 oi->type = op_inode_node;
399 oi->u.node = of_find_node_by_path("/");
400
Al Viro48fde702012-01-08 22:15:13 -0500401 s->s_root = d_make_root(root_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 if (!s->s_root)
David Howellsb88a27e2008-02-07 00:15:49 -0800403 goto out_no_root_dentry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 return 0;
405
David Howellsb88a27e2008-02-07 00:15:49 -0800406out_no_root_dentry:
David Howellsb88a27e2008-02-07 00:15:49 -0800407 ret = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408out_no_root:
409 printk("openprom_fill_super: get root inode failed\n");
David Howellsb88a27e2008-02-07 00:15:49 -0800410 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411}
412
David Howells7ab2fa72019-03-25 16:38:30 +0000413static int openpromfs_get_tree(struct fs_context *fc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414{
David Howells7ab2fa72019-03-25 16:38:30 +0000415 return get_tree_single(fc, openprom_fill_super);
416}
417
418static const struct fs_context_operations openpromfs_context_ops = {
419 .get_tree = openpromfs_get_tree,
420};
421
422static int openpromfs_init_fs_context(struct fs_context *fc)
423{
424 fc->ops = &openpromfs_context_ops;
425 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426}
427
428static struct file_system_type openprom_fs_type = {
429 .owner = THIS_MODULE,
430 .name = "openpromfs",
David Howells7ab2fa72019-03-25 16:38:30 +0000431 .init_fs_context = openpromfs_init_fs_context,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 .kill_sb = kill_anon_super,
433};
Eric W. Biederman7f78e032013-03-02 19:39:14 -0800434MODULE_ALIAS_FS("openpromfs");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
Alexey Dobriyan51cc5062008-07-25 19:45:34 -0700436static void op_inode_init_once(void *data)
David S. Miller3d824a42006-06-25 23:19:14 -0700437{
438 struct op_inode_info *oi = (struct op_inode_info *) data;
439
Christoph Lametera35afb82007-05-16 22:10:57 -0700440 inode_init_once(&oi->vfs_inode);
David S. Miller3d824a42006-06-25 23:19:14 -0700441}
442
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443static int __init init_openprom_fs(void)
444{
David S. Miller3d824a42006-06-25 23:19:14 -0700445 int err;
446
447 op_inode_cachep = kmem_cache_create("op_inode_cache",
448 sizeof(struct op_inode_info),
449 0,
450 (SLAB_RECLAIM_ACCOUNT |
Vladimir Davydov5d097052016-01-14 15:18:21 -0800451 SLAB_MEM_SPREAD | SLAB_ACCOUNT),
Paul Mundt20c2df82007-07-20 10:11:58 +0900452 op_inode_init_once);
David S. Miller3d824a42006-06-25 23:19:14 -0700453 if (!op_inode_cachep)
454 return -ENOMEM;
455
456 err = register_filesystem(&openprom_fs_type);
457 if (err)
458 kmem_cache_destroy(op_inode_cachep);
459
460 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461}
462
463static void __exit exit_openprom_fs(void)
464{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 unregister_filesystem(&openprom_fs_type);
Kirill A. Shutemov8c0a8532012-09-26 11:33:07 +1000466 /*
467 * Make sure all delayed rcu free inodes are flushed before we
468 * destroy cache.
469 */
470 rcu_barrier();
David S. Miller3d824a42006-06-25 23:19:14 -0700471 kmem_cache_destroy(op_inode_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472}
473
474module_init(init_openprom_fs)
475module_exit(exit_openprom_fs)
476MODULE_LICENSE("GPL");