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>

authored by Jesper Juhl and committed by Linus Torvalds 0bf8c869 38f7aa23

+49 -45
+49 -45
drivers/scsi/scsi_error.c
··· 3 * 4 * SCSI error/timeout handling 5 * Initial versions: Eric Youngdale. Based upon conversations with 6 - * Leonard Zubkoff and David Miller at Linux Expo, 7 * ideas originating from all over the place. 8 * 9 * Restructured scsi_unjam_host and associated functions. 10 * September 04, 2002 Mike Anderson (andmike@us.ibm.com) 11 * 12 * Forward port of Russell King's (rmk@arm.linux.org.uk) changes and 13 - * minor cleanups. 14 * September 30, 2002 Mike Anderson (andmike@us.ibm.com) 15 */ 16 ··· 129 { 130 struct scsi_cmnd *scmd = req->special; 131 enum blk_eh_timer_return rtn = BLK_EH_NOT_HANDLED; 132 133 trace_scsi_dispatch_cmd_timeout(scmd); 134 scsi_log_completion(scmd, TIMEOUT_ERROR); 135 136 - if (scmd->device->host->transportt->eh_timed_out) 137 - rtn = scmd->device->host->transportt->eh_timed_out(scmd); 138 - else if (scmd->device->host->hostt->eh_timed_out) 139 - rtn = scmd->device->host->hostt->eh_timed_out(scmd); 140 141 if (unlikely(rtn == BLK_EH_NOT_HANDLED && 142 !scsi_eh_scmd_add(scmd, SCSI_EH_CANCEL_CMD))) { ··· 196 ++total_failures; 197 if (scmd->eh_eflags & SCSI_EH_CANCEL_CMD) 198 ++cmd_cancel; 199 - else 200 ++cmd_failed; 201 } 202 } ··· 215 216 SCSI_LOG_ERROR_RECOVERY(2, printk("Total of %d commands on %d" 217 " devices require eh work\n", 218 - total_failures, devices_failed)); 219 } 220 #endif 221 ··· 295 return NEEDS_RETRY; 296 } 297 /* 298 - * if the device is in the process of becoming ready, we 299 * should retry. 300 */ 301 if ((sshdr.asc == 0x04) && (sshdr.ascq == 0x01)) ··· 489 */ 490 static void scsi_eh_done(struct scsi_cmnd *scmd) 491 { 492 - struct completion *eh_action; 493 494 SCSI_LOG_ERROR_RECOVERY(3, 495 printk("%s scmd: %p result: %x\n", ··· 508 { 509 unsigned long flags; 510 int rtn; 511 512 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Snd Host RST\n", 513 __func__)); 514 515 - if (!scmd->device->host->hostt->eh_host_reset_handler) 516 return FAILED; 517 518 - rtn = scmd->device->host->hostt->eh_host_reset_handler(scmd); 519 520 if (rtn == SUCCESS) { 521 - if (!scmd->device->host->hostt->skip_settle_delay) 522 ssleep(HOST_RESET_SETTLE_TIME); 523 - spin_lock_irqsave(scmd->device->host->host_lock, flags); 524 - scsi_report_bus_reset(scmd->device->host, 525 - scmd_channel(scmd)); 526 - spin_unlock_irqrestore(scmd->device->host->host_lock, flags); 527 } 528 529 return rtn; ··· 538 { 539 unsigned long flags; 540 int rtn; 541 542 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Snd Bus RST\n", 543 __func__)); 544 545 - if (!scmd->device->host->hostt->eh_bus_reset_handler) 546 return FAILED; 547 548 - rtn = scmd->device->host->hostt->eh_bus_reset_handler(scmd); 549 550 if (rtn == SUCCESS) { 551 - if (!scmd->device->host->hostt->skip_settle_delay) 552 ssleep(BUS_RESET_SETTLE_TIME); 553 - spin_lock_irqsave(scmd->device->host->host_lock, flags); 554 - scsi_report_bus_reset(scmd->device->host, 555 - scmd_channel(scmd)); 556 - spin_unlock_irqrestore(scmd->device->host->host_lock, flags); 557 } 558 559 return rtn; ··· 580 { 581 unsigned long flags; 582 int rtn; 583 584 - if (!scmd->device->host->hostt->eh_target_reset_handler) 585 return FAILED; 586 587 - rtn = scmd->device->host->hostt->eh_target_reset_handler(scmd); 588 if (rtn == SUCCESS) { 589 - spin_lock_irqsave(scmd->device->host->host_lock, flags); 590 __starget_for_each_device(scsi_target(scmd->device), NULL, 591 __scsi_report_device_reset); 592 - spin_unlock_irqrestore(scmd->device->host->host_lock, flags); 593 } 594 595 return rtn; ··· 610 static int scsi_try_bus_device_reset(struct scsi_cmnd *scmd) 611 { 612 int rtn; 613 614 - if (!scmd->device->host->hostt->eh_device_reset_handler) 615 return FAILED; 616 617 - rtn = scmd->device->host->hostt->eh_device_reset_handler(scmd); 618 if (rtn == SUCCESS) 619 __scsi_report_device_reset(scmd->device, NULL); 620 return rtn; 621 } 622 623 - static int scsi_try_to_abort_cmd(struct scsi_cmnd *scmd) 624 { 625 - if (!scmd->device->host->hostt->eh_abort_handler) 626 return FAILED; 627 628 - return scmd->device->host->hostt->eh_abort_handler(scmd); 629 } 630 631 static void scsi_abort_eh_cmnd(struct scsi_cmnd *scmd) 632 { 633 - if (scsi_try_to_abort_cmd(scmd) != SUCCESS) 634 if (scsi_try_bus_device_reset(scmd) != SUCCESS) 635 if (scsi_try_target_reset(scmd) != SUCCESS) 636 if (scsi_try_bus_reset(scmd) != SUCCESS) ··· 852 * 853 * Description: 854 * See if we need to request sense information. if so, then get it 855 - * now, so we have a better idea of what to do. 856 * 857 * Notes: 858 * This has the unfortunate side effect that if a shost adapter does ··· 964 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: aborting cmd:" 965 "0x%p\n", current->comm, 966 scmd)); 967 - rtn = scsi_try_to_abort_cmd(scmd); 968 if (rtn == SUCCESS || rtn == FAST_IO_FAIL) { 969 scmd->eh_eflags &= ~SCSI_EH_CANCEL_CMD; 970 if (!scsi_device_online(scmd->device) || ··· 972 !scsi_eh_tur(scmd)) { 973 scsi_eh_finish_cmd(scmd, done_q); 974 } 975 - 976 } else 977 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: aborting" 978 " cmd failed:" ··· 1015 * 1016 * Notes: 1017 * If commands are failing due to not ready, initializing command required, 1018 - * try revalidating the device, which will end up sending a start unit. 1019 */ 1020 static int scsi_eh_stu(struct Scsi_Host *shost, 1021 struct list_head *work_q, ··· 1069 * Try a bus device reset. Still, look to see whether we have multiple 1070 * devices that are jammed or not - if we have multiple devices, it 1071 * makes no sense to try bus_device_reset - we really would need to try 1072 - * a bus_reset instead. 1073 */ 1074 static int scsi_eh_bus_device_reset(struct Scsi_Host *shost, 1075 struct list_head *work_q, ··· 1169 } 1170 1171 /** 1172 - * scsi_eh_bus_reset - send a bus reset 1173 * @shost: &scsi host being recovered. 1174 * @work_q: &list_head for pending commands. 1175 * @done_q: &list_head for processed commands. ··· 1186 * we really want to loop over the various channels, and do this on 1187 * a channel by channel basis. we should also check to see if any 1188 * of the failed commands are on soft_reset devices, and if so, skip 1189 - * the reset. 1190 */ 1191 1192 for (channel = 0; channel <= shost->max_channel; channel++) { ··· 1228 } 1229 1230 /** 1231 - * scsi_eh_host_reset - send a host reset 1232 * @work_q: list_head for processed commands. 1233 * @done_q: list_head for processed commands. 1234 */ ··· 1381 return SUCCESS; 1382 /* 1383 * when the low level driver returns did_soft_error, 1384 - * it is responsible for keeping an internal retry counter 1385 * in order to avoid endless loops (db) 1386 * 1387 * actually this is a bug in this function here. we should ··· 1419 */ 1420 break; 1421 /* fallthrough */ 1422 - 1423 case DID_BUS_BUSY: 1424 case DID_PARITY: 1425 goto maybe_retry; ··· 1986 if (sb_len > 7) 1987 sshdr->additional_length = sense_buffer[7]; 1988 } else { 1989 - /* 1990 * fixed format 1991 */ 1992 if (sb_len > 2)
··· 3 * 4 * SCSI error/timeout handling 5 * Initial versions: Eric Youngdale. Based upon conversations with 6 + * Leonard Zubkoff and David Miller at Linux Expo, 7 * ideas originating from all over the place. 8 * 9 * Restructured scsi_unjam_host and associated functions. 10 * September 04, 2002 Mike Anderson (andmike@us.ibm.com) 11 * 12 * Forward port of Russell King's (rmk@arm.linux.org.uk) changes and 13 + * minor cleanups. 14 * September 30, 2002 Mike Anderson (andmike@us.ibm.com) 15 */ 16 ··· 129 { 130 struct scsi_cmnd *scmd = req->special; 131 enum blk_eh_timer_return rtn = BLK_EH_NOT_HANDLED; 132 + struct Scsi_Host *host = scmd->device->host; 133 134 trace_scsi_dispatch_cmd_timeout(scmd); 135 scsi_log_completion(scmd, TIMEOUT_ERROR); 136 137 + if (host->transportt->eh_timed_out) 138 + rtn = host->transportt->eh_timed_out(scmd); 139 + else if (host->hostt->eh_timed_out) 140 + rtn = host->hostt->eh_timed_out(scmd); 141 142 if (unlikely(rtn == BLK_EH_NOT_HANDLED && 143 !scsi_eh_scmd_add(scmd, SCSI_EH_CANCEL_CMD))) { ··· 195 ++total_failures; 196 if (scmd->eh_eflags & SCSI_EH_CANCEL_CMD) 197 ++cmd_cancel; 198 + else 199 ++cmd_failed; 200 } 201 } ··· 214 215 SCSI_LOG_ERROR_RECOVERY(2, printk("Total of %d commands on %d" 216 " devices require eh work\n", 217 + total_failures, devices_failed)); 218 } 219 #endif 220 ··· 294 return NEEDS_RETRY; 295 } 296 /* 297 + * if the device is in the process of becoming ready, we 298 * should retry. 299 */ 300 if ((sshdr.asc == 0x04) && (sshdr.ascq == 0x01)) ··· 488 */ 489 static void scsi_eh_done(struct scsi_cmnd *scmd) 490 { 491 + struct completion *eh_action; 492 493 SCSI_LOG_ERROR_RECOVERY(3, 494 printk("%s scmd: %p result: %x\n", ··· 507 { 508 unsigned long flags; 509 int rtn; 510 + struct Scsi_Host *host = scmd->device->host; 511 + struct scsi_host_template *hostt = host->hostt; 512 513 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Snd Host RST\n", 514 __func__)); 515 516 + if (!hostt->eh_host_reset_handler) 517 return FAILED; 518 519 + rtn = hostt->eh_host_reset_handler(scmd); 520 521 if (rtn == SUCCESS) { 522 + if (!hostt->skip_settle_delay) 523 ssleep(HOST_RESET_SETTLE_TIME); 524 + spin_lock_irqsave(host->host_lock, flags); 525 + scsi_report_bus_reset(host, scmd_channel(scmd)); 526 + spin_unlock_irqrestore(host->host_lock, flags); 527 } 528 529 return rtn; ··· 536 { 537 unsigned long flags; 538 int rtn; 539 + struct Scsi_Host *host = scmd->device->host; 540 + struct scsi_host_template *hostt = host->hostt; 541 542 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Snd Bus RST\n", 543 __func__)); 544 545 + if (!hostt->eh_bus_reset_handler) 546 return FAILED; 547 548 + rtn = hostt->eh_bus_reset_handler(scmd); 549 550 if (rtn == SUCCESS) { 551 + if (!hostt->skip_settle_delay) 552 ssleep(BUS_RESET_SETTLE_TIME); 553 + spin_lock_irqsave(host->host_lock, flags); 554 + scsi_report_bus_reset(host, scmd_channel(scmd)); 555 + spin_unlock_irqrestore(host->host_lock, flags); 556 } 557 558 return rtn; ··· 577 { 578 unsigned long flags; 579 int rtn; 580 + struct Scsi_Host *host = scmd->device->host; 581 + struct scsi_host_template *hostt = host->hostt; 582 583 + if (!hostt->eh_target_reset_handler) 584 return FAILED; 585 586 + rtn = hostt->eh_target_reset_handler(scmd); 587 if (rtn == SUCCESS) { 588 + spin_lock_irqsave(host->host_lock, flags); 589 __starget_for_each_device(scsi_target(scmd->device), NULL, 590 __scsi_report_device_reset); 591 + spin_unlock_irqrestore(host->host_lock, flags); 592 } 593 594 return rtn; ··· 605 static int scsi_try_bus_device_reset(struct scsi_cmnd *scmd) 606 { 607 int rtn; 608 + struct scsi_host_template *hostt = scmd->device->host->hostt; 609 610 + if (!hostt->eh_device_reset_handler) 611 return FAILED; 612 613 + rtn = hostt->eh_device_reset_handler(scmd); 614 if (rtn == SUCCESS) 615 __scsi_report_device_reset(scmd->device, NULL); 616 return rtn; 617 } 618 619 + static int scsi_try_to_abort_cmd(struct scsi_host_template *hostt, struct scsi_cmnd *scmd) 620 { 621 + if (!hostt->eh_abort_handler) 622 return FAILED; 623 624 + return hostt->eh_abort_handler(scmd); 625 } 626 627 static void scsi_abort_eh_cmnd(struct scsi_cmnd *scmd) 628 { 629 + if (scsi_try_to_abort_cmd(scmd->device->host->hostt, scmd) != SUCCESS) 630 if (scsi_try_bus_device_reset(scmd) != SUCCESS) 631 if (scsi_try_target_reset(scmd) != SUCCESS) 632 if (scsi_try_bus_reset(scmd) != SUCCESS) ··· 846 * 847 * Description: 848 * 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. 850 * 851 * Notes: 852 * This has the unfortunate side effect that if a shost adapter does ··· 958 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: aborting cmd:" 959 "0x%p\n", current->comm, 960 scmd)); 961 + rtn = scsi_try_to_abort_cmd(scmd->device->host->hostt, scmd); 962 if (rtn == SUCCESS || rtn == FAST_IO_FAIL) { 963 scmd->eh_eflags &= ~SCSI_EH_CANCEL_CMD; 964 if (!scsi_device_online(scmd->device) || ··· 966 !scsi_eh_tur(scmd)) { 967 scsi_eh_finish_cmd(scmd, done_q); 968 } 969 } else 970 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: aborting" 971 " cmd failed:" ··· 1010 * 1011 * Notes: 1012 * If commands are failing due to not ready, initializing command required, 1013 + * try revalidating the device, which will end up sending a start unit. 1014 */ 1015 static int scsi_eh_stu(struct Scsi_Host *shost, 1016 struct list_head *work_q, ··· 1064 * 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 1066 * makes no sense to try bus_device_reset - we really would need to try 1067 + * a bus_reset instead. 1068 */ 1069 static int scsi_eh_bus_device_reset(struct Scsi_Host *shost, 1070 struct list_head *work_q, ··· 1164 } 1165 1166 /** 1167 + * scsi_eh_bus_reset - send a bus reset 1168 * @shost: &scsi host being recovered. 1169 * @work_q: &list_head for pending commands. 1170 * @done_q: &list_head for processed commands. ··· 1181 * 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 1183 * of the failed commands are on soft_reset devices, and if so, skip 1184 + * the reset. 1185 */ 1186 1187 for (channel = 0; channel <= shost->max_channel; channel++) { ··· 1223 } 1224 1225 /** 1226 + * scsi_eh_host_reset - send a host reset 1227 * @work_q: list_head for processed commands. 1228 * @done_q: list_head for processed commands. 1229 */ ··· 1376 return SUCCESS; 1377 /* 1378 * when the low level driver returns did_soft_error, 1379 + * it is responsible for keeping an internal retry counter 1380 * in order to avoid endless loops (db) 1381 * 1382 * actually this is a bug in this function here. we should ··· 1414 */ 1415 break; 1416 /* fallthrough */ 1417 case DID_BUS_BUSY: 1418 case DID_PARITY: 1419 goto maybe_retry; ··· 1982 if (sb_len > 7) 1983 sshdr->additional_length = sense_buffer[7]; 1984 } else { 1985 + /* 1986 * fixed format 1987 */ 1988 if (sb_len > 2)