Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1183566 > unrolled thread

[PATCH v2] aic7xxx: replace kmalloc/strcpy by kstrdup

Started byChristophe JAILLET <christophe.jaillet@wanadoo.fr>
First post2015-07-14 12:10 +0200
Last post2015-07-14 12:10 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH v2] aic7xxx: replace kmalloc/strcpy by kstrdup Christophe JAILLET <christophe.jaillet@wanadoo.fr> - 2015-07-14 12:10 +0200
    Re: [PATCH v2] aic7xxx: replace kmalloc/strcpy by kstrdup Hannes Reinecke <hare@suse.de> - 2015-07-14 12:10 +0200

#1183566 — [PATCH v2] aic7xxx: replace kmalloc/strcpy by kstrdup

FromChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Date2015-07-14 12:10 +0200
Subject[PATCH v2] aic7xxx: replace kmalloc/strcpy by kstrdup
Message-ID<pM5jX-RW-1@gated-at.bofh.it>
This replaces kmalloc + strcpy by an equivalent call to kstrdup.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
v2: remove useless curly braces

 drivers/scsi/aic7xxx/aic79xx_osm.c | 6 ++----
 drivers/scsi/aic7xxx/aic7xxx_osm.c | 6 ++----
 2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.c b/drivers/scsi/aic7xxx/aic79xx_osm.c
index ce96a0b..ea4086e 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm.c
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.c
@@ -1250,11 +1250,9 @@ ahd_linux_register_host(struct ahd_softc *ahd, struct scsi_host_template *templa
 	ahd_set_unit(ahd, ahd_linux_unit++);
 	ahd_unlock(ahd, &s);
 	sprintf(buf, "scsi%d", host->host_no);
-	new_name = kmalloc(strlen(buf) + 1, GFP_ATOMIC);
-	if (new_name != NULL) {
-		strcpy(new_name, buf);
+	new_name = kstrdup(buf, GFP_ATOMIC);
+	if (new_name != NULL)
 		ahd_set_name(ahd, new_name);
-	}
 	host->unique_id = ahd->unit;
 	ahd_linux_initialize_scsi_bus(ahd);
 	ahd_intr_enable(ahd, TRUE);
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm.c b/drivers/scsi/aic7xxx/aic7xxx_osm.c
index a2f2c77..f0ac966 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm.c
@@ -1114,11 +1114,9 @@ ahc_linux_register_host(struct ahc_softc *ahc, struct scsi_host_template *templa
 	ahc_set_unit(ahc, ahc_linux_unit++);
 	ahc_unlock(ahc, &s);
 	sprintf(buf, "scsi%d", host->host_no);
-	new_name = kmalloc(strlen(buf) + 1, GFP_ATOMIC);
-	if (new_name != NULL) {
-		strcpy(new_name, buf);
+	new_name = kstrdup(buf, GFP_ATOMIC);
+	if (new_name != NULL)
 		ahc_set_name(ahc, new_name);
-	}
 	host->unique_id = ahc->unit;
 	ahc_linux_initialize_scsi_bus(ahc);
 	ahc_intr_enable(ahc, TRUE);
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1183572

FromHannes Reinecke <hare@suse.de>
Date2015-07-14 12:10 +0200
Message-ID<pM5jY-RW-27@gated-at.bofh.it>
In reply to#1183566
On 07/14/2015 12:02 PM, Christophe JAILLET wrote:
> This replaces kmalloc + strcpy by an equivalent call to kstrdup.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> v2: remove useless curly braces
> 
>  drivers/scsi/aic7xxx/aic79xx_osm.c | 6 ++----
>  drivers/scsi/aic7xxx/aic7xxx_osm.c | 6 ++----
>  2 files changed, 4 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.c b/drivers/scsi/aic7xxx/aic79xx_osm.c
> index ce96a0b..ea4086e 100644
> --- a/drivers/scsi/aic7xxx/aic79xx_osm.c
> +++ b/drivers/scsi/aic7xxx/aic79xx_osm.c
> @@ -1250,11 +1250,9 @@ ahd_linux_register_host(struct ahd_softc *ahd, struct scsi_host_template *templa
>  	ahd_set_unit(ahd, ahd_linux_unit++);
>  	ahd_unlock(ahd, &s);
>  	sprintf(buf, "scsi%d", host->host_no);
> -	new_name = kmalloc(strlen(buf) + 1, GFP_ATOMIC);
> -	if (new_name != NULL) {
> -		strcpy(new_name, buf);
> +	new_name = kstrdup(buf, GFP_ATOMIC);
> +	if (new_name != NULL)
>  		ahd_set_name(ahd, new_name);
> -	}
>  	host->unique_id = ahd->unit;
>  	ahd_linux_initialize_scsi_bus(ahd);
>  	ahd_intr_enable(ahd, TRUE);
> diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm.c b/drivers/scsi/aic7xxx/aic7xxx_osm.c
> index a2f2c77..f0ac966 100644
> --- a/drivers/scsi/aic7xxx/aic7xxx_osm.c
> +++ b/drivers/scsi/aic7xxx/aic7xxx_osm.c
> @@ -1114,11 +1114,9 @@ ahc_linux_register_host(struct ahc_softc *ahc, struct scsi_host_template *templa
>  	ahc_set_unit(ahc, ahc_linux_unit++);
>  	ahc_unlock(ahc, &s);
>  	sprintf(buf, "scsi%d", host->host_no);
> -	new_name = kmalloc(strlen(buf) + 1, GFP_ATOMIC);
> -	if (new_name != NULL) {
> -		strcpy(new_name, buf);
> +	new_name = kstrdup(buf, GFP_ATOMIC);
> +	if (new_name != NULL)
>  		ahc_set_name(ahc, new_name);
> -	}
>  	host->unique_id = ahc->unit;
>  	ahc_linux_initialize_scsi_bus(ahc);
>  	ahc_intr_enable(ahc, TRUE);
> 
Alright, if you insist ...

Reviewed-by: Hannes Reinecke <hare@suse.com>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		               zSeries & Storage
hare@suse.de			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web