From: Helge Deller <deller@gmx.de>
To: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>,
linux-parisc@vger.kernel.org,
James Bottomley <James.Bottomley@HansenPartnership.com>,
John David Anglin <dave.anglin@bell.net>
Subject: Re: [PATCH] parisc: pdc_stable.c: Cleaning up unnecessary use of memset in conjunction with strncpy
Date: Mon, 22 Sep 2014 20:24:55 +0200 [thread overview]
Message-ID: <20140922182455.GA4063@ls3530.box> (raw)
In-Reply-To: <1410710532-14429-1-git-send-email-rickard_strandqvist@spectrumdigital.se>
* Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>:
> Using memset before strncpy just to ensure a trailing null
> character is an unnecessary double writing of a string
Thanks for the patch Rickard!
I've modified it a little (see below) and added it to my tree.
Thanks,
Helge
> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
> ---
> drivers/parisc/pdc_stable.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c
> index 0f54ab6..76860ad 100644
> --- a/drivers/parisc/pdc_stable.c
> +++ b/drivers/parisc/pdc_stable.c
> @@ -765,8 +765,8 @@ static ssize_t pdcs_auto_write(struct kobject *kobj,
> return -EINVAL;
>
> /* We'll use a local copy of buf */
> - memset(in, 0, count+1);
> strncpy(in, buf, count);
> + in[count] = '\0';
>
> /* Current flags are stored in primary boot path entry */
> pathentry = &pdcspath_entry_primary;
parisc: pdc_stable.c: Cleaning up unnecessary use of memset in conjunction with strncpy
Using memset before strncpy just to ensure a trailing null character is
an unnecessary double writing of a string
Patch modified by Helge Deller to additionally reduce stack usage.
Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
Signed-off-by: Helge Deller <deller@gmx.de>
diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c
index 0f54ab6..e4b73c2 100644
--- a/drivers/parisc/pdc_stable.c
+++ b/drivers/parisc/pdc_stable.c
@@ -755,7 +755,7 @@ static ssize_t pdcs_auto_write(struct kobject *kobj,
{
struct pdcspath_entry *pathentry;
unsigned char flags;
- char in[count+1], *temp;
+ char in[8], *temp;
char c;
if (!capable(CAP_SYS_ADMIN))
@@ -765,8 +765,9 @@ static ssize_t pdcs_auto_write(struct kobject *kobj,
return -EINVAL;
/* We'll use a local copy of buf */
- memset(in, 0, count+1);
+ count = min_t(size_t, count, 7);
strncpy(in, buf, count);
+ in[count] = '\0';
/* Current flags are stored in primary boot path entry */
pathentry = &pdcspath_entry_primary;
prev parent reply other threads:[~2014-09-22 18:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-14 16:02 [PATCH] parisc: pdc_stable.c: Cleaning up unnecessary use of memset in conjunction with strncpy Rickard Strandqvist
2014-09-22 18:24 ` Helge Deller [this message]
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=20140922182455.GA4063@ls3530.box \
--to=deller@gmx.de \
--cc=James.Bottomley@HansenPartnership.com \
--cc=dave.anglin@bell.net \
--cc=linux-parisc@vger.kernel.org \
--cc=rickard_strandqvist@spectrumdigital.se \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.