Skip to content

Commit

Permalink
ata: libata-core: fix sloppy typing in ata_id_n_sectors()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Sergey Shtylyov authored and Damien Le Moal committed Jun 13, 2022
1 parent 6cd379f commit 79ad6a5
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions drivers/ata/libata-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}

Expand Down

0 comments on commit 79ad6a5

Please sign in to comment.