mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-09-18 22:14:16 +00:00
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>
This commit is contained in:
parent
860e98066f
commit
ba09916efb
1 changed files with 8 additions and 1 deletions
|
@ -47,6 +47,7 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
|
|||
struct regmap_config syscon_config = syscon_regmap_config;
|
||||
struct resource res;
|
||||
struct reset_control *reset;
|
||||
resource_size_t res_size;
|
||||
|
||||
WARN_ON(!mutex_is_locked(&syscon_list_lock));
|
||||
|
||||
|
@ -96,6 +97,12 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
|
|||
}
|
||||
}
|
||||
|
||||
res_size = resource_size(&res);
|
||||
if (res_size < reg_io_width) {
|
||||
ret = -EFAULT;
|
||||
goto err_regmap;
|
||||
}
|
||||
|
||||
syscon_config.name = kasprintf(GFP_KERNEL, "%pOFn@%pa", np, &res.start);
|
||||
if (!syscon_config.name) {
|
||||
ret = -ENOMEM;
|
||||
|
@ -103,7 +110,7 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
|
|||
}
|
||||
syscon_config.reg_stride = reg_io_width;
|
||||
syscon_config.val_bits = reg_io_width * 8;
|
||||
syscon_config.max_register = resource_size(&res) - reg_io_width;
|
||||
syscon_config.max_register = res_size - reg_io_width;
|
||||
if (!syscon_config.max_register)
|
||||
syscon_config.max_register_is_0 = true;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue