From patchwork Mon Oct 30 10:12:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 13440400 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 68EB0C4332F for ; Mon, 30 Oct 2023 10:13:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=QKQSUzB1iMxAPwAMrtAc2YEd8uAJcNdAQe0fCHYhh04=; b=fHFAV7XBVo/5ve aF5vGUAe6lm6QfQqCk1eqATqEcgzfA1T12/Dz2ss55V2QtKpod7NAdemjwPYPDSstGyAahi6KtYKP jZIURgFqr3B7oMSRJJwcM996vIDvTWKJEWeaeUsblRWFF79ftsYQJ9lFxwIKNIQRA22zmEqXGS7Vm 2H3kT+pgXEeCj/9OMOqOQ7FClk2KtXwf3oxhLklxJamskB/hinlXRF7+vb1VSNzEuV9yv3mqm7+lv ENcU1gviThdXrIEyA1x+zmT4hmZo0AK41JQIXmGX2InkhGro1R/dITZhHeQUkh9yvpsMTt6KDPbfI 85H0kkoz+1q7vgH7yGtg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qxPGK-00321U-2s; Mon, 30 Oct 2023 10:12:48 +0000 Received: from smtp-26.smtpout.orange.fr ([80.12.242.26] helo=smtp.smtpout.orange.fr) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qxPGH-0031zx-29 for linux-arm-kernel@lists.infradead.org; Mon, 30 Oct 2023 10:12:47 +0000 Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id xPG3qqyAE4QsMxPG3qncw9; Mon, 30 Oct 2023 11:12:34 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1698660754; bh=UlJi3Q2/4KzrolD0gZ6MzxC5lWsP/eLAiQtg1TLakIM=; h=From:To:Cc:Subject:Date; b=VdKt3ZPQ1msygyxneY6z561IdGpQL3CanQWxiVuLcgvAXqqX7L+HgUv4v3nXyd47H bUJrFPoICjbtY336Qp6+Q/Wq1Xds9VRAguAGS9Ozf7BDFO951zA9TZFyI9q5tR6du/ HtIf6tW3upFeDjQb70hvaaEWgi56YBGd1J6S9oDYUstT6KtSVM1BMMpta2awG2dZQH ckan5wUNSIKdJX+2PBRYriv1DR4zv7gXrkYfmCYirOGyBupsWyEr9VI+zxptSySldk FDIqpGsL4eHKch/IJNLcwvfWIVZnDWqkUnAB6KM5Nk42+3sQ5VAmMy/0zVlT6oLP1H 3s4F5bO+iCZ7Q== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Mon, 30 Oct 2023 11:12:34 +0100 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: Nishanth Menon , Tero Kristo , Santosh Shilimkar Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , Tero Kristo , linux-arm-kernel@lists.infradead.org Subject: [PATCH v2] firmware: ti_sci: Fix an off-by-one in ti_sci_debugfs_create() Date: Mon, 30 Oct 2023 11:12:26 +0100 Message-Id: <7158db0a4d7b19855ddd542ec61b666973aad8dc.1698660720.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231030_031245_857711_1101B2F3 X-CRM114-Status: GOOD ( 13.32 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The ending NULL is not taken into account by strncat(), so switch to snprintf() to correctly build 'debug_name'. Using snprintf() also makes the code more readable. Fixes: aa276781a64a ("firmware: Add basic support for TI System Control Interface (TI-SCI) protocol") Signed-off-by: Christophe JAILLET Reviewed-by: Dan Carpenter --- v2: - use snprintf() to simplify code [Dan Carpenter] v1: https://lore.kernel.org/all/880aeea52f3bdde5e3e8843bbedb7fd068a58be2.1698565938.git.christophe.jaillet@wanadoo.fr/ --- drivers/firmware/ti_sci.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c index 7041befc756a..8b9a2556de16 100644 --- a/drivers/firmware/ti_sci.c +++ b/drivers/firmware/ti_sci.c @@ -164,7 +164,7 @@ static int ti_sci_debugfs_create(struct platform_device *pdev, { struct device *dev = &pdev->dev; struct resource *res; - char debug_name[50] = "ti_sci_debug@"; + char debug_name[50]; /* Debug region is optional */ res = platform_get_resource_byname(pdev, IORESOURCE_MEM, @@ -181,10 +181,10 @@ static int ti_sci_debugfs_create(struct platform_device *pdev, /* Setup NULL termination */ info->debug_buffer[info->debug_region_size] = 0; - info->d = debugfs_create_file(strncat(debug_name, dev_name(dev), - sizeof(debug_name) - - sizeof("ti_sci_debug@")), - 0444, NULL, info, &ti_sci_debug_fops); + snprintf(debug_name, sizeof(debug_name), "ti_sci_debug@%s", + dev_name(dev)); + info->d = debugfs_create_file(debug_name, 0444, NULL, info, + &ti_sci_debug_fops); if (IS_ERR(info->d)) return PTR_ERR(info->d);