Skip to contentSkip to conversation

mlxsw: core_thermal: Small cleanups

PATCH Applied Petr Machata 4 participants 14 messages Jul 30, 2024 – Aug 1, 2024

Subsystems (3)
lore
Share & tools
lore

Petr Machata

author maintainer
#0 lore raw

cover mlxsw: core_thermal: Small cleanups

Ido Schimmel says:

Clean up various issues which I noticed while addressing feedback on a different patchset.

Ido Schimmel (10):
mlxsw: core_thermal: Call thermal_zone_device_unregister()
unconditionally
mlxsw: core_thermal: Remove unnecessary check
mlxsw: core_thermal: Remove another unnecessary check
mlxsw: core_thermal: Fold two loops into one
mlxsw: core_thermal: Remove unused arguments
mlxsw: core_thermal: Make mlxsw_thermal_module_{init, fini} symmetric
mlxsw: core_thermal: Simplify rollback
mlxsw: core_thermal: Remove unnecessary checks
mlxsw: core_thermal: Remove unnecessary assignments
mlxsw: core_thermal: Fix -Wformat-truncation warning

 .../ethernet/mellanox/mlxsw/core_thermal.c    | 43 ++++++-------------
 1 file changed, 12 insertions(+), 31 deletions(-)
Signature · 1 line
2.45.0
author maintainer
#1 lore raw

PATCH 1/10 mlxsw: core_thermal: Call thermal_zone_device_unregister() unconditionally

From: Ido Schimmel <[email protected]>

The function returns immediately if the thermal zone pointer is NULL so there is no need to check it before calling the function.

Remove the check.

---
 drivers/net/ethernet/mellanox/mlxsw/core_thermal.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +2 -8
index d61478c0c632..0b38bab4eaa8 100644
@@ -821,10 +821,7 @@ int mlxsw_thermal_init(struct mlxsw_core *core,
 err_thermal_gearboxes_init:
 	mlxsw_thermal_modules_fini(thermal, &thermal->line_cards[0]);
 err_thermal_modules_init:
-	if (thermal->tzdev) {
-		thermal_zone_device_unregister(thermal->tzdev);
-		thermal->tzdev = NULL;
-	}
+	thermal_zone_device_unregister(thermal->tzdev);
 err_thermal_zone_device_register:
 err_thermal_cooling_device_register:
 	for (i = 0; i < MLXSW_MFCR_PWMS_MAX; i++)
@@ -845,10 +842,7 @@ void mlxsw_thermal_fini(struct mlxsw_thermal *thermal)
 					     thermal);
 	mlxsw_thermal_gearboxes_fini(thermal, &thermal->line_cards[0]);
 	mlxsw_thermal_modules_fini(thermal, &thermal->line_cards[0]);
-	if (thermal->tzdev) {
-		thermal_zone_device_unregister(thermal->tzdev);
-		thermal->tzdev = NULL;
-	}
+	thermal_zone_device_unregister(thermal->tzdev);
 
 	for (i = 0; i < MLXSW_MFCR_PWMS_MAX; i++)
 		thermal_cooling_device_unregister(thermal->cdevs[i].cdev);
Signature · 1 line
2.45.0
author maintainer
#2 lore raw

PATCH 2/10 mlxsw: core_thermal: Remove unnecessary check

In reply to Petr Machata

From: Ido Schimmel <[email protected]>

mlxsw_thermal_modules_init() allocates an array of modules and then calls mlxsw_thermal_module_init() to initialize each entry in the array. It is therefore impossible for mlxsw_thermal_module_init() to encounter an entry that is already initialized and has its 'parent' pointer set.

Remove the unnecessary check.

---
 drivers/net/ethernet/mellanox/mlxsw/core_thermal.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +0 -3
