devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thierry Reding <thierry.reding@gmail.com>
To: Daniel Lezcano <daniel.lezcano@linaro.org>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	Thierry Reding <thierry.reding@gmail.com>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Conor Dooley <conor+dt@kernel.org>
Cc: Amit Kucheria <amitk@kernel.org>, Zhang Rui <rui.zhang@intel.com>,
	Jon Hunter <jonathanh@nvidia.com>,
	linux-pm@vger.kernel.org, devicetree@vger.kernel.org,
	linux-tegra@vger.kernel.org
Subject: [PATCH v2 07/13] thermal: tegra: Use unsigned int where appropriate
Date: Thu, 12 Oct 2023 19:58:28 +0200	[thread overview]
Message-ID: <20231012175836.3408077-8-thierry.reding@gmail.com> (raw)
In-Reply-To: <20231012175836.3408077-1-thierry.reding@gmail.com>

From: Thierry Reding <treding@nvidia.com>

Use unsigned integers more consistently, which helps to make it more
explicit about what values can be expected.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 drivers/thermal/tegra/soctherm.c | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/drivers/thermal/tegra/soctherm.c b/drivers/thermal/tegra/soctherm.c
index 105ec20d509d..c7f8e36cbeab 100644
--- a/drivers/thermal/tegra/soctherm.c
+++ b/drivers/thermal/tegra/soctherm.c
@@ -591,8 +591,9 @@ find_throttle_cfg_by_name(struct tegra_soctherm *ts, const char *name)
 
 static int tsensor_group_thermtrip_get(struct tegra_soctherm *ts, int id)
 {
-	int i, temp = min_low_temp;
 	struct tsensor_group_thermtrips *tt = ts->soc->thermtrips;
+	int temp = min_low_temp;
+	unsigned int i;
 
 	if (id >= TEGRA124_SOCTHERM_SENSOR_NUM)
 		return temp;
@@ -1469,33 +1470,34 @@ static int soctherm_thermtrips_parse(struct tegra_soctherm *ts)
 {
 	struct tsensor_group_thermtrips *tt = ts->soc->thermtrips;
 	const int max_num_prop = ts->soc->num_ttgs * 2;
+	unsigned int i, j, count;
 	u32 *tlb;
-	int i, j, n, ret;
+	int ret;
 
 	if (!tt)
 		return -ENOMEM;
 
-	n = of_property_count_u32_elems(ts->dev->of_node, "nvidia,thermtrips");
-	if (n <= 0) {
+	ret = of_property_count_u32_elems(ts->dev->of_node, "nvidia,thermtrips");
+	if (ret <= 0) {
 		dev_info(ts->dev,
-			 "missing thermtrips, will use critical trips as shut down temp\n");
-		return n;
+			 "missing thermtrips, will use critical trips as shut down temperature\n");
+		return ret;
 	}
 
-	n = min(max_num_prop, n);
+	count = min_t(unsigned int, ret, ts->soc->num_ttgs * 2);
 
 	tlb = devm_kcalloc(ts->dev, max_num_prop, sizeof(u32), GFP_KERNEL);
 	if (!tlb)
 		return -ENOMEM;
+
 	ret = of_property_read_u32_array(ts->dev->of_node, "nvidia,thermtrips",
-					 tlb, n);
+					 tlb, count);
 	if (ret) {
 		dev_err(ts->dev, "invalid num ele: thermtrips:%d\n", ret);
 		return ret;
 	}
 
-	i = 0;
-	for (j = 0; j < n; j = j + 2) {
+	for (i = 0, j = 0; j < count; j = j + 2) {
 		if (tlb[j] >= TEGRA124_SOCTHERM_SENSOR_NUM)
 			continue;
 
@@ -1612,7 +1614,7 @@ static int soctherm_throt_cfg_parse(struct tegra_soctherm *ts,
 static void soctherm_init_hw_throttling(struct tegra_soctherm *tegra)
 {
 	struct device_node *np_stc, *np_stcc;
-	int i;
+	unsigned int i;
 
 	for (i = 0; i < THROTTLE_SIZE; i++) {
 		tegra->throt_cfgs[i].name = throt_names[i];
@@ -1875,8 +1877,8 @@ static void soctherm_throttle_program(struct tegra_soctherm *ts,
 
 static void tegra_soctherm_throttle(struct tegra_soctherm *ts)
 {
+	unsigned int i;
 	u32 v;
-	int i;
 
 	/* configure LOW, MED and HIGH levels for CCROC NV_THERM */
 	if (ts->soc->use_ccroc) {
@@ -1950,8 +1952,8 @@ static int soctherm_interrupts_init(struct tegra_soctherm *tegra)
 static void soctherm_init(struct tegra_soctherm *tegra)
 {
 	const struct tegra_tsensor_group **ttgs = tegra->soc->ttgs;
-	int i;
 	u32 pdiv, hotspot;
+	unsigned int i;
 
 	/* Initialize raw sensors */
 	for (i = 0; i < tegra->soc->num_tsensors; ++i)
-- 
2.42.0


  parent reply	other threads:[~2023-10-12 17:58 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-12 17:58 [PATCH v2 00/13] thermal: tegra: Do not register cooling device Thierry Reding
2023-10-12 17:58 ` [PATCH v2 01/13] thermal: Store device tree node for thermal zone devices Thierry Reding
2023-10-12 17:58 ` [PATCH v2 02/13] dt-bindings: thermal: tegra: Document throttle temperature Thierry Reding
2023-10-16 14:02   ` Rob Herring
2023-11-10 13:58     ` Thierry Reding
2023-10-12 17:58 ` [PATCH v2 03/13] dt-bindings: thermal: tegra: Add nvidia,thermal-zones property Thierry Reding
2023-10-13 15:59   ` Daniel Lezcano
2023-10-12 17:58 ` [PATCH v2 04/13] thermal: tegra: Use driver-private data consistently Thierry Reding
2023-10-13  8:04   ` Daniel Lezcano
2023-10-13 11:40     ` Thierry Reding
2023-10-12 17:58 ` [PATCH v2 05/13] thermal: tegra: Constify SoC-specific data Thierry Reding
2023-10-12 17:58 ` [PATCH v2 06/13] thermal: tegra: Do not register cooling device Thierry Reding
2023-10-13 15:57   ` Daniel Lezcano
2023-11-10 13:55     ` Thierry Reding
2023-11-10 14:52       ` Thierry Reding
2023-10-12 17:58 ` Thierry Reding [this message]
2023-10-12 17:58 ` [PATCH v2 08/13] thermal: tegra: Avoid over-allocation of temporary array Thierry Reding
2023-10-12 17:58 ` [PATCH v2 09/13] thermal: tegra: Remove gratuitous error assignment Thierry Reding
2023-10-12 17:58 ` [PATCH v2 10/13] thermal: tegra: Minor stylistic cleanups Thierry Reding
2023-10-12 17:58 ` [PATCH v2 11/13] arm64: tegra: Rework SOCTHERM on Tegra132 and Tegra210 Thierry Reding
2023-10-12 17:58 ` [PATCH v2 11/13] ARM: tegra: Rework SOCTHERM on Tegra124 Thierry Reding
2023-10-12 17:58 ` [PATCH v2 12/13] arm64: tegra: Rework SOCTHERM on Tegra132 and Tegra210 Thierry Reding
2023-10-12 17:58 ` [PATCH v2 12/13] ARM: tegra: Rework SOCTHERM on Tegra124 Thierry Reding
2023-10-12 17:58 ` [PATCH v2 13/13] thermal: Enforce self-encapsulation Thierry Reding
2023-10-13  9:14 ` [PATCH v2 00/13] thermal: tegra: Do not register cooling device Nicolas Chauvet
2023-10-13 11:43   ` Thierry Reding
2023-10-13 12:45     ` Nicolas Chauvet
2023-10-13 13:13       ` Thierry Reding
2023-10-13 13:55         ` Nicolas Chauvet
2023-10-13 15:45           ` Thierry Reding

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231012175836.3408077-8-thierry.reding@gmail.com \
    --to=thierry.reding@gmail.com \
    --cc=amitk@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jonathanh@nvidia.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=rui.zhang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).