hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/scsi/scsi_proc.c
....@@ -83,12 +83,12 @@
8383 4 * PAGE_SIZE);
8484 }
8585
86
-static const struct file_operations proc_scsi_fops = {
87
- .open = proc_scsi_host_open,
88
- .release = single_release,
89
- .read = seq_read,
90
- .llseek = seq_lseek,
91
- .write = proc_scsi_host_write
86
+static const struct proc_ops proc_scsi_ops = {
87
+ .proc_open = proc_scsi_host_open,
88
+ .proc_release = single_release,
89
+ .proc_read = seq_read,
90
+ .proc_lseek = seq_lseek,
91
+ .proc_write = proc_scsi_host_write
9292 };
9393
9494 /**
....@@ -146,7 +146,7 @@
146146
147147 sprintf(name,"%d", shost->host_no);
148148 p = proc_create_data(name, S_IRUGO | S_IWUSR,
149
- sht->proc_dir, &proc_scsi_fops, shost);
149
+ sht->proc_dir, &proc_scsi_ops, shost);
150150 if (!p)
151151 printk(KERN_ERR "%s: Failed to register host %d in"
152152 "%s\n", __func__, shost->host_no,
....@@ -311,7 +311,7 @@
311311 size_t length, loff_t *ppos)
312312 {
313313 int host, channel, id, lun;
314
- char *buffer, *p;
314
+ char *buffer, *end, *p;
315315 int err;
316316
317317 if (!buf || length > PAGE_SIZE)
....@@ -326,10 +326,14 @@
326326 goto out;
327327
328328 err = -EINVAL;
329
- if (length < PAGE_SIZE)
330
- buffer[length] = '\0';
331
- else if (buffer[PAGE_SIZE-1])
332
- goto out;
329
+ if (length < PAGE_SIZE) {
330
+ end = buffer + length;
331
+ *end = '\0';
332
+ } else {
333
+ end = buffer + PAGE_SIZE - 1;
334
+ if (*end)
335
+ goto out;
336
+ }
333337
334338 /*
335339 * Usage: echo "scsi add-single-device 0 1 2 3" >/proc/scsi/scsi
....@@ -338,10 +342,10 @@
338342 if (!strncmp("scsi add-single-device", buffer, 22)) {
339343 p = buffer + 23;
340344
341
- host = simple_strtoul(p, &p, 0);
342
- channel = simple_strtoul(p + 1, &p, 0);
343
- id = simple_strtoul(p + 1, &p, 0);
344
- lun = simple_strtoul(p + 1, &p, 0);
345
+ host = (p < end) ? simple_strtoul(p, &p, 0) : 0;
346
+ channel = (p + 1 < end) ? simple_strtoul(p + 1, &p, 0) : 0;
347
+ id = (p + 1 < end) ? simple_strtoul(p + 1, &p, 0) : 0;
348
+ lun = (p + 1 < end) ? simple_strtoul(p + 1, &p, 0) : 0;
345349
346350 err = scsi_add_single_device(host, channel, id, lun);
347351
....@@ -352,10 +356,10 @@
352356 } else if (!strncmp("scsi remove-single-device", buffer, 25)) {
353357 p = buffer + 26;
354358
355
- host = simple_strtoul(p, &p, 0);
356
- channel = simple_strtoul(p + 1, &p, 0);
357
- id = simple_strtoul(p + 1, &p, 0);
358
- lun = simple_strtoul(p + 1, &p, 0);
359
+ host = (p < end) ? simple_strtoul(p, &p, 0) : 0;
360
+ channel = (p + 1 < end) ? simple_strtoul(p + 1, &p, 0) : 0;
361
+ id = (p + 1 < end) ? simple_strtoul(p + 1, &p, 0) : 0;
362
+ lun = (p + 1 < end) ? simple_strtoul(p + 1, &p, 0) : 0;
359363
360364 err = scsi_remove_single_device(host, channel, id, lun);
361365 }
....@@ -372,15 +376,10 @@
372376 return err;
373377 }
374378
375
-static int always_match(struct device *dev, void *data)
376
-{
377
- return 1;
378
-}
379
-
380379 static inline struct device *next_scsi_device(struct device *start)
381380 {
382
- struct device *next = bus_find_device(&scsi_bus_type, start, NULL,
383
- always_match);
381
+ struct device *next = bus_find_next_device(&scsi_bus_type, start);
382
+
384383 put_device(start);
385384 return next;
386385 }
....@@ -441,13 +440,12 @@
441440 return seq_open(file, &scsi_seq_ops);
442441 }
443442
444
-static const struct file_operations proc_scsi_operations = {
445
- .owner = THIS_MODULE,
446
- .open = proc_scsi_open,
447
- .read = seq_read,
448
- .write = proc_scsi_write,
449
- .llseek = seq_lseek,
450
- .release = seq_release,
443
+static const struct proc_ops scsi_scsi_proc_ops = {
444
+ .proc_open = proc_scsi_open,
445
+ .proc_read = seq_read,
446
+ .proc_write = proc_scsi_write,
447
+ .proc_lseek = seq_lseek,
448
+ .proc_release = seq_release,
451449 };
452450
453451 /**
....@@ -461,7 +459,7 @@
461459 if (!proc_scsi)
462460 goto err1;
463461
464
- pde = proc_create("scsi/scsi", 0, NULL, &proc_scsi_operations);
462
+ pde = proc_create("scsi/scsi", 0, NULL, &scsi_scsi_proc_ops);
465463 if (!pde)
466464 goto err2;
467465