summaryrefslogtreecommitdiffstats
path: root/src/udev/ata_id/ata_id.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2023-03-16 16:42:32 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2023-03-16 17:35:17 +0100
commitfe0637079fa943ed4255745c648f94ae33a635f9 (patch)
tree74de85ba13c10b0a550c036e94338cfea4a1eeec /src/udev/ata_id/ata_id.c
parentudev/v4l_id: use O_CLOEXEC|O_NOCTTY (diff)
downloadsystemd-fe0637079fa943ed4255745c648f94ae33a635f9.tar.xz
systemd-fe0637079fa943ed4255745c648f94ae33a635f9.zip
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.
Diffstat (limited to 'src/udev/ata_id/ata_id.c')
-rw-r--r--src/udev/ata_id/ata_id.c11
1 files changed, 6 insertions, 5 deletions
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));
}
/**