]>
Commit | Line | Data |
---|---|---|
526b4af4 | 1 | /* |
5baa1be1 | 2 | * custom_method.c - debugfs interface for customizing ACPI control method |
526b4af4 TR |
3 | */ |
4 | ||
5 | #include <linux/init.h> | |
6 | #include <linux/module.h> | |
7 | #include <linux/kernel.h> | |
8 | #include <linux/uaccess.h> | |
9 | #include <linux/debugfs.h> | |
8b48463f | 10 | #include <linux/acpi.h> |
526b4af4 TR |
11 | |
12 | #include "internal.h" | |
13 | ||
14 | #define _COMPONENT ACPI_SYSTEM_COMPONENT | |
15 | ACPI_MODULE_NAME("custom_method"); | |
16 | MODULE_LICENSE("GPL"); | |
17 | ||
18 | static struct dentry *cm_dentry; | |
19 | ||
20 | /* /sys/kernel/debug/acpi/custom_method */ | |
21 | ||
22 | static ssize_t cm_write(struct file *file, const char __user * user_buf, | |
23 | size_t count, loff_t *ppos) | |
24 | { | |
25 | static char *buf; | |
26 | static u32 max_size; | |
27 | static u32 uncopied_bytes; | |
28 | ||
29 | struct acpi_table_header table; | |
30 | acpi_status status; | |
31 | ||
3c2c82a3 MG |
32 | if (secure_modules()) |
33 | return -EPERM; | |
34 | ||
526b4af4 TR |
35 | if (!(*ppos)) { |
36 | /* parse the table header to get the table length */ | |
37 | if (count <= sizeof(struct acpi_table_header)) | |
38 | return -EINVAL; | |
39 | if (copy_from_user(&table, user_buf, | |
40 | sizeof(struct acpi_table_header))) | |
41 | return -EFAULT; | |
42 | uncopied_bytes = max_size = table.length; | |
43 | buf = kzalloc(max_size, GFP_KERNEL); | |
44 | if (!buf) | |
45 | return -ENOMEM; | |
46 | } | |
47 | ||
48 | if (buf == NULL) | |
49 | return -EINVAL; | |
50 | ||
51 | if ((*ppos > max_size) || | |
52 | (*ppos + count > max_size) || | |
53 | (*ppos + count < count) || | |
54 | (count > uncopied_bytes)) | |
55 | return -EINVAL; | |
56 | ||
57 | if (copy_from_user(buf + (*ppos), user_buf, count)) { | |
58 | kfree(buf); | |
59 | buf = NULL; | |
60 | return -EFAULT; | |
61 | } | |
62 | ||
63 | uncopied_bytes -= count; | |
64 | *ppos += count; | |
65 | ||
66 | if (!uncopied_bytes) { | |
67 | status = acpi_install_method(buf); | |
68 | kfree(buf); | |
69 | buf = NULL; | |
70 | if (ACPI_FAILURE(status)) | |
71 | return -EINVAL; | |
373d4d09 | 72 | add_taint(TAINT_OVERRIDDEN_ACPI_TABLE, LOCKDEP_NOW_UNRELIABLE); |
526b4af4 TR |
73 | } |
74 | ||
75 | return count; | |
76 | } | |
77 | ||
78 | static const struct file_operations cm_fops = { | |
79 | .write = cm_write, | |
80 | .llseek = default_llseek, | |
81 | }; | |
82 | ||
83 | static int __init acpi_custom_method_init(void) | |
84 | { | |
85 | if (acpi_debugfs_dir == NULL) | |
86 | return -ENOENT; | |
87 | ||
88 | cm_dentry = debugfs_create_file("custom_method", S_IWUSR, | |
89 | acpi_debugfs_dir, NULL, &cm_fops); | |
90 | if (cm_dentry == NULL) | |
91 | return -ENODEV; | |
92 | ||
93 | return 0; | |
94 | } | |
95 | ||
96 | static void __exit acpi_custom_method_exit(void) | |
97 | { | |
98 | if (cm_dentry) | |
99 | debugfs_remove(cm_dentry); | |
100 | } | |
101 | ||
102 | module_init(acpi_custom_method_init); | |
103 | module_exit(acpi_custom_method_exit); |