Skip to contentSkip to conversation

ACPI: Replace Ternary Operations with min()/max() Macros

PATCH Applied Prabhakar Pujeri 2 participants 4 messages Jun 26, 2024 – Jul 2, 2024

Subsystems (2)

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover ACPI: Replace Ternary Operations with min()/max() Macros

Hi all,

This patch series, generated using Coccinelle, aims to improve code readability and maintainability by replacing ternary operations with the min()
and max() macros where applicable in the ACPI subsystem.

The patches have been compiled and tested on an x86_64 system.

Prabhakar Pujeri (2):
ACPI: CPPC: Replace ternary operator with max() in cppc_find_dmi_mhz
ACPI: PM: Use max() for clearer D3 state selection in
acpi_dev_pm_get_state

 drivers/acpi/cppc_acpi.c | 2 +-
 drivers/acpi/device_pm.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.45.2
#1 lore raw

PATCH 1/2 ACPI: CPPC: Replace ternary operator with max() in cppc_find_dmi_mhz

---
 drivers/acpi/cppc_acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/cppc_acpi.c +1 -1
index 1d857978f5f4..a2591e1677f5 100644
@@ -1837,7 +1837,7 @@ static void cppc_find_dmi_mhz(const struct dmi_header *dm, void *private)
 	    dm->length >= DMI_ENTRY_PROCESSOR_MIN_LENGTH) {
 		u16 val = (u16)get_unaligned((const u16 *)
 				(dmi_data + DMI_PROCESSOR_MAX_SPEED));
-		*mhz = val > *mhz ? val : *mhz;
+		*mhz = max(val, *mhz);
 	}
 }
 
Signature · 1 line
2.45.2
maintainer Applied
#2 lore raw

Re: [PATCH 1/2] ACPI: CPPC: Replace ternary operator with max() in cppc_find_dmi_mhz

Quoted 11 lines · Prabhakar Pujeri
---
 drivers/acpi/cppc_acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/cppc_acpi.c +0 -0
index 1d857978f5f4..a2591e1677f5 100644

drivers/acpi/cppc_acpi.c static void cppc_find_dmi_mhz(const struct dmi_header *dm, void *private)

Quoted 9 lines
drivers/acpi/cppc_acpi.c +1 -2
@@ -1837,7 +1837,7 @@ static void cppc_find_dmi_mhz(const struct dmi_header *dm, void *private)
            dm->length >= DMI_ENTRY_PROCESSOR_MIN_LENGTH) {
                u16 val = (u16)get_unaligned((const u16 *)
                                (dmi_data + DMI_PROCESSOR_MAX_SPEED));
-               *mhz = val > *mhz ? val : *mhz;
+               *mhz = max(val, *mhz);
        }
 }
 
--

Applied as 6.11 material with some edits in the subject and changelog, thanks!

#3 lore raw

PATCH 2/2 ACPI: PM: Use max() for clearer D3 state selection in acpi_dev_pm_get_state

In reply to Prabhakar Pujeri
---
 drivers/acpi/device_pm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/device_pm.c +1 -1
index 3b4d048c4941..a90ae059fb60 100644
@@ -760,7 +760,7 @@ static int acpi_dev_pm_get_state(struct device *dev, struct acpi_device *adev,
 			if (!adev->power.states[ret].flags.valid)
 				ret = ACPI_STATE_D3_COLD;
 
-			d_max = ret > d_min ? ret : d_min;
+			d_max = max(ret, d_min);
 		} else {
 			return -ENODATA;
 		}
Signature · 1 line
2.45.2