From mboxrd@z Thu Jan 1 00:00:00 1970 From: Himangi Saraogi Subject: [PATCH] aic7xxx/aic7770 : Use kstrdup Date: Tue, 10 Jun 2014 19:50:37 +0530 Message-ID: <20140610142037.GA2993@himangi-Dell> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org To: Hannes Reinecke , "James E.J. Bottomley" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: julia.lawall@lip6.fr List-Id: linux-scsi@vger.kernel.org Use kstrdup when the goal of an allocation is copy a string into the allocated region. The semantic patch that makes this change is as follows: // @@ 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); // Signed-off-by: Himangi Saraogi Acked-by: Julia Lawall --- drivers/scsi/aic7xxx/aic7770_osm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/scsi/aic7xxx/aic7770_osm.c b/drivers/scsi/aic7xxx/aic7770_osm.c index 0cb8ef6..3d401d0 100644 --- a/drivers/scsi/aic7xxx/aic7770_osm.c +++ b/drivers/scsi/aic7xxx/aic7770_osm.c @@ -85,10 +85,9 @@ aic7770_probe(struct device *dev) int error; sprintf(buf, "ahc_eisa:%d", eisaBase >> 12); - name = kmalloc(strlen(buf) + 1, GFP_ATOMIC); + name = kstrdup(buf, GFP_ATOMIC); if (name == NULL) return (ENOMEM); - strcpy(name, buf); ahc = ahc_alloc(&aic7xxx_driver_template, name); if (ahc == NULL) return (ENOMEM); -- 1.9.1