Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: "James E.J. Bottomley" <JBottomley@parallels.com>
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org
Subject: [patch] [SCSI] cleanup some calls to strncmp()
Date: Fri, 14 Sep 2012 14:05:56 +0300	[thread overview]
Message-ID: <20120914110556.GB1152@elgon.mountain> (raw)

The main motivation for this patch is that for the first strncmp()
we do 'strncmp(src, "-", 20)' but "src" is a 15 character buffer not 20.

Also since we know that "-" is only two characters, the compare isn't
going to go further than 2 characters into src before deciding that it
doesn't match.

The same applies to the other strncmp()s.  In those cases "str" is
actually 10 characters so the limiter is correct but it is still not
needed when the length for "adapter" and "firmware" is known and less
than 10.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index 093d4f6..bd576ce 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -84,7 +84,7 @@ static int check_set(unsigned int *val, char *src)
 {
 	char *last;
 
-	if (strncmp(src, "-", 20) == 0) {
+	if (strcmp(src, "-") == 0) {
 		*val = SCAN_WILD_CARD;
 	} else {
 		/*
@@ -249,9 +249,9 @@ static DEVICE_ATTR(active_mode, S_IRUGO | S_IWUSR, show_shost_active_mode, NULL)
 
 static int check_reset_type(char *str)
 {
-	if (strncmp(str, "adapter", 10) == 0)
+	if (strcmp(str, "adapter") == 0)
 		return SCSI_ADAPTER_RESET;
-	else if (strncmp(str, "firmware", 10) == 0)
+	else if (strcmp(str, "firmware") == 0)
 		return SCSI_FIRMWARE_RESET;
 	else
 		return 0;

                 reply	other threads:[~2012-09-14 11:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20120914110556.GB1152@elgon.mountain \
    --to=dan.carpenter@oracle.com \
    --cc=JBottomley@parallels.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    /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