mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Kees Cook <kees@kernel.org>
Cc: "Bill Wendling" <morbo@google.com>,
	linux-kernel@vger.kernel.org,
	codemender-patching+linux@google.com,
	"Thomas Gleixner" <tglx@kernel.org>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Borislav Petkov" <bp@alien8.de>,
	"Dave Hansen" <dave.hansen@linux.intel.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	"Andrew Lunn" <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Peter Griffin" <peter.griffin@linaro.org>,
	"Linus Walleij" <linusw@kernel.org>,
	"Martin K. Petersen" <mkp@kernel.org>,
	"Trond Myklebust" <trondmy@kernel.org>,
	"Anna Schumaker" <anna@kernel.org>,
	"Jiri Pirko" <jiri@resnulli.us>,
	"Simon Horman" <horms@kernel.org>, "Chuck Lever" <cel@kernel.org>,
	"Jeff Layton" <jlayton@kernel.org>, NeilBrown <neil@brown.name>,
	"Olga Kornievskaia" <okorniev@redhat.com>,
	"Dai Ngo" <Dai.Ngo@oracle.com>, "Tom Talpey" <tom@talpey.com>,
	"Jaroslav Kysela" <perex@perex.cz>,
	"Takashi Iwai" <tiwai@suse.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Mike Rapoport (Microsoft)" <rppt@kernel.org>,
	"Kanglong Wang" <wangkanglong@loongson.cn>,
	"Tiezhu Yang" <yangtiezhu@loongson.cn>,
	"Qiang Ma" <maqianga@uniontech.com>,
	"Randy Dunlap" <rdunlap@infradead.org>,
	"Pengpeng Hou" <pengpeng@iscas.ac.cn>,
	"Ard Biesheuvel" <ardb@kernel.org>,
	"Breno Leitao" <leitao@debian.org>,
	"Thorsten Blum" <blum@kernel.org>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Dmitry Baryshkov" <dmitry.baryshkov@oss.qualcomm.com>,
	"Johan Hovold" <johan@kernel.org>,
	"Cen Zhang" <zzzccc427@gmail.com>,
	"Cássio Gabriel" <cassiogabrielcontato@gmail.com>,
	"Rong Zhang" <i@rong.moe>,
	linux-input@vger.kernel.org, linux-media@vger.kernel.org,
	netdev@vger.kernel.org, linux-wireless@vger.kernel.org,
	devicetree@vger.kernel.org, linux-gpio@vger.kernel.org,
	devel@lists.orangefs.org, linux-hardening@vger.kernel.org,
	linux-sound@vger.kernel.org
Subject: Re: [PATCH 01/28] ALSA: ac97: Refactor snd_ac97_get_name() to use snprintf()
Date: Wed, 16 Sep 2026 10:29:51 +0100	[thread overview]
Message-ID: <20260916102532.4b881a25@pumpkin> (raw)
In-Reply-To: <202609151134.361FEA04@keescook>

On Tue, 15 Sep 2026 11:39:34 -0700
Kees Cook <kees@kernel.org> wrote:

