From patchwork Sun Apr 7 20:01:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 13620278 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 1ED3BCD1292 for ; Sun, 7 Apr 2024 20:02:46 +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=kYLrLXNKMr5fRhZzZA7wEIkcbRz2M1hqxk9UOzj0UHg=; b=rheNUeSc58zmzC Qs510qB7+XjUBLDGpvxtoOF6aInJBVH7diR1PYD51p9F+uOgn8ePnb75T5yj+hCX3X61oYjy24IyW O781V/hpG5SUUniNlhZ59fYNExsy/UpXgMUlb+eA914sWl/Xmpm7JXWt891nN4kDAh+/jKxsIj/nJ hrYbFHdeEABQZnKpX5MwEQb544eVFLJX8/9zISoH9vNQqMk6sOHU0Ulhh4F5Z3xSJmHq71gVuE3C6 O50xPyRzFViLBvqNJjbR1xLAEoaG7/gkAzvijtoyr+BaCSz2FI8CbhGd7/Q6nzXBesN3oVUxhj3JV fdrTdEF8JSww2QUMRYbg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rtYib-0000000DPud-3bwE; Sun, 07 Apr 2024 20:02:21 +0000 Received: from smtp-28.smtpout.orange.fr ([80.12.242.28] helo=smtp.smtpout.orange.fr) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rtYiW-0000000DPsT-2hGT; Sun, 07 Apr 2024 20:02:19 +0000 Received: from fedora.home ([86.243.17.157]) by smtp.orange.fr with ESMTPA id tYiBrICUDz1OZtYiBrfStB; Sun, 07 Apr 2024 22:01:59 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1712520119; bh=gOBZVvTbMI4Vvy9nFHPCW2JYo+PpjPrCvqOXxjC2HGc=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=ndXKCBHemAwbLOKLOO2DOm3giezlAGq19PHmek5chO1wkT5gUZPMjUJikYvKnURdd wGHjgS0P7bENVtSp2WxQxaXAnUsnehEl+PPfoClhHm0ad3IYGBWiZjlq9Xr5h7MU8d h8XmHoL7HbSVSRY4dS4rWUnG5SR2I0CNAewO8hIpMr7fO65TS3F/YugMLCEXaGcTHU SbngVs0Sreh/6oF97hzgyZbuchAFrL34WYM2ykDORy1WiDAkweUrr/gh8Td80eY4me JViE28pwYxzW8uZlisovIEchTebYhV0fsGyuUQAGOVRH42LrmtFDROZP1qooMrHpRV JQQCItc7Q4Piw== X-ME-Helo: fedora.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 07 Apr 2024 22:01:59 +0200 X-ME-IP: 86.243.17.157 From: Christophe JAILLET To: "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Matthias Brugger , AngeloGioacchino Del Regno Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH 1/2] thermal/drivers/mediatek/lvts_thermal: Make debugfs related fields more consistent Date: Sun, 7 Apr 2024 22:01:48 +0200 Message-ID: <42a87fb9837f1760d1ad4eb7162a7536785dc6f5.1712520052.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240407_130217_164245_07A7CF2A X-CRM114-Status: UNSURE ( 9.93 ) X-CRM114-Notice: Please train this message. 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 debugfs code is only generated if CONFIG_MTK_LVTS_THERMAL_DEBUGFS is defined. So 'dom_dentry' should be included in the 'struct lvts_domain' with the same condition, instead of CONFIG_DEBUG_FS. Signed-off-by: Christophe JAILLET --- Compile tested-only --- drivers/thermal/mediatek/lvts_thermal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c index fd4bd650c77a..3003dc350766 100644 --- a/drivers/thermal/mediatek/lvts_thermal.c +++ b/drivers/thermal/mediatek/lvts_thermal.c @@ -150,7 +150,7 @@ struct lvts_domain { void __iomem *base; size_t calib_len; u8 *calib; -#ifdef CONFIG_DEBUG_FS +#ifdef CONFIG_MTK_LVTS_THERMAL_DEBUGFS struct dentry *dom_dentry; #endif }; From patchwork Sun Apr 7 20:01:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 13620277 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 CD113CD1292 for ; Sun, 7 Apr 2024 20:02:39 +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:References:In-Reply-To: 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: List-Owner; bh=AbQ+CwmfO3PMCxZ6w2obSQ5NjMyv+ZA1SPe1APpmf2Y=; b=voXNHsuIB4FzZ+ xwWMhf1DogNhh7YJRK6N+Nhhhh9uA/1BnL/6+gzS9/K8Z9gPFJipUCmJFwuq1b2z4dvIMxNtG8/5/ icIWWO0wsKPebMmw/+7LilLpVXYTgt7hvqu5Z6H9MSfqYkK92ba5E5NXdoWhjgm+wQjuxbzuQw939 V6PxfrWPfHsZtCNO10rjJtXvPOohkNYz1dOOFE6ImBFJS2N563McR+fr9Lg+9pBo+ROhzOX5B5IY7 AQL5ZQTHib4KPJ61ZXWkaQF9ilotEgjP/wMKBRGwLMaWLPt64EWSLD+CbDzxrlKk+HHqT8qzYN8ry tA4l8BJYgT5t2cKBK0xQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rtYib-0000000DPuZ-0oNE; Sun, 07 Apr 2024 20:02:21 +0000 Received: from msa-218.smtpout.orange.fr ([193.252.23.218] helo=msa.smtpout.orange.fr) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rtYiW-0000000DPss-2bvt; Sun, 07 Apr 2024 20:02:19 +0000 Received: from fedora.home ([86.243.17.157]) by smtp.orange.fr with ESMTPA id tYiBrICUDz1OZtYiJrfStr; Sun, 07 Apr 2024 22:02:05 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1712520125; bh=yDBPh3Zd5MPQHTnfbxFeCnae77YFIui58j4SxgeMCkQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=qvs10VBOaOJ7o7KEE3sCJ1qbBrUcBXVDTAqkSfuaumV8kz1YI/wUFqQCBed3AqJ4R WW9w1d1LT+Pa1WfjBHBOiD5W9T6ozKlp2uYEujckaXwRLcePiUBTE/qa2cLxOh3qhj S7bk4U7p9jur8kb5szZBdHfstJ6yS/P5BUUAvG2da6/reJuu/Uu7TVbpLYSZ8hIhED X2Y6+UD2jq7xgj6B6xCuzalrhTepBK/dHLHCu5ml/p+pEvUl53XJ5MtceIdCU6/fTY iQUdYdBqAnyNKl4jajCq1mMvX3alsRr4vn5jBA9D7wIYD3ocMw2HwzPf4hnenOfz6l IPjEMwU4liSHA== X-ME-Helo: fedora.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 07 Apr 2024 22:02:05 +0200 X-ME-IP: 86.243.17.157 From: Christophe JAILLET To: "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , Matthias Brugger , AngeloGioacchino Del Regno Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH 2/2] thermal/drivers/mediatek/lvts_thermal: Improve some memory allocation Date: Sun, 7 Apr 2024 22:01:49 +0200 Message-ID: <8cb69f245311a348164b0b5ca3dbc59386746035.1712520052.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.44.0 In-Reply-To: <42a87fb9837f1760d1ad4eb7162a7536785dc6f5.1712520052.git.christophe.jaillet@wanadoo.fr> References: <42a87fb9837f1760d1ad4eb7162a7536785dc6f5.1712520052.git.christophe.jaillet@wanadoo.fr> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240407_130217_180485_F025B573 X-CRM114-Status: GOOD ( 14.42 ) 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 lvts_debugfs_init() is called with lvts_td->num_lvts_ctrl being 2, 3 or 4. sizeof(struct debugfs_regset32) is small. 32 byres on a x86_64. So, given the overhead of devm_kzalloc(), it is better to allocate all needed regset at once. The overhead of devm_kzalloc() is 40 bytes on a x86_64, and because of rounding in memory allocation, it leads to: 2 * (32 + 40) = 2 * 72 --> 2 96 bytes allocations for a total of 192 bytes 3 * (32 + 40) = 3 * 72 --> 3 96 bytes allocations for a total of 288 bytes 4 * (32 + 40) = 4 * 72 --> 4 96 bytes allocations for a total of 384 bytes using a single devm_kcalloc(): 2 * 32 + 40 = 104 --> 1 allocation for a total of 128 3 * 32 + 40 = 136 --> 1 allocation for a total of 192 4 * 32 + 40 = 168 --> 1 allocation for a total of 192 So, this saves both a few bytes and reduce memory fragmentation. Signed-off-by: Christophe JAILLET --- Compile tested-only --- drivers/thermal/mediatek/lvts_thermal.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c index 3003dc350766..b133f731c5ba 100644 --- a/drivers/thermal/mediatek/lvts_thermal.c +++ b/drivers/thermal/mediatek/lvts_thermal.c @@ -204,7 +204,7 @@ static const struct debugfs_reg32 lvts_regs[] = { static int lvts_debugfs_init(struct device *dev, struct lvts_domain *lvts_td) { - struct debugfs_regset32 *regset; + struct debugfs_regset32 *regsets; struct lvts_ctrl *lvts_ctrl; struct dentry *dentry; char name[64]; @@ -214,8 +214,14 @@ static int lvts_debugfs_init(struct device *dev, struct lvts_domain *lvts_td) if (IS_ERR(lvts_td->dom_dentry)) return 0; + regsets = devm_kcalloc(dev, lvts_td->num_lvts_ctrl, + sizeof(*regsets), GFP_KERNEL); + if (!regsets) + return 0; + for (i = 0; i < lvts_td->num_lvts_ctrl; i++) { + struct debugfs_regset32 *regset = ®sets[i]; lvts_ctrl = &lvts_td->lvts_ctrl[i]; sprintf(name, "controller%d", i); @@ -223,10 +229,6 @@ static int lvts_debugfs_init(struct device *dev, struct lvts_domain *lvts_td) if (IS_ERR(dentry)) continue; - regset = devm_kzalloc(dev, sizeof(*regset), GFP_KERNEL); - if (!regset) - continue; - regset->base = lvts_ctrl->base; regset->regs = lvts_regs; regset->nregs = ARRAY_SIZE(lvts_regs);