Skip to content

Commit

Permalink
scsi: lib/sg_pool.c: clear 'first_chunk' in case of no preallocation
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Ming Lei authored and martinkpetersen committed Jun 20, 2019
1 parent 3dccdf5 commit b79d9a0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/sg_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ EXPORT_SYMBOL_GPL(sg_free_table_chained);
*
* Description:
* Allocate and chain SGLs in an sg table. If @nents@ is larger than
* @nents_first_chunk a chained sg table will be setup.
* @nents_first_chunk a chained sg table will be setup. @first_chunk is
* ignored if nents_first_chunk <= 1 because user expects the SGL points
* non-chain SGL.
*
**/
int sg_alloc_table_chained(struct sg_table *table, int nents,
Expand All @@ -121,7 +123,7 @@ int sg_alloc_table_chained(struct sg_table *table, int nents,
}

/* User supposes that the 1st SGL includes real entry */
if (nents_first_chunk == 1) {
if (nents_first_chunk <= 1) {
first_chunk = NULL;
nents_first_chunk = 0;
}
Expand Down

0 comments on commit b79d9a0

Please sign in to comment.