(I've just juked a lot of the 'reply to' list - too long to gmail.)

> On Tue, Sep 15, 2026 at 08:18:18AM +0000, Bill Wendling wrote:
> > --- a/sound/pci/ac97/ac97_codec.c
> > +++ b/sound/pci/ac97/ac97_codec.c
> > @@ -1850,10 +1850,12 @@ void snd_ac97_get_name(struct snd_ac97 *ac97, unsigned int id, char *name,
> >  
> >  	pid = look_for_codec_id(snd_ac97_codec_ids, id);
> >  	if (pid) {
> > -		strlcat(name, " ", maxlen);
> > -		strlcat(name, pid->name, maxlen);
> > +		int l = strlen(name);
> > +
> >  		if (pid->mask != 0xffffffff)
> > -			sprintf(name + strlen(name), " rev %u", id & ~pid->mask);
> > +			snprintf(name + l, maxlen - l, " %s rev %u", pid->name, id & ~pid->mask);
> > +		else
> > +			snprintf(name + l, maxlen - l, " %s", pid->name);
> >  		if (ac97 && pid->patch) {
> >  			if ((modem && (pid->flags & AC97_MODEM_PATCH)) ||
> >  			    (! modem && ! (pid->flags & AC97_MODEM_PATCH)))
> > @@ -1861,6 +1863,7 @@ void snd_ac97_get_name(struct snd_ac97 *ac97, unsigned int id, char *name,
> >  		}
> >  	} else {
> >  		int l = strlen(name);
> > +
> >  		snprintf(name + l, maxlen - l, " id %x", id & 0xff);
> >  	}
> >  }  
> 
> I'd rather not open-code the length math here. Can't we use seq_buf()
> instead?
> 

Or just use the length returned by the strscpy() call that wrote the initial
part of name[].
The return the name length so the callers don't have to use strcat()
themselves.
Replacing strlcat() with strlen() and a copy is just pointless.

David

  reply	other threads:[~2026-09-16  9:29 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-15  8:18 [PATCH 00/28] Replace remaining strlcat() call sites with snprintf()/seq_buf() Bill Wendling
2026-09-15  8:18 ` [PATCH 01/28] ALSA: ac97: Refactor snd_ac97_get_name() to use snprintf() Bill Wendling
2026-09-15 18:39   ` Kees Cook
2026-09-16  9:29     ` David Laight [this message]
2026-09-15  8:18 ` [PATCH 02/28] sunrpc: Refactor rpc_sockaddr2uaddr() to use snprintf() instead of strlcat() Bill Wendling
2026-09-15 10:17   ` Jeff Layton
2026-09-15  8:18 ` [PATCH 03/28] ARM: atags: Replace strlcat() with snprintf() for cmdline extend Bill Wendling
2026-09-15 19:00   ` Kees Cook
2026-09-16  8:28     ` Bill Wendling
2026-09-15  8:18 ` [PATCH 04/28] scsi: bfa: Use snprintf() in bfa_fcs_fabric_nsymb_init() Bill Wendling
2026-09-15  8:18 ` [PATCH 05/28] ALSA: usb-audio: Refactor usb_audio_make_longname() to use seq_buf Bill Wendling
2026-09-15  8:18 ` [PATCH 06/28] comedi: comedi_bond: Refactor strlcat() to seq_buf in do_dev_config() Bill Wendling
2026-09-15  8:18 ` [PATCH 07/28] scsi: bfa: Use snprintf() in bfa_fcs_fabric_psymb_init() Bill Wendling
2026-09-15  8:18 ` [PATCH 08/28] devlink: Refactor strlcat() to seq_buf in __devlink_compat_running_version() Bill Wendling
2026-09-15  8:18 ` [PATCH 09/28] drm/dp_mst: Refactor build_mst_prop_path() to use seq_buf Bill Wendling
2026-09-15  8:18 ` [PATCH 10/28] of/fdt: Replace strlcat() with snprintf() in early_init_dt_scan_chosen() Bill Wendling
2026-09-15 15:05   ` Rob Herring
2026-09-15  8:18 ` [PATCH 11/28] wifi: brcmfmac: Replace strlcat() with snprintf() in brcmf_fw_alloc_request() Bill Wendling
2026-09-15  8:18 ` [PATCH 12/28] fortify: Convert strlcat() to snprintf() in strcat() Bill Wendling
2026-09-15  8:18 ` [PATCH 13/28] i40e: Replace strlcat() with snprintf() in i40e_nvm_version_str() Bill Wendling
2026-09-15  8:18 ` [PATCH 14/28] ALSA: usb-audio: Refactor append_ctl_name() to use snprintf() Bill Wendling
2026-09-15  8:18 ` [PATCH 15/28] orangefs: Use seq_buf for debug help string generation Bill Wendling
2026-09-15  8:18 ` [PATCH 16/28] pinctrl: samsung: Use snprintf() to construct pin bank names Bill Wendling
2026-09-16  6:01   ` Loktionov, Aleksandr
2026-09-15  8:18 ` [PATCH 17/28] MIPS: cmdline: Refactor bootcmdline_append() to use snprintf() Bill Wendling
2026-09-15  8:18 ` [PATCH 18/28] LoongArch: Refactor bootcmdline_init() to use seq_buf instead of strlcat() Bill Wendling
2026-09-15  8:18 ` [PATCH 19/28] x86/setup: Use snprintf() to concatenate builtin and boot command lines Bill Wendling
2026-09-15  8:18 ` [PATCH 20/28] parisc: Refactor strlcat() to seq_buf in setup_cmdline() Bill Wendling
2026-09-15  8:18 ` [PATCH 21/28] NFS: nfsroot: Refactor root_nfs_cat() to use snprintf() Bill Wendling
2026-09-15 18:52   ` Kees Cook
2026-09-15 19:30     ` Bill Wendling
2026-09-15  8:18 ` [PATCH 22/28] media: si2165: Use snprintf() to format frontend name Bill Wendling
2026-09-16  6:02   ` Loktionov, Aleksandr
2026-09-15  8:18 ` [PATCH 23/28] Input: synaptics_usb - use seq_buf and snprintf() for name and phys Bill Wendling
2026-09-15  8:18 ` [PATCH 24/28] EDAC/thunderx: Fix stale error context in thunderx_l2c_threaded_isr() Bill Wendling
2026-09-16  6:02   ` Loktionov, Aleksandr
2026-09-15  8:18 ` [PATCH 25/28] EDAC/thunderx: Replace strlcat() with seq_buf Bill Wendling
2026-09-15 20:00   ` Kees Cook
2026-09-16  1:09     ` Borislav Petkov
2026-09-15  8:18 ` [PATCH 26/28] wifi: wil6210: Refactor resume_triggers2string() to use seq_buf Bill Wendling
2026-09-15  8:18 ` [PATCH 27/28] drm/xe/pf: Convert strlcat() to seq_buf in control_read() Bill Wendling
2026-09-15 18:25   ` Kees Cook
2026-09-15  8:18 ` [PATCH 28/28] drm/xe/pf: Refactor strlcat() to seq_buf in sched_group_engines_read() Bill Wendling
2026-09-15 18:30   ` Kees Cook
2026-09-15 11:24 ` [PATCH 00/28] Replace remaining strlcat() call sites with snprintf()/seq_buf() Takashi Iwai
2026-09-15 18:05 ` Kees Cook

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=20260916102532.4b881a25@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=Dai.Ngo@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=anna@kernel.org \
    --cc=ardb@kernel.org \
    --cc=blum@kernel.org \
    --cc=bp@alien8.de \
    --cc=cassiogabrielcontato@gmail.com \
    --cc=cel@kernel.org \
    --cc=codemender-patching+linux@google.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=devel@lists.orangefs.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.baryshkov@oss.qualcomm.com \
    --cc=edumazet@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=horms@kernel.org \
    --cc=hpa@zytor.com \
    --cc=i@rong.moe \
    --cc=jiri@resnulli.us \
    --cc=jlayton@kernel.org \
    --cc=johan@kernel.org \
    --cc=kees@kernel.org \
    --cc=kuba@kernel.org \
    --cc=leitao@debian.org \
    --cc=linusw@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=maqianga@uniontech.com \
    --cc=mingo@redhat.com \
    --cc=mkp@kernel.org \
    --cc=morbo@google.com \
    --cc=neil@brown.name \
    --cc=netdev@vger.kernel.org \
    --cc=okorniev@redhat.com \
    --cc=pabeni@redhat.com \
    --cc=pengpeng@iscas.ac.cn \
    --cc=perex@perex.cz \
    --cc=peter.griffin@linaro.org \
    --cc=rdunlap@infradead.org \
    --cc=rppt@kernel.org \
    --cc=tglx@kernel.org \
    --cc=tiwai@suse.com \
    --cc=tom@talpey.com \
    --cc=trondmy@kernel.org \
    --cc=wangkanglong@loongson.cn \
    --cc=yangtiezhu@loongson.cn \
    --cc=zzzccc427@gmail.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

all inboxes | Powered by JetHome®