linux-edac.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Len Baker <len.baker@gmx.com>
To: Robert Richter <rric@kernel.org>
Cc: Len Baker <len.baker@gmx.com>, Kees Cook <keescook@chromium.org>,
	Borislav Petkov <bp@alien8.de>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Tony Luck <tony.luck@intel.com>,
	James Morse <james.morse@arm.com>,
	linux-hardening@vger.kernel.org, linux-edac@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] drivers/edac/edac_mc: Remove all strcpy() uses
Date: Sat, 31 Jul 2021 17:57:39 +0200	[thread overview]
Message-ID: <20210731142759.GD1979@titan> (raw)
In-Reply-To: <YP/+V90D6zyxnSyU@rric.localdomain>

Hi,

On Tue, Jul 27, 2021 at 02:38:47PM +0200, Robert Richter wrote:
> On 25.07.21 18:29:54, Len Baker wrote:
> >  drivers/edac/edac_mc.c | 16 ++++++++--------
> >  1 file changed, 8 insertions(+), 8 deletions(-)
> >
> > diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c
> > index f6d462d0be2d..1286364f0e48 100644
> > --- a/drivers/edac/edac_mc.c
> > +++ b/drivers/edac/edac_mc.c
> > @@ -1027,6 +1027,7 @@ void edac_mc_handle_error(const enum hw_event_mc_err_type type,
> >  {
> >  	struct dimm_info *dimm;
> >  	char *p;
> > +	size_t p_size = 0;
>
> I would rather use a 'left' variable which is initialized with
> sizeof(e->label) close to there p = e->label is.

Ok.

> >  	int row = -1, chan = -1;
> >  	int pos[EDAC_MAX_LAYERS] = { top_layer, mid_layer, low_layer };
> >  	int i, n_labels = 0;
> > @@ -1113,12 +1114,11 @@ void edac_mc_handle_error(const enum hw_event_mc_err_type type,
> >  			p = e->label;
> >  			*p = '\0';
> >  		} else {
> > -			if (p != e->label) {
> > -				strcpy(p, OTHER_LABEL);
> > -				p += strlen(OTHER_LABEL);
> > -			}
> > -			strcpy(p, dimm->label);
> > -			p += strlen(p);
> > +			const char *or = (p != e->label) ? OTHER_LABEL : "";
> > +
> > +			p_size += scnprintf(p + p_size,
> > +					    sizeof(e->label) - p_size,
> > +					    "%s%s", or, dimm->label);
>
> My preference is to advance p here (and decrement 'left'). This is the
> pattern how p is used throughout the code. I also don't see a benefit
> of using scnprintf() here compared to the previous implementation.

Ok, no problem. I will send a new version more close to the original. The
scnprintf() returns the number of bytes writes to the buffer, so it is not
necessary to use the strlen() function. But if you prefer the current
pattern I will have no objection.

Regards,
Len

      reply	other threads:[~2021-07-31 15:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-25 16:29 [PATCH] drivers/edac/edac_mc: Remove all strcpy() uses Len Baker
2021-07-27 12:38 ` Robert Richter
2021-07-31 15:57   ` Len Baker [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=20210731142759.GD1979@titan \
    --to=len.baker@gmx.com \
    --cc=bp@alien8.de \
    --cc=james.morse@arm.com \
    --cc=keescook@chromium.org \
    --cc=linux-edac@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=rric@kernel.org \
    --cc=tony.luck@intel.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;
as well as URLs for NNTP newsgroup(s).