linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] pinctrl: aw9523: add missing mutex_destroy
@ 2024-10-01 21:27 Rosen Penev
  2024-10-01 21:27 ` [PATCH 2/2] pinctrl: aw9523: use enable for regulator Rosen Penev
  2024-10-02 13:49 ` [PATCH 1/2] pinctrl: aw9523: add missing mutex_destroy Linus Walleij
  0 siblings, 2 replies; 4+ messages in thread
From: Rosen Penev @ 2024-10-01 21:27 UTC (permalink / raw)
  To: linux-gpio; +Cc: Linus Walleij, Liam Girdwood, Mark Brown, open list

Otherwise the mutex remains after a failed kzalloc.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/pinctrl/pinctrl-aw9523.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-aw9523.c b/drivers/pinctrl/pinctrl-aw9523.c
index b5e1c467625b..1374f30166bc 100644
--- a/drivers/pinctrl/pinctrl-aw9523.c
+++ b/drivers/pinctrl/pinctrl-aw9523.c
@@ -987,8 +987,10 @@ static int aw9523_probe(struct i2c_client *client)
 	lockdep_set_subclass(&awi->i2c_lock, i2c_adapter_depth(client->adapter));
 
 	pdesc = devm_kzalloc(dev, sizeof(*pdesc), GFP_KERNEL);
-	if (!pdesc)
-		return -ENOMEM;
+	if (!pdesc) {
+		ret = -ENOMEM;
+		goto err_disable_vregs;
+	}
 
 	ret = aw9523_hw_init(awi);
 	if (ret)
-- 
2.46.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] pinctrl: aw9523: use enable for regulator
  2024-10-01 21:27 [PATCH 1/2] pinctrl: aw9523: add missing mutex_destroy Rosen Penev
@ 2024-10-01 21:27 ` Rosen Penev
  2024-10-02 13:50   ` Linus Walleij
  2024-10-02 13:49 ` [PATCH 1/2] pinctrl: aw9523: add missing mutex_destroy Linus Walleij
  1 sibling, 1 reply; 4+ messages in thread
From: Rosen Penev @ 2024-10-01 21:27 UTC (permalink / raw)
  To: linux-gpio; +Cc: Linus Walleij, Liam Girdwood, Mark Brown, open list

devm_regulator_get_enable_optional can be used to simplify the logic
here.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/pinctrl/pinctrl-aw9523.c | 21 +++++----------------
 1 file changed, 5 insertions(+), 16 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-aw9523.c b/drivers/pinctrl/pinctrl-aw9523.c
index 1374f30166bc..cf2fb26992b4 100644
--- a/drivers/pinctrl/pinctrl-aw9523.c
+++ b/drivers/pinctrl/pinctrl-aw9523.c
@@ -80,7 +80,7 @@ struct aw9523 {
 	struct regmap *regmap;
 	struct mutex i2c_lock;
 	struct gpio_desc *reset_gpio;
-	struct regulator *vio_vreg;
+	int vio_vreg;
 	struct pinctrl_dev *pctl;
 	struct gpio_chip gpio;
 	struct aw9523_irq *irq;
@@ -972,16 +972,9 @@ static int aw9523_probe(struct i2c_client *client)
 	if (IS_ERR(awi->regmap))
 		return PTR_ERR(awi->regmap);
 
-	awi->vio_vreg = devm_regulator_get_optional(dev, "vio");
-	if (IS_ERR(awi->vio_vreg)) {
-		if (PTR_ERR(awi->vio_vreg) == -EPROBE_DEFER)
-			return -EPROBE_DEFER;
-		awi->vio_vreg = NULL;
-	} else {
-		ret = regulator_enable(awi->vio_vreg);
-		if (ret)
-			return ret;
-	}
+	awi->vio_vreg = devm_regulator_get_enable_optional(dev, "vio");
+	if (awi->vio_vreg && awi->vio_vreg != -ENODEV)
+		return awi->vio_vreg;
 
 	mutex_init(&awi->i2c_lock);
 	lockdep_set_subclass(&awi->i2c_lock, i2c_adapter_depth(client->adapter));
@@ -1027,8 +1020,6 @@ static int aw9523_probe(struct i2c_client *client)
 	return ret;
 
 err_disable_vregs:
-	if (awi->vio_vreg)
-		regulator_disable(awi->vio_vreg);
 	mutex_destroy(&awi->i2c_lock);
 	return ret;
 }
@@ -1043,9 +1034,7 @@ static void aw9523_remove(struct i2c_client *client)
 	 * set the pins to hardware defaults before removing the driver
 	 * to leave it in a clean, safe and predictable state.
 	 */
-	if (awi->vio_vreg) {
-		regulator_disable(awi->vio_vreg);
-	} else {
+	if (awi->vio_vreg == -ENODEV) {
 		mutex_lock(&awi->i2c_lock);
 		aw9523_hw_init(awi);
 		mutex_unlock(&awi->i2c_lock);
-- 
2.46.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] pinctrl: aw9523: add missing mutex_destroy
  2024-10-01 21:27 [PATCH 1/2] pinctrl: aw9523: add missing mutex_destroy Rosen Penev
  2024-10-01 21:27 ` [PATCH 2/2] pinctrl: aw9523: use enable for regulator Rosen Penev
@ 2024-10-02 13:49 ` Linus Walleij
  1 sibling, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2024-10-02 13:49 UTC (permalink / raw)
  To: Rosen Penev; +Cc: linux-gpio, Liam Girdwood, Mark Brown, open list

On Tue, Oct 1, 2024 at 11:27 PM Rosen Penev <rosenp@gmail.com> wrote:

> Otherwise the mutex remains after a failed kzalloc.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>

Patch applied for fixes!

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] pinctrl: aw9523: use enable for regulator
  2024-10-01 21:27 ` [PATCH 2/2] pinctrl: aw9523: use enable for regulator Rosen Penev
@ 2024-10-02 13:50   ` Linus Walleij
  0 siblings, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2024-10-02 13:50 UTC (permalink / raw)
  To: Rosen Penev; +Cc: linux-gpio, Liam Girdwood, Mark Brown, open list

On Tue, Oct 1, 2024 at 11:27 PM Rosen Penev <rosenp@gmail.com> wrote:

> devm_regulator_get_enable_optional can be used to simplify the logic
> here.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>

Patch applied for v6.13!

Thanks!
Linus Walleij

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-10-02 13:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-01 21:27 [PATCH 1/2] pinctrl: aw9523: add missing mutex_destroy Rosen Penev
2024-10-01 21:27 ` [PATCH 2/2] pinctrl: aw9523: use enable for regulator Rosen Penev
2024-10-02 13:50   ` Linus Walleij
2024-10-02 13:49 ` [PATCH 1/2] pinctrl: aw9523: add missing mutex_destroy Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).