Received: by 2002:ab2:f03:0:b0:1ef:ffd0:ce49 with SMTP id i3csp100266lqf; Tue, 26 Mar 2024 16:05:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW7dcyR/O6eNwgU2IoJY0JxVZIRbZOMZpG1K5q847DOMUbVYaUdRLofbKDpKtcRHB3ghQhjWWs5X6tLYgHCWMjx6BDExkSIyEcC0bYiTg== X-Google-Smtp-Source: AGHT+IHx9eQkndxnbBMHzI8p9C+ISv8sQjjJF3fByqHjIOshfPJuuSL5xFGss5cGK/ZflxrLEc/J X-Received: by 2002:a50:d5c1:0:b0:566:be15:9a88 with SMTP id g1-20020a50d5c1000000b00566be159a88mr1028087edj.20.1711494321848; Tue, 26 Mar 2024 16:05:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711494321; cv=pass; d=google.com; s=arc-20160816; b=Zxq26RkHzubBmMODrfuyrhzGUgVkJvoOCqy4SroQVP3mENoFjxw1s6P8tBJV4+wSJe RUDg07A8M0ateWFii7Gi9UW3jmdRt+/WsrRvTvtiRl9TnH/6SkJltlflYbKawfHszixt ViwNSFEH8orSq7F9TMYxy02QhRltyWwaJ4BcsX4ITO6IrPiZwF3UMYeEcahjOQ0MjdhF fInjNtpk1fWL67hkbdUdr6Htr8xPNRZED3rj7+uQ/paZl8oB0yHLWNFFDiYVCNh5CJ+L il5wEe22UXMepuXwfvtoRjes/T+StE4QaHoo0dRa1SuxIpI3WUAT/5vyaZnsNCTbe8sA HdcQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=EkT5rTif+YW4w0eyx5BJU+JolFr3OXicdLhyHQXOIlY=; fh=VTI9lelDv68R60IGAVEJBWWfXIA7MmO01ixZwcI+QRM=; b=Q4FapQHifdviwn46A2OP2FOIOywKQdCRO0E1k6FpOIK5aWqBLiiXB6VGHTOjq8JbCK uA3tKlWqXJuSQVJj7hClOMTbK0fuK0dJAPnXRvtLjIPTvzWp7IrGosM9qCxuIDKZsAr2 ybRB/Odv8AQ4eh2FNdjJy+x/2NdLd2YZENIXv/Metgfxp/3lC1kvoDcZTcxCSiJSriRI s+t50xoVnUWddPvg9mSDZ6Tdcdlym2I466U0sko24hsNg6wyhSaceUtr3UBB6TvVr2Xf W+lYtjoYuD+v/WUJTkCoX8VVHo1RKZEr647bzY9jfYevSYb7ZWwWGMO0yaX5tcmfBUdS XvCw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=R7egcuOy; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-120120-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-120120-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id fj12-20020a0564022b8c00b0056bdc146261si4033105edb.148.2024.03.26.16.05.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 16:05:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-120120-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=R7egcuOy; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-120120-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-120120-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 8C3811F62AD0 for ; Tue, 26 Mar 2024 23:05:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C205713DDAD; Tue, 26 Mar 2024 23:05:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="R7egcuOy" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE86FF4E2; Tue, 26 Mar 2024 23:05:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711494314; cv=none; b=i/pbrD1SceEdUD3gztumDDi5U1hllhXZ+ch2Rb1Uhhpc1WgGyKDsfBJ3G6bHTzLn/hUmdL5SYEK4AavpmiC+5bVN/+YsSpUYz1fIyzOuK6+iKDxigjIrfCu0lMVx32tkidCOpFsVq2QWh4bFC7DDyYH6j2iTwNCLrd0TWxPUNdk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711494314; c=relaxed/simple; bh=kPs0n7s9RGFewXWD3jJW3srjuYgF49+C9LMbEpbs33Y=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=u1DB/AMEQYNNM/rbrt8PP/G0Vnjaa6aJ0vmnLJKHr7o5u02hST1f4d4Cx/VjPtPrFIR2gz7rKLdlV67dQN63h6RoS4U80QjQYRQDruCWBycl26ov9BV5Ti9Gp8FSyggYBdXkNl9aKSJ5R9QDbfL7lVXGfKiz2vFsilQdQZNUDpo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=R7egcuOy; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4162C433F1; Tue, 26 Mar 2024 23:05:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711494313; bh=kPs0n7s9RGFewXWD3jJW3srjuYgF49+C9LMbEpbs33Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=R7egcuOyeUTcDqRnRs3hibT1y6j9Vn7nDQ3OnDOSqkJHcVEhTqgIt8dGz5VrnMUAy N0ZYvYMjLHN5HMNfC2pTu/p6bIQmQMhQO2QlzYeu+f65C3YuCbFKZEdOEmJJaEpKZ2 cGWdbHszIUiaayLk7xGfX/ao3Af17u8idSHKjjcQX//nM0anlFf+If6LqHVUWZjcVQ xijNKn5VceC4T3rzZobqZSIZTrdK9Xd3gtplatC/AUQ3NpAJqZTPhQXVpElwaVYser jCJMJyBAejVvQU7VD5Imq1YJzjvwEhS6JLhkFAmOSSiZLku1WqHNfKP2+cT8aaBth0 OhxyN26gLfp1g== Date: Tue, 26 Mar 2024 16:05:11 -0700 From: Nathan Chancellor To: Arnd Bergmann Cc: llvm@lists.linux.dev, Hans de Goede , Ilpo =?iso-8859-1?Q?J=E4rvinen?= , Maximilian Luz , Arnd Bergmann , Nick Desaulniers , Bill Wendling , Justin Stitt , Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= , Andy Shevchenko , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 5/9] surface3_power: avoid format string truncation warning Message-ID: <20240326230511.GA2796782@dev-arch.thelio-3990X> References: <20240326223825.4084412-1-arnd@kernel.org> <20240326223825.4084412-6-arnd@kernel.org> 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-Disposition: inline In-Reply-To: <20240326223825.4084412-6-arnd@kernel.org> On Tue, Mar 26, 2024 at 11:38:04PM +0100, Arnd Bergmann wrote: > From: Arnd Bergmann > > clang warns about printing a pair of escaped strings into a buffer that is > too short: > > drivers/platform/surface/surface3_power.c:248:3: error: 'snprintf' will always be truncated; specified size is 10, but format string expands to at least 12 [-Werror,-Wformat-truncation-non-kprintf] > 248 | snprintf(bix->serial, ARRAY_SIZE(bix->serial), "%3pE%6pE", buf + 7, buf); > | ^ > > Change the format string two print two less bytes so it always fits. The string > is still truncated, so there is no change in behavior, but the compiler no > longer warns about it. > > Fixes: 85f7582cd484 ("platform/surface: Move Surface 3 Power OpRegion driver to platform/surface") > Signed-off-by: Arnd Bergmann > --- > Not entirely sure about this one, as I've never used escaped strings, and > don't know if gcc is correct to warn here, or if the kernel defines it > differently from the standard. As far as I understand it, this is a false positive because clang does not understand the kernel's %p extensions. GCC does not warn for overflow or truncation when %p is involved but the clang developers chose to intentionally deviate from GCC in that aspect while sticking it under a separate diagnostic that we could disable. I sent a patch that did so some time ago but I guess Masahiro never applied it... https://lore.kernel.org/20231002-disable-wformat-truncation-overflow-non-kprintf-v1-1-35179205c8d9@kernel.org/ Consider dropping the changes that fix non-kprintf warnings and including that patch as part of this series. > --- > drivers/platform/surface/surface3_power.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/platform/surface/surface3_power.c b/drivers/platform/surface/surface3_power.c > index 4c0f92562a79..72f904761fde 100644 > --- a/drivers/platform/surface/surface3_power.c > +++ b/drivers/platform/surface/surface3_power.c > @@ -245,7 +245,7 @@ static int mshw0011_bix(struct mshw0011_data *cdata, struct bix *bix) > dev_err(&client->dev, "Error reading serial no: %d\n", ret); > return ret; > } else { > - snprintf(bix->serial, ARRAY_SIZE(bix->serial), "%3pE%6pE", buf + 7, buf); > + snprintf(bix->serial, ARRAY_SIZE(bix->serial), "%3pE%4pE", buf + 7, buf); > } > > /* get cycle count */ > -- > 2.39.2 >