diff options
author | Jesper Juhl <jj@chaosbits.net> | 2011-03-21 15:47:31 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-03-21 18:54:35 -0400 |
commit | 0bf8c869701039b12c3520cb1bb1689595ab108b (patch) | |
tree | 4430e15c9e9a993a7bc63306e3bba7f65962c1cb | |
parent | 38f7aa23c4dd5f9af13dffca49879c42a61b0a01 (diff) |
Reduce sequential pointer derefs in scsi_error.c and reduce size as well
This patch reduces the number of sequential pointer derefs in
drivers/scsi/scsi_error.c
This has been submitted a number of times over a couple of years. I
believe this version adresses all comments it has gathered over time.
Please apply or reject with a reason.
The benefits are:
- makes the code easier to read. Lots of sequential derefs of the same
pointers is not easy on the eye.
- theoretically at least, just dereferencing the pointers once can
allow the compiler to generally slightly faster code, so in theory
this could also be a micro speed optimization.
- reduces size of object file (tiny effect: on x86-64, in at least one
configuration, the text size decreased from 9439 bytes to 9400)
- removes some pointless (mostly trailing) whitespace.
Signed-off-by: Jesper Juhl <jj@chaosbits.net>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | drivers/scsi/scsi_error.c | 94 |
1 files changed, 49 insertions, 45 deletions
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 991de3c15cfc..633c2395a92a 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c | |||
@@ -3,14 +3,14 @@ | |||
3 | * | 3 | * |
4 | * SCSI error/timeout handling | 4 | * SCSI error/timeout handling |
5 | * Initial versions: Eric Youngdale. Based upon conversations with | 5 | * Initial versions: Eric Youngdale. Based upon conversations with |
6 | * Leonard Zubkoff and David Miller at Linux Expo, | 6 | * Leonard Zubkoff and David Miller at Linux Expo, |
7 | * ideas originating from all over the place. | 7 | * ideas originating from all over the place. |
8 | * | 8 | * |
9 | * Restructured scsi_unjam_host and associated functions. | 9 | * Restructured scsi_unjam_host and associated functions. |
10 | * September 04, 2002 Mike Anderson (andmike@us.ibm.com) | 10 | * September 04, 2002 Mike Anderson (andmike@us.ibm.com) |
11 | * | 11 | * |
12 | * Forward port of Russell King's (rmk@arm.linux.org.uk) changes and | 12 | * Forward port of Russell King's (rmk@arm.linux.org.uk) changes and |
13 | * minor cleanups. | 13 | * minor cleanups. |
14 | * September 30, 2002 Mike Anderson (andmike@us.ibm.com) | 14 | * September 30, 2002 Mike Anderson (andmike@us.ibm.com) |
15 | */ | 15 | */ |
16 | 16 | ||
@@ -129,14 +129,15 @@ enum blk_eh_timer_return scsi_times_out(struct request *req) | |||
129 | { | 129 | { |
130 | struct scsi_cmnd *scmd = req->special; | 130 | struct scsi_cmnd *scmd = req->special; |
131 | enum blk_eh_timer_return rtn = BLK_EH_NOT_HANDLED; | 131 | enum blk_eh_timer_return rtn = BLK_EH_NOT_HANDLED; |
132 | struct Scsi_Host *host = scmd->device->host; | ||
132 | 133 | ||
133 | trace_scsi_dispatch_cmd_timeout(scmd); | 134 | trace_scsi_dispatch_cmd_timeout(scmd); |
134 | scsi_log_completion(scmd, TIMEOUT_ERROR); | 135 | scsi_log_completion(scmd, TIMEOUT_ERROR); |
135 | 136 | ||
136 | if (scmd->device->host->transportt->eh_timed_out) | 137 | if (host->transportt->eh_timed_out) |
137 | rtn = scmd->device->host->transportt->eh_timed_out(scmd); | 138 | rtn = host->transportt->eh_timed_out(scmd); |
138 | else if (scmd->device->host->hostt->eh_timed_out) | 139 | else if (host->hostt->eh_timed_out) |
139 | rtn = scmd->device->host->hostt->eh_timed_out(scmd); | 140 | rtn = host->hostt->eh_timed_out(scmd); |
140 | 141 | ||
141 | if (unlikely(rtn == BLK_EH_NOT_HANDLED && | 142 | if (unlikely(rtn == BLK_EH_NOT_HANDLED && |
142 | !scsi_eh_scmd_add(scmd, SCSI_EH_CANCEL_CMD))) { | 143 | !scsi_eh_scmd_add(scmd, SCSI_EH_CANCEL_CMD))) { |
@@ -195,7 +196,7 @@ static inline void scsi_eh_prt_fail_stats(struct Scsi_Host *shost, | |||
195 | ++total_failures; | 196 | ++total_failures; |
196 | if (scmd->eh_eflags & SCSI_EH_CANCEL_CMD) | 197 | if (scmd->eh_eflags & SCSI_EH_CANCEL_CMD) |
197 | ++cmd_cancel; | 198 | ++cmd_cancel; |
198 | else | 199 | else |
199 | ++cmd_failed; | 200 | ++cmd_failed; |
200 | } | 201 | } |
201 | } | 202 | } |
@@ -214,7 +215,7 @@ static inline void scsi_eh_prt_fail_stats(struct Scsi_Host *shost, | |||
214 | 215 | ||
215 | SCSI_LOG_ERROR_RECOVERY(2, printk("Total of %d commands on %d" | 216 | SCSI_LOG_ERROR_RECOVERY(2, printk("Total of %d commands on %d" |
216 | " devices require eh work\n", | 217 | " devices require eh work\n", |
217 | total_failures, devices_failed)); | 218 | total_failures, devices_failed)); |
218 | } | 219 | } |
219 | #endif | 220 | #endif |
220 | 221 | ||
@@ -294,7 +295,7 @@ static int scsi_check_sense(struct scsi_cmnd *scmd) | |||
294 | return NEEDS_RETRY; | 295 | return NEEDS_RETRY; |
295 | } | 296 | } |
296 | /* | 297 | /* |
297 | * if the device is in the process of becoming ready, we | 298 | * if the device is in the process of becoming ready, we |
298 | * should retry. | 299 | * should retry. |
299 | */ | 300 | */ |
300 | if ((sshdr.asc == 0x04) && (sshdr.ascq == 0x01)) | 301 | if ((sshdr.asc == 0x04) && (sshdr.ascq == 0x01)) |
@@ -488,7 +489,7 @@ static int scsi_eh_completed_normally(struct scsi_cmnd *scmd) | |||
488 | */ | 489 | */ |
489 | static void scsi_eh_done(struct scsi_cmnd *scmd) | 490 | static void scsi_eh_done(struct scsi_cmnd *scmd) |
490 | { | 491 | { |
491 | struct completion *eh_action; | 492 | struct completion *eh_action; |
492 | 493 | ||
493 | SCSI_LOG_ERROR_RECOVERY(3, | 494 | SCSI_LOG_ERROR_RECOVERY(3, |
494 | printk("%s scmd: %p result: %x\n", | 495 | printk("%s scmd: %p result: %x\n", |
@@ -507,22 +508,23 @@ static int scsi_try_host_reset(struct scsi_cmnd *scmd) | |||
507 | { | 508 | { |
508 | unsigned long flags; | 509 | unsigned long flags; |
509 | int rtn; | 510 | int rtn; |
511 | struct Scsi_Host *host = scmd->device->host; | ||
512 | struct scsi_host_template *hostt = host->hostt; | ||
510 | 513 | ||
511 | SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Snd Host RST\n", | 514 | SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Snd Host RST\n", |
512 | __func__)); | 515 | __func__)); |
513 | 516 | ||
514 | if (!scmd->device->host->hostt->eh_host_reset_handler) | 517 | if (!hostt->eh_host_reset_handler) |
515 | return FAILED; | 518 | return FAILED; |
516 | 519 | ||
517 | rtn = scmd->device->host->hostt->eh_host_reset_handler(scmd); | 520 | rtn = hostt->eh_host_reset_handler(scmd); |
518 | 521 | ||
519 | if (rtn == SUCCESS) { | 522 | if (rtn == SUCCESS) { |
520 | if (!scmd->device->host->hostt->skip_settle_delay) | 523 | if (!hostt->skip_settle_delay) |
521 | ssleep(HOST_RESET_SETTLE_TIME); | 524 | ssleep(HOST_RESET_SETTLE_TIME); |
522 | spin_lock_irqsave(scmd->device->host->host_lock, flags); | 525 | spin_lock_irqsave(host->host_lock, flags); |
523 | scsi_report_bus_reset(scmd->device->host, | 526 | scsi_report_bus_reset(host, scmd_channel(scmd)); |
524 | scmd_channel(scmd)); | 527 | spin_unlock_irqrestore(host->host_lock, flags); |
525 | spin_unlock_irqrestore(scmd->device->host->host_lock, flags); | ||
526 | } | 528 | } |
527 | 529 | ||
528 | return rtn; | 530 | return rtn; |
@@ -536,22 +538,23 @@ static int scsi_try_bus_reset(struct scsi_cmnd *scmd) | |||
536 | { | 538 | { |
537 | unsigned long flags; | 539 | unsigned long flags; |
538 | int rtn; | 540 | int rtn; |
541 | struct Scsi_Host *host = scmd->device->host; | ||
542 | struct scsi_host_template *hostt = host->hostt; | ||
539 | 543 | ||
540 | SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Snd Bus RST\n", | 544 | SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Snd Bus RST\n", |
541 | __func__)); | 545 | __func__)); |
542 | 546 | ||
543 | if (!scmd->device->host->hostt->eh_bus_reset_handler) | 547 | if (!hostt->eh_bus_reset_handler) |
544 | return FAILED; | 548 | return FAILED; |
545 | 549 | ||
546 | rtn = scmd->device->host->hostt->eh_bus_reset_handler(scmd); | 550 | rtn = hostt->eh_bus_reset_handler(scmd); |
547 | 551 | ||
548 | if (rtn == SUCCESS) { | 552 | if (rtn == SUCCESS) { |
549 | if (!scmd->device->host->hostt->skip_settle_delay) | 553 | if (!hostt->skip_settle_delay) |
550 | ssleep(BUS_RESET_SETTLE_TIME); | 554 | ssleep(BUS_RESET_SETTLE_TIME); |
551 | spin_lock_irqsave(scmd->device->host->host_lock, flags); | 555 | spin_lock_irqsave(host->host_lock, flags); |
552 | scsi_report_bus_reset(scmd->device->host, | 556 | scsi_report_bus_reset(host, scmd_channel(scmd)); |
553 | scmd_channel(scmd)); | 557 | spin_unlock_irqrestore(host->host_lock, flags); |
554 | spin_unlock_irqrestore(scmd->device->host->host_lock, flags); | ||
555 | } | 558 | } |
556 | 559 | ||
557 | return rtn; | 560 | return rtn; |
@@ -577,16 +580,18 @@ static int scsi_try_target_reset(struct scsi_cmnd *scmd) | |||
577 | { | 580 | { |
578 | unsigned long flags; | 581 | unsigned long flags; |
579 | int rtn; | 582 | int rtn; |
583 | struct Scsi_Host *host = scmd->device->host; | ||
584 | struct scsi_host_template *hostt = host->hostt; | ||
580 | 585 | ||
581 | if (!scmd->device->host->hostt->eh_target_reset_handler) | 586 | if (!hostt->eh_target_reset_handler) |
582 | return FAILED; | 587 | return FAILED; |
583 | 588 | ||
584 | rtn = scmd->device->host->hostt->eh_target_reset_handler(scmd); | 589 | rtn = hostt->eh_target_reset_handler(scmd); |
585 | if (rtn == SUCCESS) { | 590 | if (rtn == SUCCESS) { |
586 | spin_lock_irqsave(scmd->device->host->host_lock, flags); | 591 | spin_lock_irqsave(host->host_lock, flags); |
587 | __starget_for_each_device(scsi_target(scmd->device), NULL, | 592 | __starget_for_each_device(scsi_target(scmd->device), NULL, |
588 | __scsi_report_device_reset); | 593 | __scsi_report_device_reset); |
589 | spin_unlock_irqrestore(scmd->device->host->host_lock, flags); | 594 | spin_unlock_irqrestore(host->host_lock, flags); |
590 | } | 595 | } |
591 | 596 | ||
592 | return rtn; | 597 | return rtn; |
@@ -605,27 +610,28 @@ static int scsi_try_target_reset(struct scsi_cmnd *scmd) | |||
605 | static int scsi_try_bus_device_reset(struct scsi_cmnd *scmd) | 610 | static int scsi_try_bus_device_reset(struct scsi_cmnd *scmd) |
606 | { | 611 | { |
607 | int rtn; | 612 | int rtn; |
613 | struct scsi_host_template *hostt = scmd->device->host->hostt; | ||
608 | 614 | ||
609 | if (!scmd->device->host->hostt->eh_device_reset_handler) | 615 | if (!hostt->eh_device_reset_handler) |
610 | return FAILED; | 616 | return FAILED; |
611 | 617 | ||
612 | rtn = scmd->device->host->hostt->eh_device_reset_handler(scmd); | 618 | rtn = hostt->eh_device_reset_handler(scmd); |
613 | if (rtn == SUCCESS) | 619 | if (rtn == SUCCESS) |
614 | __scsi_report_device_reset(scmd->device, NULL); | 620 | __scsi_report_device_reset(scmd->device, NULL); |
615 | return rtn; | 621 | return rtn; |
616 | } | 622 | } |
617 | 623 | ||
618 | static int scsi_try_to_abort_cmd(struct scsi_cmnd *scmd) | 624 | static int scsi_try_to_abort_cmd(struct scsi_host_template *hostt, struct scsi_cmnd *scmd) |
619 | { | 625 | { |
620 | if (!scmd->device->host->hostt->eh_abort_handler) | 626 | if (!hostt->eh_abort_handler) |
621 | return FAILED; | 627 | return FAILED; |
622 | 628 | ||
623 | return scmd->device->host->hostt->eh_abort_handler(scmd); | 629 | return hostt->eh_abort_handler(scmd); |
624 | } | 630 | } |
625 | 631 | ||
626 | static void scsi_abort_eh_cmnd(struct scsi_cmnd *scmd) | 632 | static void scsi_abort_eh_cmnd(struct scsi_cmnd *scmd) |
627 | { | 633 | { |
628 | if (scsi_try_to_abort_cmd(scmd) != SUCCESS) | 634 | if (scsi_try_to_abort_cmd(scmd->device->host->hostt, scmd) != SUCCESS) |
629 | if (scsi_try_bus_device_reset(scmd) != SUCCESS) | 635 | if (scsi_try_bus_device_reset(scmd) != SUCCESS) |
630 | if (scsi_try_target_reset(scmd) != SUCCESS) | 636 | if (scsi_try_target_reset(scmd) != SUCCESS) |
631 | if (scsi_try_bus_reset(scmd) != SUCCESS) | 637 | if (scsi_try_bus_reset(scmd) != SUCCESS) |
@@ -846,7 +852,7 @@ EXPORT_SYMBOL(scsi_eh_finish_cmd); | |||
846 | * | 852 | * |
847 | * Description: | 853 | * Description: |
848 | * See if we need to request sense information. if so, then get it | 854 | * See if we need to request sense information. if so, then get it |
849 | * now, so we have a better idea of what to do. | 855 | * now, so we have a better idea of what to do. |
850 | * | 856 | * |
851 | * Notes: | 857 | * Notes: |
852 | * This has the unfortunate side effect that if a shost adapter does | 858 | * This has the unfortunate side effect that if a shost adapter does |
@@ -958,7 +964,7 @@ static int scsi_eh_abort_cmds(struct list_head *work_q, | |||
958 | SCSI_LOG_ERROR_RECOVERY(3, printk("%s: aborting cmd:" | 964 | SCSI_LOG_ERROR_RECOVERY(3, printk("%s: aborting cmd:" |
959 | "0x%p\n", current->comm, | 965 | "0x%p\n", current->comm, |
960 | scmd)); | 966 | scmd)); |
961 | rtn = scsi_try_to_abort_cmd(scmd); | 967 | rtn = scsi_try_to_abort_cmd(scmd->device->host->hostt, scmd); |
962 | if (rtn == SUCCESS || rtn == FAST_IO_FAIL) { | 968 | if (rtn == SUCCESS || rtn == FAST_IO_FAIL) { |
963 | scmd->eh_eflags &= ~SCSI_EH_CANCEL_CMD; | 969 | scmd->eh_eflags &= ~SCSI_EH_CANCEL_CMD; |
964 | if (!scsi_device_online(scmd->device) || | 970 | if (!scsi_device_online(scmd->device) || |
@@ -966,7 +972,6 @@ static int scsi_eh_abort_cmds(struct list_head *work_q, | |||
966 | !scsi_eh_tur(scmd)) { | 972 | !scsi_eh_tur(scmd)) { |
967 | scsi_eh_finish_cmd(scmd, done_q); | 973 | scsi_eh_finish_cmd(scmd, done_q); |
968 | } | 974 | } |
969 | |||
970 | } else | 975 | } else |
971 | SCSI_LOG_ERROR_RECOVERY(3, printk("%s: aborting" | 976 | SCSI_LOG_ERROR_RECOVERY(3, printk("%s: aborting" |
972 | " cmd failed:" | 977 | " cmd failed:" |
@@ -1010,7 +1015,7 @@ static int scsi_eh_try_stu(struct scsi_cmnd *scmd) | |||
1010 | * | 1015 | * |
1011 | * Notes: | 1016 | * Notes: |
1012 | * If commands are failing due to not ready, initializing command required, | 1017 | * If commands are failing due to not ready, initializing command required, |
1013 | * try revalidating the device, which will end up sending a start unit. | 1018 | * try revalidating the device, which will end up sending a start unit. |
1014 | */ | 1019 | */ |
1015 | static int scsi_eh_stu(struct Scsi_Host *shost, | 1020 | static int scsi_eh_stu(struct Scsi_Host *shost, |
1016 | struct list_head *work_q, | 1021 | struct list_head *work_q, |
@@ -1064,7 +1069,7 @@ static int scsi_eh_stu(struct Scsi_Host *shost, | |||
1064 | * Try a bus device reset. Still, look to see whether we have multiple | 1069 | * Try a bus device reset. Still, look to see whether we have multiple |
1065 | * devices that are jammed or not - if we have multiple devices, it | 1070 | * devices that are jammed or not - if we have multiple devices, it |
1066 | * makes no sense to try bus_device_reset - we really would need to try | 1071 | * makes no sense to try bus_device_reset - we really would need to try |
1067 | * a bus_reset instead. | 1072 | * a bus_reset instead. |
1068 | */ | 1073 | */ |
1069 | static int scsi_eh_bus_device_reset(struct Scsi_Host *shost, | 1074 | static int scsi_eh_bus_device_reset(struct Scsi_Host *shost, |
1070 | struct list_head *work_q, | 1075 | struct list_head *work_q, |
@@ -1164,7 +1169,7 @@ static int scsi_eh_target_reset(struct Scsi_Host *shost, | |||
1164 | } | 1169 | } |
1165 | 1170 | ||
1166 | /** | 1171 | /** |
1167 | * scsi_eh_bus_reset - send a bus reset | 1172 | * scsi_eh_bus_reset - send a bus reset |
1168 | * @shost: &scsi host being recovered. | 1173 | * @shost: &scsi host being recovered. |
1169 | * @work_q: &list_head for pending commands. | 1174 | * @work_q: &list_head for pending commands. |
1170 | * @done_q: &list_head for processed commands. | 1175 | * @done_q: &list_head for processed commands. |
@@ -1181,7 +1186,7 @@ static int scsi_eh_bus_reset(struct Scsi_Host *shost, | |||
1181 | * we really want to loop over the various channels, and do this on | 1186 | * we really want to loop over the various channels, and do this on |
1182 | * a channel by channel basis. we should also check to see if any | 1187 | * a channel by channel basis. we should also check to see if any |
1183 | * of the failed commands are on soft_reset devices, and if so, skip | 1188 | * of the failed commands are on soft_reset devices, and if so, skip |
1184 | * the reset. | 1189 | * the reset. |
1185 | */ | 1190 | */ |
1186 | 1191 | ||
1187 | for (channel = 0; channel <= shost->max_channel; channel++) { | 1192 | for (channel = 0; channel <= shost->max_channel; channel++) { |
@@ -1223,7 +1228,7 @@ static int scsi_eh_bus_reset(struct Scsi_Host *shost, | |||
1223 | } | 1228 | } |
1224 | 1229 | ||
1225 | /** | 1230 | /** |
1226 | * scsi_eh_host_reset - send a host reset | 1231 | * scsi_eh_host_reset - send a host reset |
1227 | * @work_q: list_head for processed commands. | 1232 | * @work_q: list_head for processed commands. |
1228 | * @done_q: list_head for processed commands. | 1233 | * @done_q: list_head for processed commands. |
1229 | */ | 1234 | */ |
@@ -1376,7 +1381,7 @@ int scsi_decide_disposition(struct scsi_cmnd *scmd) | |||
1376 | return SUCCESS; | 1381 | return SUCCESS; |
1377 | /* | 1382 | /* |
1378 | * when the low level driver returns did_soft_error, | 1383 | * when the low level driver returns did_soft_error, |
1379 | * it is responsible for keeping an internal retry counter | 1384 | * it is responsible for keeping an internal retry counter |
1380 | * in order to avoid endless loops (db) | 1385 | * in order to avoid endless loops (db) |
1381 | * | 1386 | * |
1382 | * actually this is a bug in this function here. we should | 1387 | * actually this is a bug in this function here. we should |
@@ -1414,7 +1419,6 @@ int scsi_decide_disposition(struct scsi_cmnd *scmd) | |||
1414 | */ | 1419 | */ |
1415 | break; | 1420 | break; |
1416 | /* fallthrough */ | 1421 | /* fallthrough */ |
1417 | |||
1418 | case DID_BUS_BUSY: | 1422 | case DID_BUS_BUSY: |
1419 | case DID_PARITY: | 1423 | case DID_PARITY: |
1420 | goto maybe_retry; | 1424 | goto maybe_retry; |
@@ -1982,7 +1986,7 @@ int scsi_normalize_sense(const u8 *sense_buffer, int sb_len, | |||
1982 | if (sb_len > 7) | 1986 | if (sb_len > 7) |
1983 | sshdr->additional_length = sense_buffer[7]; | 1987 | sshdr->additional_length = sense_buffer[7]; |
1984 | } else { | 1988 | } else { |
1985 | /* | 1989 | /* |
1986 | * fixed format | 1990 | * fixed format |
1987 | */ | 1991 | */ |
1988 | if (sb_len > 2) | 1992 | if (sb_len > 2) |