2020-06-17 02:56:47

by Souptick Joarder

[permalink] [raw]
Subject: [PATCH v2] drivers/virt/fsl_hypervisor: Correcting error handling path

First, when memory allocation for sg_list_unaligned failed, there
is no point of calling put_pages() as we haven't pinned any pages.

Second, if get_user_pages_fast() failed we should unpinned num_pinned
pages, no point of checking till num_pages.

This will address both.

Signed-off-by: Souptick Joarder <[email protected]>
Reviewed-by: Dan Carpenter <[email protected]>
Cc: John Hubbard <[email protected]>
---
v2:
Added review tag.

drivers/virt/fsl_hypervisor.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/virt/fsl_hypervisor.c b/drivers/virt/fsl_hypervisor.c
index 1b0b11b..ea344d7 100644
--- a/drivers/virt/fsl_hypervisor.c
+++ b/drivers/virt/fsl_hypervisor.c
@@ -157,7 +157,7 @@ static long ioctl_memcpy(struct fsl_hv_ioctl_memcpy __user *p)

unsigned int i;
long ret = 0;
- int num_pinned; /* return value from get_user_pages() */
+ int num_pinned = 0; /* return value from get_user_pages() */
phys_addr_t remote_paddr; /* The next address in the remote buffer */
uint32_t count; /* The number of bytes left to copy */

@@ -293,7 +293,7 @@ static long ioctl_memcpy(struct fsl_hv_ioctl_memcpy __user *p)

exit:
if (pages) {
- for (i = 0; i < num_pages; i++)
+ for (i = 0; i < num_pinned; i++)
if (pages[i])
put_page(pages[i]);
}
--
1.9.1


2020-06-22 16:29:32

by Souptick Joarder

[permalink] [raw]
Subject: Re: [PATCH v2] drivers/virt/fsl_hypervisor: Correcting error handling path

On Wed, Jun 17, 2020 at 8:22 AM Souptick Joarder <[email protected]> wrote:
>
> First, when memory allocation for sg_list_unaligned failed, there
> is no point of calling put_pages() as we haven't pinned any pages.
>
> Second, if get_user_pages_fast() failed we should unpinned num_pinned
> pages, no point of checking till num_pages.
>
> This will address both.
>
> Signed-off-by: Souptick Joarder <[email protected]>
> Reviewed-by: Dan Carpenter <[email protected]>
> Cc: John Hubbard <[email protected]>

Any suggestion, what is the right tree to take this patch forward ?

> ---
> v2:
> Added review tag.
>
> drivers/virt/fsl_hypervisor.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/virt/fsl_hypervisor.c b/drivers/virt/fsl_hypervisor.c
> index 1b0b11b..ea344d7 100644
> --- a/drivers/virt/fsl_hypervisor.c
> +++ b/drivers/virt/fsl_hypervisor.c
> @@ -157,7 +157,7 @@ static long ioctl_memcpy(struct fsl_hv_ioctl_memcpy __user *p)
>
> unsigned int i;
> long ret = 0;
> - int num_pinned; /* return value from get_user_pages() */
> + int num_pinned = 0; /* return value from get_user_pages() */
> phys_addr_t remote_paddr; /* The next address in the remote buffer */
> uint32_t count; /* The number of bytes left to copy */
>
> @@ -293,7 +293,7 @@ static long ioctl_memcpy(struct fsl_hv_ioctl_memcpy __user *p)
>
> exit:
> if (pages) {
> - for (i = 0; i < num_pages; i++)
> + for (i = 0; i < num_pinned; i++)
> if (pages[i])
> put_page(pages[i]);
> }
> --
> 1.9.1
>

2020-06-30 07:23:11

by Souptick Joarder

[permalink] [raw]
Subject: Re: [PATCH v2] drivers/virt/fsl_hypervisor: Correcting error handling path

On Mon, Jun 22, 2020 at 10:05 PM Souptick Joarder <[email protected]> wrote:
>
> On Wed, Jun 17, 2020 at 8:22 AM Souptick Joarder <[email protected]> wrote:
> >
> > First, when memory allocation for sg_list_unaligned failed, there
> > is no point of calling put_pages() as we haven't pinned any pages.
> >
> > Second, if get_user_pages_fast() failed we should unpinned num_pinned
> > pages, no point of checking till num_pages.
> >
> > This will address both.
> >
> > Signed-off-by: Souptick Joarder <[email protected]>
> > Reviewed-by: Dan Carpenter <[email protected]>
> > Cc: John Hubbard <[email protected]>
>
> Any suggestion, what is the right tree to take this patch forward ?

If no further comment, can we get this patch in queue for 5.9 ?

>
> > ---
> > v2:
> > Added review tag.
> >
> > drivers/virt/fsl_hypervisor.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/virt/fsl_hypervisor.c b/drivers/virt/fsl_hypervisor.c
> > index 1b0b11b..ea344d7 100644
> > --- a/drivers/virt/fsl_hypervisor.c
> > +++ b/drivers/virt/fsl_hypervisor.c
> > @@ -157,7 +157,7 @@ static long ioctl_memcpy(struct fsl_hv_ioctl_memcpy __user *p)
> >
> > unsigned int i;
> > long ret = 0;
> > - int num_pinned; /* return value from get_user_pages() */
> > + int num_pinned = 0; /* return value from get_user_pages() */
> > phys_addr_t remote_paddr; /* The next address in the remote buffer */
> > uint32_t count; /* The number of bytes left to copy */
> >
> > @@ -293,7 +293,7 @@ static long ioctl_memcpy(struct fsl_hv_ioctl_memcpy __user *p)
> >
> > exit:
> > if (pages) {
> > - for (i = 0; i < num_pages; i++)
> > + for (i = 0; i < num_pinned; i++)
> > if (pages[i])
> > put_page(pages[i]);
> > }
> > --
> > 1.9.1
> >