From 655da8e57a46c009a07373c4fdcf9221b5a9b9a6 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 26 Apr 2020 18:48:44 -0700 Subject: scsi: sr: Use {get,put}_unaligned_be*() instead of open-coding these functions This patch makes the sr code slightly easier to read. Link: https://lore.kernel.org/r/20200427014844.12109-1-bvanassche@acm.org Cc: Merlijn Wajer Signed-off-by: Bart Van Assche Signed-off-by: Martin K. Petersen --- drivers/scsi/sr.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'drivers/scsi/sr.c') diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index d2fe3fa470f9..7727893238c7 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -51,6 +51,8 @@ #include #include +#include + #include #include #include @@ -344,10 +346,8 @@ static int sr_done(struct scsi_cmnd *SCpnt) case ILLEGAL_REQUEST: if (!(SCpnt->sense_buffer[0] & 0x90)) break; - error_sector = (SCpnt->sense_buffer[3] << 24) | - (SCpnt->sense_buffer[4] << 16) | - (SCpnt->sense_buffer[5] << 8) | - SCpnt->sense_buffer[6]; + error_sector = + get_unaligned_be32(&SCpnt->sense_buffer[3]); if (SCpnt->request->bio != NULL) block_sectors = bio_sectors(SCpnt->request->bio); @@ -495,13 +495,9 @@ static blk_status_t sr_init_command(struct scsi_cmnd *SCpnt) SCpnt->sdb.length = this_count * s_size; } - SCpnt->cmnd[2] = (unsigned char) (block >> 24) & 0xff; - SCpnt->cmnd[3] = (unsigned char) (block >> 16) & 0xff; - SCpnt->cmnd[4] = (unsigned char) (block >> 8) & 0xff; - SCpnt->cmnd[5] = (unsigned char) block & 0xff; + put_unaligned_be32(block, &SCpnt->cmnd[2]); SCpnt->cmnd[6] = SCpnt->cmnd[9] = 0; - SCpnt->cmnd[7] = (unsigned char) (this_count >> 8) & 0xff; - SCpnt->cmnd[8] = (unsigned char) this_count & 0xff; + put_unaligned_be16(this_count, &SCpnt->cmnd[7]); /* * We shouldn't disconnect in the middle of a sector, so with a dumb @@ -854,8 +850,7 @@ static void get_sectorsize(struct scsi_cd *cd) } else { long last_written; - cd->capacity = 1 + ((buffer[0] << 24) | (buffer[1] << 16) | - (buffer[2] << 8) | buffer[3]); + cd->capacity = 1 + get_unaligned_be32(&buffer[0]); /* * READ_CAPACITY doesn't return the correct size on * certain UDF media. If last_written is larger, use @@ -866,8 +861,7 @@ static void get_sectorsize(struct scsi_cd *cd) if (!cdrom_get_last_written(&cd->cdi, &last_written)) cd->capacity = max_t(long, cd->capacity, last_written); - sector_size = (buffer[4] << 24) | - (buffer[5] << 16) | (buffer[6] << 8) | buffer[7]; + sector_size = get_unaligned_be32(&buffer[4]); switch (sector_size) { /* * HP 4020i CD-Recorder reports 2340 byte sectors @@ -955,13 +949,13 @@ static void get_capabilities(struct scsi_cd *cd) } n = data.header_length + data.block_descriptor_length; - cd->cdi.speed = ((buffer[n + 8] << 8) + buffer[n + 9]) / 176; + cd->cdi.speed = get_unaligned_be16(&buffer[n + 8]) / 176; cd->readcd_known = 1; cd->readcd_cdda = buffer[n + 5] & 0x01; /* print some capability bits */ sr_printk(KERN_INFO, cd, "scsi3-mmc drive: %dx/%dx %s%s%s%s%s%s\n", - ((buffer[n + 14] << 8) + buffer[n + 15]) / 176, + get_unaligned_be16(&buffer[n + 14]) / 176, cd->cdi.speed, buffer[n + 3] & 0x01 ? "writer " : "", /* CD Writer */ buffer[n + 3] & 0x20 ? "dvd-ram " : "", -- cgit v1.2.3