From: Dan Carpenter <dan.carpenter@oracle.com>
To: Souptick Joarder <jrdr.linux@gmail.com>
Cc: gregkh@linuxfoundation.org, jane.pnx9@gmail.com,
pakki001@umn.edu, ldufour@linux.ibm.com, harshjain32@gmail.com,
simon@nikanor.nu, walken@google.com, devel@driverdev.osuosl.org,
linux-kernel@vger.kernel.org, John Hubbard <jhubbard@nvidia.com>,
Bharath Vedartham <linux.bhar@gmail.com>
Subject: Re: [PATCH 1/4] staging: kpc2000: Unpin partial pinned pages
Date: Wed, 17 Jun 2020 14:13:22 +0300 [thread overview]
Message-ID: <20200617111321.GP4282@kadam> (raw)
In-Reply-To: <1592360843-3440-2-git-send-email-jrdr.linux@gmail.com>
On Wed, Jun 17, 2020 at 07:57:20AM +0530, Souptick Joarder wrote:
> There is a bug, when get_user_pages() failed but partially pinned
> pages are not unpinned. Fixed it.
>
> Also, int is more appropriate type for rv. Changed it.
>
> Signed-off-by: Souptick Joarder <jrdr.linux@gmail.com>
> Cc: John Hubbard <jhubbard@nvidia.com>
> Cc: Bharath Vedartham <linux.bhar@gmail.com>
> Cc: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> drivers/staging/kpc2000/kpc_dma/fileops.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/staging/kpc2000/kpc_dma/fileops.c b/drivers/staging/kpc2000/kpc_dma/fileops.c
> index 8975346..b136353 100644
> --- a/drivers/staging/kpc2000/kpc_dma/fileops.c
> +++ b/drivers/staging/kpc2000/kpc_dma/fileops.c
> @@ -35,7 +35,7 @@ static int kpc_dma_transfer(struct dev_private_data *priv,
> unsigned long iov_base, size_t iov_len)
> {
> unsigned int i = 0;
> - long rv = 0;
> + int rv = 0;
> struct kpc_dma_device *ldev;
> struct aio_cb_data *acd;
> DECLARE_COMPLETION_ONSTACK(done);
> @@ -193,6 +193,10 @@ static int kpc_dma_transfer(struct dev_private_data *priv,
> put_page(acd->user_pages[i]);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> err_get_user_pages:
> + if (rv > 0) {
> + for (i = 0; i < rv; i++)
> + put_pages(acd->user_pages[i])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> + }
This isn't a complete fix. "rv" is the negative error code but here we
are returning a positive value on this path. Also it's ugly to have
same put_page() loop repeated twice.
It would be better to write it like this:
rv = get_user_pages(iov_base, acd->page_count, FOLL_TOUCH | FOLL_WRITE | FOLL_GET, acd->user_pages, NULL);
mmap_read_unlock(current->mm); /* release the semaphore */
if (rv < 0)
goto free_pages;
if (rv != acd->page_count) {
acd->page_count = rv;
rv = -EFAULT;
goto put_pages;
}
...
put_pages:
for (i = 0 ; i < acd->page_count ; i++)
put_pages(acd->user_pages[i]);
free_pages:
kfree(acd->user_pages);
regards,
dan carpenter
next prev parent reply other threads:[~2020-06-17 11:13 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-17 2:27 [PATCH 0/4] staging: kpc2000: kpc_dma: Few clean up and Convert to pin_user_pages() Souptick Joarder
2020-06-17 2:27 ` [PATCH 1/4] staging: kpc2000: Unpin partial pinned pages Souptick Joarder
2020-06-17 11:13 ` Dan Carpenter [this message]
2020-06-17 17:43 ` Souptick Joarder
2020-06-17 17:59 ` Dan Carpenter
2020-06-17 19:29 ` Souptick Joarder
2020-06-18 10:50 ` Dan Carpenter
2020-06-17 2:27 ` [PATCH 2/4] staging: kpc2000: kpc_dma: Convert set_page_dirty() --> set_page_dirty_lock() Souptick Joarder
2020-06-27 17:51 ` Souptick Joarder
2020-06-17 2:27 ` [PATCH 3/4] staging: kpc2000: kpc_dma: Convert get_user_pages() --> pin_user_pages() Souptick Joarder
2020-06-17 2:27 ` [PATCH 4/4] staging: kpc2000: kpc_dma: Remove excess goto statement Souptick Joarder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200617111321.GP4282@kadam \
--to=dan.carpenter@oracle.com \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@linuxfoundation.org \
--cc=harshjain32@gmail.com \
--cc=jane.pnx9@gmail.com \
--cc=jhubbard@nvidia.com \
--cc=jrdr.linux@gmail.com \
--cc=ldufour@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux.bhar@gmail.com \
--cc=pakki001@umn.edu \
--cc=simon@nikanor.nu \
--cc=walken@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.