Skip to contentSkip to conversation

scsi: aacraid: Use memdup_user() as a cleanup

PATCH In review Zou Wei 2 participants 3 messages Apr 22, 2020 – Apr 26, 2020

Subsystems (2)
lore
Share & tools
lore

Zou Wei

author
#0 lore raw

PATCH 1/1 scsi: aacraid: Use memdup_user() as a cleanup

Fix coccicheck warning which recommends to use memdup_user().

This patch fixes the following coccicheck warnings:

drivers/scsi/aacraid/commctrl.c:516:15-22: WARNING opportunity for memdup_user

Fixes 4645df1035b3 ("[PATCH] aacraid: swapped kmalloc args.")
---
 drivers/scsi/aacraid/commctrl.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)
drivers/scsi/aacraid/commctrl.c +3 -11
index ffe41bc..1ce1620 100644
@@ -513,17 +513,9 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 		goto cleanup;
 	}
 
-	user_srbcmd = kmalloc(fibsize, GFP_KERNEL);
-	if (!user_srbcmd) {
-		dprintk((KERN_DEBUG"aacraid: Could not make a copy of the srb\n"));
-		rcode = -ENOMEM;
-		goto cleanup;
-	}
-	if(copy_from_user(user_srbcmd, user_srb,fibsize)){
-		dprintk((KERN_DEBUG"aacraid: Could not copy srb from user\n"));
-		rcode = -EFAULT;
-		goto cleanup;
-	}
+	user_srbcmd = memdup_user(user_srb, fibsize);
+	if (IS_ERR(user_srbcmd))
+		return PTR_ERR(user_srbcmd);
 
 	flags = user_srbcmd->flags; /* from user in cpu order */
 	switch (flags & (SRB_DataIn | SRB_DataOut)) {
Signature · 1 line
2.6.2
#1 lore raw

Zou,

Quoted 15 lines
drivers/scsi/aacraid/commctrl.c +0 -7
index ffe41bc..1ce1620 100644
@@ -513,17 +513,9 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 		goto cleanup;
 	}
 
-	user_srbcmd = kmalloc(fibsize, GFP_KERNEL);
-	if (!user_srbcmd) {
-		dprintk((KERN_DEBUG"aacraid: Could not make a copy of the srb\n"));
-		rcode = -ENOMEM;
-		goto cleanup;
-	}
-	if(copy_from_user(user_srbcmd, user_srb,fibsize)){

drivers/scsi/aacraid/commctrl.c static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg) · line 521

Quoted 10 lines
drivers/scsi/aacraid/commctrl.c +3 -4
-		dprintk((KERN_DEBUG"aacraid: Could not copy srb from user\n"));
-		rcode = -EFAULT;
-		goto cleanup;
-	}
+	user_srbcmd = memdup_user(user_srb, fibsize);
+	if (IS_ERR(user_srbcmd))
+		return PTR_ERR(user_srbcmd);
 
 	flags = user_srbcmd->flags; /* from user in cpu order */
 	switch (flags & (SRB_DataIn | SRB_DataOut)) {

This is not equivalent, is it? The original code does a goto cleanup; whereas your patch returns on error.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
author
#2 lore raw

Hi Martin,

Thanks for your review and reply.
You are right, it is not equivalent. I will keep the original goto cleanup. But the return value is changed to use of PTR_ERR (user_srbcmd), and assign it to rcode. I will send the v2 soon later

Quoted 32 lines · Martin K. Petersen

Zou,

Quoted 15 lines
drivers/scsi/aacraid/commctrl.c +0 -7
index ffe41bc..1ce1620 100644
@@ -513,17 +513,9 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
  		goto cleanup;
  	}
 
-	user_srbcmd = kmalloc(fibsize, GFP_KERNEL);
-	if (!user_srbcmd) {
-		dprintk((KERN_DEBUG"aacraid: Could not make a copy of the srb\n"));
-		rcode = -ENOMEM;
-		goto cleanup;
-	}
-	if(copy_from_user(user_srbcmd, user_srb,fibsize)){

drivers/scsi/aacraid/commctrl.c static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg) · line 521

Quoted 10 lines
drivers/scsi/aacraid/commctrl.c +3 -4
-		dprintk((KERN_DEBUG"aacraid: Could not copy srb from user\n"));
-		rcode = -EFAULT;
-		goto cleanup;
-	}
+	user_srbcmd = memdup_user(user_srb, fibsize);
+	if (IS_ERR(user_srbcmd))
+		return PTR_ERR(user_srbcmd);
 
  	flags = user_srbcmd->flags; /* from user in cpu order */
  	switch (flags & (SRB_DataIn | SRB_DataOut)) {

This is not equivalent, is it? The original code does a goto cleanup; whereas your patch returns on error.