Skip to content

Commit 0bf8c86

Browse files
jjuhltorvalds
authored andcommitted
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 <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 38f7aa2 commit 0bf8c86

File tree

1 file changed

+49
-45
lines changed

1 file changed

+49
-45
lines changed

drivers/scsi/scsi_error.c

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
*
44
* SCSI error/timeout handling
55
* 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,
77
* ideas originating from all over the place.
88
*
99
* Restructured scsi_unjam_host and associated functions.
1010
* September 04, 2002 Mike Anderson ([email protected])
1111
*
1212
* Forward port of Russell King's ([email protected]) changes and
13-
* minor cleanups.
13+
* minor cleanups.
1414
* September 30, 2002 Mike Anderson ([email protected])
1515
*/
1616

@@ -129,14 +129,15 @@ enum blk_eh_timer_return scsi_times_out(struct request *req)
129129
{
130130
struct scsi_cmnd *scmd = req->special;
131131
enum blk_eh_timer_return rtn = BLK_EH_NOT_HANDLED;
132+
struct Scsi_Host *host = scmd->device->host;
132133

133134
trace_scsi_dispatch_cmd_timeout(scmd);
134135
scsi_log_completion(scmd, TIMEOUT_ERROR);
135136

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);
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);
140141

141142
if (unlikely(rtn == BLK_EH_NOT_HANDLED &&
142143
!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,
195196
++total_failures;
196197
if (scmd->eh_eflags & SCSI_EH_CANCEL_CMD)
197198
++cmd_cancel;
198-
else
199+
else
199200
++cmd_failed;
200201
}
201202
}
@@ -214,7 +215,7 @@ static inline void scsi_eh_prt_fail_stats(struct Scsi_Host *shost,
214215

215216
SCSI_LOG_ERROR_RECOVERY(2, printk("Total of %d commands on %d"
216217
" devices require eh work\n",
217-
total_failures, devices_failed));
218+
total_failures, devices_failed));
218219
}
219220
#endif
220221

