Skip to content

Commit c04996a

Browse files
hreineckegregkh
authored andcommitted
scsi: sg: factor out sg_fill_request_table()
commit 4759df905a474d245752c9dc94288e779b8734dd upstream. Factor out sg_fill_request_table() for better readability. [mkp: typos, applied by hand] Signed-off-by: Hannes Reinecke <hare@suse.com> Reviewed-by: Bart Van Assche <bart.vanassche@wdc.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f0cd701 commit c04996a

1 file changed

Lines changed: 35 additions & 26 deletions

File tree

drivers/scsi/sg.c

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

842+
static void
843+
sg_fill_request_table(Sg_fd *sfp, sg_req_info_t *rinfo)
844+
{
845+
Sg_request *srp;
846+
int val;
847+
unsigned int ms;
848+
849+
val = 0;
850+
list_for_each_entry(srp, &sfp->rq_list, entry) {
851+
if (val > SG_MAX_QUEUE)
852+
break;
853+
memset(&rinfo[val], 0, SZ_SG_REQ_INFO);
854+
rinfo[val].req_state = srp->done + 1;
855+
rinfo[val].problem =
856+
srp->header.masked_status &
857+
srp->header.host_status &
858+
srp->header.driver_status;
859+
if (srp->done)
860+
rinfo[val].duration =
861+
srp->header.duration;
862+
else {
863+
ms = jiffies_to_msecs(jiffies);
864+
rinfo[val].duration =
865+
(ms > srp->header.duration) ?
866+
(ms - srp->header.duration) : 0;
867+
}
868+
rinfo[val].orphan = srp->orphan;
869+
rinfo[val].sg_io_owned = srp->sg_io_owned;
870+
rinfo[val].pack_id = srp->header.pack_id;
871+
rinfo[val].usr_ptr = srp->header.usr_ptr;
872+
val++;
873+
}
874+
}
875+
842876
static long
843877
sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
844878
{
@@ -1032,38 +1066,13 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
10321066
return -EFAULT;
10331067
else {
10341068
sg_req_info_t *rinfo;
1035-
unsigned int ms;
10361069

10371070
rinfo = kmalloc(SZ_SG_REQ_INFO * SG_MAX_QUEUE,
10381071
GFP_KERNEL);
10391072
if (!rinfo)
10401073
return -ENOMEM;
10411074
read_lock_irqsave(&sfp->rq_list_lock, iflags);
1042-
val = 0;
1043-
list_for_each_entry(srp, &sfp->rq_list, entry) {
1044-
if (val >= SG_MAX_QUEUE)
1045-
break;
1046-
memset(&rinfo[val], 0, SZ_SG_REQ_INFO);
1047-
rinfo[val].req_state = srp->done + 1;
1048-
rinfo[val].problem =
1049-
srp->header.masked_status &
1050-
srp->header.host_status &
1051-
srp->header.driver_status;
1052-
if (srp->done)
1053-
rinfo[val].duration =
1054-
srp->header.duration;
1055-
else {
1056-
ms = jiffies_to_msecs(jiffies);
1057-
rinfo[val].duration =
1058-
(ms > srp->header.duration) ?
1059-
(ms - srp->header.duration) : 0;
1060-
}
1061-
rinfo[val].orphan = srp->orphan;
1062-
rinfo[val].sg_io_owned = srp->sg_io_owned;
1063-
rinfo[val].pack_id = srp->header.pack_id;
1064-
rinfo[val].usr_ptr = srp->header.usr_ptr;
1065-
val++;
1066-
}
1075+
sg_fill_request_table(sfp, rinfo);
10671076
read_unlock_irqrestore(&sfp->rq_list_lock, iflags);
10681077
result = __copy_to_user(p, rinfo,
10691078
SZ_SG_REQ_INFO * SG_MAX_QUEUE);

0 commit comments

Comments
 (0)