summaryrefslogtreecommitdiff
path: root/drivers/ata/libata-core.c
diff options
context:
space:
mode:
authorSergey Shtylyov <s.shtylyov@omp.ru>2022-05-13 23:50:14 +0300
committerDamien Le Moal <damien.lemoal@opensource.wdc.com>2022-06-13 05:42:58 +0300
commit79ad6a561958777d6d8ecfa66e51d09d35ec6450 (patch)
tree865f89ae992297ebfef43478ac508a0fc1206b43 /drivers/ata/libata-core.c
parent6cd379f75f424b874ea1f35e3c02fa4090246eaf (diff)
downloadlinux-79ad6a561958777d6d8ecfa66e51d09d35ec6450.tar.xz
ata: libata-core: fix sloppy typing in ata_id_n_sectors()
The code multiplying the # of cylinders/heads/sectors in ata_id_n_sectors() to get a disk capacity implicitly uses the *int* type for that calculation and casting the result to 'u64' before returning ensues a sign extension. Explicitly casting the 'u16' typed multipliers to 'u32' results in avoiding a sign extension instruction and so in a more compact code... Found by Linux Verification Center (linuxtesting.org) with the SVACE static analysis tool. Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru> Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Diffstat (limited to 'drivers/ata/libata-core.c')
-rw-r--r--drivers/ata/libata-core.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 9601fa92950a..e3f1c3da5950 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -1107,11 +1107,13 @@ static u64 ata_id_n_sectors(const u16 *id)
return ata_id_u32(id, ATA_ID_LBA_CAPACITY);
} else {
if (ata_id_current_chs_valid(id))
- return id[ATA_ID_CUR_CYLS] * id[ATA_ID_CUR_HEADS] *
- id[ATA_ID_CUR_SECTORS];
+ return (u32)id[ATA_ID_CUR_CYLS] *
+ (u32)id[ATA_ID_CUR_HEADS] *
+ (u32)id[ATA_ID_CUR_SECTORS];
else
- return id[ATA_ID_CYLS] * id[ATA_ID_HEADS] *
- id[ATA_ID_SECTORS];
+ return (u32)id[ATA_ID_CYLS] *
+ (u32)id[ATA_ID_HEADS] *
+ (u32)id[ATA_ID_SECTORS];
}
}