Applied, thanks.

(I also removed the "gfp_t flags" argument because its always GFP_KERNEL.

Mikulas



On Tue, 5 Aug 2025, Dmitry Antipov wrote:

> Following commit ebbd17695e9e ("dm: ima: avoid extra calls to
> strlen()"), convert 'dm_ima_alloc_and_copy_capacity_str()' to
> return the number of characters emitted by 'scnprintf()' and
> simplify the users accordingly. Compile tested only.
> 
> Signed-off-by: Dmitry Antipov <dmanti...@yandex.ru>
> ---
>  drivers/md/dm-ima.c | 40 ++++++++++++++++------------------------
>  1 file changed, 16 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/md/dm-ima.c b/drivers/md/dm-ima.c
> index 8b50c908c6f4..f5c0ecc7cb0b 100644
> --- a/drivers/md/dm-ima.c
> +++ b/drivers/md/dm-ima.c
> @@ -157,10 +157,8 @@ static int dm_ima_alloc_and_copy_capacity_str(struct 
> mapped_device *md, char **c
>       if (!(*capacity_str))
>               return -ENOMEM;
>  
> -     scnprintf(*capacity_str, DM_IMA_DEVICE_BUF_LEN, 
> "current_device_capacity=%llu;",
> -               capacity);
> -
> -     return 0;
> +     return scnprintf(*capacity_str, DM_IMA_DEVICE_BUF_LEN, 
> "current_device_capacity=%llu;",
> +                      capacity);
>  }
>  
>  /*
> @@ -371,18 +369,18 @@ void dm_ima_measure_on_device_resume(struct 
> mapped_device *md, bool swap)
>  {
>       char *device_table_data, *dev_name = NULL, *dev_uuid = NULL, 
> *capacity_str = NULL;
>       char active[] = "active_table_hash=";
> -     unsigned int active_len = strlen(active), capacity_len = 0;
> +     unsigned int active_len = strlen(active);
>       unsigned int l = 0;
>       bool noio = true;
>       bool nodata = true;
> -     int r;
> +     int capacity_len;
>  
>       device_table_data = dm_ima_alloc(DM_IMA_DEVICE_BUF_LEN, GFP_KERNEL, 
> noio);
>       if (!device_table_data)
>               return;
>  
> -     r = dm_ima_alloc_and_copy_capacity_str(md, &capacity_str, noio);
> -     if (r)
> +     capacity_len = dm_ima_alloc_and_copy_capacity_str(md, &capacity_str, 
> noio);
> +     if (capacity_len < 0)
>               goto error;
>  
>       memcpy(device_table_data + l, DM_IMA_VERSION_STR, 
> md->ima.dm_version_str_len);
> @@ -445,8 +443,7 @@ void dm_ima_measure_on_device_resume(struct mapped_device 
> *md, bool swap)
>       }
>  
>       if (nodata) {
> -             r = dm_ima_alloc_and_copy_name_uuid(md, &dev_name, &dev_uuid, 
> noio);
> -             if (r)
> +             if (dm_ima_alloc_and_copy_name_uuid(md, &dev_name, &dev_uuid, 
> noio))
>                       goto error;
>  
>               l = scnprintf(device_table_data, DM_IMA_DEVICE_BUF_LEN,
> @@ -454,7 +451,6 @@ void dm_ima_measure_on_device_resume(struct mapped_device 
> *md, bool swap)
>                             DM_IMA_VERSION_STR, dev_name, dev_uuid);
>       }
>  
> -     capacity_len = strlen(capacity_str);
>       memcpy(device_table_data + l, capacity_str, capacity_len);
>       l += capacity_len;
>  
> @@ -483,18 +479,17 @@ void dm_ima_measure_on_device_remove(struct 
> mapped_device *md, bool remove_all)
>       unsigned int device_active_len = strlen(device_active_str);
>       unsigned int device_inactive_len = strlen(device_inactive_str);
>       unsigned int remove_all_len = strlen(remove_all_str);
> -     unsigned int capacity_len = 0;
>       unsigned int l = 0;
>       bool noio = true;
>       bool nodata = true;
> -     int r;
> +     int capacity_len;
>  
>       device_table_data = dm_ima_alloc(DM_IMA_DEVICE_BUF_LEN*2, GFP_KERNEL, 
> noio);
>       if (!device_table_data)
>               goto exit;
>  
> -     r = dm_ima_alloc_and_copy_capacity_str(md, &capacity_str, noio);
> -     if (r) {
> +     capacity_len = dm_ima_alloc_and_copy_capacity_str(md, &capacity_str, 
> noio);
> +     if (capacity_len < 0) {
>               kfree(device_table_data);
>               goto exit;
>       }
> @@ -570,7 +565,6 @@ void dm_ima_measure_on_device_remove(struct mapped_device 
> *md, bool remove_all)
>       memcpy(device_table_data + l, remove_all ? "y;" : "n;", 2);
>       l += 2;
>  
> -     capacity_len = strlen(capacity_str);
>       memcpy(device_table_data + l, capacity_str, capacity_len);
>       l += capacity_len;
>  
> @@ -602,20 +596,20 @@ void dm_ima_measure_on_device_remove(struct 
> mapped_device *md, bool remove_all)
>   */
>  void dm_ima_measure_on_table_clear(struct mapped_device *md, bool new_map)
>  {
> -     unsigned int l = 0, capacity_len = 0;
> +     unsigned int l = 0;
>       char *device_table_data = NULL, *dev_name = NULL, *dev_uuid = NULL, 
> *capacity_str = NULL;
>       char inactive_str[] = "inactive_table_hash=";
>       unsigned int inactive_len = strlen(inactive_str);
>       bool noio = true;
>       bool nodata = true;
> -     int r;
> +     int capacity_len;
>  
>       device_table_data = dm_ima_alloc(DM_IMA_DEVICE_BUF_LEN, GFP_KERNEL, 
> noio);
>       if (!device_table_data)
>               return;
>  
> -     r = dm_ima_alloc_and_copy_capacity_str(md, &capacity_str, noio);
> -     if (r)
> +     capacity_len = dm_ima_alloc_and_copy_capacity_str(md, &capacity_str, 
> noio);
> +     if (capacity_len < 0)
>               goto error1;
>  
>       memcpy(device_table_data + l, DM_IMA_VERSION_STR, 
> md->ima.dm_version_str_len);
> @@ -650,7 +644,6 @@ void dm_ima_measure_on_table_clear(struct mapped_device 
> *md, bool new_map)
>                             DM_IMA_VERSION_STR, dev_name, dev_uuid);
>       }
>  
> -     capacity_len = strlen(capacity_str);
>       memcpy(device_table_data + l, capacity_str, capacity_len);
>       l += capacity_len;
>  
> @@ -703,7 +696,7 @@ void dm_ima_measure_on_device_rename(struct mapped_device 
> *md)
>       char *old_device_data = NULL, *new_device_data = NULL, 
> *combined_device_data = NULL;
>       char *new_dev_name = NULL, *new_dev_uuid = NULL, *capacity_str = NULL;
>       bool noio = true;
> -     int r, len;
> +     int len;
>  
>       if (dm_ima_alloc_and_copy_device_data(md, &new_device_data,
>                                             md->ima.active_table.num_targets, 
> noio))
> @@ -716,8 +709,7 @@ void dm_ima_measure_on_device_rename(struct mapped_device 
> *md)
>       if (!combined_device_data)
>               goto error;
>  
> -     r = dm_ima_alloc_and_copy_capacity_str(md, &capacity_str, noio);
> -     if (r)
> +     if (dm_ima_alloc_and_copy_capacity_str(md, &capacity_str, noio) < 0)
>               goto error;
>  
>       old_device_data = md->ima.active_table.device_metadata;
> -- 
> 2.50.1
> 


Reply via email to