mic: vop: Fix use-after-free on remove
[linux/fpc-iii.git] / drivers / firmware / google / memconsole.c
blob166f07c68c02c895b93a8bd881516c3afcc92329
1 /*
2 * memconsole.c
4 * Architecture-independent parts of the memory based BIOS console.
6 * Copyright 2017 Google Inc.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License v2.0 as published by
10 * the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
18 #include <linux/init.h>
19 #include <linux/sysfs.h>
20 #include <linux/kobject.h>
21 #include <linux/module.h>
23 #include "memconsole.h"
25 static ssize_t (*memconsole_read_func)(char *, loff_t, size_t);
27 static ssize_t memconsole_read(struct file *filp, struct kobject *kobp,
28 struct bin_attribute *bin_attr, char *buf,
29 loff_t pos, size_t count)
31 if (WARN_ON_ONCE(!memconsole_read_func))
32 return -EIO;
33 return memconsole_read_func(buf, pos, count);
36 static struct bin_attribute memconsole_bin_attr = {
37 .attr = {.name = "log", .mode = 0444},
38 .read = memconsole_read,
41 void memconsole_setup(ssize_t (*read_func)(char *, loff_t, size_t))
43 memconsole_read_func = read_func;
45 EXPORT_SYMBOL(memconsole_setup);
47 int memconsole_sysfs_init(void)
49 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
51 EXPORT_SYMBOL(memconsole_sysfs_init);
53 void memconsole_exit(void)
55 sysfs_remove_bin_file(firmware_kobj, &memconsole_bin_attr);
57 EXPORT_SYMBOL(memconsole_exit);
59 MODULE_AUTHOR("Google, Inc.");
60 MODULE_LICENSE("GPL");