Message ID | 20200721105239.8270-11-mlevitsk@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | RFC: move logical block size checking to the block core | expand |
On 2020/07/21 19:55, Maxim Levitsky wrote: > Plus some tiny refactoring. > > Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com> > --- > drivers/scsi/sr.c | 31 +++++++++++++------------------ > 1 file changed, 13 insertions(+), 18 deletions(-) > > diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c > index 0c4aa4665a2f9..0e96338029310 100644 > --- a/drivers/scsi/sr.c > +++ b/drivers/scsi/sr.c > @@ -866,31 +866,26 @@ static void get_sectorsize(struct scsi_cd *cd) > cd->capacity = max_t(long, cd->capacity, last_written); > > sector_size = get_unaligned_be32(&buffer[4]); > - switch (sector_size) { > - /* > - * HP 4020i CD-Recorder reports 2340 byte sectors > - * Philips CD-Writers report 2352 byte sectors > - * > - * Use 2k sectors for them.. > - */ > - case 0: > - case 2340: > - case 2352: > + > + /* > + * HP 4020i CD-Recorder reports 2340 byte sectors > + * Philips CD-Writers report 2352 byte sectors > + * > + * Use 2k sectors for them.. > + */ > + No need for the blank line here. > + if (!sector_size || sector_size == 2340 || sector_size == 2352) > sector_size = 2048; > - /* fall through */ > - case 2048: > - cd->capacity *= 4; > - /* fall through */ > - case 512: > - break; > - default: > + > + cd->capacity *= (sector_size >> SECTOR_SHIFT); Where does this come from ? There is no such code in sr get_sectorsize()... > + > + if (!blk_is_valid_logical_block_size(sector_size)) { > sr_printk(KERN_INFO, cd, > "unsupported sector size %d.", sector_size); > cd->capacity = 0; > } > > cd->device->sector_size = sector_size; > - White line change. > /* > * Add this so that we have the ability to correctly gauge > * what the device is capable of. >
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index 0c4aa4665a2f9..0e96338029310 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -866,31 +866,26 @@ static void get_sectorsize(struct scsi_cd *cd) cd->capacity = max_t(long, cd->capacity, last_written); sector_size = get_unaligned_be32(&buffer[4]); - switch (sector_size) { - /* - * HP 4020i CD-Recorder reports 2340 byte sectors - * Philips CD-Writers report 2352 byte sectors - * - * Use 2k sectors for them.. - */ - case 0: - case 2340: - case 2352: + + /* + * HP 4020i CD-Recorder reports 2340 byte sectors + * Philips CD-Writers report 2352 byte sectors + * + * Use 2k sectors for them.. + */ + + if (!sector_size || sector_size == 2340 || sector_size == 2352) sector_size = 2048; - /* fall through */ - case 2048: - cd->capacity *= 4; - /* fall through */ - case 512: - break; - default: + + cd->capacity *= (sector_size >> SECTOR_SHIFT); + + if (!blk_is_valid_logical_block_size(sector_size)) { sr_printk(KERN_INFO, cd, "unsupported sector size %d.", sector_size); cd->capacity = 0; } cd->device->sector_size = sector_size; - /* * Add this so that we have the ability to correctly gauge * what the device is capable of.
Plus some tiny refactoring. Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com> --- drivers/scsi/sr.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-)