Linux I2C development
 help / color / mirror / Atom feed
From: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
To: Linux I2C <linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Cc: Randy Dunlap <randy.dunlap-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
Subject: [PATCH] i2c: Sanity checks on adapter registration
Date: Fri, 5 Nov 2010 13:42:30 +0100	[thread overview]
Message-ID: <20101105134230.16b1fb0b@endymion.delvare> (raw)

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

Signed-off-by: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
---
Randy, please apply this patch and check if it catches anything.

 drivers/i2c/i2c-core.c |   15 +++++++++++++++
 1 file changed, 15 insertions(+)

--- linux-2.6.37-rc1.orig/drivers/i2c/i2c-core.c	2010-11-05 11:37:34.000000000 +0100
+++ linux-2.6.37-rc1/drivers/i2c/i2c-core.c	2010-11-05 11:54:34.000000000 +0100
@@ -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);


-- 
Jean Delvare

                 reply	other threads:[~2010-11-05 12:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20101105134230.16b1fb0b@endymion.delvare \
    --to=khali-puyad+kwke1g9huczpvpmw@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=randy.dunlap-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox