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