Skip to content

Commit ba09916

Browse files
efzrhlag-linaro
authored andcommitted
mfd: syscon: Add check for invalid resource size
Add a consistency check to avoid assigning an invalid value to max_register due to a possible DT misconfiguration. Suggested-by: Mark Langsdorf <mlangsdo@redhat.com> Signed-off-by: Eder Zulian <ezulian@redhat.com> Link: https://lore.kernel.org/r/20250212184524.585882-1-ezulian@redhat.com Signed-off-by: Lee Jones <lee@kernel.org>
1 parent 860e980 commit ba09916

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

drivers/mfd/syscon.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
4747
struct regmap_config syscon_config = syscon_regmap_config;
4848
struct resource res;
4949
struct reset_control *reset;
50+
resource_size_t res_size;
5051

5152
WARN_ON(!mutex_is_locked(&syscon_list_lock));
5253

@@ -96,14 +97,20 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
9697
}
9798
}
9899

100+
res_size = resource_size(&res);
101+
if (res_size < reg_io_width) {
102+
ret = -EFAULT;
103+
goto err_regmap;
104+
}
105+
99106
syscon_config.name = kasprintf(GFP_KERNEL, "%pOFn@%pa", np, &res.start);
100107
if (!syscon_config.name) {
101108
ret = -ENOMEM;
102109
goto err_regmap;
103110
}
104111
syscon_config.reg_stride = reg_io_width;
105112
syscon_config.val_bits = reg_io_width * 8;
106-
syscon_config.max_register = resource_size(&res) - reg_io_width;
113+
syscon_config.max_register = res_size - reg_io_width;
107114
if (!syscon_config.max_register)
108115
syscon_config.max_register_is_0 = true;
109116

0 commit comments

Comments
 (0)