From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E499ECCF9EA for ; Mon, 27 Oct 2025 09:33:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=kqA2FjUWt5iFwl4HjsgJ2e7hSVARDCBYpBO/uzoBp7w=; b=tqV7POOGfboH1ZqZcDKMnjQgzL vKxomWNBLevef/5SfiePyn69AhJBpJ8bI2ipYY/cefkUwg705zEVsFSouHg43f1FRosLf6aclxN/D th0GRokvpdHo94EI8gTMU/CYOdNb2vWlVvGhlqPtNQG9L5IvllETYXhRhku7MONz/CynKjT0eLIU3 ryxtfPXRT+fqh/Iig7BmMNuag9bHPJEVUlTrm/zUTQ3EYz8szYBvsDHIRaT1fP2Wf2QChN5hnQUKj vpG3wUd2BOVykoH3YzMBnUagAXMn2m9Vl7lYjP8UP6x2J4E4zi9Facqum4kpdJ1AZqKzkm7yeAvT3 6d2ZQPAw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vDJb3-0000000DYDr-2nUi; Mon, 27 Oct 2025 09:33:01 +0000 Received: from bali.collaboradmins.com ([2a01:4f8:201:9162::2]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vDJb0-0000000DY9i-1srU; Mon, 27 Oct 2025 09:32:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1761557574; bh=rTgPzkbHTz6CLV0HalVq6PovgVJUM7yM8MpMHc6txvU=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=IavK31t9oKFUguKtvnj6uUkl+zZI+2ndJShUTkxMkNWpcz2bSvDuzD5rtx60eMNt8 NDmQKPXEFtuCJJWZMwkxMrnG3rMnZVoqZMJYeFFz17yMfxjVufSmsS2QKdryuAjeNx muCM3jfql29XKccecm0ynWrjB1jGjzICzT79uuefqvgthH4u9IRtTNN2vSRXVtmRSR h8L6R8tyqkEHVsb7t6+dMJvp0jTCBs5fZNZ4HFGlM9HywZ3XswhoQf4IT1hswUjLOl jgGqJVhhFBykQja9wHsa+7QwEE0fds7lb/cwX2y5D9ewxRdVJ0EjHCtl6mdmZv5Bpg bJoUySTZRf2og== Received: from [192.168.1.100] (2-237-20-237.ip236.fastwebnet.it [2.237.20.237]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by bali.collaboradmins.com (Postfix) with ESMTPSA id C691017E1340; Mon, 27 Oct 2025 10:32:53 +0100 (CET) Message-ID: <158c16f0-9d50-45f9-a3cb-5deb36d09366@collabora.com> Date: Mon, 27 Oct 2025 10:32:53 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] remoteproc: mtk_scp: change the snprintf() checking To: Dan Carpenter , Bjorn Andersson Cc: Mathieu Poirier , Matthias Brugger , linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, kernel-janitors@vger.kernel.org References: From: AngeloGioacchino Del Regno Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251027_023258_683376_00AA37CB X-CRM114-Status: GOOD ( 21.82 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Il 27/10/25 08:08, Dan Carpenter ha scritto: > The snprintf() calls here work but they have several minor style issues: > > 1) It uses ARRAY_SIZE() which is the number of elements in an array. > Since were talking about char that works, but it's more common to > use sizeof() which is the number of bytes. > 2) The printf format is "%1d". The "1" ensures we always print at > least 1 character but since numbers all have at least 1 digit this > can be removed. > 3) The kernel implementation of snprintf() cannot return negative error > codes. Also these particular calls to snprintf() can't return zero > and the code to handle that zero return is sort of questionable. > 4) In the current kernel the only "core_id" we print is "0" but if it > was more than 9 then the output would be truncated so GCC complains. > Add an "a >= sizeof(scp_fw_file)" check for output which is too long. > > Signed-off-by: Dan Carpenter Reviewed-by: AngeloGioacchino Del Regno > --- > v2: The v1 introduced a W=1 warning because of the truncation issue. > It's a false positive because GCC assumes that "core_id" can be > every possible value of int but actually it can only be zero. And > also generally, in the kernel, truncating is fine and it is fine > here too. > > But let's use that as an opportunity to do more cleanups. > > drivers/remoteproc/mtk_scp.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c > index 10e3f9eb8cd2..db8fd045468d 100644 > --- a/drivers/remoteproc/mtk_scp.c > +++ b/drivers/remoteproc/mtk_scp.c > @@ -1127,11 +1127,11 @@ static const char *scp_get_default_fw_path(struct device *dev, int core_id) > return ERR_PTR(-EINVAL); > > if (core_id >= 0) > - ret = snprintf(scp_fw_file, ARRAY_SIZE(scp_fw_file), "scp_c%1d", core_id); > + ret = snprintf(scp_fw_file, sizeof(scp_fw_file), "scp_c%d", core_id); > else > - ret = snprintf(scp_fw_file, ARRAY_SIZE(scp_fw_file), "scp"); > - if (ret <= 0) > - return ERR_PTR(ret); > + ret = snprintf(scp_fw_file, sizeof(scp_fw_file), "scp"); > + if (ret >= sizeof(scp_fw_file)) > + return ERR_PTR(-ENAMETOOLONG); > > /* Not using strchr here, as strlen of a const gets optimized by compiler */ > soc = &compatible[strlen("mediatek,")];