lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <95be5a0c504611263952d850124f053fd6204e94.1756573982.git.christophe.jaillet@wanadoo.fr>
Date: Sat, 30 Aug 2025 19:13:59 +0200
From: Christophe JAILLET <christophe.jaillet@...adoo.fr>
To: Andrew Lunn <andrew@...n.ch>,
	Vladimir Oltean <olteanv@...il.com>,
	"David S. Miller" <davem@...emloft.net>,
	Eric Dumazet <edumazet@...gle.com>,
	Jakub Kicinski <kuba@...nel.org>,
	Paolo Abeni <pabeni@...hat.com>,
	Russell King <linux@...linux.org.uk>,
	Helmut Buchsbaum <helmut.buchsbaum@...il.com>
Cc: linux-kernel@...r.kernel.org,
	kernel-janitors@...r.kernel.org,
	Christophe JAILLET <christophe.jaillet@...adoo.fr>,
	netdev@...r.kernel.org
Subject: [PATCH net] net: dsa: ks8995: Fix some error handling path in ks8995_probe()

If an error occurs after calling gpiod_set_value_cansleep(..., 0), it must
be undone by a corresponding gpiod_set_value_cansleep(..., 1) call as
already done in the remove function.

In order to easily do the needed clean-up in the probe, add a new
devm_add_action_or_reset() call and simplify the remove function
accordingly.

Fixes: cd6f288cbaab ("net: phy: spi_ks8995: add support for resetting switch using GPIO")
Signed-off-by: Christophe JAILLET <christophe.jaillet@...adoo.fr>
---
Compile tested only
---
 drivers/net/dsa/ks8995.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/net/dsa/ks8995.c b/drivers/net/dsa/ks8995.c
index 5c4c83e00477..debb2cd7ab61 100644
--- a/drivers/net/dsa/ks8995.c
+++ b/drivers/net/dsa/ks8995.c
@@ -742,6 +742,14 @@ static const struct dsa_switch_ops ks8995_ds_ops = {
 	.phylink_get_caps = ks8995_phylink_get_caps,
 };
 
+static void devm_reset_assert(void *data)
+{
+	struct ks8995_switch *ks = data;
+
+	/* assert reset */
+	gpiod_set_value_cansleep(ks->reset_gpio, 1);
+}
+
 /* ------------------------------------------------------------------------ */
 static int ks8995_probe(struct spi_device *spi)
 {
@@ -784,6 +792,11 @@ static int ks8995_probe(struct spi_device *spi)
 		 */
 		gpiod_set_value_cansleep(ks->reset_gpio, 0);
 		udelay(100);
+
+		err = devm_add_action_or_reset(&spi->dev,
+					       devm_reset_assert, ks);
+		if (err)
+			return err;
 	}
 
 	spi_set_drvdata(spi, ks);
@@ -834,8 +847,6 @@ static void ks8995_remove(struct spi_device *spi)
 	struct ks8995_switch *ks = spi_get_drvdata(spi);
 
 	dsa_unregister_switch(ks->ds);
-	/* assert reset */
-	gpiod_set_value_cansleep(ks->reset_gpio, 1);
 }
 
 /* ------------------------------------------------------------------------ */
-- 
2.51.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