Skip to content

Commit a319147

Browse files
dmantipovMikulas Patocka
authored andcommitted
dm-ima: more strlen() drops
Following commit ebbd176 ("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 <dmantipov@yandex.ru> Reviewed-by: Hou Tao <houtao1@huawei.com> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
1 parent 5d1c829 commit a319147

1 file changed

Lines changed: 16 additions & 24 deletions

File tree

drivers/md/dm-ima.c

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,8 @@ static int dm_ima_alloc_and_copy_capacity_str(struct mapped_device *md, char **c
157157
if (!(*capacity_str))
158158
return -ENOMEM;
159159

160-
scnprintf(*capacity_str, DM_IMA_DEVICE_BUF_LEN, "current_device_capacity=%llu;",
161-
capacity);
162-
163-
return 0;
160+
return scnprintf(*capacity_str, DM_IMA_DEVICE_BUF_LEN, "current_device_capacity=%llu;",
161+
capacity);
164162
}
165163

166164
/*
@@ -371,18 +369,18 @@ void dm_ima_measure_on_device_resume(struct mapped_device *md, bool swap)
371369
{
372370
char *device_table_data, *dev_name = NULL, *dev_uuid = NULL, *capacity_str = NULL;
373371
char active[] = "active_table_hash=";
374-
unsigned int active_len = strlen(active), capacity_len = 0;
372+
unsigned int active_len = strlen(active);
375373
unsigned int l = 0;
376374
bool noio = true;
377375
bool nodata = true;
378-
int r;
376+
int capacity_len;
379377

380378
device_table_data = dm_ima_alloc(DM_IMA_DEVICE_BUF_LEN, GFP_KERNEL, noio);
381379
if (!device_table_data)
382380
return;
383381

384-
r = dm_ima_alloc_and_copy_capacity_str(md, &capacity_str, noio);
385-
if (r)
382+
capacity_len = dm_ima_alloc_and_copy_capacity_str(md, &capacity_str, noio);
383+
if (capacity_len < 0)
386384
goto error;
387385

388386
memcpy(device_table_data + l, DM_IMA_VERSION_STR, md->ima.dm_version_str_len);
@@ -445,16 +443,14 @@ void dm_ima_measure_on_device_resume(struct mapped_device *md, bool swap)
445443
}
446444

447445
if (nodata) {
448-
r = dm_ima_alloc_and_copy_name_uuid(md, &dev_name, &dev_uuid, noio);
449-
if (r)
446+
if (dm_ima_alloc_and_copy_name_uuid(md, &dev_name, &dev_uuid, noio))
450447
goto error;
451448

452449
l = scnprintf(device_table_data, DM_IMA_DEVICE_BUF_LEN,
453450
"%sname=%s,uuid=%s;device_resume=no_data;",
454451
DM_IMA_VERSION_STR, dev_name, dev_uuid);
455452
}
456453

457-
capacity_len = strlen(capacity_str);
458454
memcpy(device_table_data + l, capacity_str, capacity_len);
459455
l += capacity_len;
460456

@@ -483,18 +479,17 @@ void dm_ima_measure_on_device_remove(struct mapped_device *md, bool remove_all)
483479
unsigned int device_active_len = strlen(device_active_str);
484480
unsigned int device_inactive_len = strlen(device_inactive_str);
485481
unsigned int remove_all_len = strlen(remove_all_str);
486-
unsigned int capacity_len = 0;
487482
unsigned int l = 0;
488483
bool noio = true;
489484
bool nodata = true;
490-
int r;
485+
int capacity_len;
491486

492487
device_table_data = dm_ima_alloc(DM_IMA_DEVICE_BUF_LEN*2, GFP_KERNEL, noio);
493488
if (!device_table_data)
494489
goto exit;
495490

496-
r = dm_ima_alloc_and_copy_capacity_str(md, &capacity_str, noio);
497-
if (r) {
491+
capacity_len = dm_ima_alloc_and_copy_capacity_str(md, &capacity_str, noio);
492+
if (capacity_len < 0) {
498493
kfree(device_table_data);
499494
goto exit;
500495
}
@@ -570,7 +565,6 @@ void dm_ima_measure_on_device_remove(struct mapped_device *md, bool remove_all)
570565
memcpy(device_table_data + l, remove_all ? "y;" : "n;", 2);
571566
l += 2;
572567

573-
capacity_len = strlen(capacity_str);
574568
memcpy(device_table_data + l, capacity_str, capacity_len);
575569
l += capacity_len;
576570

@@ -602,20 +596,20 @@ void dm_ima_measure_on_device_remove(struct mapped_device *md, bool remove_all)
602596
*/
603597
void dm_ima_measure_on_table_clear(struct mapped_device *md, bool new_map)
604598
{
605-
unsigned int l = 0, capacity_len = 0;
599+
unsigned int l = 0;
606600
char *device_table_data = NULL, *dev_name = NULL, *dev_uuid = NULL, *capacity_str = NULL;
607601
char inactive_str[] = "inactive_table_hash=";
608602
unsigned int inactive_len = strlen(inactive_str);
609603
bool noio = true;
610604
bool nodata = true;
611-
int r;
605+
int capacity_len;
612606

613607
device_table_data = dm_ima_alloc(DM_IMA_DEVICE_BUF_LEN, GFP_KERNEL, noio);
614608
if (!device_table_data)
615609
return;
616610

617-
r = dm_ima_alloc_and_copy_capacity_str(md, &capacity_str, noio);
618-
if (r)
611+
capacity_len = dm_ima_alloc_and_copy_capacity_str(md, &capacity_str, noio);
612+
if (capacity_len < 0)
619613
goto error1;
620614

621615
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)
650644
DM_IMA_VERSION_STR, dev_name, dev_uuid);
651645
}
652646

653-
capacity_len = strlen(capacity_str);
654647
memcpy(device_table_data + l, capacity_str, capacity_len);
655648
l += capacity_len;
656649

@@ -703,7 +696,7 @@ void dm_ima_measure_on_device_rename(struct mapped_device *md)
703696
char *old_device_data = NULL, *new_device_data = NULL, *combined_device_data = NULL;
704697
char *new_dev_name = NULL, *new_dev_uuid = NULL, *capacity_str = NULL;
705698
bool noio = true;
706-
int r, len;
699+
int len;
707700

708701
if (dm_ima_alloc_and_copy_device_data(md, &new_device_data,
709702
md->ima.active_table.num_targets, noio))
@@ -716,8 +709,7 @@ void dm_ima_measure_on_device_rename(struct mapped_device *md)
716709
if (!combined_device_data)
717710
goto error;
718711

719-
r = dm_ima_alloc_and_copy_capacity_str(md, &capacity_str, noio);
720-
if (r)
712+
if (dm_ima_alloc_and_copy_capacity_str(md, &capacity_str, noio) < 0)
721713
goto error;
722714

723715
old_device_data = md->ima.active_table.device_metadata;

0 commit comments

Comments
 (0)