Re: [PATCH] scsi: bfa: bfad_attr.c: Optimization of the Code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 06/04/14 20:08, Rickard Strandqvist wrote:
> Minimized the use of snprintf()
> And removed a variable that was only used for the temporary storage.
> 
> This was partly found using a static code analysis program called cppcheck.
> 
> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@xxxxxxxxxxxxxxxxxx>
> ---
>  drivers/scsi/bfa/bfad_attr.c |   14 ++++++++------
>  1 file changed, 8 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/scsi/bfa/bfad_attr.c b/drivers/scsi/bfa/bfad_attr.c
> index 40be670..5f5917a 100644
> --- a/drivers/scsi/bfa/bfad_attr.c
> +++ b/drivers/scsi/bfa/bfad_attr.c
> @@ -839,12 +839,10 @@ bfad_im_symbolic_name_show(struct device *dev, struct device_attribute *attr,
>  			(struct bfad_im_port_s *) shost->hostdata[0];
>  	struct bfad_s *bfad = im_port->bfad;
>  	struct bfa_lport_attr_s port_attr;
> -	char symname[BFA_SYMNAME_MAXLEN];
>  
>  	bfa_fcs_lport_get_attr(&bfad->bfa_fcs.fabric.bport, &port_attr);
> -	strncpy(symname, port_attr.port_cfg.sym_name.symname,
> -			BFA_SYMNAME_MAXLEN);
> -	return snprintf(buf, PAGE_SIZE, "%s\n", symname);
> +	return snprintf(buf, PAGE_SIZE, "%s\n",
> +			port_attr.port_cfg.sym_name.symname);
>  }
>  
>  static ssize_t
> @@ -865,7 +863,9 @@ static ssize_t
>  bfad_im_drv_version_show(struct device *dev, struct device_attribute *attr,
>  				char *buf)
>  {
> -	return snprintf(buf, PAGE_SIZE, "%s\n", BFAD_DRIVER_VERSION);
> +	strncpy(buf, BFAD_DRIVER_VERSION  "\n" , PAGE_SIZE);
> +	buf[PAGE_SIZE - 1] = '\0';
> +	return strlen(buf);
>  }
>  
>  static ssize_t
> @@ -913,7 +913,9 @@ static ssize_t
>  bfad_im_drv_name_show(struct device *dev, struct device_attribute *attr,
>  				char *buf)
>  {
> -	return snprintf(buf, PAGE_SIZE, "%s\n", BFAD_DRIVER_NAME);
> +	strncpy(buf, BFAD_DRIVER_NAME  "\n" , PAGE_SIZE);
> +	buf[PAGE_SIZE - 1] = '\0';
> +	return strlen(buf);
>  }

This is ugly. Please use sprintf(buf, "%.*s\n", PAGE_SIZE - 1, str)
instead of strncpy() + strlen().

Bart.

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]
  Powered by Linux