index 0b38bab4eaa8..394e4fd633ef 100644
@@ -453,9 +453,6 @@ mlxsw_thermal_module_init(struct device *dev, struct mlxsw_core *core,
 	struct mlxsw_thermal_module *module_tz;
 
 	module_tz = &area->tz_module_arr[module];
-	/* Skip if parent is already set (case of port split). */
-	if (module_tz->parent)
-		return;
 	module_tz->module = module;
 	module_tz->slot_index = area->slot_index;
 	module_tz->parent = thermal;
Signature · 1 line
2.45.0
author maintainer
#3 lore raw

PATCH 3/10 mlxsw: core_thermal: Remove another unnecessary check

In reply to Petr Machata

From: Ido Schimmel <[email protected]>

mlxsw_thermal_modules_init() allocates an array of modules and then initializes each entry by calling mlxsw_thermal_module_init() which among other things initializes the 'parent' pointer of the entry.

mlxsw_thermal_modules_init() then traverses over the array again, but skips over entries that do not have their 'parent' pointer set which is impossible given the above.

Therefore, remove the unnecessary check.

---
 drivers/net/ethernet/mellanox/mlxsw/core_thermal.c | 2 --
 1 file changed, 2 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +0 -2
index 394e4fd633ef..afd8fe85a94d 100644
@@ -505,8 +505,6 @@ mlxsw_thermal_modules_init(struct device *dev, struct mlxsw_core *core,
 
 	for (i = 0; i < area->tz_module_num; i++) {
 		module_tz = &area->tz_module_arr[i];
-		if (!module_tz->parent)
-			continue;
 		err = mlxsw_thermal_module_tz_init(module_tz);
 		if (err)
 			goto err_thermal_module_tz_init;
Signature · 1 line
2.45.0
author maintainer
#4 lore raw

PATCH 4/10 mlxsw: core_thermal: Fold two loops into one

In reply to Petr Machata

From: Ido Schimmel <[email protected]>

There is no need to traverse the same array twice. Do it once by folding both loops into one.

---
 drivers/net/ethernet/mellanox/mlxsw/core_thermal.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +1 -3
index afd8fe85a94d..b2a4eea859d1 100644
@@ -500,10 +500,8 @@ mlxsw_thermal_modules_init(struct device *dev, struct mlxsw_core *core,
 	if (!area->tz_module_arr)
 		return -ENOMEM;
 
-	for (i = 0; i < area->tz_module_num; i++)
-		mlxsw_thermal_module_init(dev, core, thermal, area, i);
-
 	for (i = 0; i < area->tz_module_num; i++) {
+		mlxsw_thermal_module_init(dev, core, thermal, area, i);
 		module_tz = &area->tz_module_arr[i];
 		err = mlxsw_thermal_module_tz_init(module_tz);
 		if (err)
Signature · 1 line
2.45.0
author maintainer
#5 lore raw

PATCH 5/10 mlxsw: core_thermal: Remove unused arguments

In reply to Petr Machata

From: Ido Schimmel <[email protected]>

'dev' and 'core' arguments are not used by mlxsw_thermal_module_init(). Remove them.

---
 drivers/net/ethernet/mellanox/mlxsw/core_thermal.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +2 -3
index b2a4eea859d1..95821e91da18 100644
@@ -446,8 +446,7 @@ static void mlxsw_thermal_module_tz_fini(struct thermal_zone_device *tzdev)
 }
 
 static void
-mlxsw_thermal_module_init(struct device *dev, struct mlxsw_core *core,
-			  struct mlxsw_thermal *thermal,
+mlxsw_thermal_module_init(struct mlxsw_thermal *thermal,
 			  struct mlxsw_thermal_area *area, u8 module)
 {
 	struct mlxsw_thermal_module *module_tz;
@@ -501,7 +500,7 @@ mlxsw_thermal_modules_init(struct device *dev, struct mlxsw_core *core,
 		return -ENOMEM;
 
 	for (i = 0; i < area->tz_module_num; i++) {
-		mlxsw_thermal_module_init(dev, core, thermal, area, i);
+		mlxsw_thermal_module_init(thermal, area, i);
 		module_tz = &area->tz_module_arr[i];
 		err = mlxsw_thermal_module_tz_init(module_tz);
 		if (err)
Signature · 1 line
2.45.0
author maintainer
#6 lore raw

PATCH 6/10 mlxsw: core_thermal: Make mlxsw_thermal_module_{init, fini} symmetric

In reply to Petr Machata

From: Ido Schimmel <[email protected]>

mlxsw_thermal_module_fini() de-initializes the module's thermal zone, but mlxsw_thermal_module_init() does not initialize it. Make both functions symmetric by moving the initialization of the module's thermal zone to mlxsw_thermal_module_init().

---
 drivers/net/ethernet/mellanox/mlxsw/core_thermal.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +6 -7
index 95821e91da18..36b883a7ee60 100644
@@ -445,7 +445,7 @@ static void mlxsw_thermal_module_tz_fini(struct thermal_zone_device *tzdev)
 	thermal_zone_device_unregister(tzdev);
 }
 
-static void
+static int
 mlxsw_thermal_module_init(struct mlxsw_thermal *thermal,
 			  struct mlxsw_thermal_area *area, u8 module)
 {
@@ -461,6 +461,8 @@ mlxsw_thermal_module_init(struct mlxsw_thermal *thermal,
 	       sizeof(thermal->trips));
 	memcpy(module_tz->cooling_states, default_cooling_states,
 	       sizeof(thermal->cooling_states));
+
+	return mlxsw_thermal_module_tz_init(module_tz);
 }
 
 static void mlxsw_thermal_module_fini(struct mlxsw_thermal_module *module_tz)
@@ -477,7 +479,6 @@ mlxsw_thermal_modules_init(struct device *dev, struct mlxsw_core *core,
 			   struct mlxsw_thermal *thermal,
 			   struct mlxsw_thermal_area *area)
 {
-	struct mlxsw_thermal_module *module_tz;
 	char mgpir_pl[MLXSW_REG_MGPIR_LEN];
 	int i, err;
 
@@ -500,16 +501,14 @@ mlxsw_thermal_modules_init(struct device *dev, struct mlxsw_core *core,
 		return -ENOMEM;
 
 	for (i = 0; i < area->tz_module_num; i++) {
-		mlxsw_thermal_module_init(thermal, area, i);
-		module_tz = &area->tz_module_arr[i];
-		err = mlxsw_thermal_module_tz_init(module_tz);
+		err = mlxsw_thermal_module_init(thermal, area, i);
 		if (err)
-			goto err_thermal_module_tz_init;
+			goto err_thermal_module_init;
 	}
 
 	return 0;
 
-err_thermal_module_tz_init:
+err_thermal_module_init:
 	for (i = area->tz_module_num - 1; i >= 0; i--)
 		mlxsw_thermal_module_fini(&area->tz_module_arr[i]);
 	kfree(area->tz_module_arr);
Signature · 1 line
2.45.0
author maintainer
#7 lore raw

PATCH 7/10 mlxsw: core_thermal: Simplify rollback

In reply to Petr Machata

From: Ido Schimmel <[email protected]>

During rollback, instead of calling mlxsw_thermal_module_fini() for all the modules, only call it for modules that were successfully initialized. This is not a bug fix since mlxsw_thermal_module_fini() first checks that the module was initialized.

---
 drivers/net/ethernet/mellanox/mlxsw/core_thermal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +1 -1
index 36b883a7ee60..e9bf11a38ae9 100644
@@ -509,7 +509,7 @@ mlxsw_thermal_modules_init(struct device *dev, struct mlxsw_core *core,
 	return 0;
 
 err_thermal_module_init:
-	for (i = area->tz_module_num - 1; i >= 0; i--)
+	for (i--; i >= 0; i--)
 		mlxsw_thermal_module_fini(&area->tz_module_arr[i]);
 	kfree(area->tz_module_arr);
 	return err;
Signature · 1 line
2.45.0
author maintainer
#8 lore raw

PATCH 8/10 mlxsw: core_thermal: Remove unnecessary checks

In reply to Petr Machata

From: Ido Schimmel <[email protected]>

mlxsw_thermal_module_fini() cannot be invoked with a thermal module which is NULL or which is not associated with a thermal zone, so remove these checks.

---
 drivers/net/ethernet/mellanox/mlxsw/core_thermal.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +3 -5
index e9bf11a38ae9..cfbfabec816e 100644
@@ -467,11 +467,9 @@ mlxsw_thermal_module_init(struct mlxsw_thermal *thermal,
 
 static void mlxsw_thermal_module_fini(struct mlxsw_thermal_module *module_tz)
 {
-	if (module_tz && module_tz->tzdev) {
-		mlxsw_thermal_module_tz_fini(module_tz->tzdev);
-		module_tz->tzdev = NULL;
-		module_tz->parent = NULL;
-	}
+	mlxsw_thermal_module_tz_fini(module_tz->tzdev);
+	module_tz->tzdev = NULL;
+	module_tz->parent = NULL;
 }
 
 static int
Signature · 1 line
2.45.0
author maintainer
#9 lore raw

PATCH 9/10 mlxsw: core_thermal: Remove unnecessary assignments

In reply to Petr Machata

From: Ido Schimmel <[email protected]>

Setting both pointers to NULL is unnecessary since the code never checks whether these pointers are NULL or not. Remove the assignments.

---
 drivers/net/ethernet/mellanox/mlxsw/core_thermal.c | 2 --
 1 file changed, 2 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +0 -2
index cfbfabec816e..269c4986ea24 100644
@@ -468,8 +468,6 @@ mlxsw_thermal_module_init(struct mlxsw_thermal *thermal,
 static void mlxsw_thermal_module_fini(struct mlxsw_thermal_module *module_tz)
 {
 	mlxsw_thermal_module_tz_fini(module_tz->tzdev);
-	module_tz->tzdev = NULL;
-	module_tz->parent = NULL;
 }
 
 static int
Signature · 1 line
2.45.0
author maintainer
#10 lore raw

PATCH 10/10 mlxsw: core_thermal: Fix -Wformat-truncation warning

In reply to Petr Machata

From: Ido Schimmel <[email protected]>

The name of a thermal zone device cannot be longer than 19 characters ('THERMAL_NAME_LENGTH - 1'). The format string 'mlxsw-lc%d-module%d' can exceed this limitation if the maximum number of line cards cannot be represented using a single digit and the maximum number of transceiver modules cannot be represented using two digits.

This is not the case with current systems nor future ones. Therefore, increase the size of the result buffer beyond 'THERMAL_NAME_LENGTH' and suppress the following build warning [1].

If this limitation is ever exceeded, we will know about it since the thermal core validates the thermal device's name during registration.

[1]
drivers/net/ethernet/mellanox/mlxsw/core_thermal.c: In function ‘mlxsw_thermal_modules_init.part.0’:
drivers/net/ethernet/mellanox/mlxsw/core_thermal.c:418:70: error: ‘%d’ directive output may be truncated writing between 1 and 3 bytes into a region of size between 2 and 4 [-Werror=format-truncation=]
418 | snprintf(tz_name, sizeof(tz_name), "mlxsw-lc%d-module%d",
| ^~
In function ‘mlxsw_thermal_module_tz_init’,
inlined from ‘mlxsw_thermal_module_init’ at drivers/net/ethernet/mellanox/mlxsw/core_thermal.c:465:9,
inlined from ‘mlxsw_thermal_modules_init.part.0’ at drivers/net/ethernet/mellanox/mlxsw/core_thermal.c:500:9:
drivers/net/ethernet/mellanox/mlxsw/core_thermal.c:418:52: note: directive argument in the range [1, 256]
418 | snprintf(tz_name, sizeof(tz_name), "mlxsw-lc%d-module%d",

      |                                                    ^~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/mellanox/mlxsw/core_thermal.c:418:17: note: ‘snprintf’ output between 18 and 22 bytes into a destination of size 20
  418 |                 snprintf(tz_name, sizeof(tz_name), "mlxsw-lc%d-module%d",
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  419 |                          module_tz->slot_index, module_tz->module + 1);
      |                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
 drivers/net/ethernet/mellanox/mlxsw/core_thermal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +1 -1
index 269c4986ea24..303d2ce4dc1e 100644
@@ -411,7 +411,7 @@ static const struct thermal_cooling_device_ops mlxsw_cooling_ops = {
 static int
 mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz)
 {
-	char tz_name[THERMAL_NAME_LENGTH];
+	char tz_name[40];
 	int err;
 
 	if (module_tz->slot_index)
Signature · 1 line
2.45.0
maintainer
#11 lore raw

Re: [PATCH net-next 10/10] mlxsw: core_thermal: Fix -Wformat-truncation warning

Quoted 7 lines · On Tue, 30 Jul 2024 15:58:21 +0200 Petr Machata wrote:

From: Ido Schimmel <[email protected]>

The name of a thermal zone device cannot be longer than 19 characters ('THERMAL_NAME_LENGTH - 1'). The format string 'mlxsw-lc%d-module%d' can exceed this limitation if the maximum number of line cards cannot be represented using a single digit and the maximum number of transceiver modules cannot be represented using two digits.

The ordering could have been better since this comes from patch 6 in the same series :(

Reviewed-by on the v1 series
#12 lore raw
In reply to Petr Machata
Quoted 4 lines · Petr Machata

Ido Schimmel says:

Clean up various issues which I noticed while addressing feedback on a different patchset.

For the whole series:

Quoted 17 lines

Ido Schimmel (10):
mlxsw: core_thermal: Call thermal_zone_device_unregister()
unconditionally
mlxsw: core_thermal: Remove unnecessary check
mlxsw: core_thermal: Remove another unnecessary check
mlxsw: core_thermal: Fold two loops into one
mlxsw: core_thermal: Remove unused arguments
mlxsw: core_thermal: Make mlxsw_thermal_module_{init, fini} symmetric
mlxsw: core_thermal: Simplify rollback
mlxsw: core_thermal: Remove unnecessary checks
mlxsw: core_thermal: Remove unnecessary assignments
mlxsw: core_thermal: Fix -Wformat-truncation warning

 .../ethernet/mellanox/mlxsw/core_thermal.c    | 43 ++++++-------------
 1 file changed, 12 insertions(+), 31 deletions(-)
#13 lore raw
In reply to Petr Machata
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 18 lines · On Tue, 30 Jul 2024 15:58:11 +0200 you wrote:

Ido Schimmel says:

Clean up various issues which I noticed while addressing feedback on a different patchset.

Ido Schimmel (10):
mlxsw: core_thermal: Call thermal_zone_device_unregister()
unconditionally
mlxsw: core_thermal: Remove unnecessary check
mlxsw: core_thermal: Remove another unnecessary check
mlxsw: core_thermal: Fold two loops into one
mlxsw: core_thermal: Remove unused arguments
mlxsw: core_thermal: Make mlxsw_thermal_module_{init, fini} symmetric
mlxsw: core_thermal: Simplify rollback
mlxsw: core_thermal: Remove unnecessary checks
mlxsw: core_thermal: Remove unnecessary assignments
mlxsw: core_thermal: Fix -Wformat-truncation warning

Quoted 1 line

[...]

Here is the summary with links:
- [net-next,01/10] mlxsw: core_thermal: Call thermal_zone_device_unregister() unconditionally

    https://git.kernel.org/netdev/net-next/c/a1bb54b1a066
  - [net-next,02/10] mlxsw: core_thermal: Remove unnecessary check
    https://git.kernel.org/netdev/net-next/c/4be011d76408
  - [net-next,03/10] mlxsw: core_thermal: Remove another unnecessary check
    https://git.kernel.org/netdev/net-next/c/2a1c9dcb52dd
  - [net-next,04/10] mlxsw: core_thermal: Fold two loops into one
    https://git.kernel.org/netdev/net-next/c/d81d71434036
  - [net-next,05/10] mlxsw: core_thermal: Remove unused arguments
    https://git.kernel.org/netdev/net-next/c/73c18f9998fd
  - [net-next,06/10] mlxsw: core_thermal: Make mlxsw_thermal_module_{init, fini} symmetric
    https://git.kernel.org/netdev/net-next/c/fb76ea1d4b12
  - [net-next,07/10] mlxsw: core_thermal: Simplify rollback
    https://git.kernel.org/netdev/net-next/c/e25f3040a619
  - [net-next,08/10] mlxsw: core_thermal: Remove unnecessary checks
    https://git.kernel.org/netdev/net-next/c/e7e3a450e552
  - [net-next,09/10] mlxsw: core_thermal: Remove unnecessary assignments
    https://git.kernel.org/netdev/net-next/c/ec672931d150
  - [net-next,10/10] mlxsw: core_thermal: Fix -Wformat-truncation warning
    https://git.kernel.org/netdev/net-next/c/b0d21321140c

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html