Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

aic7xxx: Use kstrdup

Use kstrdup when the goal of an allocation is copy a string into the
allocated region.

The Coccinelle semantic patch that makes this change is as follows:

// <smpl>
@@
expression from,to;
expression flag,E1,E2;
statement S;
@@

- to = kmalloc(strlen(from) + 1,flag);
+ to = kstrdup(from, flag);
... when != \(from = E1 \| to = E1 \)
if (to==NULL || ...) S
... when != \(from = E2 \| to = E2 \)
- strcpy(to, from);
// </smpl>

Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Christoph Hellwig <hch@lst.de>

authored by

Himangi Saraogi and committed by
Christoph Hellwig
1f3d2d9e c21a2c1a

+3 -6
+1 -2
drivers/scsi/aic7xxx/aic7770_osm.c
··· 85 85 int error; 86 86 87 87 sprintf(buf, "ahc_eisa:%d", eisaBase >> 12); 88 - name = kmalloc(strlen(buf) + 1, GFP_ATOMIC); 88 + name = kstrdup(buf, GFP_ATOMIC); 89 89 if (name == NULL) 90 90 return (ENOMEM); 91 - strcpy(name, buf); 92 91 ahc = ahc_alloc(&aic7xxx_driver_template, name); 93 92 if (ahc == NULL) 94 93 return (ENOMEM);
+1 -2
drivers/scsi/aic7xxx/aic79xx_osm_pci.c
··· 178 178 ahd_get_pci_bus(pci), 179 179 ahd_get_pci_slot(pci), 180 180 ahd_get_pci_function(pci)); 181 - name = kmalloc(strlen(buf) + 1, GFP_ATOMIC); 181 + name = kstrdup(buf, GFP_ATOMIC); 182 182 if (name == NULL) 183 183 return (-ENOMEM); 184 - strcpy(name, buf); 185 184 ahd = ahd_alloc(NULL, name); 186 185 if (ahd == NULL) 187 186 return (-ENOMEM);
+1 -2
drivers/scsi/aic7xxx/aic7xxx_osm_pci.c
··· 225 225 ahc_get_pci_bus(pci), 226 226 ahc_get_pci_slot(pci), 227 227 ahc_get_pci_function(pci)); 228 - name = kmalloc(strlen(buf) + 1, GFP_ATOMIC); 228 + name = kstrdup(buf, GFP_ATOMIC); 229 229 if (name == NULL) 230 230 return (-ENOMEM); 231 - strcpy(name, buf); 232 231 ahc = ahc_alloc(NULL, name); 233 232 if (ahc == NULL) 234 233 return (-ENOMEM);