* [PATCH] rtc: pcf2127: use const per-variant regmap_config tables
@ 2026-11-25 12:44 Akshat Rawat
2026-11-25 12:47 ` sashiko-bot
2026-11-25 14:58 ` Hugo Villeneuve
0 siblings, 2 replies; 3+ messages in thread
From: Akshat Rawat @ 2026-11-25 12:44 UTC (permalink / raw)
To: Alexandre Belloni
Cc: linux-rtc, linux-kernel, stable, Hugo Villeneuve, Elena Popa,
Akshat Rawat
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
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] rtc: pcf2127: use const per-variant regmap_config tables
2026-11-25 12:44 [PATCH] rtc: pcf2127: use const per-variant regmap_config tables Akshat Rawat
@ 2026-11-25 12:47 ` sashiko-bot
2026-11-25 14:58 ` Hugo Villeneuve
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-25 12:47 UTC (permalink / raw)
To: Akshat Rawat; +Cc: linux-rtc, Alexandre Belloni
> 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>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125124416.468-1-akshatrawat095@gmail.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] rtc: pcf2127: use const per-variant regmap_config tables
2026-11-25 12:44 [PATCH] rtc: pcf2127: use const per-variant regmap_config tables Akshat Rawat
2026-11-25 12:47 ` sashiko-bot
@ 2026-11-25 14:58 ` Hugo Villeneuve
1 sibling, 0 replies; 3+ messages in thread
From: Hugo Villeneuve @ 2026-11-25 14:58 UTC (permalink / raw)
To: Akshat Rawat
Cc: Alexandre Belloni, linux-rtc, linux-kernel, stable,
Hugo Villeneuve, Elena Popa
Hi Akshat,
On Wed, 25 Nov 2026 12:44:15 +0000
Akshat Rawat <akshatrawat095@gmail.com> wrote:
> [You don't often get email from akshatrawat095@gmail.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
Your commit title message should indicate why you do it, not how. If
you fix a bug, it should say so.
> 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.
Your entire patch can be simplified by simply removing the static
qualifier from structs in pcf2127_i2c_probe() and pcf2127_spi_probe().
> 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
>
--
Hugo Villeneuve
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-25 14:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 12:44 [PATCH] rtc: pcf2127: use const per-variant regmap_config tables Akshat Rawat
2026-11-25 12:47 ` sashiko-bot
2026-11-25 14:58 ` Hugo Villeneuve
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox