Skip to contentSkip to conversation

ACPI / CPPC: Use 64-bit arithmetic instead of 32-bit

PATCH Applied Gustavo A. R. Silva 3 participants 3 messages Feb 6, 2018 – Feb 8, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ACPI / CPPC: Use 64-bit arithmetic instead of 32-bit

Add suffix ULL to constant 500 in order to give the compiler complete information about the proper arithmetic to use. Notice that this constant is used in a context that expects an expression of type u64 (64 bits, unsigned).

The expression NUM_RETRIES * cppc_ss->latency at line 578, which at preprocessing time translates to 500 * cppc_ss->latency is currently being evaluated using 32-bit arithmetic.

Addresses-Coverity-ID: 1382602

---
Notice that another option is to cast NUM_RETRIES to u64 at line 578, but as there is only one instace in which this macro is being used I think adding the ULL is just enough.

 drivers/acpi/cppc_acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/cppc_acpi.c +1 -1
index 06ea474..0afbb26 100644
@@ -119,7 +119,7 @@ static DEFINE_PER_CPU(struct cpc_desc *, cpc_desc_ptr);
  * to PCC commands. Keeping it high enough to cover emulators where
  * the processors run painfully slow.
  */
-#define NUM_RETRIES 500
+#define NUM_RETRIES 500ULL
 
 struct cppc_attr {
 	struct attribute attr;
Signature · 1 line
2.7.4
#1 lore raw
Quoted 25 lines · CET Gustavo A. R. Silva

Add suffix ULL to constant 500 in order to give the compiler complete information about the proper arithmetic to use. Notice that this constant is used in a context that expects an expression of type u64 (64 bits, unsigned).

The expression NUM_RETRIES * cppc_ss->latency at line 578, which at preprocessing time translates to 500 * cppc_ss->latency is currently being evaluated using 32-bit arithmetic.

Addresses-Coverity-ID: 1382602

---
Notice that another option is to cast NUM_RETRIES to u64 at line 578, but as there is only one instace in which this macro is being used I think adding the ULL is just enough.

 drivers/acpi/cppc_acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/cppc_acpi.c +0 -0
index 06ea474..0afbb26 100644

drivers/acpi/cppc_acpi.c static DEFINE_PER_CPU(struct cpc_desc *, cpc_desc_ptr); · line 125

Quoted 8 lines
drivers/acpi/cppc_acpi.c +1 -1
@@ -119,7 +119,7 @@ static DEFINE_PER_CPU(struct cpc_desc *, cpc_desc_ptr);
  * to PCC commands. Keeping it high enough to cover emulators where
  * the processors run painfully slow.
  */
-#define NUM_RETRIES 500
+#define NUM_RETRIES 500ULL
 
 struct cppc_attr {
 	struct attribute attr;

Applied, thanks!

#2 lore raw
Quoted 31 lines · Rafael J. Wysocki
Quoted 30 lines · CET Gustavo A. R. Silva

Add suffix ULL to constant 500 in order to give the compiler complete information about the proper arithmetic to use. Notice that this constant is used in a context that expects an expression of type u64 (64 bits, unsigned).

The expression NUM_RETRIES * cppc_ss->latency at line 578, which at preprocessing time translates to 500 * cppc_ss->latency is currently being evaluated using 32-bit arithmetic.

Addresses-Coverity-ID: 1382602

---
Notice that another option is to cast NUM_RETRIES to u64 at line 578, but as there is only one instace in which this macro is being used I think adding the ULL is just enough.

  drivers/acpi/cppc_acpi.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/cppc_acpi.c +1 -1
index 06ea474..0afbb26 100644
@@ -119,7 +119,7 @@ static DEFINE_PER_CPU(struct cpc_desc *, cpc_desc_ptr);
   * to PCC commands. Keeping it high enough to cover emulators where
   * the processors run painfully slow.
   */
-#define NUM_RETRIES 500
+#define NUM_RETRIES 500ULL
 
Quoted 7 lines

drivers/acpi/cppc_acpi.c static DEFINE_PER_CPU(struct cpc_desc *, cpc_desc_ptr); · line 125

Quoted 3 lines
drivers/acpi/cppc_acpi.c +0 -0
  struct cppc_attr {
  	struct attribute attr;

Applied, thanks!

Thank you, Rafael.

Signature · 1 line
Gustavo