From c146e8fdb9df3a6a3f092d1171a1d7be9c12f02d Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Mon, 12 Jul 2010 00:18:56 +0200 Subject: [PATCH] zero-copy: release src pages on error When the second call to __get_userbuf fails, the already reserved user pages for data input need to be released first before bailing out. --- cryptodev_main.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/cryptodev_main.c b/cryptodev_main.c index dffbead..c2acec7 100644 --- a/cryptodev_main.c +++ b/cryptodev_main.c @@ -477,6 +477,15 @@ __crypto_run_std(struct csession *ses_ptr, struct crypt_op *cop) #ifndef DISABLE_ZCOPY +static void release_user_pages(struct page **pg, int pagecount) +{ + while (pagecount--) { + if (!PageReserved(pg[pagecount])) + SetPageDirty(pg[pagecount]); + page_cache_release(pg[pagecount]); + } +} + /* last page - first page + 1 */ #define PAGECOUNT(buf, buflen) \ ((((unsigned long)(buf + buflen - 1) & PAGE_MASK) >> PAGE_SHIFT) - \ @@ -558,21 +567,13 @@ static int get_userbuf(struct csession *ses, if (__get_userbuf(cop->dst, cop->len, dst_pagecount, ses->pages + src_pagecount, *dst_sg)) { printk(KERN_ERR "%s: failed to get user pages\n", __func__); + release_user_pages(ses->pages, src_pagecount); return -EINVAL; } } return 0; } -static void release_user_pages(struct page **pg, int pagecount) -{ - while (pagecount--) { - if (!PageReserved(pg[pagecount])) - SetPageDirty(pg[pagecount]); - page_cache_release(pg[pagecount]); - } -} - /* This is the main crypto function - zero-copy edition */ static int __crypto_run_zc(struct csession *ses_ptr, struct crypt_op *cop) -- 2.11.4.GIT