All of lore.kernel.org
 help / color / mirror / Atom feed
From: Damien Le Moal <dlemoal@kernel.org>
To: Bart Van Assche <bvanassche@acm.org>,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	linux-scsi@vger.kernel.org
Subject: Re: [PATCH v3 1/2] scsi: sd: Prevent logical_to_bytes() from returning overflowed values
Date: Fri, 13 Jun 2025 14:55:43 +0900	[thread overview]
Message-ID: <bdeb7235-3295-4cd9-b892-60515b76c366@kernel.org> (raw)
In-Reply-To: <9cabd627-b22b-4ef3-87b0-cb5a9a97aea8@acm.org>

On 6/13/25 00:53, Bart Van Assche wrote:
> On 6/11/25 11:02 PM, Damien Le Moal wrote:
>> Make sure that logical_to_bytes() does not return an overflowed value
>> by changing its return type from unsigned int (32-bits) to size_t
>> (64-bits).
> 
> size_t is only 64 bits on 64-bit systems. Shouldn't size_t be changed
> into u64? See also https://en.wikipedia.org/wiki/64-bit_computing.
> 
>> -static inline unsigned int logical_to_bytes(struct scsi_device *sdev, sector_t blocks)
>> +static inline size_t logical_to_bytes(struct scsi_device *sdev, sector_t blocks)
>>   {
>>   	return blocks * sdev->sector_size;
>>   }
> 
> Since 'blocks' represents an LBA instead of a byte offset divided by
> 512, please consider changing "sector_t blocks" into
> "u64 logical_blocks". Independent of this patch, "sector_size" probably
> should be renamed into "logical_block_size" since the word "sector" is
> only used in references to "physical sector" in the SBC specification.

Well, one could argue that struct scsi_device is SPC territory, not SBC, and
that "sector_size" or block size has no business being in struct scsi_device.
But changing that would not make access to that value easy when all we have is a
scsi command :)

> 
> Otherwise this patch looks good to me.
> 
> Thanks,
> 
> Bart.


-- 
Damien Le Moal
Western Digital Research

  reply	other threads:[~2025-06-13  5:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-12  6:02 [PATCH v3 0/2] Improve optimal IO size initialization Damien Le Moal
2025-06-12  6:02 ` [PATCH v3 1/2] scsi: sd: Prevent logical_to_bytes() from returning overflowed values Damien Le Moal
2025-06-12 15:53   ` Bart Van Assche
2025-06-13  5:55     ` Damien Le Moal [this message]
2025-06-12  6:02 ` [PATCH v3 2/2] scsi: sd: Set a default optimal IO size if one is not defined Damien Le Moal
2025-06-12 15:55   ` Bart Van Assche

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=bdeb7235-3295-4cd9-b892-60515b76c366@kernel.org \
    --to=dlemoal@kernel.org \
    --cc=bvanassche@acm.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.