Skip to content

Commit 4759df9

Browse files
hreineckemartinkpetersen
authored andcommitted
scsi: sg: factor out sg_fill_request_table()
Factor out sg_fill_request_table() for better readability. [mkp: typos, applied by hand] Signed-off-by: Hannes Reinecke <[email protected]> Reviewed-by: Bart Van Assche <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 9c95be0 commit 4759df9

File tree

1 file changed

+35
-26
lines changed

1 file changed

+35
-26
lines changed

drivers/scsi/sg.c

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,40 @@ static int max_sectors_bytes(struct request_queue *q)
828828
return max_sectors << 9;
829829
}
830830

831+
static void
832+
sg_fill_request_table(Sg_fd *sfp, sg_req_info_t *rinfo)
833+
{
834+
Sg_request *srp;
835+
int val;
836+
unsigned int ms;
837+
838+
val = 0;
839+
list_for_each_entry(srp, &sfp->rq_list, entry) {
840+
if (val > SG_MAX_QUEUE)
841+
break;
842+
memset(&rinfo[val], 0, SZ_SG_REQ_INFO);
843+
rinfo[val].req_state = srp->done + 1;
844+
rinfo[val].problem =
845+
srp->header.masked_status &
846+
srp->header.host_status &
847+
srp->header.driver_status;
848+
if (srp->done)
849+
rinfo[val].duration =
850+
srp->header.duration;
851+
else {
852+
ms = jiffies_to_msecs(jiffies);
853+
rinfo[val].duration =
854+
(ms > srp->header.duration) ?
855+
(ms - srp->header.duration) : 0;
856+
}
857+
rinfo[val].orphan = srp->orphan;
858+
rinfo[val].sg_io_owned = srp->sg_io_owned;
859+
rinfo[val].pack_id = srp->header.pack_id;
860+
rinfo[val].usr_ptr = srp->header.usr_ptr;
861+
val++;
862+
}
863+
}
864+
831865
static long
832866
sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
833867
{
@@ -1012,38 +1046,13 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
10121046
return -EFAULT;
10131047
else {
10141048
sg_req_info_t *rinfo;
1015-
unsigned int ms;
10161049

10171050
rinfo = kmalloc(SZ_SG_REQ_INFO * SG_MAX_QUEUE,
10181051
GFP_KERNEL);
10191052
if (!rinfo)
10201053
return -ENOMEM;
10211054
read_lock_irqsave(&sfp->rq_list_lock, iflags);
1022-
val = 0;
1023-
list_for_each_entry(srp, &sfp->rq_list, entry) {
1024-
if (val >= SG_MAX_QUEUE)
1025-
break;
1026-
memset(&rinfo[val], 0, SZ_SG_REQ_INFO);
1027-
rinfo[val].req_state = srp->done + 1;
1028-
rinfo[val].problem =
1029-
srp->header.masked_status &
1030-
srp->header.host_status &
1031-
srp->header.driver_status;
1032-
if (srp->done)
1033-
rinfo[val].duration =
1034-
srp->header.duration;
1035-
else {
1036-
ms = jiffies_to_msecs(jiffies);
1037-
rinfo[val].duration =
1038-
(ms > srp->header.duration) ?
1039-
(ms - srp->header.duration) : 0;
1040-
}
1041-
rinfo[val].orphan = srp->orphan;
1042-
rinfo[val].sg_io_owned = srp->sg_io_owned;
1043-
rinfo[val].pack_id = srp->header.pack_id;
1044-
rinfo[val].usr_ptr = srp->header.usr_ptr;
1045-
val++;
1046-
}
1055+
sg_fill_request_table(sfp, rinfo);
10471056
read_unlock_irqrestore(&sfp->rq_list_lock, iflags);
10481057
result = __copy_to_user(p, rinfo,
10491058
SZ_SG_REQ_INFO * SG_MAX_QUEUE);

0 commit comments

Comments
 (0)