@@ -294,7 +295,7 @@ static int scsi_check_sense(struct scsi_cmnd *scmd)
294295
return NEEDS_RETRY;
295296
}
296297
/*
297-
* if the device is in the process of becoming ready, we
298+
* if the device is in the process of becoming ready, we
298299
* should retry.
299300
*/
300301
if ((sshdr.asc == 0x04) && (sshdr.ascq == 0x01))
@@ -488,7 +489,7 @@ static int scsi_eh_completed_normally(struct scsi_cmnd *scmd)
488489
*/
489490
static void scsi_eh_done(struct scsi_cmnd *scmd)
490491
{
491-
struct completion *eh_action;
492+
struct completion *eh_action;
492493

493494
SCSI_LOG_ERROR_RECOVERY(3,
494495
printk("%s scmd: %p result: %x\n",
@@ -507,22 +508,23 @@ static int scsi_try_host_reset(struct scsi_cmnd *scmd)
507508
{
508509
unsigned long flags;
509510
int rtn;
511+
struct Scsi_Host *host = scmd->device->host;
512+
struct scsi_host_template *hostt = host->hostt;
510513

511514
SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Snd Host RST\n",
512515
__func__));
513516

514-
if (!scmd->device->host->hostt->eh_host_reset_handler)
517+
if (!hostt->eh_host_reset_handler)
515518
return FAILED;
516519

517-
rtn = scmd->device->host->hostt->eh_host_reset_handler(scmd);
520+
rtn = hostt->eh_host_reset_handler(scmd);
518521

519522
if (rtn == SUCCESS) {
520-
if (!scmd->device->host->hostt->skip_settle_delay)
523+
if (!hostt->skip_settle_delay)
521524
ssleep(HOST_RESET_SETTLE_TIME);
522-
spin_lock_irqsave(scmd->device->host->host_lock, flags);
523-
scsi_report_bus_reset(scmd->device->host,
524-
scmd_channel(scmd));
525-
spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
525+
spin_lock_irqsave(host->host_lock, flags);
526+
scsi_report_bus_reset(host, scmd_channel(scmd));
527+
spin_unlock_irqrestore(host->host_lock, flags);
526528
}
527529

528530
return rtn;
@@ -536,22 +538,23 @@ static int scsi_try_bus_reset(struct scsi_cmnd *scmd)
536538
{
537539
unsigned long flags;
538540
int rtn;
541+
struct Scsi_Host *host = scmd->device->host;
542+
struct scsi_host_template *hostt = host->hostt;
539543

540544
SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Snd Bus RST\n",
541545
__func__));
542546

543-
if (!scmd->device->host->hostt->eh_bus_reset_handler)
547+
if (!hostt->eh_bus_reset_handler)
544548
return FAILED;
545549

546-
rtn = scmd->device->host->hostt->eh_bus_reset_handler(scmd);
550+
rtn = hostt->eh_bus_reset_handler(scmd);
547551

548552
if (rtn == SUCCESS) {
549-
if (!scmd->device->host->hostt->skip_settle_delay)
553+
if (!hostt->skip_settle_delay)
550554
ssleep(BUS_RESET_SETTLE_TIME);
551-
spin_lock_irqsave(scmd->device->host->host_lock, flags);
552-
scsi_report_bus_reset(scmd->device->host,
553-
scmd_channel(scmd));
554-
spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
555+
spin_lock_irqsave(host->host_lock, flags);
556+
scsi_report_bus_reset(host, scmd_channel(scmd));
557+
spin_unlock_irqrestore(host->host_lock, flags);
555558
}
556559

557560
return rtn;
@@ -577,16 +580,18 @@ static int scsi_try_target_reset(struct scsi_cmnd *scmd)
577580
{
578581
unsigned long flags;
579582
int rtn;
583+
struct Scsi_Host *host = scmd->device->host;
584+
struct scsi_host_template *hostt = host->hostt;
580585

581-
if (!scmd->device->host->hostt->eh_target_reset_handler)
586+
if (!hostt->eh_target_reset_handler)
582587
return FAILED;
583588

584-
rtn = scmd->device->host->hostt->eh_target_reset_handler(scmd);
589+
rtn = hostt->eh_target_reset_handler(scmd);
585590
if (rtn == SUCCESS) {
586-
spin_lock_irqsave(scmd->device->host->host_lock, flags);
591+
spin_lock_irqsave(host->host_lock, flags);
587592
__starget_for_each_device(scsi_target(scmd->device), NULL,
588593
__scsi_report_device_reset);
589-
spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
594+
spin_unlock_irqrestore(host->host_lock, flags);
590595
}
591596

592597
return rtn;
@@ -605,27 +610,28 @@ static int scsi_try_target_reset(struct scsi_cmnd *scmd)
605610
static int scsi_try_bus_device_reset(struct scsi_cmnd *scmd)
606611
{
607612
int rtn;
613+
struct scsi_host_template *hostt = scmd->device->host->hostt;
608614

609-
if (!scmd->device->host->hostt->eh_device_reset_handler)
615+
if (!hostt->eh_device_reset_handler)
610616
return FAILED;
611617

612-
rtn = scmd->device->host->hostt->eh_device_reset_handler(scmd);
618+
rtn = hostt->eh_device_reset_handler(scmd);
613619
if (rtn == SUCCESS)
614620
__scsi_report_device_reset(scmd->device, NULL);
615621
return rtn;
616622
}
617623

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)
619625
{
620-
if (!scmd->device->host->hostt->eh_abort_handler)
626+
if (!hostt->eh_abort_handler)
621627
return FAILED;
622628

623-
return scmd->device->host->hostt->eh_abort_handler(scmd);
629+
return hostt->eh_abort_handler(scmd);
624630
}
625631

626632
static void scsi_abort_eh_cmnd(struct scsi_cmnd *scmd)
627633
{
628-
if (scsi_try_to_abort_cmd(scmd) != SUCCESS)
634+
if (scsi_try_to_abort_cmd(scmd->device->host->hostt, scmd) != SUCCESS)
629635
if (scsi_try_bus_device_reset(scmd) != SUCCESS)
630636
if (scsi_try_target_reset(scmd) != SUCCESS)
631637
if (scsi_try_bus_reset(scmd) != SUCCESS)
@@ -846,7 +852,7 @@ EXPORT_SYMBOL(scsi_eh_finish_cmd);
846852
*
847853
* Description:
848854
* 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.
850856
*
851857
* Notes:
852858
* This has the unfortunate side effect that if a shost adapter does
@@ -958,15 +964,14 @@ static int scsi_eh_abort_cmds(struct list_head *work_q,
958964
SCSI_LOG_ERROR_RECOVERY(3, printk("%s: aborting cmd:"
959965
"0x%p\n", current->comm,
960966
scmd));
961-
rtn = scsi_try_to_abort_cmd(scmd);
967+
rtn = scsi_try_to_abort_cmd(scmd->device->host->hostt, scmd);
962968
if (rtn == SUCCESS || rtn == FAST_IO_FAIL) {
963969
scmd->eh_eflags &= ~SCSI_EH_CANCEL_CMD;
964970
if (!scsi_device_online(scmd->device) ||
965971
rtn == FAST_IO_FAIL ||
966972
!scsi_eh_tur(scmd)) {
967973
scsi_eh_finish_cmd(scmd, done_q);
968974
}
969-
970975
} else
971976
SCSI_LOG_ERROR_RECOVERY(3, printk("%s: aborting"
972977
" cmd failed:"
@@ -1010,7 +1015,7 @@ static int scsi_eh_try_stu(struct scsi_cmnd *scmd)
10101015
*
10111016
* Notes:
10121017
* 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.
10141019
*/
10151020
static int scsi_eh_stu(struct Scsi_Host *shost,
10161021
struct list_head *work_q,
@@ -1064,7 +1069,7 @@ static int scsi_eh_stu(struct Scsi_Host *shost,
10641069
* Try a bus device reset. Still, look to see whether we have multiple
10651070
* devices that are jammed or not - if we have multiple devices, it
10661071
* makes no sense to try bus_device_reset - we really would need to try
1067-
* a bus_reset instead.
1072+
* a bus_reset instead.
10681073
*/
10691074
static int scsi_eh_bus_device_reset(struct Scsi_Host *shost,
10701075
struct list_head *work_q,
@@ -1164,7 +1169,7 @@ static int scsi_eh_target_reset(struct Scsi_Host *shost,
11641169
}
11651170

11661171
/**
1167-
* scsi_eh_bus_reset - send a bus reset
1172+
* scsi_eh_bus_reset - send a bus reset
11681173
* @shost: &scsi host being recovered.
11691174
* @work_q: &list_head for pending commands.
11701175
* @done_q: &list_head for processed commands.
@@ -1181,7 +1186,7 @@ static int scsi_eh_bus_reset(struct Scsi_Host *shost,
11811186
* we really want to loop over the various channels, and do this on
11821187
* a channel by channel basis. we should also check to see if any
11831188
* of the failed commands are on soft_reset devices, and if so, skip
1184-
* the reset.
1189+
* the reset.
11851190
*/
11861191

11871192
for (channel = 0; channel <= shost->max_channel; channel++) {
@@ -1223,7 +1228,7 @@ static int scsi_eh_bus_reset(struct Scsi_Host *shost,
12231228
}
12241229

12251230
/**
1226-
* scsi_eh_host_reset - send a host reset
1231+
* scsi_eh_host_reset - send a host reset
12271232
* @work_q: list_head for processed commands.
12281233
* @done_q: list_head for processed commands.
12291234
*/
@@ -1376,7 +1381,7 @@ int scsi_decide_disposition(struct scsi_cmnd *scmd)
13761381
return SUCCESS;
13771382
/*
13781383
* 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
13801385
* in order to avoid endless loops (db)
13811386
*
13821387
* actually this is a bug in this function here. we should
@@ -1414,7 +1419,6 @@ int scsi_decide_disposition(struct scsi_cmnd *scmd)
14141419
*/
14151420
break;
14161421
/* fallthrough */
1417-
14181422
case DID_BUS_BUSY:
14191423
case DID_PARITY:
14201424
goto maybe_retry;
@@ -1982,7 +1986,7 @@ int scsi_normalize_sense(const u8 *sense_buffer, int sb_len,
19821986
if (sb_len > 7)
19831987
sshdr->additional_length = sense_buffer[7];
19841988
} else {
1985-
/*
1989+
/*
19861990
* fixed format
19871991
*/
19881992
if (sb_len > 2)

0 commit comments

Comments
 (0)