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: <20240625063459.429953-1-W_Armin@gmx.de>
Date: Tue, 25 Jun 2024 08:34:58 +0200
From: Armin Wolf <W_Armin@....de>
To: arnd@...db.de,
	gregkh@...uxfoundation.org
Cc: hkallweit1@...il.com,
	u.kleine-koenig@...gutronix.de,
	srinivas.kandagatla@...aro.org,
	linux-kernel@...r.kernel.org
Subject: [PATCH 1/2] eeprom: ee1004: Use devres for bus data cleanup

Use devm_add_action_or_reset() to clean up the bus data at
driver removal or when an error occurs during probe.
This will allow us to use other devres-based APIs later.

Tested on a Dell Inspiron 3505.

Signed-off-by: Armin Wolf <W_Armin@....de>
---
 drivers/misc/eeprom/ee1004.c | 42 ++++++++++++++++++------------------
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/drivers/misc/eeprom/ee1004.c b/drivers/misc/eeprom/ee1004.c
index bf4f65dc6d9a..b1f760cc3be0 100644
--- a/drivers/misc/eeprom/ee1004.c
+++ b/drivers/misc/eeprom/ee1004.c
@@ -9,6 +9,7 @@
  * Copyright (C) 2008 Wolfram Sang, Pengutronix
  */

+#include <linux/device.h>
 #include <linux/i2c.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
@@ -207,6 +208,16 @@ static void ee1004_cleanup(int idx, struct ee1004_bus_data *bd)
 	}
 }

+static void ee1004_cleanup_bus_data(void *data)
+{
+	struct ee1004_bus_data *bd = data;
+
+	/* Remove page select clients if this is the last device */
+	mutex_lock(&ee1004_bus_lock);
+	ee1004_cleanup(EE1004_NUM_PAGES, bd);
+	mutex_unlock(&ee1004_bus_lock);
+}
+
 static int ee1004_probe(struct i2c_client *client)
 {
 	struct ee1004_bus_data *bd;
@@ -228,6 +239,10 @@ static int ee1004_probe(struct i2c_client *client)
 				     "Only %d busses supported", EE1004_MAX_BUSSES);
 	}

+	err = devm_add_action_or_reset(&client->dev, ee1004_cleanup_bus_data, bd);
+	if (err < 0)
+		return err;
+
 	i2c_set_clientdata(client, bd);

 	if (++bd->dev_count == 1) {
@@ -237,16 +252,18 @@ static int ee1004_probe(struct i2c_client *client)

 			cl = i2c_new_dummy_device(client->adapter, EE1004_ADDR_SET_PAGE + cnr);
 			if (IS_ERR(cl)) {
-				err = PTR_ERR(cl);
-				goto err_clients;
+				mutex_unlock(&ee1004_bus_lock);
+				return PTR_ERR(cl);
 			}
 			bd->set_page[cnr] = cl;
 		}

 		/* Remember current page to avoid unneeded page select */
 		err = ee1004_get_current_page(bd);
-		if (err < 0)
-			goto err_clients;
+		if (err < 0) {
+			mutex_unlock(&ee1004_bus_lock);
+			return err;
+		}
 		dev_dbg(&client->dev, "Currently selected page: %d\n", err);
 		bd->current_page = err;
 	}
@@ -260,22 +277,6 @@ static int ee1004_probe(struct i2c_client *client)
 		 EE1004_EEPROM_SIZE);

 	return 0;
-
- err_clients:
-	ee1004_cleanup(cnr, bd);
-	mutex_unlock(&ee1004_bus_lock);
-
-	return err;
-}
-
-static void ee1004_remove(struct i2c_client *client)
-{
-	struct ee1004_bus_data *bd = i2c_get_clientdata(client);
-
-	/* Remove page select clients if this is the last device */
-	mutex_lock(&ee1004_bus_lock);
-	ee1004_cleanup(EE1004_NUM_PAGES, bd);
-	mutex_unlock(&ee1004_bus_lock);
 }

 /*-------------------------------------------------------------------------*/
@@ -286,7 +287,6 @@ static struct i2c_driver ee1004_driver = {
 		.dev_groups = ee1004_groups,
 	},
 	.probe = ee1004_probe,
-	.remove = ee1004_remove,
 	.id_table = ee1004_ids,
 };
 module_i2c_driver(ee1004_driver);
--
2.39.2


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