public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
From: David Brownell <david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
To: Greg KH <greg-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
Cc: i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
Subject: Re: class_for_each_device() oops
Date: Wed, 23 Jul 2008 16:43:47 -0700	[thread overview]
Message-ID: <200807231643.47802.david-b@pacbell.net> (raw)
In-Reply-To: <20080723231859.GB30234-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>

On Wednesday 23 July 2008, Greg KH wrote:
> > In this case adding 
> > 
> >       if (!class->p)
> >               return -EINVAL;
> > 
> > at the top of class_for_each_device() would prevent such
> > oopses from ever happening.
> 
> Makes sense, care to send a real patch for this?

Here you go ... I noticed another place with the same
type of oops-affinity, and fixed that too.

===== CUT HERE
From: David Brownell <dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>

Anti-oops medicine for the class iterators ... the oops was
observed when a class was implicitly referenced before it
was initialized.

Signed-off-by: David Brownell <dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
---
 drivers/base/class.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/drivers/base/class.c	2008-07-22 15:27:52.000000000 -0700
+++ b/drivers/base/class.c	2008-07-23 16:39:58.000000000 -0700
@@ -292,7 +292,7 @@ int class_for_each_device(struct class *
 	struct device *dev;
 	int error = 0;
 
-	if (!class)
+	if (!class || !class->p)
 		return -EINVAL;
 	mutex_lock(&class->p->class_mutex);
 	list_for_each_entry(dev, &class->p->class_devices, node) {
@@ -341,7 +341,7 @@ struct device *class_find_device(struct 
 	struct device *dev;
 	int found = 0;
 
-	if (!class)
+	if (!class || !class->p)
 		return NULL;
 
 	mutex_lock(&class->p->class_mutex);


_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c

      parent reply	other threads:[~2008-07-23 23:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-23 23:06 class_for_each_device() oops David Brownell
     [not found] ` <200807231606.48016.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2008-07-23 23:18   ` Greg KH
     [not found]     ` <20080723231859.GB30234-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2008-07-23 23:43       ` David Brownell [this message]

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=200807231643.47802.david-b@pacbell.net \
    --to=david-b-ybekhbn/0ldr7s880joybq@public.gmane.org \
    --cc=greg-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org \
    --cc=i2c-GZX6beZjE8VD60Wz+7aTrA@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