lkml.org 
[lkml]   [2004]   [Aug]   [6]   [last100]   RSS Feed
Views: [more markup]  [less markup]  [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
FromThomas Koeller <>
SubjectRe: [PATCH] Device class reference counting
DateFri, 6 Aug 2004 11:37:46 +0200
On Friday 06 August 2004 00:46, Greg KH wrote:
> On Fri, Jul 30, 2004 at 06:03:00PM +0200, Thomas Koeller wrote:
> > Hi,
> >
> > I found a little issue with reference counting for
> > device classes in 2.6.8-rc2. Patch attached.
> >
> > --- linux-mips/drivers/base/class.c	2004-07-14 16:21:33.000000000 +0200
> > +++ linux-mips-work/drivers/base/class.c	2004-07-30 17:51:09.477331128
> > +0200 @@ -353,8 +353,8 @@
> >  	struct class_interface * class_intf;
> >  	int error;
> >
> > -	class_dev = class_device_get(class_dev);
> > -	if (!class_dev || !strlen(class_dev->class_id))
> > +	if (!strlen(class_dev->class_id)
> > +		|| !(class_dev = class_device_get(class_dev)))
> >  		return -EINVAL;
>
> I don't understand what you are trying to fix here.  In fact, if
> class_dev is NULL, you will now oops.
>
> Hm, I guess if class_dev->class_id is null, we will exit with an extra
> reference grabbed on the class_dev.  Is that what you are trying to fix
> here?
>
> If so, please rework the patch.
>
> thanks,
>
> greg k-h

You guessed it - pretty obvious, isn't it? Well, I assumed the case
where class_dev is NULL didn't matter, as this could only happen if
there is a bug in some other place - seems I was wrong. So how's
about this patch:


--- linux-mips/drivers/base/class.c     2004-07-14 16:21:33.000000000 +0200
+++ linux-mips-work/drivers/base/class.c        2004-08-06 11:06:10.983688216 +0200
@@ -349,14 +349,19 @@

 int class_device_add(struct class_device *class_dev)
 {
-       struct class * parent;
+       struct class * parent = NULL;
        struct class_interface * class_intf;
        int error;

        class_dev = class_device_get(class_dev);
-       if (!class_dev || !strlen(class_dev->class_id))
+       if (!class_dev)
                return -EINVAL;

+       if (!strlen(class_dev->class_id)) {
+               error = -EINVAL;
+               goto register_done;
+       }
+
        parent = class_get(class_dev->class);

        pr_debug("CLASS: registering class device: ID = '%s'\n",


-- 
--------------------------------------------------
Thomas Koeller, Software Development
Basler Vision Technologies

thomas dot koeller at baslerweb dot com
http://www.baslerweb.com

==============================
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
\
 
 \ /
  Last update: 2005-03-22 14:05    [from the cache]
©2003-2008