Skip to contentSkip to conversation

drivers/virt/fsl_hypervisor: Correcting error handling path

PATCH Superseded Souptick Joarder 2 participants 3 messages Jul 29, 2020 – Aug 25, 2020

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 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.

---
v2:
Added review tag.

 drivers/virt/fsl_hypervisor.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/virt/fsl_hypervisor.c +2 -2
index 1b0b11b..ea344d7 100644
@@ -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]);
 	}
Signature · 1 line
1.9.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 5 lines · Souptick Joarder

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.

Hi Souptick,

For both of the above, the wording "no point" is so overly gentle as to be misleading. That's because calling put_page() on any pages beyond num_pinned is a *bug*.

So let's reword that. And let's change the patch subject from "Correcting" to "fix".

And probably good to add a Fixes: tag, too.

More:

Quoted 27 lines

This will address both.

---
v2:
Added review tag.

  drivers/virt/fsl_hypervisor.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/virt/fsl_hypervisor.c +1 -1
index 1b0b11b..ea344d7 100644
@@ -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 */
 

drivers/virt/fsl_hypervisor.c static long ioctl_memcpy(struct fsl_hv_ioctl_memcpy __user *p) · line 297

Quoted 6 lines
drivers/virt/fsl_hypervisor.c +1 -1
@@ -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])

I suspect that this "if" is unnecessary now.

Either way, the diff itself looks good to me, so with the wording changes to the commit description, you can add:

thanks,

Signature · 2 lines
John Hubbard
NVIDIA
Quoted 3 lines
drivers/virt/fsl_hypervisor.c +0 -0
  				put_page(pages[i]);
  	}
#2 lore raw
Quoted 10 lines · John Hubbard
Quoted 5 lines · Souptick Joarder

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.

Hi Souptick,

Quoted 8 lines

For both of the above, the wording "no point" is so overly gentle as to be misleading. That's because calling put_page() on any pages beyond num_pinned is a *bug*.

So let's reword that. And let's change the patch subject from "Correcting" to "fix".

And probably good to add a Fixes: tag, too.

Is there any scripts/ settings to fetch Fixes: tag other than using git blame ?

Quoted 53 lines

More:

Quoted 27 lines

This will address both.

---
v2:
Added review tag.

  drivers/virt/fsl_hypervisor.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/virt/fsl_hypervisor.c +1 -1
index 1b0b11b..ea344d7 100644
@@ -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 */
 

drivers/virt/fsl_hypervisor.c static long ioctl_memcpy(struct fsl_hv_ioctl_memcpy __user *p) · line 297

Quoted 6 lines
drivers/virt/fsl_hypervisor.c +1 -1
@@ -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])

I suspect that this "if" is unnecessary now.

Either way, the diff itself looks good to me, so with the wording changes to the commit description, you can add:

thanks,
--
John Hubbard
NVIDIA

Quoted 3 lines
drivers/virt/fsl_hypervisor.c +0 -0
                              put_page(pages[i]);
      }