Plus some tiny refactoring. Signed-off-by: Maxim Levitsky <mlevitsk@xxxxxxxxxx> --- 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.. + */ + + 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. -- 2.26.2