Skip to contentSkip to conversation

I2C: Check for unregistered adapter in i2c_del_adapter

PATCH New Jean Delvare 2 participants 2 messages May 19, 2005 I2C

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 I2C: Check for unregistered adapter in i2c_del_adapter

Hi Greg, hi all,

This is the patch we discussed about yesterday. I post it here so that it can receive the public reviewing it deserves.

The patch adds a check at the beginning of i2c_del_adapter in case someone attempts to remove an adapter that was never added in the first place. This sounds like a good safety, as doing so will lead to an oops at the moment. Also, I have a need for it in the latest version of my i2c-amd756-s4882 patch. I need to remove the original adapter and install the virtual ones instead, but I have no way to know if the original adapter was succesfully added beforehand or not.

Thanks.

drivers/i2c/i2c-core.c renamed from drivers/i2c/i2c-core.c.orig +13 -0
@@ -177,12 +177,25 @@
 int i2c_del_adapter(struct i2c_adapter *adap)
 {
 	struct list_head  *item, *_n;
+	struct i2c_adapter *adap_from_list;
 	struct i2c_driver *driver;
 	struct i2c_client *client;
 	int res = 0;
 
 	down(&core_lists);
 
+	/* First make sure that this adapter was ever added */
+	list_for_each_entry(adap_from_list, &adapters, list) {
+		if (adap_from_list = adap)
+			break;
+	}
+	if (adap_from_list != adap) {
+		pr_debug("I2C: Attempting to delete an unregistered "
+			 "adapter\n");
+		res = -EINVAL;
+		goto out_unlock;
+	}
+
 	list_for_each(item,&drivers) {
 		driver = list_entry(item, struct i2c_driver, list);
 		if (driver->detach_adapter)
Signature · 2 lines
Jean Delvare
http://khali.linux-fr.org/
Applied
#1 lore raw

PATCH 1/1 I2C: Check for unregistered adapter in

Quoted 13 lines · Jean Delvare

Hi Greg, hi all,

This is the patch we discussed about yesterday. I post it here so that it can receive the public reviewing it deserves.

The patch adds a check at the beginning of i2c_del_adapter in case someone attempts to remove an adapter that was never added in the first place. This sounds like a good safety, as doing so will lead to an oops at the moment. Also, I have a need for it in the latest version of my i2c-amd756-s4882 patch. I need to remove the original adapter and install the virtual ones instead, but I have no way to know if the original adapter was succesfully added beforehand or not.

Quoted 3 lines

Thanks.

Applied, thanks.

greg k-h