Skip to contentSkip to conversation

i2c: Sanity checks on adapter registration

PATCH New Jean Delvare 1 participant 1 message Nov 5, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: Sanity checks on adapter registration

Make sure I2C adapters being registered have the required struct fields set. If they don't, problems will happen later.

---
Randy, please apply this patch and check if it catches anything.

 drivers/i2c/i2c-core.c |   15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/i2c/i2c-core.c +15 -0
@@ -848,6 +848,21 @@ static int i2c_register_adapter(struct i
 		goto out_list;
 	}
 
+	/* Sanity checks */
+	if (adap->name[0] == '\0') {
+		pr_err("i2c-core: Attempt to register an adapter with "
+		       "no name!\n");
+		return -EINVAL;
+	}
+	if (!adap->algo) {
+		pr_err("i2c-core: Attempt to register adapter '%s' with "
+		       "no algo!\n", adap->name);
+		return -EINVAL;
+	}
+	if (!adap->owner)
+		pr_warn("i2c-core: Attempt to register adapter '%s' with "
+		       "no owner!\n", adap->name);
+
 	rt_mutex_init(&adap->bus_lock);
 	mutex_init(&adap->userspace_clients_lock);
 	INIT_LIST_HEAD(&adap->userspace_clients);
Signature · 1 line
Jean Delvare