]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev/ata_id: use unliagned helpers 26785/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 16 Mar 2023 15:42:32 +0000 (16:42 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 16 Mar 2023 16:35:17 +0000 (17:35 +0100)
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

index 7760d248cfb6aac69ab176b4b95663270d7ad55c..0b1f0b7157df4fe6861746c0ad0b4cc96886a9fc 100644 (file)
@@ -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));
 }
 
 /**