* [patch] [SCSI] aacraid: use lower snprintf() limit
@ 2011-10-05 5:50 Dan Carpenter
2011-10-05 7:35 ` Rolf Eike Beer
0 siblings, 1 reply; 7+ messages in thread
From: Dan Carpenter @ 2011-10-05 5:50 UTC (permalink / raw)
To: Adaptec OEM Raid Solutions
Cc: James E.J. Bottomley, linux-scsi, linux-kernel, kernel-janitors
This is just a cleanup, to silence static checker warnings. It
doesn't change how the code works.
buf[] can either be BUF_SIZE if this is called from sysfs, or it can
be 16 if it's called from aac_get_adapter_info() via
aac_get_serial_number(). We use the smaller limit here.
sizeof(dev->supplement_adapter_info.MfgPcbaSerialNo) is 12 so there
is actually no chance of hitting either limit.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index 3382475..ea8d96e 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -894,15 +894,20 @@ static ssize_t aac_show_serial_number(struct device *device,
int len = 0;
if (le32_to_cpu(dev->adapter_info.serial[0]) != 0xBAD0)
- len = snprintf(buf, PAGE_SIZE, "%06X\n",
+ len = snprintf(buf, 16, "%06X\n",
le32_to_cpu(dev->adapter_info.serial[0]));
if (len &&
!memcmp(&dev->supplement_adapter_info.MfgPcbaSerialNo[
sizeof(dev->supplement_adapter_info.MfgPcbaSerialNo)-len],
buf, len-1))
- len = snprintf(buf, PAGE_SIZE, "%.*s\n",
+ len = snprintf(buf, 16, "%.*s\n",
(int)sizeof(dev->supplement_adapter_info.MfgPcbaSerialNo),
dev->supplement_adapter_info.MfgPcbaSerialNo);
+
+
+ if (len > 16)
+ len = 16;
+
return len;
}
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [patch] [SCSI] aacraid: use lower snprintf() limit
2011-10-05 5:50 [patch] [SCSI] aacraid: use lower snprintf() limit Dan Carpenter
@ 2011-10-05 7:35 ` Rolf Eike Beer
2011-10-05 12:19 ` Achim Leubner
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Rolf Eike Beer @ 2011-10-05 7:35 UTC (permalink / raw)
To: Dan Carpenter
Cc: Adaptec OEM Raid Solutions, James E.J. Bottomley, linux-scsi,
linux-kernel, kernel-janitors
> This is just a cleanup, to silence static checker warnings. It
> doesn't change how the code works.
>
> buf[] can either be BUF_SIZE if this is called from sysfs, or it can
> be 16 if it's called from aac_get_adapter_info() via
> aac_get_serial_number(). We use the smaller limit here.
>
> sizeof(dev->supplement_adapter_info.MfgPcbaSerialNo) is 12 so there
> is actually no chance of hitting either limit.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>
> diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
> index 3382475..ea8d96e 100644
> --- a/drivers/scsi/aacraid/linit.c
> +++ b/drivers/scsi/aacraid/linit.c
> @@ -894,15 +894,20 @@ static ssize_t aac_show_serial_number(struct device
> *device,
> int len = 0;
>
> if (le32_to_cpu(dev->adapter_info.serial[0]) != 0xBAD0)
> - len = snprintf(buf, PAGE_SIZE, "%06X\n",
> + len = snprintf(buf, 16, "%06X\n",
> le32_to_cpu(dev->adapter_info.serial[0]));
> if (len &&
> !memcmp(&dev->supplement_adapter_info.MfgPcbaSerialNo[
> sizeof(dev->supplement_adapter_info.MfgPcbaSerialNo)-len],
> buf, len-1))
> - len = snprintf(buf, PAGE_SIZE, "%.*s\n",
> + len = snprintf(buf, 16, "%.*s\n",
> (int)sizeof(dev->supplement_adapter_info.MfgPcbaSerialNo),
> dev->supplement_adapter_info.MfgPcbaSerialNo);
> +
> +
One newline too much.
> + if (len > 16)
> + len = 16;
max()?
Eike
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: [patch] [SCSI] aacraid: use lower snprintf() limit
2011-10-05 7:35 ` Rolf Eike Beer
@ 2011-10-05 12:19 ` Achim Leubner
2011-10-06 14:30 ` Dan Carpenter
2011-10-06 14:27 ` Dan Carpenter
2011-10-08 10:45 ` [patch v2] " Dan Carpenter
2 siblings, 1 reply; 7+ messages in thread
From: Achim Leubner @ 2011-10-05 12:19 UTC (permalink / raw)
To: Rolf Eike Beer, Dan Carpenter
Cc: Adaptec OEM Raid Solutions, James E.J. Bottomley, linux-scsi,
linux-kernel, kernel-janitors
Looks good so far. But do we really need the last two lines?
> + if (len > 16)
> + len = 16;
Acked-by: Achim Leubner <Achim_Leubner@pmc-sierra.com>
Thanks,
Achim
-----Original Message-----
From: linux-scsi-owner@vger.kernel.org
[mailto:linux-scsi-owner@vger.kernel.org] On Behalf Of Rolf Eike Beer
Sent: Mittwoch, 5. Oktober 2011 09:35
To: Dan Carpenter
Cc: Adaptec OEM Raid Solutions; James E.J. Bottomley;
linux-scsi@vger.kernel.org; linux-kernel@vger.kernel.org;
kernel-janitors@vger.kernel.org
Subject: Re: [patch] [SCSI] aacraid: use lower snprintf() limit
> This is just a cleanup, to silence static checker warnings. It
> doesn't change how the code works.
>
> buf[] can either be BUF_SIZE if this is called from sysfs, or it can
> be 16 if it's called from aac_get_adapter_info() via
> aac_get_serial_number(). We use the smaller limit here.
>
> sizeof(dev->supplement_adapter_info.MfgPcbaSerialNo) is 12 so there
> is actually no chance of hitting either limit.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>
> diff --git a/drivers/scsi/aacraid/linit.c
b/drivers/scsi/aacraid/linit.c
> index 3382475..ea8d96e 100644
> --- a/drivers/scsi/aacraid/linit.c
> +++ b/drivers/scsi/aacraid/linit.c
> @@ -894,15 +894,20 @@ static ssize_t aac_show_serial_number(struct
device
> *device,
> int len = 0;
>
> if (le32_to_cpu(dev->adapter_info.serial[0]) != 0xBAD0)
> - len = snprintf(buf, PAGE_SIZE, "%06X\n",
> + len = snprintf(buf, 16, "%06X\n",
> le32_to_cpu(dev->adapter_info.serial[0]));
> if (len &&
> !memcmp(&dev->supplement_adapter_info.MfgPcbaSerialNo[
> sizeof(dev->supplement_adapter_info.MfgPcbaSerialNo)-len],
> buf, len-1))
> - len = snprintf(buf, PAGE_SIZE, "%.*s\n",
> + len = snprintf(buf, 16, "%.*s\n",
>
(int)sizeof(dev->supplement_adapter_info.MfgPcbaSerialNo),
> dev->supplement_adapter_info.MfgPcbaSerialNo);
> +
> +
One newline too much.
> + if (len > 16)
> + len = 16;
max()?
Eike
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch] [SCSI] aacraid: use lower snprintf() limit
2011-10-05 7:35 ` Rolf Eike Beer
2011-10-05 12:19 ` Achim Leubner
@ 2011-10-06 14:27 ` Dan Carpenter
2011-10-08 10:45 ` [patch v2] " Dan Carpenter
2 siblings, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2011-10-06 14:27 UTC (permalink / raw)
To: Rolf Eike Beer
Cc: Adaptec OEM Raid Solutions, James E.J. Bottomley, linux-scsi,
linux-kernel, kernel-janitors
On Wed, Oct 05, 2011 at 09:35:13AM +0200, Rolf Eike Beer wrote:
> > dev->supplement_adapter_info.MfgPcbaSerialNo);
> > +
> > +
>
> One newline too much.
>
True. I wish checkpatch.pl checked for that...
> > + if (len > 16)
> > + len = 16;
>
> max()?
min() actually. I don't know that it improves the readability, but
can do.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch] [SCSI] aacraid: use lower snprintf() limit
2011-10-05 12:19 ` Achim Leubner
@ 2011-10-06 14:30 ` Dan Carpenter
2011-10-11 14:46 ` Achim Leubner
0 siblings, 1 reply; 7+ messages in thread
From: Dan Carpenter @ 2011-10-06 14:30 UTC (permalink / raw)
To: Achim Leubner
Cc: Rolf Eike Beer, Adaptec OEM Raid Solutions, James E.J. Bottomley,
linux-scsi, linux-kernel, kernel-janitors
On Wed, Oct 05, 2011 at 05:19:12AM -0700, Achim Leubner wrote:
> Looks good so far. But do we really need the last two lines?
> > + if (len > 16)
> > + len = 16;
>
snprintf() returns the number of characters that it _would_ have
copied if it had space. We want to return the number of bytes
actually copied.
Again, the snprintf() values do fit so this change doesn't actually
make any difference.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 7+ messages in thread
* [patch v2] [SCSI] aacraid: use lower snprintf() limit
2011-10-05 7:35 ` Rolf Eike Beer
2011-10-05 12:19 ` Achim Leubner
2011-10-06 14:27 ` Dan Carpenter
@ 2011-10-08 10:45 ` Dan Carpenter
2 siblings, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2011-10-08 10:45 UTC (permalink / raw)
To: Rolf Eike Beer
Cc: Adaptec OEM Raid Solutions, James E.J. Bottomley, linux-scsi,
linux-kernel, kernel-janitors
This is just a cleanup, to silence static checker warnings. It
doesn't change how the code works.
buf[] can either be BUF_SIZE if this is called from sysfs, or it can
be 16 if it's called from aac_get_adapter_info() via
aac_get_serial_number(). We use the smaller limit here.
sizeof(dev->supplement_adapter_info.MfgPcbaSerialNo) is 12 so there
is actually no chance of hitting either limit.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2: fix a whitespace issue, and use the min() macro.
diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index 3382475..4aa76d6 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -894,16 +894,17 @@ static ssize_t aac_show_serial_number(struct device *device,
int len = 0;
if (le32_to_cpu(dev->adapter_info.serial[0]) != 0xBAD0)
- len = snprintf(buf, PAGE_SIZE, "%06X\n",
+ len = snprintf(buf, 16, "%06X\n",
le32_to_cpu(dev->adapter_info.serial[0]));
if (len &&
!memcmp(&dev->supplement_adapter_info.MfgPcbaSerialNo[
sizeof(dev->supplement_adapter_info.MfgPcbaSerialNo)-len],
buf, len-1))
- len = snprintf(buf, PAGE_SIZE, "%.*s\n",
+ len = snprintf(buf, 16, "%.*s\n",
(int)sizeof(dev->supplement_adapter_info.MfgPcbaSerialNo),
dev->supplement_adapter_info.MfgPcbaSerialNo);
- return len;
+
+ return min(len, 16);
}
static ssize_t aac_show_max_channel(struct device *device,
^ permalink raw reply related [flat|nested] 7+ messages in thread
* RE: [patch] [SCSI] aacraid: use lower snprintf() limit
2011-10-06 14:30 ` Dan Carpenter
@ 2011-10-11 14:46 ` Achim Leubner
0 siblings, 0 replies; 7+ messages in thread
From: Achim Leubner @ 2011-10-11 14:46 UTC (permalink / raw)
To: Dan Carpenter
Cc: Rolf Eike Beer, Adaptec OEM Raid Solutions, James E.J. Bottomley,
linux-scsi, linux-kernel, kernel-janitors
Agreed.
Thanks,
Achim
-----Original Message-----
From: Dan Carpenter [mailto:dan.carpenter@oracle.com]
Sent: Donnerstag, 6. Oktober 2011 16:31
To: Achim Leubner
Cc: Rolf Eike Beer; Adaptec OEM Raid Solutions; James E.J. Bottomley;
linux-scsi@vger.kernel.org; linux-kernel@vger.kernel.org;
kernel-janitors@vger.kernel.org
Subject: Re: [patch] [SCSI] aacraid: use lower snprintf() limit
On Wed, Oct 05, 2011 at 05:19:12AM -0700, Achim Leubner wrote:
> Looks good so far. But do we really need the last two lines?
> > + if (len > 16)
> > + len = 16;
>
snprintf() returns the number of characters that it _would_ have
copied if it had space. We want to return the number of bytes
actually copied.
Again, the snprintf() values do fit so this change doesn't actually
make any difference.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2011-10-11 14:46 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-05 5:50 [patch] [SCSI] aacraid: use lower snprintf() limit Dan Carpenter
2011-10-05 7:35 ` Rolf Eike Beer
2011-10-05 12:19 ` Achim Leubner
2011-10-06 14:30 ` Dan Carpenter
2011-10-11 14:46 ` Achim Leubner
2011-10-06 14:27 ` Dan Carpenter
2011-10-08 10:45 ` [patch v2] " Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox