From fe0637079fa943ed4255745c648f94ae33a635f9 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Thu, 16 Mar 2023 16:42:32 +0100 Subject: udev/ata_id: use unliagned helpers The array is a union, aligned as uint16_t, so we were accessing fields at offsets of two, so we didn't do actually do unaligned access. But let's make this explicit. --- src/udev/ata_id/ata_id.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/udev/ata_id/ata_id.c') diff --git a/src/udev/ata_id/ata_id.c b/src/udev/ata_id/ata_id.c index 7760d248cf..0b1f0b7157 100644 --- a/src/udev/ata_id/ata_id.c +++ b/src/udev/ata_id/ata_id.c @@ -30,6 +30,7 @@ #include "main-func.h" #include "memory-util.h" #include "udev-util.h" +#include "unaligned.h" #define COMMAND_TIMEOUT_MSEC (30 * 1000) @@ -271,15 +272,15 @@ static void disk_identify_fixup_string( uint8_t identify[512], unsigned offset_words, size_t len) { + assert(offset_words < 512/2); disk_identify_get_string(identify, offset_words, (char *) identify + offset_words * 2, len); } -static void disk_identify_fixup_uint16 (uint8_t identify[512], unsigned offset_words) { - uint16_t *p; - - p = (uint16_t *) identify; - p[offset_words] = le16toh (p[offset_words]); +static void disk_identify_fixup_uint16(uint8_t identify[512], unsigned offset_words) { + assert(offset_words < 512/2); + unaligned_write_ne16(identify + offset_words * 2, + unaligned_read_le16(identify + offset_words * 2)); } /** -- cgit v1.2.3