summaryrefslogtreecommitdiffstats
path: root/lib/sg_pool.c
diff options
context:
space:
mode:
authorMing Lei <ming.lei@redhat.com>2019-06-06 04:34:08 -0400
committerMartin K. Petersen <martin.petersen@oracle.com>2019-06-20 15:21:33 -0400
commitb79d9a09ae23c7047bdce3a15e284398334198ea (patch)
treeb2cdeab4564fdd2bc3706eb1aa0864e3e4ec1e6f /lib/sg_pool.c
parent3dccdf53c2f38399b11085ded4447ce1467f006c (diff)
scsi: lib/sg_pool.c: clear 'first_chunk' in case of no preallocation
If user doesn't ask to preallocate by passing zero 'nents_first_chunk' to sg_alloc_table_chained, we need to make sure that 'first_chunk' is cleared. Otherwise, __sg_alloc_table() still may think that the 1st SGL should be from the preallocation. Fixes the issue by clearing 'first_chunk' in sg_alloc_table_chained() if 'nents_first_chunk' is zero. Cc: Christoph Hellwig <hch@lst.de> Cc: Bart Van Assche <bvanassche@acm.org> Cc: Ewan D. Milne <emilne@redhat.com> Cc: Hannes Reinecke <hare@suse.com> Cc: Guenter Roeck <linux@roeck-us.net> Reported-by: Guenter Roeck <linux@roeck-us.net> Tested-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Diffstat (limited to 'lib/sg_pool.c')
-rw-r--r--lib/sg_pool.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/sg_pool.c b/lib/sg_pool.c
index b3b8cf62ff49..f1cc8372df67 100644
--- a/lib/sg_pool.c
+++ b/lib/sg_pool.c
@@ -102,7 +102,9 @@ EXPORT_SYMBOL_GPL(sg_free_table_chained);
102 * 102 *
103 * Description: 103 * Description:
104 * Allocate and chain SGLs in an sg table. If @nents@ is larger than 104 * Allocate and chain SGLs in an sg table. If @nents@ is larger than
105 * @nents_first_chunk a chained sg table will be setup. 105 * @nents_first_chunk a chained sg table will be setup. @first_chunk is
106 * ignored if nents_first_chunk <= 1 because user expects the SGL points
107 * non-chain SGL.
106 * 108 *
107 **/ 109 **/
108int sg_alloc_table_chained(struct sg_table *table, int nents, 110int sg_alloc_table_chained(struct sg_table *table, int nents,
@@ -121,7 +123,7 @@ int sg_alloc_table_chained(struct sg_table *table, int nents,
121 } 123 }
122 124
123 /* User supposes that the 1st SGL includes real entry */ 125 /* User supposes that the 1st SGL includes real entry */
124 if (nents_first_chunk == 1) { 126 if (nents_first_chunk <= 1) {
125 first_chunk = NULL; 127 first_chunk = NULL;
126 nents_first_chunk = 0; 128 nents_first_chunk = 0;
127 } 129 }