diff options
author | Chunyan Zhang <chunyan.zhang@unisoc.com> | 2023-03-16 10:36:24 +0800 |
---|---|---|
committer | Stephen Boyd <sboyd@kernel.org> | 2023-03-16 16:33:11 -0700 |
commit | 47d43086531f10539470a63e8ad92803e686a3dd (patch) | |
tree | ac5e2f26677e0c2bcf0163192579fdacdbddb9b6 /drivers/clk/sprd | |
parent | 5cf9d015be160e2d90d29ae74ef1364390e8fce8 (diff) | |
download | linux-47d43086531f10539470a63e8ad92803e686a3dd.tar.gz linux-47d43086531f10539470a63e8ad92803e686a3dd.tar.bz2 linux-47d43086531f10539470a63e8ad92803e686a3dd.zip |
clk: sprd: set max_register according to mapping range
In sprd clock driver, regmap_config.max_register was set to a fixed value
which is likely larger than the address range configured in device tree,
when reading registers through debugfs it would cause access violation.
Fixes: d41f59fd92f2 ("clk: sprd: Add common infrastructure")
Signed-off-by: Chunyan Zhang <chunyan.zhang@unisoc.com>
Link: https://lore.kernel.org/r/20230316023624.758204-1-chunyan.zhang@unisoc.com
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
Diffstat (limited to 'drivers/clk/sprd')
-rw-r--r-- | drivers/clk/sprd/common.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/drivers/clk/sprd/common.c b/drivers/clk/sprd/common.c index ce81e4087a8f..2bfbab8db94b 100644 --- a/drivers/clk/sprd/common.c +++ b/drivers/clk/sprd/common.c @@ -17,7 +17,6 @@ static const struct regmap_config sprdclk_regmap_config = { .reg_bits = 32, .reg_stride = 4, .val_bits = 32, - .max_register = 0xffff, .fast_io = true, }; @@ -43,6 +42,8 @@ int sprd_clk_regmap_init(struct platform_device *pdev, struct device *dev = &pdev->dev; struct device_node *node = dev->of_node, *np; struct regmap *regmap; + struct resource *res; + struct regmap_config reg_config = sprdclk_regmap_config; if (of_find_property(node, "sprd,syscon", NULL)) { regmap = syscon_regmap_lookup_by_phandle(node, "sprd,syscon"); @@ -59,12 +60,14 @@ int sprd_clk_regmap_init(struct platform_device *pdev, return PTR_ERR(regmap); } } else { - base = devm_platform_ioremap_resource(pdev, 0); + base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); if (IS_ERR(base)) return PTR_ERR(base); + reg_config.max_register = resource_size(res) - reg_config.reg_stride; + regmap = devm_regmap_init_mmio(&pdev->dev, base, - &sprdclk_regmap_config); + ®_config); if (IS_ERR(regmap)) { pr_err("failed to init regmap\n"); return PTR_ERR(regmap); |