libata-scsi cleanup
cover libata-scsi cleanup
3 small patches to cleanup the code in libata-scsi. No functional change is introduced.
Damien Le Moal (3):
ata: libata-scsi: Cleanup ata_get_xlat_func()
ata: libata-scsi: Simplify ata_scsi_mode_select_xlat()
ata: libata-scsi: Simplify scsi_XX_lba_len()
drivers/ata/libata-scsi.c | 47 ++++++++------------------------------- 1 file changed, 9 insertions(+), 38 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/3 ata: libata-scsi: Cleanup ata_get_xlat_func()
Remove the unnecessary "break" after the return statement in the MODE_SELECT/MODE_SELECT_10 case.
--- drivers/ata/libata-scsi.c | 1 - 1 file changed, 1 deletion(-)
drivers/ata/libata-scsi.c +0 -1
@@ -3933,7 +3933,6 @@ static inline ata_xlat_func_t ata_get_xlat_func(struct ata_device *dev, u8 cmd)case MODE_SELECT :case MODE_SELECT_10 :return ata_scsi_mode_select_xlat; -break ;case ZBC_IN :return ata_scsi_zbc_in_xlat;
Signature · 1 line
2.34.1
Re: [PATCH 1/3] ata: libata-scsi: Cleanup ata_get_xlat_func()
Quoted 13 lines · Damien Le Moal
Remove the unnecessary "break" after the return statement in the MODE_SELECT/MODE_SELECT_10 case.
Signed-off-by Damien Le Moal <[email protected]>--- drivers/ata/libata-scsi.c | 1 - 1 file changed, 1 deletion(-)drivers/ata/libata-scsi.c +0
-0
drivers/ata/libata-scsi.c static inline ata_xlat_func_t ata_get_xlat_func(struct ata_device *dev, u8 cmd) · line 3938
Quoted 7 lines
drivers/ata/libata-scsi.c +0
-1@@ -3933,7 +3933,6 @@ static inline ata_xlat_func_t ata_get_xlat_func(struct ata_device *dev, u8 cmd)case MODE_SELECT :case MODE_SELECT_10 :return ata_scsi_mode_select_xlat; -break ;case ZBC_IN :return ata_scsi_zbc_in_xlat;
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), GF: Felix Imendörffer
PATCH 2/3 ata: libata-scsi: Simplify ata_scsi_mode_select_xlat()
In reply to Damien Le MoalUse get_unaligned_be16() instead of using hardcoded accesses to 16-bits big endian cdb fields.
--- drivers/ata/libata-scsi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/ata/libata-scsi.c +3 -3
@@ -3672,7 +3672,7 @@ static unsigned int ata_scsi_mode_select_xlat(struct ata_queued_cmd *qc) goto invalid_fld; } - len = (cdb[7 ] <<8 ) + cdb[8 ]; + len =get_unaligned_be16 (&cdb[7 ]); hdr_len =8 ; }
@@ -3698,7 +3698,7 @@ static unsigned int ata_scsi_mode_select_xlat(struct ata_queued_cmd *qc)if (six_byte) bd_len = p[3 ];else - bd_len = (p[6 ] <<8 ) + p[7 ]; + bd_len =get_unaligned_be16 (&p[6 ]); len -= hdr_len; p += hdr_len;
@@ -3722,7 +3722,7 @@ static unsigned int ata_scsi_mode_select_xlat(struct ata_queued_cmd *qc) goto invalid_param_len; spg = p[1 ]; - pg_len = (p[2 ] <<8 ) | p[3 ]; + pg_len =get_unaligned_be16 (&p[2 ]); p +=4 ; len -=4 ; }else {
Signature · 1 line
2.34.1
Re: [PATCH 2/3] ata: libata-scsi: Simplify ata_scsi_mode_select_xlat()
Quoted 8 lines · Damien Le Moal
Use
get_unaligned_be16()instead of using hardcoded accesses to 16-bits big endian cdb fields.Signed-off-by Damien Le Moal <[email protected]>--- drivers/ata/libata-scsi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), GF: Felix Imendörffer
PATCH 3/3 ata: libata-scsi: Simplify scsi_XX_lba_len()
In reply to Damien Le MoalIn scsi_10_lba_len() and scsi_16_lba_len() functions, use get_unaligned_bexx() to access a cdb LBA and length fields instead of hardcoding the byte retrieval. With these simplification, the functions can also be declared inline.
--- drivers/ata/libata-scsi.c | 40 ++++++--------------------------------- 1 file changed, 6 insertions(+), 34 deletions(-)
drivers/ata/libata-scsi.c +6 -34
@@ -1314,21 +1314,10 @@ static void scsi_6_lba_len(const u8 *cdb, u64 *plba, u32 *plen)* @plba: the LBA * @plen: the transfer length */ -static void scsi_10_lba_len (const u8 *cdb,u64 *plba,u32 *plen) +static inline void scsi_10_lba_len (const u8 *cdb,u64 *plba,u32 *plen) { -u64 lba =0 ; -u32 len =0 ; - - lba |= ((u64 )cdb[2 ]) <<24 ; - lba |= ((u64 )cdb[3 ]) <<16 ; - lba |= ((u64 )cdb[4 ]) <<8 ; - lba |= ((u64 )cdb[5 ]); - - len |= ((u32 )cdb[7 ]) <<8 ; - len |= ((u32 )cdb[8 ]); - - *plba = lba; - *plen = len; + *plba =get_unaligned_be32 (&cdb[2 ]); + *plen =get_unaligned_be16 (&cdb[7 ]); }/**
@@ -1341,27 +1330,10 @@ static void scsi_10_lba_len(const u8 *cdb, u64 *plba, u32 *plen)* @plba: the LBA * @plen: the transfer length */ -static void scsi_16_lba_len (const u8 *cdb,u64 *plba,u32 *plen) +static inline void scsi_16_lba_len (const u8 *cdb,u64 *plba,u32 *plen) { -u64 lba =0 ; -u32 len =0 ; - - lba |= ((u64 )cdb[2 ]) <<56 ; - lba |= ((u64 )cdb[3 ]) <<48 ; - lba |= ((u64 )cdb[4 ]) <<40 ; - lba |= ((u64 )cdb[5 ]) <<32 ; - lba |= ((u64 )cdb[6 ]) <<24 ; - lba |= ((u64 )cdb[7 ]) <<16 ; - lba |= ((u64 )cdb[8 ]) <<8 ; - lba |= ((u64 )cdb[9 ]); - - len |= ((u32 )cdb[10 ]) <<24 ; - len |= ((u32 )cdb[11 ]) <<16 ; - len |= ((u32 )cdb[12 ]) <<8 ; - len |= ((u32 )cdb[13 ]); - - *plba = lba; - *plen = len; + *plba =get_unaligned_be64 (&cdb[2 ]); + *plen =get_unaligned_be32 (&cdb[10 ]); }/**
Signature · 1 line
2.34.1
Re: [PATCH 3/3] ata: libata-scsi: Simplify scsi_XX_lba_len()
Quoted 10 lines · Damien Le Moal
In
scsi_10_lba_len()andscsi_16_lba_len()functions, useget_unaligned_bexx()to access a cdb LBA and length fields instead of hardcoding the byte retrieval. With these simplification, the functions can also be declared inline.Signed-off-by Damien Le Moal <[email protected]>--- drivers/ata/libata-scsi.c | 40 ++++++--------------------------------- 1 file changed, 6 insertions(+), 34 deletions(-)
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), GF: Felix Imendörffer