aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/scsi/scsi_debug.c79
1 files changed, 13 insertions, 66 deletions
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 3abd2861a58a..7a2a3edcc723 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -591,81 +591,37 @@ static int check_readiness(struct scsi_cmnd * SCpnt, int reset_only,
591} 591}
592 592
593/* Returns 0 if ok else (DID_ERROR << 16). Sets scp->resid . */ 593/* Returns 0 if ok else (DID_ERROR << 16). Sets scp->resid . */
594static int fill_from_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr, 594static int fill_from_dev_buffer(struct scsi_cmnd *scp, unsigned char *arr,
595 int arr_len) 595 int arr_len)
596{ 596{
597 int k, req_len, act_len, len, active; 597 int act_len;
598 void * kaddr;
599 void * kaddr_off;
600 struct scatterlist *sg;
601 struct scsi_data_buffer *sdb = scsi_in(scp); 598 struct scsi_data_buffer *sdb = scsi_in(scp);
602 599
603 if (!sdb->length) 600 if (!sdb->length)
604 return 0; 601 return 0;
605 if (!sdb->table.sgl)
606 return (DID_ERROR << 16);
607 if (!(scsi_bidi_cmnd(scp) || scp->sc_data_direction == DMA_FROM_DEVICE)) 602 if (!(scsi_bidi_cmnd(scp) || scp->sc_data_direction == DMA_FROM_DEVICE))
608 return (DID_ERROR << 16); 603 return (DID_ERROR << 16);
609 active = 1; 604
610 req_len = act_len = 0; 605 act_len = sg_copy_from_buffer(sdb->table.sgl, sdb->table.nents,
611 for_each_sg(sdb->table.sgl, sg, sdb->table.nents, k) { 606 arr, arr_len);
612 if (active) {
613 kaddr = (unsigned char *)
614 kmap_atomic(sg_page(sg), KM_USER0);
615 if (NULL == kaddr)
616 return (DID_ERROR << 16);
617 kaddr_off = (unsigned char *)kaddr + sg->offset;
618 len = sg->length;
619 if ((req_len + len) > arr_len) {
620 active = 0;
621 len = arr_len - req_len;
622 }
623 memcpy(kaddr_off, arr + req_len, len);
624 kunmap_atomic(kaddr, KM_USER0);
625 act_len += len;
626 }
627 req_len += sg->length;
628 }
629 if (sdb->resid) 607 if (sdb->resid)
630 sdb->resid -= act_len; 608 sdb->resid -= act_len;
631 else 609 else
632 sdb->resid = req_len - act_len; 610 sdb->resid = scsi_bufflen(scp) - act_len;
611
633 return 0; 612 return 0;
634} 613}
635 614
636/* Returns number of bytes fetched into 'arr' or -1 if error. */ 615/* Returns number of bytes fetched into 'arr' or -1 if error. */
637static int fetch_to_dev_buffer(struct scsi_cmnd * scp, unsigned char * arr, 616static int fetch_to_dev_buffer(struct scsi_cmnd *scp, unsigned char *arr,
638 int max_arr_len) 617 int arr_len)
639{ 618{
640 int k, req_len, len, fin; 619 if (!scsi_bufflen(scp))
641 void * kaddr;
642 void * kaddr_off;
643 struct scatterlist * sg;
644
645 if (0 == scsi_bufflen(scp))
646 return 0; 620 return 0;
647 if (NULL == scsi_sglist(scp))
648 return -1;
649 if (!(scsi_bidi_cmnd(scp) || scp->sc_data_direction == DMA_TO_DEVICE)) 621 if (!(scsi_bidi_cmnd(scp) || scp->sc_data_direction == DMA_TO_DEVICE))
650 return -1; 622 return -1;
651 req_len = fin = 0; 623
652 scsi_for_each_sg(scp, sg, scsi_sg_count(scp), k) { 624 return scsi_sg_copy_to_buffer(scp, arr, arr_len);
653 kaddr = (unsigned char *)kmap_atomic(sg_page(sg), KM_USER0);
654 if (NULL == kaddr)
655 return -1;
656 kaddr_off = (unsigned char *)kaddr + sg->offset;
657 len = sg->length;
658 if ((req_len + len) > max_arr_len) {
659 len = max_arr_len - req_len;
660 fin = 1;
661 }
662 memcpy(arr + req_len, kaddr_off, len);
663 kunmap_atomic(kaddr, KM_USER0);
664 if (fin)
665 return req_len + len;
666 req_len += sg->length;
667 }
668 return req_len;
669} 625}
670 626
671 627
@@ -1965,16 +1921,7 @@ static int resp_xdwriteread(struct scsi_cmnd *scp, unsigned long long lba,
1965 if (!buf) 1921 if (!buf)
1966 return ret; 1922 return ret;
1967 1923
1968 offset = 0; 1924 scsi_sg_copy_to_buffer(scp, buf, scsi_bufflen(scp));
1969 scsi_for_each_sg(scp, sg, scsi_sg_count(scp), i) {
1970 kaddr = (unsigned char *)kmap_atomic(sg_page(sg), KM_USER0);
1971 if (!kaddr)
1972 goto out;
1973
1974 memcpy(buf + offset, kaddr + sg->offset, sg->length);
1975 offset += sg->length;
1976 kunmap_atomic(kaddr, KM_USER0);
1977 }
1978 1925
1979 offset = 0; 1926 offset = 0;
1980 for_each_sg(sdb->table.sgl, sg, sdb->table.nents, i) { 1927 for_each_sg(sdb->table.sgl, sg, sdb->table.nents, i) {