Skip to contentSkip to conversation

aic79xx: use kmemdup

PATCH New Muhammad Falak R Wani 3 participants 5 messages May 19, 2016 – Jun 1, 2016

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

PATCH 1/1 aic79xx: use kmemdup

Use kmemdup when some other buffer is immediately copied into allocated region. It replaces call to allocation followed by memcpy, by a single call to kmemdup.

---
 drivers/scsi/aic7xxx/aic79xx_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/aic7xxx/aic79xx_core.c +2 -2
index 109e2c9..8592448 100644
@@ -9494,10 +9494,10 @@ ahd_loadseq(struct ahd_softc *ahd)
 	if (cs_count != 0) {
 
 		cs_count *= sizeof(struct cs);
-		ahd->critical_sections = kmalloc(cs_count, GFP_ATOMIC);
+		ahd->critical_sections = kmemdup(cs_table, cs_count,
+						 GFP_ATOMIC);
 		if (ahd->critical_sections == NULL)
 			panic("ahd_loadseq: Could not malloc");
-		memcpy(ahd->critical_sections, cs_table, cs_count);
 	}
 	ahd_outb(ahd, SEQCTL0, PERRORDIS|FAILDIS|FASTMODE);
 
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/1 aic7xxx: use kmemdup

Use kmemdup when some other buffer is immediately copied into allocated region. It replaces call to allocation followed by memcpy, by a single call to kmemdup.

---
 drivers/scsi/aic7xxx/aic7xxx_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/aic7xxx/aic7xxx_core.c +2 -2
index 64ab9ea..2672c39 100644
@@ -6940,10 +6940,10 @@ ahc_loadseq(struct ahc_softc *ahc)
 	if (cs_count != 0) {
 
 		cs_count *= sizeof(struct cs);
-		ahc->critical_sections = kmalloc(cs_count, GFP_ATOMIC);
+		ahc->critical_sections = kmemdup(cs_table, cs_count,
+						 GFP_ATOMIC);
 		if (ahc->critical_sections == NULL)
 			panic("ahc_loadseq: Could not malloc");
-		memcpy(ahc->critical_sections, cs_table, cs_count);
 	}
 	ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE);
 
Signature · 1 line
1.9.1
#2 lore raw

PATCH 1/1 aacraid: use kmemdup

In reply to Muhammad Falak R Wani

Use kmemdup when some other buffer is immediately copied into allocated region. It replaces call to allocation followed by memcpy, by a single call to kmemdup.

---
 drivers/scsi/aacraid/commctrl.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/scsi/aacraid/commctrl.c +3 -4
index 4b3bb52..b381b37 100644
@@ -635,15 +635,14 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
 			}
 		} else {
 			struct user_sgmap* usg;
-			usg = kmalloc(actual_fibsize - sizeof(struct aac_srb)
-			  + sizeof(struct sgmap), GFP_KERNEL);
+			usg = kmemdup(upsg,
+				      actual_fibsize - sizeof(struct aac_srb)
+				      + sizeof(struct sgmap), GFP_KERNEL);
 			if (!usg) {
 				dprintk((KERN_DEBUG"aacraid: Allocation error in Raw SRB command\n"));
 				rcode = -ENOMEM;
 				goto cleanup;
 			}
-			memcpy (usg, upsg, actual_fibsize - sizeof(struct aac_srb)
-			  + sizeof(struct sgmap));
 			actual_fibsize = actual_fibsize64;
 
 			for (i = 0; i < usg->count; i++) {
Signature · 1 line
1.9.1
Reviewed-by on v1 1/1
#3 lore raw

RE: [PATCH] [SCSI] aacraid: use kmemdup

Quoted 46 lines

-----Original Message-----
From: [email protected] [mailto:linux-scsi- [email protected]] On Behalf Of Muhammad Falak R Wani
Sent: Thursday, May 19, 2016 7:09 AM
To: Hannes Reinecke
Cc: Adaptec OEM Raid Solutions; James E.J. Bottomley; Martin K. Petersen; [email protected]; [email protected]
Subject: [PATCH] [SCSI] aacraid: use kmemdup

EXTERNAL EMAIL

Use kmemdup when some other buffer is immediately copied into allocated region. It replaces call to allocation followed by memcpy, by a single call to kmemdup.

---
 drivers/scsi/aacraid/commctrl.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/scsi/aacraid/commctrl.c +3 -4
index 4b3bb52..b381b37 100644
@@ -635,15 +635,14 @@ static int aac_send_raw_srb(struct aac_dev* dev,
 void __user * arg)
                        }
                } else {
                        struct user_sgmap* usg;
-                       usg = kmalloc(actual_fibsize - sizeof(struct aac_srb)
-                         + sizeof(struct sgmap), GFP_KERNEL);
+                       usg = kmemdup(upsg,
+                                     actual_fibsize - sizeof(struct aac_srb)
+                                     + sizeof(struct sgmap), GFP_KERNEL);
                        if (!usg) {
                                dprintk((KERN_DEBUG"aacraid: Allocation error in Raw SRB
 command\n"));
                                rcode = -ENOMEM;
                                goto cleanup;
                        }
-                       memcpy (usg, upsg, actual_fibsize - sizeof(struct aac_srb)
-                         + sizeof(struct sgmap));
                        actual_fibsize = actual_fibsize64;
Quoted 1 line
                        for (i = 0; i < usg->count; i++) {
#4 lore raw

Re: [PATCH] [SCSI] aacraid: use kmemdup

In reply to Muhammad Falak R Wani
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Muhammad" == Muhammad Falak R Wani <[email protected]> writes:

Muhammad> Use kmemdup when some other buffer is immediately copied into Muhammad> allocated region. It replaces call to allocation followed by Muhammad> memcpy, by a single call to kmemdup.

Applied to 4.8/scsi-queue.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering