]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: (jmicron_raid) avoid modifying shared buffer
authorThomas Weißschuh <thomas@t-8ch.de>
Tue, 29 Aug 2023 10:29:31 +0000 (12:29 +0200)
committerThomas Weißschuh <thomas@t-8ch.de>
Tue, 29 Aug 2023 10:46:00 +0000 (12:46 +0200)
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
libblkid/src/superblocks/jmicron_raid.c

index 580c38533b3ee5e38d8d85d5b00026aea37813e1..cd84c9dcbcb331e9193d8c063c726a1e084044fd 100644 (file)
@@ -17,8 +17,8 @@
 #include "superblocks.h"
 
 #define JM_SIGNATURE           "JM"
-#define JM_MINOR_VERSION(_x)   ((_x)->version & 0xFF)
-#define JM_MAJOR_VERSION(_x)   ((_x)->version >> 8)
+#define JM_MINOR_VERSION(_x)   (le16_to_cpu((_x)->version) & 0xFF)
+#define JM_MAJOR_VERSION(_x)   (le16_to_cpu((_x)->version) >> 8)
 #define JM_SPARES              2
 #define JM_MEMBERS             8
 
@@ -51,26 +51,6 @@ struct jm_metadata {
        uint8_t         filler2[0x20];
 } __attribute__ ((packed));
 
-static void jm_to_cpu(struct jm_metadata *jm)
-{
-       unsigned int i;
-
-       jm->version = le16_to_cpu(jm->version);
-       jm->checksum = le16_to_cpu(jm->checksum);
-       jm->identity = le32_to_cpu(jm->identity);
-       jm->segment.base = le32_to_cpu(jm->segment.base);
-       jm->segment.range = le32_to_cpu(jm->segment.range);
-       jm->segment.range2 = le16_to_cpu(jm->segment.range2);
-
-       jm->attribute = le16_to_cpu(jm->attribute);
-
-       for (i = 0; i < JM_SPARES; i++)
-               jm->spare[i] = le32_to_cpu(jm->spare[i]);
-
-       for (i = 0; i < JM_MEMBERS; i++)
-               jm->member[i] = le32_to_cpu(jm->member[i]);
-}
-
 static int jm_checksum(const struct jm_metadata *jm)
 {
         size_t count = sizeof(*jm) / sizeof(uint16_t);
@@ -93,7 +73,7 @@ static int probe_jmraid(blkid_probe pr,
                const struct blkid_idmag *mag __attribute__((__unused__)))
 {
        uint64_t off;
-       struct jm_metadata *jm;
+       const struct jm_metadata *jm;
 
        if (pr->size < 0x10000)
                return 1;
@@ -114,8 +94,6 @@ static int probe_jmraid(blkid_probe pr,
        if (!jm_checksum(jm))
                return 1;
 
-       jm_to_cpu(jm);
-
        if (jm->mode > 5)
                return 1;