From: Akshat Rawat <akshatrawat095@gmail.com>
To: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org,
Hugo Villeneuve <hvilleneuve@dimonoff.com>,
Elena Popa <elena.popa@nxp.com>,
Akshat Rawat <akshatrawat095@gmail.com>
Subject: [PATCH] rtc: pcf2127: use const per-variant regmap_config tables
Date: Wed, 25 Nov 2026 12:44:15 +0000 [thread overview]
Message-ID: <20261125124416.468-1-akshatrawat095@gmail.com> (raw)
Both pcf2127_i2c_probe() and pcf2127_spi_probe() declare config as a
static struct regmap_config and update it in place based on the chip
variant.
In pcf2127_spi_probe(), if a PCF2131 probes first, read_flag_mask and
write_flag_mask are overwritten to 0 and never restored. Any PCF2127 or
PCF2129 probed later reuses those zeroed masks instead of 0xa0/0x20,
breaking SPI register access. Modifying static max_register and flag
masks also races if multiple instances probe concurrently.
Replace the shared mutable config structs in both probe paths with
per-variant static const struct regmap_config tables, and drop the
now-unused max_register field from struct pcf21xx_config.
Fixes: fd28ceb4603f ("rtc: pcf2127: add variant-specific configuration structure")
Fixes: fa78e9b606a4 ("rtc: pcf2127: fix SPI command byte for PCF2131")
Cc: stable@vger.kernel.org
Signed-off-by: Akshat Rawat <akshatrawat095@gmail.com>
---
Compile-tested (x86_64 gcc 15.2.0, W=1, CONFIG_WERROR=y) with
I2C+SPI, I2C-only, and SPI-only configs; not tested on hardware.
drivers/rtc/rtc-pcf2127.c | 65 +++++++++++++++++++++++++--------------
1 file changed, 42 insertions(+), 23 deletions(-)
diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c
index 27c5fb9b2aaa..b665728c6c1d 100644
--- a/drivers/rtc/rtc-pcf2127.c
+++ b/drivers/rtc/rtc-pcf2127.c
@@ -186,7 +186,6 @@ struct pcf21xx_ts_config {
struct pcf21xx_config {
int type; /* IC variant */
- int max_register;
unsigned int has_nvmem:1;
unsigned int has_bit_wd_ctl_cd0:1;
unsigned int wd_val_reg_readable:1; /* If watchdog value register can be read. */
@@ -1020,7 +1019,6 @@ static struct attribute *pcf2131_attrs[] = {
static struct pcf21xx_config pcf21xx_cfg[] = {
[PCF2127] = {
.type = PCF2127,
- .max_register = 0x1d,
.has_nvmem = 1,
.has_bit_wd_ctl_cd0 = 1,
.wd_val_reg_readable = 1,
@@ -1048,7 +1046,6 @@ static struct pcf21xx_config pcf21xx_cfg[] = {
},
[PCF2129] = {
.type = PCF2129,
- .max_register = 0x19,
.has_nvmem = 0,
.has_bit_wd_ctl_cd0 = 0,
.wd_val_reg_readable = 1,
@@ -1076,7 +1073,6 @@ static struct pcf21xx_config pcf21xx_cfg[] = {
},
[PCF2131] = {
.type = PCF2131,
- .max_register = 0x36,
.has_nvmem = 0,
.has_bit_wd_ctl_cd0 = 0,
.wd_val_reg_readable = 0,
@@ -1452,13 +1448,27 @@ static const struct i2c_device_id pcf2127_i2c_id[] = {
};
MODULE_DEVICE_TABLE(i2c, pcf2127_i2c_id);
+static const struct regmap_config pcf2127_i2c_regmap_config[PCF21XX_LAST_ID] = {
+ [PCF2127] = {
+ .reg_bits = 8,
+ .val_bits = 8,
+ .max_register = 0x1d,
+ },
+ [PCF2129] = {
+ .reg_bits = 8,
+ .val_bits = 8,
+ .max_register = 0x19,
+ },
+ [PCF2131] = {
+ .reg_bits = 8,
+ .val_bits = 8,
+ .max_register = 0x36,
+ },
+};
+
static int pcf2127_i2c_probe(struct i2c_client *client)
{
struct regmap *regmap;
- static struct regmap_config config = {
- .reg_bits = 8,
- .val_bits = 8,
- };
const struct pcf21xx_config *variant;
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
@@ -1468,10 +1478,9 @@ static int pcf2127_i2c_probe(struct i2c_client *client)
if (!variant)
return -ENODEV;
- config.max_register = variant->max_register,
-
regmap = devm_regmap_init(&client->dev, &pcf2127_i2c_regmap,
- &client->dev, &config);
+ &client->dev,
+ &pcf2127_i2c_regmap_config[variant->type]);
if (IS_ERR(regmap)) {
dev_err(&client->dev, "%s: regmap allocation failed: %ld\n",
__func__, PTR_ERR(regmap));
@@ -1518,14 +1527,30 @@ static void pcf2127_i2c_unregister_driver(void)
static struct spi_driver pcf2127_spi_driver;
static const struct spi_device_id pcf2127_spi_id[];
-static int pcf2127_spi_probe(struct spi_device *spi)
-{
- static struct regmap_config config = {
+static const struct regmap_config pcf2127_spi_regmap_config[PCF21XX_LAST_ID] = {
+ [PCF2127] = {
+ .reg_bits = 8,
+ .val_bits = 8,
+ .read_flag_mask = 0xa0,
+ .write_flag_mask = 0x20,
+ .max_register = 0x1d,
+ },
+ [PCF2129] = {
.reg_bits = 8,
.val_bits = 8,
.read_flag_mask = 0xa0,
.write_flag_mask = 0x20,
- };
+ .max_register = 0x19,
+ },
+ [PCF2131] = {
+ .reg_bits = 8,
+ .val_bits = 8,
+ .max_register = 0x36,
+ },
+};
+
+static int pcf2127_spi_probe(struct spi_device *spi)
+{
struct regmap *regmap;
const struct pcf21xx_config *variant;
@@ -1541,14 +1566,8 @@ static int pcf2127_spi_probe(struct spi_device *spi)
variant = &pcf21xx_cfg[type];
}
- if (variant->type == PCF2131) {
- config.read_flag_mask = 0x0;
- config.write_flag_mask = 0x0;
- }
-
- config.max_register = variant->max_register;
-
- regmap = devm_regmap_init_spi(spi, &config);
+ regmap = devm_regmap_init_spi(spi,
+ &pcf2127_spi_regmap_config[variant->type]);
if (IS_ERR(regmap)) {
dev_err(&spi->dev, "%s: regmap allocation failed: %ld\n",
__func__, PTR_ERR(regmap));
--
2.56.1.windows.1
reply other threads:[~2026-11-25 12:43 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261125124416.468-1-akshatrawat095@gmail.com \
--to=akshatrawat095@gmail.com \
--cc=alexandre.belloni@bootlin.com \
--cc=elena.popa@nxp.com \
--cc=hvilleneuve@dimonoff.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=stable@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
all inboxes | Powered by JetHome®