diff mbox

[1/7] aacraid: Use memdup_user() rather than duplicating its implementation

Message ID 23c56a66-74a6-6033-f209-ac3e4ba83e61@users.sourceforge.net (mailing list archive)
State Changes Requested, archived
Headers show

Commit Message

SF Markus Elfring Aug. 21, 2016, 7:19 a.m. UTC
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 20 Aug 2016 20:05:24 +0200

Reuse existing functionality from memdup_user() instead of keeping
duplicate source code.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/scsi/aacraid/commctrl.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

Comments

Dave Carroll Aug. 22, 2016, 6 p.m. UTC | #1
> From: Markus Elfring <elfring@users.sourceforge.net>

> Date: Sat, 20 Aug 2016 20:05:24 +0200

> 

> Reuse existing functionality from memdup_user() instead of keeping duplicate

> source code.

> 

> This issue was detected by using the Coccinelle software.

> 

> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>

> ---

>  drivers/scsi/aacraid/commctrl.c | 12 +++---------

>  1 file changed, 3 insertions(+), 9 deletions(-)

> 

> diff --git a/drivers/scsi/aacraid/commctrl.c b/drivers/scsi/aacraid/commctrl.c

> index 5648b71..1af3084 100644

> --- a/drivers/scsi/aacraid/commctrl.c

> +++ b/drivers/scsi/aacraid/commctrl.c

> @@ -526,15 +526,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;

> +       user_srbcmd = memdup_user(user_srb, fibsize);

> +       if (IS_ERR(user_srbcmd)) {

> +               rcode = PTR_ERR(user_srbcmd);

>                 goto cleanup;

>         }

> 

> --


Hi Markus,

Patch 2/7 should precede Patch 1/7, as falling into kfree() would not look pretty.

Thanks, -Dave
SF Markus Elfring Aug. 22, 2016, 8:23 p.m. UTC | #2
>> @@ -526,15 +526,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;
>> +       user_srbcmd = memdup_user(user_srb, fibsize);
>> +       if (IS_ERR(user_srbcmd)) {
>> +               rcode = PTR_ERR(user_srbcmd);
>>                 goto cleanup;
>>         }
>>
>> --
> 
> Hi Markus,
> 
> Patch 2/7 should precede Patch 1/7, as falling into kfree() would not look pretty.

Do you eventually prefer that this source code adjustment should be combined with
the update suggestion "[2/7] aacraid: One function call less in aac_send_raw_srb()
after error detection" in a single update step?

Regards,
Markus
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Dave Carroll Aug. 24, 2016, 11:01 p.m. UTC | #3
> >

> > Hi Markus,

> >

> > Patch 2/7 should precede Patch 1/7, as falling into kfree() would not look

> pretty.

> 

> Do you eventually prefer that this source code adjustment should be combined

> with the update suggestion "[2/7] aacraid: One function call less in

> aac_send_raw_srb() after error detection" in a single update step?

> 


Hi Markus,

My primary objective in this would be the ability to bisect ... The secondary would be one issue/patch. I think my preference would be to swap patches 1 and 2.

Thanks, -Dave
diff mbox

Patch

diff --git a/drivers/scsi/aacraid/commctrl.c b/drivers/scsi/aacraid/commctrl.c
index 5648b71..1af3084 100644
--- a/drivers/scsi/aacraid/commctrl.c
+++ b/drivers/scsi/aacraid/commctrl.c
@@ -526,15 +526,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;
+	user_srbcmd = memdup_user(user_srb, fibsize);
+	if (IS_ERR(user_srbcmd)) {
+		rcode = PTR_ERR(user_srbcmd);
 		goto cleanup;
 	}