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: 786793 Received: from smtp.smtpout.orange.fr (smtp-27.smtpout.orange.fr [80.12.242.27]) (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 C5EEA11181; Sun, 7 Apr 2024 20:03:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.12.242.27 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712520192; cv=none; b=dqADoRVlVdM9ttww1jNWF8Zxx0pywF7BHFUxzZ7mHr+FWd+nRnrP5r1kilv49HXrzxtHAINvg/0STBk7fu+K7NUiQDIbzf7znlPsPOXUaMSGQMdcbua2f8LaM3cNM63wCm8vT8THx4w1C7G6x7ERiXOpp/8xjtUHy2dklK/EJRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712520192; c=relaxed/simple; bh=keKEy/3Xr8accsTk/JDqcRgA2FSs4IU5nT8QrCVYNHE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Yn3BqJDtt50VX+cFmpXHEn19VVlWO4hDnu/MaNr9w/95NhhBdYivJWSjPMBe+lsWCEMq1un6nq6nOoeAimqqNeCh2h+Qyd7FFLqlAP38dQXSW3hOIemZAkiwqGHHn/qKiu+r3aF1PUtykJUMIWSHXOTfzyEBtKZdKvy5edILRAg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wanadoo.fr; spf=pass smtp.mailfrom=wanadoo.fr; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b=ndXKCBHe; arc=none smtp.client-ip=80.12.242.27 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wanadoo.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wanadoo.fr Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b="ndXKCBHe" 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 Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 787106 Received: from smtp.smtpout.orange.fr (smtp-27.smtpout.orange.fr [80.12.242.27]) (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 165F03EA93; Sun, 7 Apr 2024 20:03:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.12.242.27 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712520197; cv=none; b=WAGJKuXX1EgYrOmV8WJrVrAvcZbyeJTDO1INGnOnkKMW5imnoB1lNV2zNdS387gbRCsXnASEV0k3e5OefHyXDl5/4wYnw5S5lmUd2YQsHDYehTfSO1xMkFEoyZRYmpi+bRrL2n8ltzNkPl5BRb+IYYbkkitIdMCZRZkFSnyVDCM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712520197; c=relaxed/simple; bh=lHqg1QJCxrsNhs4z4v/Y14TlaLQ598KsjsJ/Pyg4uMA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JbN5LdtnGNPjXGHspKLjWAvo7vpXEX3OscEDdkoqVzvfLJTwqo6ZK/q01sNzd0dDr1LJCUHnKUUgrCNHI138JLv2fqJtzlXa8o+MLSTsWyTZcbc1mGTVdyTYoYtQfzVjAhMmojIzU/jbJp0FYGvMB2oqbBX06KviMXTUTB/sH4w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wanadoo.fr; spf=pass smtp.mailfrom=wanadoo.fr; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b=qvs10VBO; arc=none smtp.client-ip=80.12.242.27 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wanadoo.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wanadoo.fr Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wanadoo.fr header.i=@wanadoo.fr header.b="qvs10VBO" 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> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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);