Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1616446 > unrolled thread
| Started by | "Martin K. Petersen" <martin.petersen@oracle.com> |
|---|---|
| First post | 2017-04-05 01:40 +0200 |
| Last post | 2017-04-05 02:00 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: [PATCH] sd: close hole in > 2T device rejection when !CONFIG_LBDAF "Martin K. Petersen" <martin.petersen@oracle.com> - 2017-04-05 01:40 +0200
Re: [PATCH] sd: close hole in > 2T device rejection when !CONFIG_LBDAF Bart Van Assche <Bart.VanAssche@sandisk.com> - 2017-04-05 02:00 +0200
| From | "Martin K. Petersen" <martin.petersen@oracle.com> |
|---|---|
| Date | 2017-04-05 01:40 +0200 |
| Subject | Re: [PATCH] sd: close hole in > 2T device rejection when !CONFIG_LBDAF |
| Message-ID | <tsGdj-39m-7@gated-at.bofh.it> |
Bart Van Assche <Bart.VanAssche@sandisk.com> writes:
Hi Bart,
> Sorry but I still don't understand why the two checks are
> different. How about the (untested) patch below? The approach below
> avoids that the check is duplicated and - at least in my opinion -
> results in code that is easier to read.
Just tripped over this issue in connection with something else. However,
I had to make a few passes to convince myself that your proposed fix was
correct. How about something like the following?
Martin
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index fb9b4d29af0b..6084c415c070 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -2102,6 +2102,16 @@ static void read_capacity_error(struct scsi_disk *sdkp, struct scsi_device *sdp,
#define READ_CAPACITY_RETRIES_ON_RESET 10
+static bool sd_addressable_capacity(u64 lba, unsigned int sector_size)
+{
+ u64 last_sector = lba + 1ULL << ilog2(sector_size) - 9;
+
+ if (sizeof(sector_t) == 4 && last_sector > 0xffffffffULL)
+ return false;
+
+ return true;
+}
+
static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp,
unsigned char *buffer)
{
@@ -2167,7 +2177,7 @@ static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp,
return -ENODEV;
}
- if ((sizeof(sdkp->capacity) == 4) && (lba >= 0xffffffffULL)) {
+ if (!sd_addressable_capacity(lba, sector_size)) {
sd_printk(KERN_ERR, sdkp, "Too big for this kernel. Use a "
"kernel compiled with support for large block "
"devices.\n");
@@ -2256,7 +2266,7 @@ static int read_capacity_10(struct scsi_disk *sdkp, struct scsi_device *sdp,
return sector_size;
}
- if ((sizeof(sdkp->capacity) == 4) && (lba == 0xffffffff)) {
+ if (!sd_addressable_capacity(lba, sector_size)) {
sd_printk(KERN_ERR, sdkp, "Too big for this kernel. Use a "
"kernel compiled with support for large block "
"devices.\n");
[toc] | [next] | [standalone]
| From | Bart Van Assche <Bart.VanAssche@sandisk.com> |
|---|---|
| Date | 2017-04-05 02:00 +0200 |
| Subject | Re: [PATCH] sd: close hole in > 2T device rejection when !CONFIG_LBDAF |
| Message-ID | <tsGwF-3hw-5@gated-at.bofh.it> |
| In reply to | #1616446 |
On Tue, 2017-04-04 at 19:35 -0400, Martin K. Petersen wrote:
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index fb9b4d29af0b..6084c415c070 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -2102,6 +2102,16 @@ static void read_capacity_error(struct scsi_disk *sdkp, struct scsi_device *sdp,
>
> #define READ_CAPACITY_RETRIES_ON_RESET 10
>
> +static bool sd_addressable_capacity(u64 lba, unsigned int sector_size)
> +{
> + u64 last_sector = lba + 1ULL << ilog2(sector_size) - 9;
> +
> + if (sizeof(sector_t) == 4 && last_sector > 0xffffffffULL)
> + return false;
> +
> + return true;
> +}
Hello Martin,
How about replacing 0xffffffffULL with U32_MAX, adding parentheses in the
last_sector computation to make clear that + and - have precedence over <<
and adding a comment aboveĀ sd_addressable_capacity() that explains its
purpose and also that the shift operation must not be replaced with a call
to logical_to_sectors()? Otherwise this patch looks fine to me.
Thanks,
Bart.
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web