mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-28 18:51:56 -04:00
misc: mic: scif: Fix error handling path
[ Upstream commit a81072a9c0ae734b7889929b0bc070fe3f353f0e ]
Inside __scif_pin_pages(), when map_flags != SCIF_MAP_KERNEL it
will call pin_user_pages_fast() to map nr_pages. However,
pin_user_pages_fast() might fail with a return value -ERRNO.
The return value is stored in pinned_pages->nr_pages. which in
turn is passed to unpin_user_pages(), which expects
pinned_pages->nr_pages >=0, else disaster.
Fix this by assigning pinned_pages->nr_pages to 0 if
pin_user_pages_fast() returns -ERRNO.
Fixes: ba612aa8b4 ("misc: mic: SCIF memory registration and unregistration")
Cc: John Hubbard <[email protected]>
Cc: Ira Weiny <[email protected]>
Cc: Dan Carpenter <[email protected]>
Reviewed-by: John Hubbard <[email protected]>
Signed-off-by: Souptick Joarder <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
This commit is contained in:
parent
a7bf4cf31f
commit
6f04266d08
1 changed files with 2 additions and 2 deletions
|
|
@ -1381,6 +1381,8 @@ retry:
|
|||
(prot & SCIF_PROT_WRITE) ? FOLL_WRITE : 0,
|
||||
pinned_pages->pages);
|
||||
if (nr_pages != pinned_pages->nr_pages) {
|
||||
if (pinned_pages->nr_pages < 0)
|
||||
pinned_pages->nr_pages = 0;
|
||||
if (try_upgrade) {
|
||||
if (ulimit)
|
||||
__scif_dec_pinned_vm_lock(mm, nr_pages);
|
||||
|
|
@ -1400,7 +1402,6 @@ retry:
|
|||
|
||||
if (pinned_pages->nr_pages < nr_pages) {
|
||||
err = -EFAULT;
|
||||
pinned_pages->nr_pages = nr_pages;
|
||||
goto dec_pinned;
|
||||
}
|
||||
|
||||
|
|
@ -1413,7 +1414,6 @@ dec_pinned:
|
|||
__scif_dec_pinned_vm_lock(mm, nr_pages);
|
||||
/* Something went wrong! Rollback */
|
||||
error_unmap:
|
||||
pinned_pages->nr_pages = nr_pages;
|
||||
scif_destroy_pinned_pages(pinned_pages);
|
||||
*pages = NULL;
|
||||
dev_dbg(scif_info.mdev.this_device,
|
||||
|
|
|
|||
Loading…
Reference in a new issue