From: Nishanth Menon <nm@ti.com>
To: Arnd Bergmann <arnd@arndb.de>, Lee Jones <lee@kernel.org>
Cc: <linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>, <afd@ti.com>, <bb@ti.com>,
<d-gole@ti.com>, Nishanth Menon <nm@ti.com>,
Jan Dakinevich <jan.dakinevich@salutedevices.com>,
Mark Brown <broonie@kernel.org>
Subject: [PATCH] mfd: syscon: Set max_register_is_0 when syscon points to a single register
Date: Wed, 28 Aug 2024 07:10:08 -0500 [thread overview]
Message-ID: <20240828121008.3066002-1-nm@ti.com> (raw)
Commit 0ec74ad3c157 ("regmap: rework ->max_register handling")
introduced explicit handling in regmap framework for register maps
that is exactly 1 register wide. As a result, a syscon pointing
to a single register would cause regmap checks to skip checks
(or in the case of regmap_get_max_register, return -EINVAL) as
max_register_is_set will not be true.
Fixes: 0ec74ad3c157 ("regmap: rework ->max_register handling")
Signed-off-by: Nishanth Menon <nm@ti.com>
---
Cc: Jan Dakinevich <jan.dakinevich@salutedevices.com>
Cc: Mark Brown <broonie@kernel.org>
WARNING:
This is probably going to expose some other hidden bugs in other code
bases, for example: https://lore.kernel.org/r/20240827131342.6wrielete3yeoinl@bryanbrattlof.com
exposed a very interesting behavior - regmap_read now correctly fails
with -EIO in https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/cpufreq/ti-cpufreq.c#n343
when the dt is modified to provide exact syscon register, but cpufreq
driver attempts to read at 0x18 reg offset, but then, the code assumes
that invalid regmap ranges imply OMAP3 and goes and reads some random
register.. (fixes for cpufreq is pending).
in the above example: adding prints in cpufreq driver (in the same
location pointed above):
before this patch:
read returns 0 with value 0x00000243 and regmap_get_max_register would
return -EINVAL
After this patch:
read returns -EIO with value 0x00000000 and regmap_get_max_register would
return 0x0
This would be the correct behavior.
drivers/mfd/syscon.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c
index 2ce15f60eb10..3e1d699ba934 100644
--- a/drivers/mfd/syscon.c
+++ b/drivers/mfd/syscon.c
@@ -108,6 +108,8 @@ 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;
+ if (!syscon_config.max_register)
+ syscon_config.max_register_is_0 = true;
regmap = regmap_init_mmio(NULL, base, &syscon_config);
kfree(syscon_config.name);
@@ -357,6 +359,9 @@ static int syscon_probe(struct platform_device *pdev)
return -ENOMEM;
syscon_config.max_register = resource_size(res) - 4;
+ if (!syscon_config.max_register)
+ syscon_config.max_register_is_0 = true;
+
if (pdata)
syscon_config.name = pdata->label;
syscon->regmap = devm_regmap_init_mmio(dev, base, &syscon_config);
--
2.43.0
next reply other threads:[~2024-08-28 12:11 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-28 12:10 Nishanth Menon [this message]
2024-08-28 12:57 ` [PATCH] mfd: syscon: Set max_register_is_0 when syscon points to a single register Mark Brown
2024-08-28 13:32 ` Nishanth Menon
2024-08-28 14:27 ` Mark Brown
2024-08-28 14:44 ` Nishanth Menon
2024-08-28 20:26 ` Mark Brown
2024-08-29 5:04 ` Nishanth Menon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240828121008.3066002-1-nm@ti.com \
--to=nm@ti.com \
--cc=afd@ti.com \
--cc=arnd@arndb.de \
--cc=bb@ti.com \
--cc=broonie@kernel.org \
--cc=d-gole@ti.com \
--cc=jan.dakinevich@salutedevices.com \
--cc=lee@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox