diff options
author | Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> | 2022-01-20 13:18:33 +0100 |
---|---|---|
committer | Jes Sorensen <jsorensen@fb.com> | 2022-04-05 03:29:43 +0200 |
commit | 5f21d67472ad08c1e96b4385254adba79aa1c467 (patch) | |
tree | 10144774aa470f040ff41e750eab055a94e3c137 /sysfs.c | |
parent | Create, Build: use default_layout() (diff) | |
download | mdadm-5f21d67472ad08c1e96b4385254adba79aa1c467.tar.xz mdadm-5f21d67472ad08c1e96b4385254adba79aa1c467.zip |
mdadm: add map_num_s()
map_num() returns NULL if key is not defined. This patch adds
alternative, non NULL version for cases where NULL is not expected.
There are many printf() calls where map_num() is called on variable
without NULL verification. It works, even if NULL is passed because
gcc is able to ignore NULL argument quietly but the behavior is
undefined. For safety reasons such usages will use map_num_s() now.
It is a potential point of regression.
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
Diffstat (limited to 'sysfs.c')
-rw-r--r-- | sysfs.c | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -689,7 +689,7 @@ int sysfs_set_array(struct mdinfo *info, int vers) if (info->array.level < 0) return 0; /* FIXME */ rv |= sysfs_set_str(info, NULL, "level", - map_num(pers, info->array.level)); + map_num_s(pers, info->array.level)); if (info->reshape_active && info->delta_disks != UnSet) raid_disks -= info->delta_disks; rv |= sysfs_set_num(info, NULL, "raid_disks", raid_disks); @@ -724,9 +724,10 @@ int sysfs_set_array(struct mdinfo *info, int vers) } if (info->consistency_policy == CONSISTENCY_POLICY_PPL) { - if (sysfs_set_str(info, NULL, "consistency_policy", - map_num(consistency_policies, - info->consistency_policy))) { + char *policy = map_num_s(consistency_policies, + info->consistency_policy); + + if (sysfs_set_str(info, NULL, "consistency_policy", policy)) { pr_err("This kernel does not support PPL. Falling back to consistency-policy=resync.\n"); info->consistency_policy = CONSISTENCY_POLICY_RESYNC; } |