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 /Grow.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 'Grow.c')
-rw-r--r-- | Grow.c | 16 |
1 files changed, 8 insertions, 8 deletions
@@ -547,7 +547,7 @@ int Grow_consistency_policy(char *devname, int fd, struct context *c, struct sha if (s->consistency_policy != CONSISTENCY_POLICY_RESYNC && s->consistency_policy != CONSISTENCY_POLICY_PPL) { pr_err("Operation not supported for consistency policy %s\n", - map_num(consistency_policies, s->consistency_policy)); + map_num_s(consistency_policies, s->consistency_policy)); return 1; } @@ -578,14 +578,14 @@ int Grow_consistency_policy(char *devname, int fd, struct context *c, struct sha if (sra->consistency_policy == (unsigned)s->consistency_policy) { pr_err("Consistency policy is already %s\n", - map_num(consistency_policies, s->consistency_policy)); + map_num_s(consistency_policies, s->consistency_policy)); ret = 1; goto free_info; } else if (sra->consistency_policy != CONSISTENCY_POLICY_RESYNC && sra->consistency_policy != CONSISTENCY_POLICY_PPL) { pr_err("Current consistency policy is %s, cannot change to %s\n", - map_num(consistency_policies, sra->consistency_policy), - map_num(consistency_policies, s->consistency_policy)); + map_num_s(consistency_policies, sra->consistency_policy), + map_num_s(consistency_policies, s->consistency_policy)); ret = 1; goto free_info; } @@ -704,8 +704,8 @@ int Grow_consistency_policy(char *devname, int fd, struct context *c, struct sha } ret = sysfs_set_str(sra, NULL, "consistency_policy", - map_num(consistency_policies, - s->consistency_policy)); + map_num_s(consistency_policies, + s->consistency_policy)); if (ret) pr_err("Failed to change array consistency policy\n"); @@ -2241,7 +2241,7 @@ size_change_error: info.new_layout = UnSet; if (info.array.level == 6 && info.new_level == UnSet) { char l[40], *h; - strcpy(l, map_num(r6layout, info.array.layout)); + strcpy(l, map_num_s(r6layout, info.array.layout)); h = strrchr(l, '-'); if (h && strcmp(h, "-6") == 0) { *h = 0; @@ -2266,7 +2266,7 @@ size_change_error: info.new_layout = info.array.layout; else if (info.array.level == 5 && info.new_level == 6) { char l[40]; - strcpy(l, map_num(r5layout, info.array.layout)); + strcpy(l, map_num_s(r5layout, info.array.layout)); strcat(l, "-6"); info.new_layout = map_name(r6layout, l); } else { |