]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
dm-ima: remove dm_ima_reset_data()
authorBenjamin Marzinski <bmarzins@redhat.com>
Wed, 29 Apr 2026 20:20:59 +0000 (16:20 -0400)
committerMikulas Patocka <mpatocka@redhat.com>
Mon, 4 May 2026 12:52:18 +0000 (14:52 +0200)
There's no point in saving the string length of DM_IMA_VERSION_STR. It's
a constant, so the compiler will precompute it. dm_create() will already
zero out the rest of dm->ima.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
drivers/md/dm-ima.c
drivers/md/dm-ima.h
drivers/md/dm.c

index 9495ca0350563f4bdf36deced60aa01487cb1f39..a639bb0fe6c3d9c11ab50cf4e80b9a86ef2e7fe5 100644 (file)
@@ -159,15 +159,6 @@ static int dm_ima_alloc_and_copy_capacity_str(struct mapped_device *md, char **c
                         capacity);
 }
 
-/*
- * Initialize/reset the dm ima related data structure variables.
- */
-void dm_ima_reset_data(struct mapped_device *md)
-{
-       memset(&(md->ima), 0, sizeof(md->ima));
-       md->ima.dm_version_str_len = strlen(DM_IMA_VERSION_STR);
-}
-
 /*
  * Build up the IMA data for each target, and finally measure.
  */
@@ -204,8 +195,8 @@ void dm_ima_measure_on_table_load(struct dm_table *table, unsigned int status_fl
 
        sha256_init(&hash_ctx);
 
-       memcpy(ima_buf + l, DM_IMA_VERSION_STR, table->md->ima.dm_version_str_len);
-       l += table->md->ima.dm_version_str_len;
+       memcpy(ima_buf + l, DM_IMA_VERSION_STR, strlen(DM_IMA_VERSION_STR));
+       l += strlen(DM_IMA_VERSION_STR);
 
        device_data_buf_len = strlen(device_data_buf);
        memcpy(ima_buf + l, device_data_buf, device_data_buf_len);
@@ -260,8 +251,8 @@ void dm_ima_measure_on_table_load(struct dm_table *table, unsigned int status_fl
                         * prefix, so that multiple records from the same "dm_table_load" for
                         * a given device can be linked together.
                         */
-                       memcpy(ima_buf + l, DM_IMA_VERSION_STR, table->md->ima.dm_version_str_len);
-                       l += table->md->ima.dm_version_str_len;
+                       memcpy(ima_buf + l, DM_IMA_VERSION_STR, strlen(DM_IMA_VERSION_STR));
+                       l += strlen(DM_IMA_VERSION_STR);
 
                        memcpy(ima_buf + l, device_data_buf, device_data_buf_len);
                        l += device_data_buf_len;
@@ -349,8 +340,8 @@ void dm_ima_measure_on_device_resume(struct mapped_device *md, bool swap)
        if (capacity_len < 0)
                goto error;
 
-       memcpy(device_table_data + l, DM_IMA_VERSION_STR, md->ima.dm_version_str_len);
-       l += md->ima.dm_version_str_len;
+       memcpy(device_table_data + l, DM_IMA_VERSION_STR, strlen(DM_IMA_VERSION_STR));
+       l += strlen(DM_IMA_VERSION_STR);
 
        if (swap) {
                if (md->ima.active_table.hash != md->ima.inactive_table.hash)
@@ -460,8 +451,8 @@ void dm_ima_measure_on_device_remove(struct mapped_device *md, bool remove_all)
                goto exit;
        }
 
-       memcpy(device_table_data + l, DM_IMA_VERSION_STR, md->ima.dm_version_str_len);
-       l += md->ima.dm_version_str_len;
+       memcpy(device_table_data + l, DM_IMA_VERSION_STR, strlen(DM_IMA_VERSION_STR));
+       l += strlen(DM_IMA_VERSION_STR);
 
        if (md->ima.active_table.device_metadata) {
                memcpy(device_table_data + l, device_active_str, device_active_len);
@@ -551,7 +542,8 @@ exit:
        if (md->ima.active_table.hash != md->ima.inactive_table.hash)
                kfree(md->ima.inactive_table.hash);
 
-       dm_ima_reset_data(md);
+       memset(&md->ima.active_table, 0, sizeof(md->ima.active_table));
+       memset(&md->ima.inactive_table, 0, sizeof(md->ima.inactive_table));
 
        kfree(dev_name);
        kfree(dev_uuid);
@@ -578,8 +570,8 @@ void dm_ima_measure_on_table_clear(struct mapped_device *md, bool new_map)
        if (capacity_len < 0)
                goto error1;
 
-       memcpy(device_table_data + l, DM_IMA_VERSION_STR, md->ima.dm_version_str_len);
-       l += md->ima.dm_version_str_len;
+       memcpy(device_table_data + l, DM_IMA_VERSION_STR, strlen(DM_IMA_VERSION_STR));
+       l += strlen(DM_IMA_VERSION_STR);
 
        if (md->ima.inactive_table.device_metadata_len &&
            md->ima.inactive_table.hash_len) {
index a403deca6093e3fc825a1cabb28febfb6058e1d1..b0b166aa2283b59ecd583d320db514daef3c2fb1 100644 (file)
@@ -52,10 +52,8 @@ struct dm_ima_device_table_metadata {
 struct dm_ima_measurements {
        struct dm_ima_device_table_metadata active_table;
        struct dm_ima_device_table_metadata inactive_table;
-       unsigned int dm_version_str_len;
 };
 
-void dm_ima_reset_data(struct mapped_device *md);
 void dm_ima_measure_on_table_load(struct dm_table *table, unsigned int status_flags);
 void dm_ima_measure_on_device_resume(struct mapped_device *md, bool swap);
 void dm_ima_measure_on_device_remove(struct mapped_device *md, bool remove_all);
@@ -64,7 +62,6 @@ void dm_ima_measure_on_device_rename(struct mapped_device *md);
 
 #else
 
-static inline void dm_ima_reset_data(struct mapped_device *md) {}
 static inline void dm_ima_measure_on_table_load(struct dm_table *table, unsigned int status_flags) {}
 static inline void dm_ima_measure_on_device_resume(struct mapped_device *md, bool swap) {}
 static inline void dm_ima_measure_on_device_remove(struct mapped_device *md, bool remove_all) {}
index e178fe19973ea380abc0d3586fde7e7ff66b2fa9..8b60c9804f5b7e9919d53e0760e04fb697304aaf 100644 (file)
@@ -2546,8 +2546,6 @@ int dm_create(int minor, struct mapped_device **result)
        if (!md)
                return -ENXIO;
 
-       dm_ima_reset_data(md);
-
        *result = md;
        return 0;
 }