Skip to content

Commit e95d50d

Browse files
yishaihjgunthorpe
authored andcommitted
lib/scatterlist: Fix to merge contiguous pages into the last SG properly
When sg_alloc_append_table_from_pages() calls to pages_are_mergeable() in its 'sgt_append->prv' flow to check whether it can merge contiguous pages into the last SG, it passes the page arguments in the wrong order. The first parameter should be the next candidate page to be merged to the last page and not the opposite. The current code leads to a corrupted SG which resulted in OOPs and unexpected errors when non-contiguous pages are merged wrongly. Fix to pass the page parameters in the right order. Fixes: 1567b49 ("lib/scatterlist: add check when merging zone device pages") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Yishai Hadas <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Reviewed-by: Logan Gunthorpe <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 8de8482 commit e95d50d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/scatterlist.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ int sg_alloc_append_table_from_pages(struct sg_append_table *sgt_append,
476476
/* Merge contiguous pages into the last SG */
477477
prv_len = sgt_append->prv->length;
478478
last_pg = sg_page(sgt_append->prv);
479-
while (n_pages && pages_are_mergeable(last_pg, pages[0])) {
479+
while (n_pages && pages_are_mergeable(pages[0], last_pg)) {
480480
if (sgt_append->prv->length + PAGE_SIZE > max_segment)
481481
break;
482482
sgt_append->prv->length += PAGE_SIZE;

0 commit comments

Comments
 (0)