summaryrefslogtreecommitdiff
path: root/src/class
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2021-04-26 21:04:57 +0700
committerGitHub <[email protected]>2021-04-26 21:04:57 +0700
commit684fba315210fe35233283dac2af07ccae48e92a (patch)
treed4147812e360743e8ca2aff384286fd33f2e6227 /src/class
parentd8fd4352a3e6c621c22e6789243a8634ed134acb (diff)
parent1be9f3bcfa6f1bca8c4cd978177ac8658219e082 (diff)
Merge pull request #808 from hathach/lpc55-port1-hs
Lpc55 port1 hs
Diffstat (limited to 'src/class')
-rw-r--r--src/class/msc/msc_device.c19
1 files changed, 5 insertions, 14 deletions
diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c
index 194f4d3cb..539941935 100644
--- a/src/class/msc/msc_device.c
+++ b/src/class/msc/msc_device.c
@@ -77,28 +77,19 @@ static void proc_write10_cmd(uint8_t rhport, mscd_interface_t* p_msc);
static inline uint32_t rdwr10_get_lba(uint8_t const command[])
{
- // read10 & write10 has the same format
- scsi_write10_t* p_rdwr10 = (scsi_write10_t*) command;
+ // use offsetof to avoid pointer to the odd/unaligned address
+ uint32_t const lba = tu_unaligned_read32(command + offsetof(scsi_write10_t, lba));
- // copy first to prevent mis-aligned access
- uint32_t lba;
- // use offsetof to avoid pointer to the odd/misaligned address
- memcpy(&lba, (uint8_t*) p_rdwr10 + offsetof(scsi_write10_t, lba), 4);
-
- // lba is in Big Endian format
+ // lba is in Big Endian
return tu_ntohl(lba);
}
static inline uint16_t rdwr10_get_blockcount(uint8_t const command[])
{
- // read10 & write10 has the same format
- scsi_write10_t* p_rdwr10 = (scsi_write10_t*) command;
-
- // copy first to prevent mis-aligned access
- uint16_t block_count;
// use offsetof to avoid pointer to the odd/misaligned address
- memcpy(&block_count, (uint8_t*) p_rdwr10 + offsetof(scsi_write10_t, block_count), 2);
+ uint16_t const block_count = tu_unaligned_read16(command + offsetof(scsi_write10_t, block_count));
+ // block count is in Big Endian
return tu_ntohs(block_count);
}