public inbox for linux-ide@vger.kernel.org
 help / color / mirror / Atom feed
From: Sergey Shtylyov <s.shtylyov@omp.ru>
To: Damien Le Moal <damien.lemoal@opensource.wdc.com>,
	<linux-ide@vger.kernel.org>
Subject: Re: [PATCH] ata: libata-core: fix sloppy typing in ata_id_n_sectors()
Date: Thu, 9 Jun 2022 23:15:05 +0300	[thread overview]
Message-ID: <1651775c-cb00-0bdc-e27f-700d0580ec88@omp.ru> (raw)
In-Reply-To: <2a523107-9838-0940-1402-3b6bdad7e1e1@opensource.wdc.com>

On 6/8/22 9:47 AM, Damien Le Moal wrote:

>> 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>
>>
>> ---
>> This patch is against the 'for-next' branch of Damien's 'libata.git' repo.
>>
>>  drivers/ata/libata-core.c |   10 ++++++----
>>  1 file changed, 6 insertions(+), 4 deletions(-)
>>
>> Index: libata/drivers/ata/libata-core.c
>> ===================================================================
>> --- libata.orig/drivers/ata/libata-core.c
>> +++ libata/drivers/ata/libata-core.c
>> @@ -1107,11 +1107,13 @@ static u64 ata_id_n_sectors(const u16 *i
>>  			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];
>>  	}
>>  }
>>  
> 
> Applied to for-5.20. Thanks !

   Actually I was going to redo it (changing the order of multiplications), but well,
it's OK as is...

MBR, Sergey

      reply	other threads:[~2022-06-09 20:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-13 20:50 [PATCH] ata: libata-core: fix sloppy typing in ata_id_n_sectors() Sergey Shtylyov
2022-05-16 11:29 ` Damien Le Moal
2022-05-17 19:43   ` Sergey Shtylyov
2022-05-22 22:26     ` Damien Le Moal
2022-06-08  6:47 ` Damien Le Moal
2022-06-09 20:15   ` Sergey Shtylyov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1651775c-cb00-0bdc-e27f-700d0580ec88@omp.ru \
    --to=s.shtylyov@omp.ru \
    --cc=damien.lemoal@opensource.wdc.com \
    --cc=linux-ide@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox