public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>,
	Anil Gurumurthy <anil.gurumurthy@qlogic.com>,
	Sudarsana Kalluru <sudarsana.kalluru@qlogic.com>
Cc: "James E.J. Bottomley" <JBottomley@parallels.com>,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] scsi: bfa: bfad_attr.c:  Optimization of the Code
Date: Thu, 05 Jun 2014 08:55:59 +0200	[thread overview]
Message-ID: <5390147F.8070803@acm.org> (raw)
In-Reply-To: <1401905288-32642-1-git-send-email-rickard_strandqvist@spectrumdigital.se>

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@spectrumdigital.se>
> ---
>  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.


  reply	other threads:[~2014-06-05  6:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-04 18:08 [PATCH] scsi: bfa: bfad_attr.c: Optimization of the Code Rickard Strandqvist
2014-06-05  6:55 ` Bart Van Assche [this message]
2014-06-05  7:10   ` Bart Van Assche
2014-06-06 22:03     ` Rickard Strandqvist
  -- strict thread matches above, loose matches on Subject: below --
2014-06-06 22:04 [PATCH] scsi: bfa: bfad_attr.c: Optimization of the code Rickard Strandqvist

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5390147F.8070803@acm.org \
    --to=bvanassche@acm.org \
    --cc=JBottomley@parallels.com \
    --cc=anil.gurumurthy@qlogic.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=rickard_strandqvist@spectrumdigital.se \
    --cc=sudarsana.kalluru@qlogic.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox