From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (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 BE52B3161BD for ; Fri, 7 Nov 2025 09:12:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762506774; cv=none; b=L1a+fXq+4x+PdKZhuQhoqWC2PuOLSB/gUUHNk1T/DZE8FRCPfctkEWoo8kgi2woNUPAk+GyB1N+GNX0GKC+FR9PqwCEEk2kxn5rtWVI2cpyrbLmh3AzGt/WKB3gVy7Jt2EsfXPJ/tpXj/APDFqMRyXZA5zKqXoGCexmycvryrz8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762506774; c=relaxed/simple; bh=ySb+pop94SqpdbyZsYpGfmunwgkKv5LASXUw8Mbt2b0=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QaX50VLeZg22HRbvg6cTUs4xtXqqT4753b6A8h/tiFw+yJ9U+afH7JFh6FgJATpl09iF+e82osY/J+OK9zQiKSw9z2AHR8059bW/z8arv6LlxnbAZ98AhDomxeaD61MVjKliB8qu3pbilr3eFbN5js4Zdwaef8/woFL+2FPrQN4= 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=mZJ+Tzia; arc=none smtp.client-ip=209.85.221.46 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="mZJ+Tzia" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-421851bcb25so242420f8f.2 for ; Fri, 07 Nov 2025 01:12:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762506771; x=1763111571; 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=cwbNx98NAV67oyTmVbgDZ/t5BsyU5lLwVlOoJ6t3e0g=; b=mZJ+TziathtEj0lCeVghoJ8qe5Og/eCculTzvtfLW7O4TCQmbpYaopK8zm+OfFQAVe 50Cl9A9mjJX1v6BDyftxzxMIOK4K4XmF3xdtLz3dYY2n2dHduLbqcBrc7lpEZc8/pSQ+ AmtSmiTIa/pswSLxfcxQ6a8wS+HWHlofa2FnCPKICvxo9m1PL0BDQHMVQWwd0nKgDuf4 /aIq3e3Uy0tGEmL6tBbwmdlRlqdG0e8xcVU+ovpw2qE+R9zEOuNXpFezzj4R2XDNVFZ3 wZS1kAIAlLEzs63cLGCBj+4cmz9hmrM97e5HMceViOtkiGL/8jACByqHknakrcpI76XU cY+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762506771; x=1763111571; 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=cwbNx98NAV67oyTmVbgDZ/t5BsyU5lLwVlOoJ6t3e0g=; b=PwI0Q1fsAeDpZaBa994djt5vmgwgEgJdj2uKcEy91Wq/Y8DiyFl0WvMUKr2VTzWqiO EotPgWQzWR0etmBdqwkfwKmtlICncUNEuGonUq0urJpowBNLugQt39MWTcjIjw59QkVn /hRFxI4kjYMJpXsFwjuBW0zikKCuzNvS/FLp1BMMS2AQNspdjwvXYavteef331v44YCH yX/5NioaRIlY70kSRaEV/Ebcsi1hhpj9nqdpfW3Rr2g4TLXHpHyi+Fm6bP5BSrqaT4fW E1PV84FudaD54fWIu+FhgtUtVCDwmwr2tDzD6uaaQKXAnIjHoLn2M+8JA0w4l3L9eMwV OoeA== X-Forwarded-Encrypted: i=1; AJvYcCU6rVqrr5IAJLZdg3YqPBOP6YbtF9aGM/8kRf21qMJbG16byVO7gK1XFnUIFJJpU+XwdZuDm7XIuUlb5A==@vger.kernel.org X-Gm-Message-State: AOJu0YxDkMA5cTSVvh1BsLS/jb9leuLMeGo8yV+NV3t4Gou8tygNetD6 +ph8g6ufphajLHpkSXoAZkhVDtv/HR9KV/HZ5HmnG0vYR0D0L3Fw5sv+ X-Gm-Gg: ASbGncs7TVG1wCxrdA6zdO+SeidMDe32D0ooL4EPrmaD3j8cBCQt0/QCAvoilwWDLuU MPeJe77bwDlFb6T1a1OsjTfgZzzy9QoluRw6WYPoNIJ1i4uYhyK3sRybphaPb+b++KTBsRbKzxs oDYMtBAyfoUBFd0Choc50HPzJS5fjZKYJ2j6D3bjWueC2pIBVa4ctQEFxMYLXfxiAG7VUefnl2f W1didniHxTA+u2c5blxv+ieaJZg3bJmBg5NOfSjeFHFNU1VN3xfTPnTz1RvBflfBE0smFMpq6mQ Uwt/BomXKSrCbtcXSsA53cCUNrZYDkEb0s7P8dX5Q+QZpLfheIizGk9iclT5j+QSlzhUjrIZ73L 8DjhS7EASGUyFKOjHPBwiuj43ReojVc/shcvojUM2v1DESsaxsME10pMjElFz9GhDXv63VSilPx iovbpPXnXGUKnXmyFt5pY+r90XtW7I6q21Mr/RYD/nPirte6596If9 X-Google-Smtp-Source: AGHT+IG9saNXs40oR1IEnqn2ZJqpHZqHgNAPFU5PXOa3lUzB4P6UMLrs3Ay2s/I5KpU2wmqmBc0PbQ== X-Received: by 2002:a05:6000:40db:b0:3e7:5f26:f1e5 with SMTP id ffacd0b85a97d-42ae58812c9mr1862887f8f.23.1762506770833; Fri, 07 Nov 2025 01:12:50 -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 ffacd0b85a97d-42abe62bf35sm4130393f8f.7.2025.11.07.01.12.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Nov 2025 01:12:50 -0800 (PST) Date: Fri, 7 Nov 2025 09:12:46 +0000 From: David Laight To: Andrew Morton Cc: Junrui Luo , linux-kernel@vger.kernel.org, pmladek@suse.com, rostedt@goodmis.org, andriy.shevchenko@linux.intel.com, tiwai@suse.com, perex@perex.cz, linux-sound@vger.kernel.org, mchehab@kernel.org, awalls@md.metrocast.net, linux-media@vger.kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org Subject: Re: [PATCH 1/4] lib/sprintf: add scnprintf_append() helper function Message-ID: <20251107091246.4e5900f4@pumpkin> In-Reply-To: <20251106213833.546c8eaba8aec6aa6a5e30b6@linux-foundation.org> References: <20251107051616.21606-1-moonafterrain@outlook.com> <20251106213833.546c8eaba8aec6aa6a5e30b6@linux-foundation.org> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-sound@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 Thu, 6 Nov 2025 21:38:33 -0800 Andrew Morton wrote: > On Fri, 7 Nov 2025 13:16:13 +0800 Junrui Luo wrote: > > > +/** > > + * scnprintf_append - Append a formatted string to a buffer > > + * @buf: The buffer to append to (must be null-terminated) > > + * @size: The size of the buffer > > + * @fmt: Format string > > + * @...: Arguments for the format string > > + * > > + * This function appends a formatted string to an existing null-terminated > > + * buffer. It is safe to use in a chain of calls, as it returns the total > > + * length of the string. > > + * > > + * Returns: The total length of the string in @buf > > It wouldn't hurt to describe the behavior when this runs out of space > in *buf. > > > > The whole thing is a bit unweildy - how much space must the caller > allocate for `buf'? I bet that's a wild old guess. That is true for all the snprintf() functions. > I wonder if we should instead implement a kasprintf() version of this > which reallocs each time and then switch all the callers over to that. That adds the cost of a malloc, and I, like kasprintf() probably ends up doing all the work of snprintf twice. I'd be tempted to avoid the strlen() by passing in the offset. So (say): #define scnprintf_at(buf, len, off, ...) \ scnprintf((buf) + off, (len) - off, __VA_ARGS__) Then you can chain calls, eg: off = scnprintf(buf, sizeof buf, ....); off += scnprintf_at(buf, sizeof buf, off, ....); David