* [patch 3/4] skd: use strncpy() as a cleanup
@ 2013-09-13 8:05 Dan Carpenter
2013-09-13 12:03 ` Geert Uytterhoeven
0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2013-09-13 8:05 UTC (permalink / raw)
To: Jens Axboe
Cc: Jeff Moyer, Ramprasad Chinthekindi, Akhil Bhansali, linux-kernel,
kernel-janitors
The code here is copying the version to inq.driver_version but we don't
want it to be NUL terminated. Instead we pad the rest of the array with
spaces. It's fewer lines to use strncpy() and maybe a little nicer.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/drivers/block/skd_main.c b/drivers/block/skd_main.c
index f892d95..20ad843 100644
--- a/drivers/block/skd_main.c
+++ b/drivers/block/skd_main.c
@@ -2899,9 +2899,7 @@ static void skd_do_inq_page_da(struct skd_device *skdev,
volatile struct fit_comp_error_info *skerr,
uint8_t *cdb, uint8_t *buf)
{
- unsigned ver_byte;
unsigned max_bytes;
- char *ver = DRV_VER_COMPL;
struct driver_inquiry_data inq;
u16 val;
@@ -2945,12 +2943,8 @@ static void skd_do_inq_page_da(struct skd_device *skdev,
/* Driver version, fixed lenth, padded with spaces on the right */
inq.driver_version_length = sizeof(inq.driver_version);
memset(&inq.driver_version, ' ', sizeof(inq.driver_version));
- for (ver_byte = 0; ver_byte < sizeof(inq.driver_version); ver_byte++) {
- if (ver[ver_byte] != 0)
- inq.driver_version[ver_byte] = ver[ver_byte];
- else
- break;
- }
+ strncpy(inq.driver_version, DRV_VER_COMPL,
+ min(sizeof(inq.driver_version), strlen(DRV_VER_COMPL)));
inq.page_length = cpu_to_be16((sizeof(inq) - 4));
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [patch 3/4] skd: use strncpy() as a cleanup
2013-09-13 8:05 [patch 3/4] skd: use strncpy() as a cleanup Dan Carpenter
@ 2013-09-13 12:03 ` Geert Uytterhoeven
2013-09-13 12:53 ` [patch 3/4 v2] skd: use memcpy() " Dan Carpenter
2013-09-13 12:56 ` [patch 3/4] skd: use strncpy() " Dan Carpenter
0 siblings, 2 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2013-09-13 12:03 UTC (permalink / raw)
To: Dan Carpenter
Cc: Jens Axboe, Jeff Moyer, Ramprasad Chinthekindi, Akhil Bhansali,
linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
On Fri, Sep 13, 2013 at 10:05 AM, Dan Carpenter
<dan.carpenter@oracle.com> wrote:
> The code here is copying the version to inq.driver_version but we don't
> want it to be NUL terminated. Instead we pad the rest of the array with
> spaces. It's fewer lines to use strncpy() and maybe a little nicer.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>
> diff --git a/drivers/block/skd_main.c b/drivers/block/skd_main.c
> index f892d95..20ad843 100644
> --- a/drivers/block/skd_main.c
> +++ b/drivers/block/skd_main.c
> @@ -2899,9 +2899,7 @@ static void skd_do_inq_page_da(struct skd_device *skdev,
> volatile struct fit_comp_error_info *skerr,
> uint8_t *cdb, uint8_t *buf)
> {
> - unsigned ver_byte;
> unsigned max_bytes;
> - char *ver = DRV_VER_COMPL;
> struct driver_inquiry_data inq;
> u16 val;
>
> @@ -2945,12 +2943,8 @@ static void skd_do_inq_page_da(struct skd_device *skdev,
> /* Driver version, fixed lenth, padded with spaces on the right */
> inq.driver_version_length = sizeof(inq.driver_version);
> memset(&inq.driver_version, ' ', sizeof(inq.driver_version));
> - for (ver_byte = 0; ver_byte < sizeof(inq.driver_version); ver_byte++) {
> - if (ver[ver_byte] != 0)
> - inq.driver_version[ver_byte] = ver[ver_byte];
> - else
> - break;
> - }
> + strncpy(inq.driver_version, DRV_VER_COMPL,
> + min(sizeof(inq.driver_version), strlen(DRV_VER_COMPL)));
This does the exact same thing as memcpy(), right? So why not use that?
memcpy() has much simpler semantics than strncpy().
> inq.page_length = cpu_to_be16((sizeof(inq) - 4));
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 4+ messages in thread* [patch 3/4 v2] skd: use memcpy() as a cleanup
2013-09-13 12:03 ` Geert Uytterhoeven
@ 2013-09-13 12:53 ` Dan Carpenter
2013-09-13 12:56 ` [patch 3/4] skd: use strncpy() " Dan Carpenter
1 sibling, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2013-09-13 12:53 UTC (permalink / raw)
To: Jens Axboe
Cc: Jeff Moyer, Ramprasad Chinthekindi, Akhil Bhansali,
Geert Uytterhoeven, linux-kernel, kernel-janitors
The code here is copying the version to inq.driver_version but we don't
want it to be NUL terminated. Instead we pad the rest of the array with
spaces. It's fewer lines to use memcpy() and maybe a little nicer.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2: use memcpy() instead of strncpy()
diff --git a/drivers/block/skd_main.c b/drivers/block/skd_main.c
index f892d95..20ad843 100644
--- a/drivers/block/skd_main.c
+++ b/drivers/block/skd_main.c
@@ -2899,9 +2899,7 @@ static void skd_do_inq_page_da(struct skd_device *skdev,
volatile struct fit_comp_error_info *skerr,
uint8_t *cdb, uint8_t *buf)
{
- unsigned ver_byte;
unsigned max_bytes;
- char *ver = DRV_VER_COMPL;
struct driver_inquiry_data inq;
u16 val;
@@ -2945,12 +2943,8 @@ static void skd_do_inq_page_da(struct skd_device *skdev,
/* Driver version, fixed lenth, padded with spaces on the right */
inq.driver_version_length = sizeof(inq.driver_version);
memset(&inq.driver_version, ' ', sizeof(inq.driver_version));
- for (ver_byte = 0; ver_byte < sizeof(inq.driver_version); ver_byte++) {
- if (ver[ver_byte] != 0)
- inq.driver_version[ver_byte] = ver[ver_byte];
- else
- break;
- }
+ memcpy(inq.driver_version, DRV_VER_COMPL,
+ min(sizeof(inq.driver_version), strlen(DRV_VER_COMPL)));
inq.page_length = cpu_to_be16((sizeof(inq) - 4));
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [patch 3/4] skd: use strncpy() as a cleanup
2013-09-13 12:03 ` Geert Uytterhoeven
2013-09-13 12:53 ` [patch 3/4 v2] skd: use memcpy() " Dan Carpenter
@ 2013-09-13 12:56 ` Dan Carpenter
1 sibling, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2013-09-13 12:56 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Jens Axboe, Jeff Moyer, Ramprasad Chinthekindi, Akhil Bhansali,
linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
On Fri, Sep 13, 2013 at 02:03:23PM +0200, Geert Uytterhoeven wrote:
> On Fri, Sep 13, 2013 at 10:05 AM, Dan Carpenter
> > + strncpy(inq.driver_version, DRV_VER_COMPL,
> > + min(sizeof(inq.driver_version), strlen(DRV_VER_COMPL)));
>
> This does the exact same thing as memcpy(), right? So why not use that?
> memcpy() has much simpler semantics than strncpy().
You're right. I've redone this.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-09-13 12:56 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-13 8:05 [patch 3/4] skd: use strncpy() as a cleanup Dan Carpenter
2013-09-13 12:03 ` Geert Uytterhoeven
2013-09-13 12:53 ` [patch 3/4 v2] skd: use memcpy() " Dan Carpenter
2013-09-13 12:56 ` [patch 3/4] skd: use strncpy() " Dan Carpenter
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).