Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * drivers/s390/cio/blacklist.c |
| 3 | * S/390 common I/O routines -- blacklisting of specific devices |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 1999-2002 IBM Deutschland Entwicklung GmbH, |
| 6 | * IBM Corporation |
| 7 | * Author(s): Ingo Adlung (adlung@de.ibm.com) |
Cornelia Huck | 4ce3b30 | 2006-01-14 13:21:04 -0800 | [diff] [blame] | 8 | * Cornelia Huck (cornelia.huck@de.ibm.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * Arnd Bergmann (arndb@de.ibm.com) |
| 10 | */ |
| 11 | |
Michael Ernst | e6d5a42 | 2008-12-25 13:39:36 +0100 | [diff] [blame] | 12 | #define KMSG_COMPONENT "cio" |
| 13 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/init.h> |
| 16 | #include <linux/vmalloc.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/proc_fs.h> |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 19 | #include <linux/seq_file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/ctype.h> |
| 21 | #include <linux/device.h> |
| 22 | |
| 23 | #include <asm/cio.h> |
| 24 | #include <asm/uaccess.h> |
| 25 | |
| 26 | #include "blacklist.h" |
| 27 | #include "cio.h" |
| 28 | #include "cio_debug.h" |
| 29 | #include "css.h" |
Peter Oberparleiter | ecf5d9e | 2008-10-10 21:33:06 +0200 | [diff] [blame] | 30 | #include "device.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
| 32 | /* |
| 33 | * "Blacklisting" of certain devices: |
| 34 | * Device numbers given in the commandline as cio_ignore=... won't be known |
| 35 | * to Linux. |
| 36 | * |
| 37 | * These can be single devices or ranges of devices |
| 38 | */ |
| 39 | |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 40 | /* 65536 bits for each set to indicate if a devno is blacklisted or not */ |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 41 | #define __BL_DEV_WORDS ((__MAX_SUBCHANNEL + (8*sizeof(long) - 1)) / \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | (8*sizeof(long))) |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 43 | static unsigned long bl_dev[__MAX_SSID + 1][__BL_DEV_WORDS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | typedef enum {add, free} range_action; |
| 45 | |
| 46 | /* |
| 47 | * Function: blacklist_range |
| 48 | * (Un-)blacklist the devices from-to |
| 49 | */ |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 50 | static int blacklist_range(range_action action, unsigned int from_ssid, |
| 51 | unsigned int to_ssid, unsigned int from, |
| 52 | unsigned int to, int msgtrigger) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | { |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 54 | if ((from_ssid > to_ssid) || ((from_ssid == to_ssid) && (from > to))) { |
| 55 | if (msgtrigger) |
Michael Ernst | e6d5a42 | 2008-12-25 13:39:36 +0100 | [diff] [blame] | 56 | pr_warning("0.%x.%04x to 0.%x.%04x is not a valid " |
| 57 | "range for cio_ignore\n", from_ssid, from, |
| 58 | to_ssid, to); |
| 59 | |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 60 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | } |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 62 | |
| 63 | while ((from_ssid < to_ssid) || ((from_ssid == to_ssid) && |
| 64 | (from <= to))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | if (action == add) |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 66 | set_bit(from, bl_dev[from_ssid]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | else |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 68 | clear_bit(from, bl_dev[from_ssid]); |
| 69 | from++; |
| 70 | if (from > __MAX_SUBCHANNEL) { |
| 71 | from_ssid++; |
| 72 | from = 0; |
| 73 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 79 | static int pure_hex(char **cp, unsigned int *val, int min_digit, |
| 80 | int max_digit, int max_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | { |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 82 | int diff; |
| 83 | unsigned int value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 85 | diff = 0; |
| 86 | *val = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 88 | while (isxdigit(**cp) && (diff <= max_digit)) { |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 89 | |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 90 | if (isdigit(**cp)) |
| 91 | value = **cp - '0'; |
| 92 | else |
| 93 | value = tolower(**cp) - 'a' + 10; |
| 94 | *val = *val * 16 + value; |
| 95 | (*cp)++; |
| 96 | diff++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | } |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 98 | |
| 99 | if ((diff < min_digit) || (diff > max_digit) || (*val > max_val)) |
| 100 | return 1; |
| 101 | |
| 102 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Cornelia Huck | 1282912 | 2008-06-10 10:03:19 +0200 | [diff] [blame] | 105 | static int parse_busid(char *str, unsigned int *cssid, unsigned int *ssid, |
| 106 | unsigned int *devno, int msgtrigger) |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 107 | { |
| 108 | char *str_work; |
| 109 | int val, rc, ret; |
| 110 | |
| 111 | rc = 1; |
| 112 | |
| 113 | if (*str == '\0') |
| 114 | goto out; |
| 115 | |
| 116 | /* old style */ |
| 117 | str_work = str; |
| 118 | val = simple_strtoul(str, &str_work, 16); |
| 119 | |
| 120 | if (*str_work == '\0') { |
| 121 | if (val <= __MAX_SUBCHANNEL) { |
| 122 | *devno = val; |
| 123 | *ssid = 0; |
| 124 | *cssid = 0; |
| 125 | rc = 0; |
| 126 | } |
| 127 | goto out; |
| 128 | } |
| 129 | |
| 130 | /* new style */ |
| 131 | str_work = str; |
| 132 | ret = pure_hex(&str_work, cssid, 1, 2, __MAX_CSSID); |
| 133 | if (ret || (str_work[0] != '.')) |
| 134 | goto out; |
| 135 | str_work++; |
| 136 | ret = pure_hex(&str_work, ssid, 1, 1, __MAX_SSID); |
| 137 | if (ret || (str_work[0] != '.')) |
| 138 | goto out; |
| 139 | str_work++; |
| 140 | ret = pure_hex(&str_work, devno, 4, 4, __MAX_SUBCHANNEL); |
| 141 | if (ret || (str_work[0] != '\0')) |
| 142 | goto out; |
| 143 | |
| 144 | rc = 0; |
| 145 | out: |
| 146 | if (rc && msgtrigger) |
Michael Ernst | e6d5a42 | 2008-12-25 13:39:36 +0100 | [diff] [blame] | 147 | pr_warning("%s is not a valid device for the cio_ignore " |
| 148 | "kernel parameter\n", str); |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 149 | |
| 150 | return rc; |
| 151 | } |
| 152 | |
| 153 | static int blacklist_parse_parameters(char *str, range_action action, |
| 154 | int msgtrigger) |
| 155 | { |
Cornelia Huck | 1282912 | 2008-06-10 10:03:19 +0200 | [diff] [blame] | 156 | unsigned int from_cssid, to_cssid, from_ssid, to_ssid, from, to; |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 157 | int rc, totalrc; |
| 158 | char *parm; |
| 159 | range_action ra; |
| 160 | |
| 161 | totalrc = 0; |
| 162 | |
| 163 | while ((parm = strsep(&str, ","))) { |
| 164 | rc = 0; |
| 165 | ra = action; |
| 166 | if (*parm == '!') { |
| 167 | if (ra == add) |
| 168 | ra = free; |
| 169 | else |
| 170 | ra = add; |
| 171 | parm++; |
| 172 | } |
| 173 | if (strcmp(parm, "all") == 0) { |
| 174 | from_cssid = 0; |
| 175 | from_ssid = 0; |
| 176 | from = 0; |
| 177 | to_cssid = __MAX_CSSID; |
| 178 | to_ssid = __MAX_SSID; |
| 179 | to = __MAX_SUBCHANNEL; |
| 180 | } else { |
| 181 | rc = parse_busid(strsep(&parm, "-"), &from_cssid, |
| 182 | &from_ssid, &from, msgtrigger); |
| 183 | if (!rc) { |
| 184 | if (parm != NULL) |
| 185 | rc = parse_busid(parm, &to_cssid, |
| 186 | &to_ssid, &to, |
| 187 | msgtrigger); |
| 188 | else { |
| 189 | to_cssid = from_cssid; |
| 190 | to_ssid = from_ssid; |
| 191 | to = from; |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | if (!rc) { |
| 196 | rc = blacklist_range(ra, from_ssid, to_ssid, from, to, |
| 197 | msgtrigger); |
| 198 | if (rc) |
Peter Oberparleiter | ecf5d9e | 2008-10-10 21:33:06 +0200 | [diff] [blame] | 199 | totalrc = -EINVAL; |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 200 | } else |
Peter Oberparleiter | ecf5d9e | 2008-10-10 21:33:06 +0200 | [diff] [blame] | 201 | totalrc = -EINVAL; |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | return totalrc; |
| 205 | } |
| 206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | static int __init |
| 208 | blacklist_setup (char *str) |
| 209 | { |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 210 | CIO_MSG_EVENT(6, "Reading blacklist parameters\n"); |
| 211 | if (blacklist_parse_parameters(str, add, 1)) |
| 212 | return 0; |
| 213 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | __setup ("cio_ignore=", blacklist_setup); |
| 217 | |
| 218 | /* Checking if devices are blacklisted */ |
| 219 | |
| 220 | /* |
| 221 | * Function: is_blacklisted |
| 222 | * Returns 1 if the given devicenumber can be found in the blacklist, |
| 223 | * otherwise 0. |
| 224 | * Used by validate_subchannel() |
| 225 | */ |
| 226 | int |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 227 | is_blacklisted (int ssid, int devno) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | { |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 229 | return test_bit (devno, bl_dev[ssid]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | #ifdef CONFIG_PROC_FS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | /* |
| 234 | * Function: blacklist_parse_proc_parameters |
| 235 | * parse the stuff which is piped to /proc/cio_ignore |
| 236 | */ |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 237 | static int blacklist_parse_proc_parameters(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | { |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 239 | int rc; |
| 240 | char *parm; |
| 241 | |
| 242 | parm = strsep(&buf, " "); |
| 243 | |
| 244 | if (strcmp("free", parm) == 0) |
| 245 | rc = blacklist_parse_parameters(buf, free, 0); |
| 246 | else if (strcmp("add", parm) == 0) |
| 247 | rc = blacklist_parse_parameters(buf, add, 0); |
Peter Oberparleiter | ecf5d9e | 2008-10-10 21:33:06 +0200 | [diff] [blame] | 248 | else if (strcmp("purge", parm) == 0) |
| 249 | return ccw_purge_blacklisted(); |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 250 | else |
Peter Oberparleiter | ecf5d9e | 2008-10-10 21:33:06 +0200 | [diff] [blame] | 251 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
Peter Oberparleiter | 40154b8 | 2006-06-29 14:57:03 +0200 | [diff] [blame] | 253 | css_schedule_reprobe(); |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 254 | |
| 255 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 258 | /* Iterator struct for all devices. */ |
| 259 | struct ccwdev_iter { |
| 260 | int devno; |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 261 | int ssid; |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 262 | int in_range; |
| 263 | }; |
| 264 | |
| 265 | static void * |
| 266 | cio_ignore_proc_seq_start(struct seq_file *s, loff_t *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | { |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 268 | struct ccwdev_iter *iter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 270 | if (*offset >= (__MAX_SUBCHANNEL + 1) * (__MAX_SSID + 1)) |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 271 | return NULL; |
Cornelia Huck | 3b79306 | 2006-01-06 00:19:26 -0800 | [diff] [blame] | 272 | iter = kzalloc(sizeof(struct ccwdev_iter), GFP_KERNEL); |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 273 | if (!iter) |
| 274 | return ERR_PTR(-ENOMEM); |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 275 | iter->ssid = *offset / (__MAX_SUBCHANNEL + 1); |
| 276 | iter->devno = *offset % (__MAX_SUBCHANNEL + 1); |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 277 | return iter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 280 | static void |
| 281 | cio_ignore_proc_seq_stop(struct seq_file *s, void *it) |
| 282 | { |
| 283 | if (!IS_ERR(it)) |
| 284 | kfree(it); |
| 285 | } |
| 286 | |
| 287 | static void * |
| 288 | cio_ignore_proc_seq_next(struct seq_file *s, void *it, loff_t *offset) |
| 289 | { |
| 290 | struct ccwdev_iter *iter; |
| 291 | |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 292 | if (*offset >= (__MAX_SUBCHANNEL + 1) * (__MAX_SSID + 1)) |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 293 | return NULL; |
Cornelia Huck | 3b79306 | 2006-01-06 00:19:26 -0800 | [diff] [blame] | 294 | iter = it; |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 295 | if (iter->devno == __MAX_SUBCHANNEL) { |
| 296 | iter->devno = 0; |
| 297 | iter->ssid++; |
| 298 | if (iter->ssid > __MAX_SSID) |
| 299 | return NULL; |
| 300 | } else |
| 301 | iter->devno++; |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 302 | (*offset)++; |
| 303 | return iter; |
| 304 | } |
| 305 | |
| 306 | static int |
| 307 | cio_ignore_proc_seq_show(struct seq_file *s, void *it) |
| 308 | { |
| 309 | struct ccwdev_iter *iter; |
| 310 | |
Cornelia Huck | 3b79306 | 2006-01-06 00:19:26 -0800 | [diff] [blame] | 311 | iter = it; |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 312 | if (!is_blacklisted(iter->ssid, iter->devno)) |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 313 | /* Not blacklisted, nothing to output. */ |
| 314 | return 0; |
| 315 | if (!iter->in_range) { |
| 316 | /* First device in range. */ |
| 317 | if ((iter->devno == __MAX_SUBCHANNEL) || |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 318 | !is_blacklisted(iter->ssid, iter->devno + 1)) |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 319 | /* Singular device. */ |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 320 | return seq_printf(s, "0.%x.%04x\n", |
| 321 | iter->ssid, iter->devno); |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 322 | iter->in_range = 1; |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 323 | return seq_printf(s, "0.%x.%04x-", iter->ssid, iter->devno); |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 324 | } |
| 325 | if ((iter->devno == __MAX_SUBCHANNEL) || |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 326 | !is_blacklisted(iter->ssid, iter->devno + 1)) { |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 327 | /* Last device in range. */ |
| 328 | iter->in_range = 0; |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 329 | return seq_printf(s, "0.%x.%04x\n", iter->ssid, iter->devno); |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 330 | } |
| 331 | return 0; |
| 332 | } |
| 333 | |
| 334 | static ssize_t |
| 335 | cio_ignore_write(struct file *file, const char __user *user_buf, |
| 336 | size_t user_len, loff_t *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | { |
| 338 | char *buf; |
Sebastian Ott | 94cbc20 | 2009-03-26 15:24:16 +0100 | [diff] [blame] | 339 | ssize_t rc, ret, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 341 | if (*offset) |
| 342 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | if (user_len > 65536) |
| 344 | user_len = 65536; |
| 345 | buf = vmalloc (user_len + 1); /* maybe better use the stack? */ |
| 346 | if (buf == NULL) |
| 347 | return -ENOMEM; |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 348 | memset(buf, 0, user_len + 1); |
| 349 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | if (strncpy_from_user (buf, user_buf, user_len) < 0) { |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 351 | rc = -EFAULT; |
| 352 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 355 | i = user_len - 1; |
| 356 | while ((i >= 0) && (isspace(buf[i]) || (buf[i] == 0))) { |
| 357 | buf[i] = '\0'; |
| 358 | i--; |
| 359 | } |
| 360 | ret = blacklist_parse_proc_parameters(buf); |
| 361 | if (ret) |
Peter Oberparleiter | ecf5d9e | 2008-10-10 21:33:06 +0200 | [diff] [blame] | 362 | rc = ret; |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 363 | else |
| 364 | rc = user_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 366 | out_free: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | vfree (buf); |
Michael Ernst | 5b89098 | 2008-05-07 09:22:55 +0200 | [diff] [blame] | 368 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | } |
| 370 | |
Jan Engelhardt | 5c81cdb | 2008-01-26 14:11:29 +0100 | [diff] [blame] | 371 | static const struct seq_operations cio_ignore_proc_seq_ops = { |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 372 | .start = cio_ignore_proc_seq_start, |
| 373 | .stop = cio_ignore_proc_seq_stop, |
| 374 | .next = cio_ignore_proc_seq_next, |
| 375 | .show = cio_ignore_proc_seq_show, |
| 376 | }; |
| 377 | |
| 378 | static int |
| 379 | cio_ignore_proc_open(struct inode *inode, struct file *file) |
| 380 | { |
| 381 | return seq_open(file, &cio_ignore_proc_seq_ops); |
| 382 | } |
| 383 | |
Arjan van de Ven | d54b1fd | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 384 | static const struct file_operations cio_ignore_proc_fops = { |
Cornelia Huck | 678a395 | 2006-01-06 00:19:24 -0800 | [diff] [blame] | 385 | .open = cio_ignore_proc_open, |
| 386 | .read = seq_read, |
| 387 | .llseek = seq_lseek, |
| 388 | .release = seq_release, |
| 389 | .write = cio_ignore_write, |
| 390 | }; |
| 391 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | static int |
| 393 | cio_ignore_proc_init (void) |
| 394 | { |
| 395 | struct proc_dir_entry *entry; |
| 396 | |
Denis V. Lunev | 8b59400 | 2008-04-29 01:02:20 -0700 | [diff] [blame] | 397 | entry = proc_create("cio_ignore", S_IFREG | S_IRUGO | S_IWUSR, NULL, |
| 398 | &cio_ignore_proc_fops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | if (!entry) |
Cornelia Huck | a7fbf6b | 2006-04-10 22:53:45 -0700 | [diff] [blame] | 400 | return -ENOENT; |
Cornelia Huck | a7fbf6b | 2006-04-10 22:53:45 -0700 | [diff] [blame] | 401 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | __initcall (cio_ignore_proc_init); |
| 405 | |
| 406 | #endif /* CONFIG_PROC_FS */ |