Skip to content

Commit b0407d8

Browse files
GustavoARSilvagroeck
authored andcommitted
hwmon: (occ) Fix potential integer overflow
Cast get_unaligned_be32(...) to u64 in order to give the compiler complete information about the proper arithmetic to use and avoid a potential integer overflow. Notice that such function call is used in contexts that expect expressions of type u64 (64 bits, unsigned); and the following expressions are currently being evaluated using 32-bit arithmetic: val = get_unaligned_be32(&power->update_tag) * occ->powr_sample_time_us; val = get_unaligned_be32(&power->vdn.update_tag) * occ->powr_sample_time_us; Addresses-Coverity-ID: 1442357 ("Unintentional integer overflow") Addresses-Coverity-ID: 1442476 ("Unintentional integer overflow") Addresses-Coverity-ID: 1442508 ("Unintentional integer overflow") Fixes: ff692d8 ("hwmon (occ): Add sensor types and versions") Cc: stable@vger.kernel.org Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com> Reviewed-by: Eddie James <eajames@linux.ibm.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent 07bd14c commit b0407d8

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

drivers/hwmon/occ/common.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ static ssize_t occ_show_power_1(struct device *dev,
380380
val *= 1000000ULL;
381381
break;
382382
case 2:
383-
val = get_unaligned_be32(&power->update_tag) *
384-
occ->powr_sample_time_us;
383+
val = (u64)get_unaligned_be32(&power->update_tag) *
384+
occ->powr_sample_time_us;
385385
break;
386386
case 3:
387387
val = get_unaligned_be16(&power->value) * 1000000ULL;
@@ -425,8 +425,8 @@ static ssize_t occ_show_power_2(struct device *dev,
425425
&power->update_tag);
426426
break;
427427
case 2:
428-
val = get_unaligned_be32(&power->update_tag) *
429-
occ->powr_sample_time_us;
428+
val = (u64)get_unaligned_be32(&power->update_tag) *
429+
occ->powr_sample_time_us;
430430
break;
431431
case 3:
432432
val = get_unaligned_be16(&power->value) * 1000000ULL;
@@ -463,8 +463,8 @@ static ssize_t occ_show_power_a0(struct device *dev,
463463
&power->system.update_tag);
464464
break;
465465
case 2:
466-
val = get_unaligned_be32(&power->system.update_tag) *
467-
occ->powr_sample_time_us;
466+
val = (u64)get_unaligned_be32(&power->system.update_tag) *
467+
occ->powr_sample_time_us;
468468
break;
469469
case 3:
470470
val = get_unaligned_be16(&power->system.value) * 1000000ULL;
@@ -477,8 +477,8 @@ static ssize_t occ_show_power_a0(struct device *dev,
477477
&power->proc.update_tag);
478478
break;
479479
case 6:
480-
val = get_unaligned_be32(&power->proc.update_tag) *
481-
occ->powr_sample_time_us;
480+
val = (u64)get_unaligned_be32(&power->proc.update_tag) *
481+
occ->powr_sample_time_us;
482482
break;
483483
case 7:
484484
val = get_unaligned_be16(&power->proc.value) * 1000000ULL;
@@ -491,8 +491,8 @@ static ssize_t occ_show_power_a0(struct device *dev,
491491
&power->vdd.update_tag);
492492
break;
493493
case 10:
494-
val = get_unaligned_be32(&power->vdd.update_tag) *
495-
occ->powr_sample_time_us;
494+
val = (u64)get_unaligned_be32(&power->vdd.update_tag) *
495+
occ->powr_sample_time_us;
496496
break;
497497
case 11:
498498
val = get_unaligned_be16(&power->vdd.value) * 1000000ULL;
@@ -505,8 +505,8 @@ static ssize_t occ_show_power_a0(struct device *dev,
505505
&power->vdn.update_tag);
506506
break;
507507
case 14:
508-
val = get_unaligned_be32(&power->vdn.update_tag) *
509-
occ->powr_sample_time_us;
508+
val = (u64)get_unaligned_be32(&power->vdn.update_tag) *
509+
occ->powr_sample_time_us;
510510
break;
511511
case 15:
512512
val = get_unaligned_be16(&power->vdn.value) * 1000000ULL;

0 commit comments

Comments
 (0)