From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A524D3164BF for ; Mon, 29 Dec 2025 14:17:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767017855; cv=none; b=cWcFt7F5Gq+M7nI9AXz4JGhlrXJ+ooJqyzz8uv0fJ7Z90YbxxmXsi8hnRyvQyLAhFJmVjm7bL5Qg3jlWXFkhSpQ1hWDNpIJMjKIZ00/ZpIUL5sQpkCFV3MJdxOka3D7Yly9dJMm4tYnj7bBlGHMYnlpskXTVxM0NaEOhlvrfTpY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767017855; c=relaxed/simple; bh=idWBxsg7evd6xv3ze1XDMsv3tEcoQzARmjAxZyH6Z6s=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AU59JyymP3XGO8jan6xTjueGF99BkonMztX1DoMv047GRvWCOnafuUEJw2ZAF/lTavTKt6WoybsA0OU0IpwMItZPbi+A5ZJtOWiTTJu7D2CAezbyERAHCu69jegy0HAkl3/DcKqOm83v9W9HVeIbDADvIZHW+UCKMGj1WFi+nnY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=D+2a39u1; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="D+2a39u1" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-477a2ab455fso87401915e9.3 for ; Mon, 29 Dec 2025 06:17:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767017852; x=1767622652; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=OxmPqDzQ1eh73iQT4nuH91AB3I70CPbxlV27YCDsWcI=; b=D+2a39u1xGowa8xYyCQUn/0rljX4rEd7vnnslK8/XYoWXfwi4tDtA+jggyaO4G3odc laptuyCO5WkJ9liXFDOe9nXZFvssTKKjhsKjzjPRMnza0YXelbTI3ii/WxWAxwyYgx5a EFxMxgf/gNU6Uu93J4TUFUg4xZ/2W53D3D4RWqj5QqA2iZUNxEMY8fMop1Y3PBnU14dU Ga3vkxMTvbyPiPhGXV32Hi5f1IMZi3AgpN1HcBrE3NFaw6nl7gYhvn/eF4QpgfAV8rZU 2dKgoFFqm1jv3GvEmQryEpax7+ntyyzN6e88nExmlNs3vt1z1aLeh+tUgcvTl7y8nyLd FOIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767017852; x=1767622652; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=OxmPqDzQ1eh73iQT4nuH91AB3I70CPbxlV27YCDsWcI=; b=XXcwt+0xkuOuzd4n+yxM46R0T1FBi+kdnzBuooskJ6OxbEYtdcdZ3i4RNKipOJ9GZ9 J86FAOy+Km5mtHC9xJd0IZtMC8iKEGqNdBu5n/qdsaRDzIweAa3lkA0RrS9RQZJqhtRt zc1isBNYi5XoiwWrq7PpEupyrMN2jHV462xxwSQZyDYFJ/uTIx6Euya/db3cwAclc6Ln 8QH6YsbO85JcLp5BXcJjS8i2BgmOTP5+V68bqdVDGFsw1kgzzXK00SgN1hIJO+EUg1w+ C8b4ey3HP7Jff/BKjV9w4qPcFkNQ/rvsr+md3cQ/uPJMp1Vl/rN3AHmyFi0DiYxTVd+1 +LEQ== X-Forwarded-Encrypted: i=1; AJvYcCXWzM8VnSvODJTj3TsqgUTXFyS0xcegEsPJJoFsadrGA3/fb4Cktb0smV1f5xP9WJPY6j4VdMANf6fwgmI=@vger.kernel.org X-Gm-Message-State: AOJu0Yz2BR/+jguMDwmIgZioETpwnGP8MeAStW8jxg9JSo+lK+kTktuP D9PHNiKLBDx75iNgMG67MMoRBR4Cq8G8YLcBH6ruFH+vn8Xe/DB82CPy X-Gm-Gg: AY/fxX4Xt/9jtI+xmU76qgksfUvMZs6uIdXWVTVeIJd3VMIgdV6YRkdFpFbg0tTbADY NQtOmBs5FbPuF0g4wfNFVeWVFJekXBL4JvdpkhWpaSJlN9MoMEOONXKuGv8rMWJozXcoqVX833M wUV5ELbyC6DzH/5fRFFU0hWukfII64+PVGLXgVigQRB0fMKi/RecyGiPMP7+5kLr4cFXsFPunZB X733ooMHy+PgyUOPWrS7zWluK1hyxPGhaxlAUFqJxtpY5Puv1SMK/iHQZbJEaZ+XVmtG9CDYZmy dqokMehStSUlo51yqgUr1k4MYv6F773v+HReYHBi8quETB/6dYjvb40k9enn3Wmh4QF2OlGtaq3 wCuanp1fVXyCMejIWKw0tkgBkHpeZMTC2RoRUgLc2NRHNgFr9flsIRZ6adtGhpa387Md8vK4wI3 dYU1pRploStnuyFJYy56yIMiHktPLtVvaMfL0IbMp8FwLX7lYqESrw X-Google-Smtp-Source: AGHT+IFqLIYpIhCE0+V2lfdDOxx33PVDlLSyI+RSX7t/Dwp3SJx49tBapNLAXp/LwZmAS6YB0rdsMQ== X-Received: by 2002:a05:600c:310e:b0:479:2a3c:f31a with SMTP id 5b1f17b1804b1-47d1956eb70mr359769615e9.1.1767017851748; Mon, 29 Dec 2025 06:17:31 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47d19352306sm531408705e9.5.2025.12.29.06.17.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Dec 2025 06:17:31 -0800 (PST) Date: Mon, 29 Dec 2025 14:17:30 +0000 From: David Laight To: Sun Jian Cc: Vaibhav Agarwal , Mark Greer , Alex Elder , Greg Kroah-Hartman , greybus-dev@lists.linaro.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH] staging: greybus: audio: avoid snprintf truncation warnings Message-ID: <20251229141730.2b863ba9@pumpkin> In-Reply-To: <20251229112649.137391-1-sun.jian.kdev@gmail.com> References: <20251229112649.137391-1-sun.jian.kdev@gmail.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 29 Dec 2025 19:26:49 +0800 Sun Jian wrote: > W=1 reports possible truncation when formatting widget and control names > using snprintf() with a %s argument and fixed-size buffers. Build the > prefixed names using scnprintf() plus strlcat() instead, so truncation, > if any, is handled by the string helpers rather than during printf > formatting. That is just brain dead - more so than the fact the the warning is pretty hard to ignore. Commonning up the code as: static void prefix_div_id(char *name, size_t name_len, unsigned int dev_id) { char temp_name[32], *cp = temp_name; strscpy(temp_name, name, sizeof temp_name); OPTIMISER_HIDE_VAR(cp); snprintf(name, name_len, "GB %d %s", dev_id, cp); } should be enough and is about the best you can do. Possibly worth a comment that name_len is expected to be 32. The way this code processes the tplg_data isn't nice at all. Convert the offsets to correctly typed pointers as soon as possible. You might want to verify that the separate arrays don't overlap. There is also the: curr = (void *)curr + w_size; which AFIACT is just 'curr++'; David > > No functional change intended. > > Signed-off-by: Sun Jian > --- > drivers/staging/greybus/audio_topology.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/drivers/staging/greybus/audio_topology.c b/drivers/staging/greybus/audio_topology.c > index 76146f91cddc..4293ab899390 100644 > --- a/drivers/staging/greybus/audio_topology.c > +++ b/drivers/staging/greybus/audio_topology.c > @@ -1087,7 +1087,8 @@ static int gbaudio_tplg_create_widget(struct gbaudio_module_info *module, > > /* Prefix dev_id to widget control_name */ > strscpy(temp_name, w->name, sizeof(temp_name)); > - snprintf(w->name, sizeof(w->name), "GB %d %s", module->dev_id, temp_name); > + scnprintf(w->name, sizeof(w->name), "GB %d ", module->dev_id); > + strlcat(w->name, temp_name, sizeof(w->name)); > > switch (w->type) { > case snd_soc_dapm_spk: > @@ -1169,8 +1170,8 @@ static int gbaudio_tplg_process_kcontrols(struct gbaudio_module_info *module, > control->id = curr->id; > /* Prefix dev_id to widget_name */ > strscpy(temp_name, curr->name, sizeof(temp_name)); > - snprintf(curr->name, sizeof(curr->name), "GB %d %s", module->dev_id, > - temp_name); > + scnprintf(curr->name, sizeof(curr->name), "GB %d ", module->dev_id); > + strlcat(curr->name, temp_name, sizeof(curr->name)); > control->name = curr->name; > if (curr->info.type == GB_AUDIO_CTL_ELEM_TYPE_ENUMERATED) { > struct gb_audio_enumerated *gbenum =