Use the scatterlist iterators and remove direct indexing of the
scatterlist array.

This way allows us to pre-allocate one small scatterlist, which can be
chained with one runtime allocated scatterlist if the pre-allocated one
isn't enough for the whole request.

Cc: Kim Bradley <kim.jamie.brad...@gmail.com>
Cc: de...@driverdev.osuosl.org
Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org>
Signed-off-by: Ming Lei <ming....@redhat.com>
---
 drivers/staging/rts5208/rtsx_transport.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/rts5208/rtsx_transport.c 
b/drivers/staging/rts5208/rtsx_transport.c
index 8277d7895608..407c9079b052 100644
--- a/drivers/staging/rts5208/rtsx_transport.c
+++ b/drivers/staging/rts5208/rtsx_transport.c
@@ -63,6 +63,8 @@ unsigned int rtsx_stor_access_xfer_buf(unsigned char *buffer,
                struct scatterlist *sg =
                                (struct scatterlist *)scsi_sglist(srb)
                                + *index;
+               if (sg_is_chain(sg))
+                       sg = sg_chain_ptr(sg);
 
                /*
                 * This loop handles a single s-g list entry, which may
@@ -86,7 +88,7 @@ unsigned int rtsx_stor_access_xfer_buf(unsigned char *buffer,
                                /* Transfer continues to next s-g entry */
                                *offset = 0;
                                ++*index;
-                               ++sg;
+                               sg = sg_next(sg);
                        }
 
                        while (sglen > 0) {
-- 
2.20.1

Reply via email to