diff options
Diffstat (limited to 'drivers/block/ub.c')
-rw-r--r-- | drivers/block/ub.c | 245 |
1 files changed, 9 insertions, 236 deletions
diff --git a/drivers/block/ub.c b/drivers/block/ub.c index f04d864770ad..f73446f580df 100644 --- a/drivers/block/ub.c +++ b/drivers/block/ub.c | |||
@@ -8,7 +8,6 @@ | |||
8 | * and is not licensed separately. See file COPYING for details. | 8 | * and is not licensed separately. See file COPYING for details. |
9 | * | 9 | * |
10 | * TODO (sorted by decreasing priority) | 10 | * TODO (sorted by decreasing priority) |
11 | * -- Kill first_open (Al Viro fixed the block layer now) | ||
12 | * -- set readonly flag for CDs, set removable flag for CF readers | 11 | * -- set readonly flag for CDs, set removable flag for CF readers |
13 | * -- do inquiry and verify we got a disk and not a tape (for LUN mismatch) | 12 | * -- do inquiry and verify we got a disk and not a tape (for LUN mismatch) |
14 | * -- special case some senses, e.g. 3a/0 -> no media present, reduce retries | 13 | * -- special case some senses, e.g. 3a/0 -> no media present, reduce retries |
@@ -181,6 +180,7 @@ struct ub_dev; | |||
181 | #define UB_DIR_ILLEGAL2 2 | 180 | #define UB_DIR_ILLEGAL2 2 |
182 | #define UB_DIR_WRITE 3 | 181 | #define UB_DIR_WRITE 3 |
183 | 182 | ||
183 | /* P3 */ | ||
184 | #define UB_DIR_CHAR(c) (((c)==UB_DIR_WRITE)? 'w': \ | 184 | #define UB_DIR_CHAR(c) (((c)==UB_DIR_WRITE)? 'w': \ |
185 | (((c)==UB_DIR_READ)? 'r': 'n')) | 185 | (((c)==UB_DIR_READ)? 'r': 'n')) |
186 | 186 | ||
@@ -196,24 +196,11 @@ enum ub_scsi_cmd_state { | |||
196 | UB_CMDST_DONE /* Final state */ | 196 | UB_CMDST_DONE /* Final state */ |
197 | }; | 197 | }; |
198 | 198 | ||
199 | static char *ub_scsi_cmd_stname[] = { | ||
200 | ". ", | ||
201 | "Cmd", | ||
202 | "dat", | ||
203 | "c2s", | ||
204 | "sts", | ||
205 | "clr", | ||
206 | "crs", | ||
207 | "Sen", | ||
208 | "fin" | ||
209 | }; | ||
210 | |||
211 | struct ub_scsi_cmd { | 199 | struct ub_scsi_cmd { |
212 | unsigned char cdb[UB_MAX_CDB_SIZE]; | 200 | unsigned char cdb[UB_MAX_CDB_SIZE]; |
213 | unsigned char cdb_len; | 201 | unsigned char cdb_len; |
214 | 202 | ||
215 | unsigned char dir; /* 0 - none, 1 - read, 3 - write. */ | 203 | unsigned char dir; /* 0 - none, 1 - read, 3 - write. */ |
216 | unsigned char trace_index; | ||
217 | enum ub_scsi_cmd_state state; | 204 | enum ub_scsi_cmd_state state; |
218 | unsigned int tag; | 205 | unsigned int tag; |
219 | struct ub_scsi_cmd *next; | 206 | struct ub_scsi_cmd *next; |
@@ -250,28 +237,6 @@ struct ub_capacity { | |||
250 | }; | 237 | }; |
251 | 238 | ||
252 | /* | 239 | /* |
253 | * The SCSI command tracing structure. | ||
254 | */ | ||
255 | |||
256 | #define SCMD_ST_HIST_SZ 8 | ||
257 | #define SCMD_TRACE_SZ 63 /* Less than 4KB of 61-byte lines */ | ||
258 | |||
259 | struct ub_scsi_cmd_trace { | ||
260 | int hcur; | ||
261 | unsigned int tag; | ||
262 | unsigned int req_size, act_size; | ||
263 | unsigned char op; | ||
264 | unsigned char dir; | ||
265 | unsigned char key, asc, ascq; | ||
266 | char st_hst[SCMD_ST_HIST_SZ]; | ||
267 | }; | ||
268 | |||
269 | struct ub_scsi_trace { | ||
270 | int cur; | ||
271 | struct ub_scsi_cmd_trace vec[SCMD_TRACE_SZ]; | ||
272 | }; | ||
273 | |||
274 | /* | ||
275 | * This is a direct take-off from linux/include/completion.h | 240 | * This is a direct take-off from linux/include/completion.h |
276 | * The difference is that I do not wait on this thing, just poll. | 241 | * The difference is that I do not wait on this thing, just poll. |
277 | * When I want to wait (ub_probe), I just use the stock completion. | 242 | * When I want to wait (ub_probe), I just use the stock completion. |
@@ -334,7 +299,6 @@ struct ub_lun { | |||
334 | int changed; /* Media was changed */ | 299 | int changed; /* Media was changed */ |
335 | int removable; | 300 | int removable; |
336 | int readonly; | 301 | int readonly; |
337 | int first_open; /* Kludge. See ub_bd_open. */ | ||
338 | 302 | ||
339 | struct ub_request urq; | 303 | struct ub_request urq; |
340 | 304 | ||
@@ -390,7 +354,6 @@ struct ub_dev { | |||
390 | wait_queue_head_t reset_wait; | 354 | wait_queue_head_t reset_wait; |
391 | 355 | ||
392 | int sg_stat[6]; | 356 | int sg_stat[6]; |
393 | struct ub_scsi_trace tr; | ||
394 | }; | 357 | }; |
395 | 358 | ||
396 | /* | 359 | /* |
@@ -460,137 +423,6 @@ static int ub_qlock_next = 0; | |||
460 | static DEFINE_SPINLOCK(ub_lock); /* Locks globals and ->openc */ | 423 | static DEFINE_SPINLOCK(ub_lock); /* Locks globals and ->openc */ |
461 | 424 | ||
462 | /* | 425 | /* |
463 | * The SCSI command tracing procedures. | ||
464 | */ | ||
465 | |||
466 | static void ub_cmdtr_new(struct ub_dev *sc, struct ub_scsi_cmd *cmd) | ||
467 | { | ||
468 | int n; | ||
469 | struct ub_scsi_cmd_trace *t; | ||
470 | |||
471 | if ((n = sc->tr.cur + 1) == SCMD_TRACE_SZ) n = 0; | ||
472 | t = &sc->tr.vec[n]; | ||
473 | |||
474 | memset(t, 0, sizeof(struct ub_scsi_cmd_trace)); | ||
475 | t->tag = cmd->tag; | ||
476 | t->op = cmd->cdb[0]; | ||
477 | t->dir = cmd->dir; | ||
478 | t->req_size = cmd->len; | ||
479 | t->st_hst[0] = cmd->state; | ||
480 | |||
481 | sc->tr.cur = n; | ||
482 | cmd->trace_index = n; | ||
483 | } | ||
484 | |||
485 | static void ub_cmdtr_state(struct ub_dev *sc, struct ub_scsi_cmd *cmd) | ||
486 | { | ||
487 | int n; | ||
488 | struct ub_scsi_cmd_trace *t; | ||
489 | |||
490 | t = &sc->tr.vec[cmd->trace_index]; | ||
491 | if (t->tag == cmd->tag) { | ||
492 | if ((n = t->hcur + 1) == SCMD_ST_HIST_SZ) n = 0; | ||
493 | t->st_hst[n] = cmd->state; | ||
494 | t->hcur = n; | ||
495 | } | ||
496 | } | ||
497 | |||
498 | static void ub_cmdtr_act_len(struct ub_dev *sc, struct ub_scsi_cmd *cmd) | ||
499 | { | ||
500 | struct ub_scsi_cmd_trace *t; | ||
501 | |||
502 | t = &sc->tr.vec[cmd->trace_index]; | ||
503 | if (t->tag == cmd->tag) | ||
504 | t->act_size = cmd->act_len; | ||
505 | } | ||
506 | |||
507 | static void ub_cmdtr_sense(struct ub_dev *sc, struct ub_scsi_cmd *cmd, | ||
508 | unsigned char *sense) | ||
509 | { | ||
510 | struct ub_scsi_cmd_trace *t; | ||
511 | |||
512 | t = &sc->tr.vec[cmd->trace_index]; | ||
513 | if (t->tag == cmd->tag) { | ||
514 | t->key = sense[2] & 0x0F; | ||
515 | t->asc = sense[12]; | ||
516 | t->ascq = sense[13]; | ||
517 | } | ||
518 | } | ||
519 | |||
520 | static ssize_t ub_diag_show(struct device *dev, struct device_attribute *attr, | ||
521 | char *page) | ||
522 | { | ||
523 | struct usb_interface *intf; | ||
524 | struct ub_dev *sc; | ||
525 | struct list_head *p; | ||
526 | struct ub_lun *lun; | ||
527 | int cnt; | ||
528 | unsigned long flags; | ||
529 | int nc, nh; | ||
530 | int i, j; | ||
531 | struct ub_scsi_cmd_trace *t; | ||
532 | |||
533 | intf = to_usb_interface(dev); | ||
534 | sc = usb_get_intfdata(intf); | ||
535 | if (sc == NULL) | ||
536 | return 0; | ||
537 | |||
538 | cnt = 0; | ||
539 | spin_lock_irqsave(sc->lock, flags); | ||
540 | |||
541 | cnt += sprintf(page + cnt, | ||
542 | "poison %d reset %d\n", | ||
543 | atomic_read(&sc->poison), sc->reset); | ||
544 | cnt += sprintf(page + cnt, | ||
545 | "qlen %d qmax %d\n", | ||
546 | sc->cmd_queue.qlen, sc->cmd_queue.qmax); | ||
547 | cnt += sprintf(page + cnt, | ||
548 | "sg %d %d %d %d %d .. %d\n", | ||
549 | sc->sg_stat[0], | ||
550 | sc->sg_stat[1], | ||
551 | sc->sg_stat[2], | ||
552 | sc->sg_stat[3], | ||
553 | sc->sg_stat[4], | ||
554 | sc->sg_stat[5]); | ||
555 | |||
556 | list_for_each (p, &sc->luns) { | ||
557 | lun = list_entry(p, struct ub_lun, link); | ||
558 | cnt += sprintf(page + cnt, | ||
559 | "lun %u changed %d removable %d readonly %d\n", | ||
560 | lun->num, lun->changed, lun->removable, lun->readonly); | ||
561 | } | ||
562 | |||
563 | if ((nc = sc->tr.cur + 1) == SCMD_TRACE_SZ) nc = 0; | ||
564 | for (j = 0; j < SCMD_TRACE_SZ; j++) { | ||
565 | t = &sc->tr.vec[nc]; | ||
566 | |||
567 | cnt += sprintf(page + cnt, "%08x %02x", t->tag, t->op); | ||
568 | if (t->op == REQUEST_SENSE) { | ||
569 | cnt += sprintf(page + cnt, " [sense %x %02x %02x]", | ||
570 | t->key, t->asc, t->ascq); | ||
571 | } else { | ||
572 | cnt += sprintf(page + cnt, " %c", UB_DIR_CHAR(t->dir)); | ||
573 | cnt += sprintf(page + cnt, " [%5d %5d]", | ||
574 | t->req_size, t->act_size); | ||
575 | } | ||
576 | if ((nh = t->hcur + 1) == SCMD_ST_HIST_SZ) nh = 0; | ||
577 | for (i = 0; i < SCMD_ST_HIST_SZ; i++) { | ||
578 | cnt += sprintf(page + cnt, " %s", | ||
579 | ub_scsi_cmd_stname[(int)t->st_hst[nh]]); | ||
580 | if (++nh == SCMD_ST_HIST_SZ) nh = 0; | ||
581 | } | ||
582 | cnt += sprintf(page + cnt, "\n"); | ||
583 | |||
584 | if (++nc == SCMD_TRACE_SZ) nc = 0; | ||
585 | } | ||
586 | |||
587 | spin_unlock_irqrestore(sc->lock, flags); | ||
588 | return cnt; | ||
589 | } | ||
590 | |||
591 | static DEVICE_ATTR(diag, S_IRUGO, ub_diag_show, NULL); /* N.B. World readable */ | ||
592 | |||
593 | /* | ||
594 | * The id allocator. | 426 | * The id allocator. |
595 | * | 427 | * |
596 | * This also stores the host for indexing by minor, which is somewhat dirty. | 428 | * This also stores the host for indexing by minor, which is somewhat dirty. |
@@ -1092,7 +924,6 @@ static int ub_scsi_cmd_start(struct ub_dev *sc, struct ub_scsi_cmd *cmd) | |||
1092 | add_timer(&sc->work_timer); | 924 | add_timer(&sc->work_timer); |
1093 | 925 | ||
1094 | cmd->state = UB_CMDST_CMD; | 926 | cmd->state = UB_CMDST_CMD; |
1095 | ub_cmdtr_state(sc, cmd); | ||
1096 | return 0; | 927 | return 0; |
1097 | } | 928 | } |
1098 | 929 | ||
@@ -1145,12 +976,10 @@ static void ub_scsi_dispatch(struct ub_dev *sc) | |||
1145 | ub_cmdq_pop(sc); | 976 | ub_cmdq_pop(sc); |
1146 | (*cmd->done)(sc, cmd); | 977 | (*cmd->done)(sc, cmd); |
1147 | } else if (cmd->state == UB_CMDST_INIT) { | 978 | } else if (cmd->state == UB_CMDST_INIT) { |
1148 | ub_cmdtr_new(sc, cmd); | ||
1149 | if ((rc = ub_scsi_cmd_start(sc, cmd)) == 0) | 979 | if ((rc = ub_scsi_cmd_start(sc, cmd)) == 0) |
1150 | break; | 980 | break; |
1151 | cmd->error = rc; | 981 | cmd->error = rc; |
1152 | cmd->state = UB_CMDST_DONE; | 982 | cmd->state = UB_CMDST_DONE; |
1153 | ub_cmdtr_state(sc, cmd); | ||
1154 | } else { | 983 | } else { |
1155 | if (!ub_is_completed(&sc->work_done)) | 984 | if (!ub_is_completed(&sc->work_done)) |
1156 | break; | 985 | break; |
@@ -1247,7 +1076,6 @@ static void ub_scsi_urb_compl(struct ub_dev *sc, struct ub_scsi_cmd *cmd) | |||
1247 | return; | 1076 | return; |
1248 | } | 1077 | } |
1249 | cmd->state = UB_CMDST_CLEAR; | 1078 | cmd->state = UB_CMDST_CLEAR; |
1250 | ub_cmdtr_state(sc, cmd); | ||
1251 | return; | 1079 | return; |
1252 | case -ESHUTDOWN: /* unplug */ | 1080 | case -ESHUTDOWN: /* unplug */ |
1253 | case -EILSEQ: /* unplug timeout on uhci */ | 1081 | case -EILSEQ: /* unplug timeout on uhci */ |
@@ -1279,7 +1107,6 @@ static void ub_scsi_urb_compl(struct ub_dev *sc, struct ub_scsi_cmd *cmd) | |||
1279 | return; | 1107 | return; |
1280 | } | 1108 | } |
1281 | cmd->state = UB_CMDST_CLR2STS; | 1109 | cmd->state = UB_CMDST_CLR2STS; |
1282 | ub_cmdtr_state(sc, cmd); | ||
1283 | return; | 1110 | return; |
1284 | } | 1111 | } |
1285 | if (urb->status == -EOVERFLOW) { | 1112 | if (urb->status == -EOVERFLOW) { |
@@ -1304,7 +1131,6 @@ static void ub_scsi_urb_compl(struct ub_dev *sc, struct ub_scsi_cmd *cmd) | |||
1304 | if (urb->status != 0 || | 1131 | if (urb->status != 0 || |
1305 | len != cmd->sgv[cmd->current_sg].length) { | 1132 | len != cmd->sgv[cmd->current_sg].length) { |
1306 | cmd->act_len += len; | 1133 | cmd->act_len += len; |
1307 | ub_cmdtr_act_len(sc, cmd); | ||
1308 | 1134 | ||
1309 | cmd->error = -EIO; | 1135 | cmd->error = -EIO; |
1310 | ub_state_stat(sc, cmd); | 1136 | ub_state_stat(sc, cmd); |
@@ -1331,7 +1157,6 @@ static void ub_scsi_urb_compl(struct ub_dev *sc, struct ub_scsi_cmd *cmd) | |||
1331 | } | 1157 | } |
1332 | 1158 | ||
1333 | cmd->act_len += urb->actual_length; | 1159 | cmd->act_len += urb->actual_length; |
1334 | ub_cmdtr_act_len(sc, cmd); | ||
1335 | 1160 | ||
1336 | if (++cmd->current_sg < cmd->nsg) { | 1161 | if (++cmd->current_sg < cmd->nsg) { |
1337 | ub_data_start(sc, cmd); | 1162 | ub_data_start(sc, cmd); |
@@ -1357,7 +1182,6 @@ static void ub_scsi_urb_compl(struct ub_dev *sc, struct ub_scsi_cmd *cmd) | |||
1357 | cmd->error = -EIO; /* A cheap trick... */ | 1182 | cmd->error = -EIO; /* A cheap trick... */ |
1358 | 1183 | ||
1359 | cmd->state = UB_CMDST_CLRRS; | 1184 | cmd->state = UB_CMDST_CLRRS; |
1360 | ub_cmdtr_state(sc, cmd); | ||
1361 | return; | 1185 | return; |
1362 | } | 1186 | } |
1363 | 1187 | ||
@@ -1441,7 +1265,6 @@ static void ub_scsi_urb_compl(struct ub_dev *sc, struct ub_scsi_cmd *cmd) | |||
1441 | return; | 1265 | return; |
1442 | } | 1266 | } |
1443 | cmd->state = UB_CMDST_DONE; | 1267 | cmd->state = UB_CMDST_DONE; |
1444 | ub_cmdtr_state(sc, cmd); | ||
1445 | ub_cmdq_pop(sc); | 1268 | ub_cmdq_pop(sc); |
1446 | (*cmd->done)(sc, cmd); | 1269 | (*cmd->done)(sc, cmd); |
1447 | 1270 | ||
@@ -1496,7 +1319,6 @@ static void ub_data_start(struct ub_dev *sc, struct ub_scsi_cmd *cmd) | |||
1496 | add_timer(&sc->work_timer); | 1319 | add_timer(&sc->work_timer); |
1497 | 1320 | ||
1498 | cmd->state = UB_CMDST_DATA; | 1321 | cmd->state = UB_CMDST_DATA; |
1499 | ub_cmdtr_state(sc, cmd); | ||
1500 | } | 1322 | } |
1501 | 1323 | ||
1502 | /* | 1324 | /* |
@@ -1508,7 +1330,6 @@ static void ub_state_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd, int rc) | |||
1508 | 1330 | ||
1509 | cmd->error = rc; | 1331 | cmd->error = rc; |
1510 | cmd->state = UB_CMDST_DONE; | 1332 | cmd->state = UB_CMDST_DONE; |
1511 | ub_cmdtr_state(sc, cmd); | ||
1512 | ub_cmdq_pop(sc); | 1333 | ub_cmdq_pop(sc); |
1513 | (*cmd->done)(sc, cmd); | 1334 | (*cmd->done)(sc, cmd); |
1514 | } | 1335 | } |
@@ -1554,7 +1375,6 @@ static void ub_state_stat(struct ub_dev *sc, struct ub_scsi_cmd *cmd) | |||
1554 | 1375 | ||
1555 | cmd->stat_count = 0; | 1376 | cmd->stat_count = 0; |
1556 | cmd->state = UB_CMDST_STAT; | 1377 | cmd->state = UB_CMDST_STAT; |
1557 | ub_cmdtr_state(sc, cmd); | ||
1558 | } | 1378 | } |
1559 | 1379 | ||
1560 | /* | 1380 | /* |
@@ -1573,7 +1393,6 @@ static void ub_state_stat_counted(struct ub_dev *sc, struct ub_scsi_cmd *cmd) | |||
1573 | return; | 1393 | return; |
1574 | 1394 | ||
1575 | cmd->state = UB_CMDST_STAT; | 1395 | cmd->state = UB_CMDST_STAT; |
1576 | ub_cmdtr_state(sc, cmd); | ||
1577 | } | 1396 | } |
1578 | 1397 | ||
1579 | /* | 1398 | /* |
@@ -1611,7 +1430,6 @@ static void ub_state_sense(struct ub_dev *sc, struct ub_scsi_cmd *cmd) | |||
1611 | scmd->tag = sc->tagcnt++; | 1430 | scmd->tag = sc->tagcnt++; |
1612 | 1431 | ||
1613 | cmd->state = UB_CMDST_SENSE; | 1432 | cmd->state = UB_CMDST_SENSE; |
1614 | ub_cmdtr_state(sc, cmd); | ||
1615 | 1433 | ||
1616 | ub_cmdq_insert(sc, scmd); | 1434 | ub_cmdq_insert(sc, scmd); |
1617 | return; | 1435 | return; |
@@ -1668,11 +1486,6 @@ static void ub_top_sense_done(struct ub_dev *sc, struct ub_scsi_cmd *scmd) | |||
1668 | struct ub_scsi_cmd *cmd; | 1486 | struct ub_scsi_cmd *cmd; |
1669 | 1487 | ||
1670 | /* | 1488 | /* |
1671 | * Ignoring scmd->act_len, because the buffer was pre-zeroed. | ||
1672 | */ | ||
1673 | ub_cmdtr_sense(sc, scmd, sense); | ||
1674 | |||
1675 | /* | ||
1676 | * Find the command which triggered the unit attention or a check, | 1489 | * Find the command which triggered the unit attention or a check, |
1677 | * save the sense into it, and advance its state machine. | 1490 | * save the sense into it, and advance its state machine. |
1678 | */ | 1491 | */ |
@@ -1693,6 +1506,9 @@ static void ub_top_sense_done(struct ub_dev *sc, struct ub_scsi_cmd *scmd) | |||
1693 | return; | 1506 | return; |
1694 | } | 1507 | } |
1695 | 1508 | ||
1509 | /* | ||
1510 | * Ignoring scmd->act_len, because the buffer was pre-zeroed. | ||
1511 | */ | ||
1696 | cmd->key = sense[2] & 0x0F; | 1512 | cmd->key = sense[2] & 0x0F; |
1697 | cmd->asc = sense[12]; | 1513 | cmd->asc = sense[12]; |
1698 | cmd->ascq = sense[13]; | 1514 | cmd->ascq = sense[13]; |
@@ -1849,26 +1665,6 @@ static int ub_bd_open(struct inode *inode, struct file *filp) | |||
1849 | sc->openc++; | 1665 | sc->openc++; |
1850 | spin_unlock_irqrestore(&ub_lock, flags); | 1666 | spin_unlock_irqrestore(&ub_lock, flags); |
1851 | 1667 | ||
1852 | /* | ||
1853 | * This is a workaround for a specific problem in our block layer. | ||
1854 | * In 2.6.9, register_disk duplicates the code from rescan_partitions. | ||
1855 | * However, if we do add_disk with a device which persistently reports | ||
1856 | * a changed media, add_disk calls register_disk, which does do_open, | ||
1857 | * which will call rescan_paritions for changed media. After that, | ||
1858 | * register_disk attempts to do it all again and causes double kobject | ||
1859 | * registration and a eventually an oops on module removal. | ||
1860 | * | ||
1861 | * The bottom line is, Al Viro says that we should not allow | ||
1862 | * bdev->bd_invalidated to be set when doing add_disk no matter what. | ||
1863 | */ | ||
1864 | if (lun->first_open) { | ||
1865 | lun->first_open = 0; | ||
1866 | if (lun->changed) { | ||
1867 | rc = -ENOMEDIUM; | ||
1868 | goto err_open; | ||
1869 | } | ||
1870 | } | ||
1871 | |||
1872 | if (lun->removable || lun->readonly) | 1668 | if (lun->removable || lun->readonly) |
1873 | check_disk_change(inode->i_bdev); | 1669 | check_disk_change(inode->i_bdev); |
1874 | 1670 | ||
@@ -2007,9 +1803,8 @@ static int ub_sync_tur(struct ub_dev *sc, struct ub_lun *lun) | |||
2007 | init_completion(&compl); | 1803 | init_completion(&compl); |
2008 | 1804 | ||
2009 | rc = -ENOMEM; | 1805 | rc = -ENOMEM; |
2010 | if ((cmd = kmalloc(ALLOC_SIZE, GFP_KERNEL)) == NULL) | 1806 | if ((cmd = kzalloc(ALLOC_SIZE, GFP_KERNEL)) == NULL) |
2011 | goto err_alloc; | 1807 | goto err_alloc; |
2012 | memset(cmd, 0, ALLOC_SIZE); | ||
2013 | 1808 | ||
2014 | cmd->cdb[0] = TEST_UNIT_READY; | 1809 | cmd->cdb[0] = TEST_UNIT_READY; |
2015 | cmd->cdb_len = 6; | 1810 | cmd->cdb_len = 6; |
@@ -2062,9 +1857,8 @@ static int ub_sync_read_cap(struct ub_dev *sc, struct ub_lun *lun, | |||
2062 | init_completion(&compl); | 1857 | init_completion(&compl); |
2063 | 1858 | ||
2064 | rc = -ENOMEM; | 1859 | rc = -ENOMEM; |
2065 | if ((cmd = kmalloc(ALLOC_SIZE, GFP_KERNEL)) == NULL) | 1860 | if ((cmd = kzalloc(ALLOC_SIZE, GFP_KERNEL)) == NULL) |
2066 | goto err_alloc; | 1861 | goto err_alloc; |
2067 | memset(cmd, 0, ALLOC_SIZE); | ||
2068 | p = (char *)cmd + sizeof(struct ub_scsi_cmd); | 1862 | p = (char *)cmd + sizeof(struct ub_scsi_cmd); |
2069 | 1863 | ||
2070 | cmd->cdb[0] = 0x25; | 1864 | cmd->cdb[0] = 0x25; |
@@ -2405,9 +2199,8 @@ static int ub_probe(struct usb_interface *intf, | |||
2405 | return -ENXIO; | 2199 | return -ENXIO; |
2406 | 2200 | ||
2407 | rc = -ENOMEM; | 2201 | rc = -ENOMEM; |
2408 | if ((sc = kmalloc(sizeof(struct ub_dev), GFP_KERNEL)) == NULL) | 2202 | if ((sc = kzalloc(sizeof(struct ub_dev), GFP_KERNEL)) == NULL) |
2409 | goto err_core; | 2203 | goto err_core; |
2410 | memset(sc, 0, sizeof(struct ub_dev)); | ||
2411 | sc->lock = ub_next_lock(); | 2204 | sc->lock = ub_next_lock(); |
2412 | INIT_LIST_HEAD(&sc->luns); | 2205 | INIT_LIST_HEAD(&sc->luns); |
2413 | usb_init_urb(&sc->work_urb); | 2206 | usb_init_urb(&sc->work_urb); |
@@ -2438,9 +2231,6 @@ static int ub_probe(struct usb_interface *intf, | |||
2438 | if (ub_get_pipes(sc, sc->dev, intf) != 0) | 2231 | if (ub_get_pipes(sc, sc->dev, intf) != 0) |
2439 | goto err_dev_desc; | 2232 | goto err_dev_desc; |
2440 | 2233 | ||
2441 | if (device_create_file(&sc->intf->dev, &dev_attr_diag) != 0) | ||
2442 | goto err_diag; | ||
2443 | |||
2444 | /* | 2234 | /* |
2445 | * At this point, all USB initialization is done, do upper layer. | 2235 | * At this point, all USB initialization is done, do upper layer. |
2446 | * We really hate halfway initialized structures, so from the | 2236 | * We really hate halfway initialized structures, so from the |
@@ -2480,19 +2270,8 @@ static int ub_probe(struct usb_interface *intf, | |||
2480 | 2270 | ||
2481 | nluns = 1; | 2271 | nluns = 1; |
2482 | for (i = 0; i < 3; i++) { | 2272 | for (i = 0; i < 3; i++) { |
2483 | if ((rc = ub_sync_getmaxlun(sc)) < 0) { | 2273 | if ((rc = ub_sync_getmaxlun(sc)) < 0) |
2484 | /* | ||
2485 | * This segment is taken from usb-storage. They say | ||
2486 | * that ZIP-100 needs this, but my own ZIP-100 works | ||
2487 | * fine without this. | ||
2488 | * Still, it does not seem to hurt anything. | ||
2489 | */ | ||
2490 | if (rc == -EPIPE) { | ||
2491 | ub_probe_clear_stall(sc, sc->recv_bulk_pipe); | ||
2492 | ub_probe_clear_stall(sc, sc->send_bulk_pipe); | ||
2493 | } | ||
2494 | break; | 2274 | break; |
2495 | } | ||
2496 | if (rc != 0) { | 2275 | if (rc != 0) { |
2497 | nluns = rc; | 2276 | nluns = rc; |
2498 | break; | 2277 | break; |
@@ -2505,8 +2284,6 @@ static int ub_probe(struct usb_interface *intf, | |||
2505 | } | 2284 | } |
2506 | return 0; | 2285 | return 0; |
2507 | 2286 | ||
2508 | /* device_remove_file(&sc->intf->dev, &dev_attr_diag); */ | ||
2509 | err_diag: | ||
2510 | err_dev_desc: | 2287 | err_dev_desc: |
2511 | usb_set_intfdata(intf, NULL); | 2288 | usb_set_intfdata(intf, NULL); |
2512 | // usb_put_intf(sc->intf); | 2289 | // usb_put_intf(sc->intf); |
@@ -2524,9 +2301,8 @@ static int ub_probe_lun(struct ub_dev *sc, int lnum) | |||
2524 | int rc; | 2301 | int rc; |
2525 | 2302 | ||
2526 | rc = -ENOMEM; | 2303 | rc = -ENOMEM; |
2527 | if ((lun = kmalloc(sizeof(struct ub_lun), GFP_KERNEL)) == NULL) | 2304 | if ((lun = kzalloc(sizeof(struct ub_lun), GFP_KERNEL)) == NULL) |
2528 | goto err_alloc; | 2305 | goto err_alloc; |
2529 | memset(lun, 0, sizeof(struct ub_lun)); | ||
2530 | lun->num = lnum; | 2306 | lun->num = lnum; |
2531 | 2307 | ||
2532 | rc = -ENOSR; | 2308 | rc = -ENOSR; |
@@ -2541,7 +2317,6 @@ static int ub_probe_lun(struct ub_dev *sc, int lnum) | |||
2541 | 2317 | ||
2542 | lun->removable = 1; /* XXX Query this from the device */ | 2318 | lun->removable = 1; /* XXX Query this from the device */ |
2543 | lun->changed = 1; /* ub_revalidate clears only */ | 2319 | lun->changed = 1; /* ub_revalidate clears only */ |
2544 | lun->first_open = 1; | ||
2545 | ub_revalidate(sc, lun); | 2320 | ub_revalidate(sc, lun); |
2546 | 2321 | ||
2547 | rc = -ENOMEM; | 2322 | rc = -ENOMEM; |
@@ -2636,7 +2411,6 @@ static void ub_disconnect(struct usb_interface *intf) | |||
2636 | while ((cmd = ub_cmdq_peek(sc)) != NULL) { | 2411 | while ((cmd = ub_cmdq_peek(sc)) != NULL) { |
2637 | cmd->error = -ENOTCONN; | 2412 | cmd->error = -ENOTCONN; |
2638 | cmd->state = UB_CMDST_DONE; | 2413 | cmd->state = UB_CMDST_DONE; |
2639 | ub_cmdtr_state(sc, cmd); | ||
2640 | ub_cmdq_pop(sc); | 2414 | ub_cmdq_pop(sc); |
2641 | (*cmd->done)(sc, cmd); | 2415 | (*cmd->done)(sc, cmd); |
2642 | cnt++; | 2416 | cnt++; |
@@ -2687,7 +2461,6 @@ static void ub_disconnect(struct usb_interface *intf) | |||
2687 | * and no URBs left in transit. | 2461 | * and no URBs left in transit. |
2688 | */ | 2462 | */ |
2689 | 2463 | ||
2690 | device_remove_file(&sc->intf->dev, &dev_attr_diag); | ||
2691 | usb_set_intfdata(intf, NULL); | 2464 | usb_set_intfdata(intf, NULL); |
2692 | // usb_put_intf(sc->intf); | 2465 | // usb_put_intf(sc->intf); |
2693 | sc->intf = NULL; | 2466 | sc->intf = NULL; |