mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] pinctrl: qcom: spmi-gpio: don't cache new config until we know it's applied
@ 2026-11-10 15:14 Bartosz Golaszewski
  0 siblings, 0 replies; only message in thread
From: Bartosz Golaszewski @ 2026-11-10 15:14 UTC (permalink / raw)
  To: Bjorn Andersson, Bartosz Golaszewski, Linus Walleij,
	Ivan T. Ivanov, Konrad Dybcio
  Cc: linux-arm-msm, linux-gpio, linux-kernel, stable, Bartosz Golaszewski

pmic_gpio_config_set() modifies the in-memory settings cache before
performing any register writes. If any of the calls to pmic_gpio_write()
fails, the modifications are never reverted and the real state diverges
from what linux stores in memory.

Work on a local copy of the relevant pad and only modify the cache after
all writes succeeded.

Cc: stable@vger.kernel.org
Fixes: eadff3024472 ("pinctrl: Qualcomm SPMI PMIC GPIO pin controller driver")
Closes: https://sashiko.dev/#/bug/linux-49f0403d-732b-497d-980c-109c36c92597
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
 drivers/pinctrl/qcom/pinctrl-spmi-gpio.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c b/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c
index 05291b7397d6b15531e66f073b8771ed318ed5fd..7c4266efaa27619508f0cc3cee8f8a607f7bda57 100644
--- a/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c
+++ b/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c
@@ -480,12 +480,14 @@ static int pmic_gpio_config_set(struct pinctrl_dev *pctldev, unsigned int pin,
 				unsigned long *configs, unsigned nconfs)
 {
 	struct pmic_gpio_state *state = pinctrl_dev_get_drvdata(pctldev);
-	struct pmic_gpio_pad *pad;
+	struct pmic_gpio_pad *old, *pad, cpy;
 	unsigned param, arg;
 	unsigned int val;
 	int i, ret;
 
-	pad = pctldev->desc->pins[pin].drv_data;
+	old = pctldev->desc->pins[pin].drv_data;
+	cpy = *old;
+	pad = &cpy;
 
 	pad->is_enabled = true;
 	for (i = 0; i < nconfs; i++) {
@@ -651,8 +653,11 @@ static int pmic_gpio_config_set(struct pinctrl_dev *pctldev, unsigned int pin,
 	val = pad->is_enabled << PMIC_GPIO_REG_MASTER_EN_SHIFT;
 
 	ret = pmic_gpio_write(state, pad, PMIC_GPIO_REG_EN_CTL, val);
+	if (ret < 0)
+		return ret;
 
-	return ret;
+	*old = cpy;
+	return 0;
 }
 
 static void pmic_gpio_config_dbg_show(struct pinctrl_dev *pctldev,

---
base-commit: 630059a5a632377b9b7b487baccde92b7ae1dd47
change-id: 20261110-qcom-spmi-gpio-cache-sync-6941bf152459

Best regards,
-- 
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-10 15:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-10 15:14 [PATCH] pinctrl: qcom: spmi-gpio: don't cache new config until we know it's applied Bartosz Golaszewski

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®