linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] aic7xxx: replace kmalloc/strcpy by kstrdup
@ 2015-07-14  7:25 Christophe JAILLET
  2015-07-14  9:08 ` Dan Carpenter
  2015-07-14 10:02 ` [PATCH v2] " Christophe JAILLET
  0 siblings, 2 replies; 5+ messages in thread
From: Christophe JAILLET @ 2015-07-14  7:25 UTC (permalink / raw)
  To: hare, JBottomley
  Cc: linux-scsi, linux-kernel, kernel-janitors, Christophe JAILLET

This replaces kmalloc + strcpy by an equivalent call to kstrdup.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/scsi/aic7xxx/aic79xx_osm.c | 3 +--
 drivers/scsi/aic7xxx/aic7xxx_osm.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.c b/drivers/scsi/aic7xxx/aic79xx_osm.c
index ce96a0b..ae78e6d 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm.c
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.c
@@ -1250,9 +1250,8 @@ 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);
+	new_name = kstrdup(buf, GFP_ATOMIC);
 	if (new_name != NULL) {
-		strcpy(new_name, buf);
 		ahd_set_name(ahd, new_name);
 	}
 	host->unique_id = ahd->unit;
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm.c b/drivers/scsi/aic7xxx/aic7xxx_osm.c
index a2f2c77..ba59947 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm.c
@@ -1114,9 +1114,8 @@ 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);
+	new_name = kstrdup(buf, GFP_ATOMIC);
 	if (new_name != NULL) {
-		strcpy(new_name, buf);
 		ahc_set_name(ahc, new_name);
 	}
 	host->unique_id = ahc->unit;
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] aic7xxx: replace kmalloc/strcpy by kstrdup
  2015-07-14  7:25 [PATCH] aic7xxx: replace kmalloc/strcpy by kstrdup Christophe JAILLET
@ 2015-07-14  9:08 ` Dan Carpenter
  2015-07-14 10:02 ` [PATCH v2] " Christophe JAILLET
  1 sibling, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2015-07-14  9:08 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: hare, JBottomley, linux-scsi, linux-kernel, kernel-janitors

On Tue, Jul 14, 2015 at 09:25:16AM +0200, Christophe JAILLET wrote:
> --- a/drivers/scsi/aic7xxx/aic79xx_osm.c
> +++ b/drivers/scsi/aic7xxx/aic79xx_osm.c
> @@ -1250,9 +1250,8 @@ 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);
> +	new_name = kstrdup(buf, GFP_ATOMIC);
>  	if (new_name != NULL) {
> -		strcpy(new_name, buf);
>  		ahd_set_name(ahd, new_name);
>  	}

Remove the curly braces.  And below as well.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] aic7xxx: replace kmalloc/strcpy by kstrdup
  2015-07-14  7:25 [PATCH] aic7xxx: replace kmalloc/strcpy by kstrdup Christophe JAILLET
  2015-07-14  9:08 ` Dan Carpenter
@ 2015-07-14 10:02 ` Christophe JAILLET
  2015-07-14 10:07   ` Hannes Reinecke
  1 sibling, 1 reply; 5+ messages in thread
From: Christophe JAILLET @ 2015-07-14 10:02 UTC (permalink / raw)
  To: hare, JBottomley
  Cc: linux-scsi, linux-kernel, kernel-janitors, Christophe JAILLET

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] aic7xxx: replace kmalloc/strcpy by kstrdup
  2015-07-14 10:02 ` [PATCH v2] " Christophe JAILLET
@ 2015-07-14 10:07   ` Hannes Reinecke
  2015-07-14 11:27     ` walter harms
  0 siblings, 1 reply; 5+ messages in thread
From: Hannes Reinecke @ 2015-07-14 10:07 UTC (permalink / raw)
  To: Christophe JAILLET, JBottomley; +Cc: linux-scsi, linux-kernel, kernel-janitors

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)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] aic7xxx: replace kmalloc/strcpy by kstrdup
  2015-07-14 10:07   ` Hannes Reinecke
@ 2015-07-14 11:27     ` walter harms
  0 siblings, 0 replies; 5+ messages in thread
From: walter harms @ 2015-07-14 11:27 UTC (permalink / raw)
  To: Hannes Reinecke
  Cc: Christophe JAILLET, JBottomley, linux-scsi, linux-kernel,
	kernel-janitors



Am 14.07.2015 12:07, schrieb Hannes Reinecke:
> 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>



If i did not miss an other use of buf,
you can replace the sprintf/strdup combo with:

new_name = kasprintf(GFP_ATOMIC, "scsi%d", host->host_no);


just my 2 cents
re,
 wh


> Cheers,
> 
> Hannes

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-07-14 11:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-14  7:25 [PATCH] aic7xxx: replace kmalloc/strcpy by kstrdup Christophe JAILLET
2015-07-14  9:08 ` Dan Carpenter
2015-07-14 10:02 ` [PATCH v2] " Christophe JAILLET
2015-07-14 10:07   ` Hannes Reinecke
2015-07-14 11:27     ` walter harms

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).