Skip to contentSkip to conversation

ocxl: Fix potential bad errno on irq allocation

PATCH Applied Frederic Barrat 3 participants 3 messages Feb 16, 2018 – Feb 21, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ocxl: Fix potential bad errno on irq allocation

Fix some issues found by a static checker:

When allocating an AFU interrupt, if the driver cannot copy the output parameters to userland, the errno value was not set to EFAULT

Remove a (now) useless cast.

---
 drivers/misc/ocxl/file.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/misc/ocxl/file.c +4 -2
index 2dd2db9bc1c9..337462e1569f 100644
@@ -133,8 +133,10 @@ static long afu_ioctl(struct file *file, unsigned int cmd,
 		if (!rc) {
 			rc = copy_to_user((u64 __user *) args, &irq_offset,
 					sizeof(irq_offset));
-			if (rc)
+			if (rc) {
 				ocxl_afu_irq_free(ctx, irq_offset);
+				return -EFAULT;
+			}
 		}
 		break;
 
@@ -329,7 +331,7 @@ static ssize_t afu_read(struct file *file, char __user *buf, size_t count,
 
 	used += sizeof(header);
 
-	rc = (ssize_t) used;
+	rc = used;
 	return rc;
 }
 
Signature · 1 line
2.14.1
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Frederic Barrat

Fix some issues found by a static checker:

When allocating an AFU interrupt, if the driver cannot copy the output parameters to userland, the errno value was not set to EFAULT

Remove a (now) useless cast.

Quoted 29 lines
---
  drivers/misc/ocxl/file.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/misc/ocxl/file.c +4 -2
index 2dd2db9bc1c9..337462e1569f 100644
@@ -133,8 +133,10 @@ static long afu_ioctl(struct file *file, unsigned int cmd,
  		if (!rc) {
  			rc = copy_to_user((u64 __user *) args, &irq_offset,
  					sizeof(irq_offset));
-			if (rc)
+			if (rc) {
  				ocxl_afu_irq_free(ctx, irq_offset);
+				return -EFAULT;
+			}
  		}
  		break;
 
@@ -329,7 +331,7 @@ static ssize_t afu_read(struct file *file, char __user *buf, size_t count,
 
  	used += sizeof(header);
 
-	rc = (ssize_t) used;
+	rc = used;
  	return rc;
  }
 
Signature · 2 lines
Andrew Donnellan              OzLabs, ADL Canberra
[email protected]  IBM Australia Limited
#2 lore raw
In reply to Frederic Barrat
Quoted 10 lines · Frederic Barrat

Fix some issues found by a static checker:

When allocating an AFU interrupt, if the driver cannot copy the output parameters to userland, the errno value was not set to EFAULT

Remove a (now) useless cast.

Applied to powerpc fixes, thanks.

https://git.kernel.org/powerpc/c/423688abd9ab654044bddd82eb5983

cheers