Skip to content

Commit b79d9a0

Browse files
Ming Leimartinkpetersen
authored andcommitted
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 <[email protected]> Cc: Bart Van Assche <[email protected]> Cc: Ewan D. Milne <[email protected]> Cc: Hannes Reinecke <[email protected]> Cc: Guenter Roeck <[email protected]> Reported-by: Guenter Roeck <[email protected]> Tested-by: Guenter Roeck <[email protected]> Signed-off-by: Ming Lei <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 3dccdf5 commit b79d9a0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/sg_pool.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ EXPORT_SYMBOL_GPL(sg_free_table_chained);
102102
*
103103
* Description:
104104
* 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.
106108
*
107109
**/
108110
int 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,
121123
}
122124

123125
/* User supposes that the 1st SGL includes real entry */
124-
if (nents_first_chunk == 1) {
126+
if (nents_first_chunk <= 1) {
125127
first_chunk = NULL;
126128
nents_first_chunk = 0;
127129
}

0 commit comments

Comments
 (0)