[cpia] [PATCH] Devices do not get de-registered on module removal

Duncan Haldane f.duncan.m.haldane@worldnet.att.net
Fri, 18 Oct 2002 03:01:00 -0400 (EDT)


Hi

I've been maintaining the old cpia driver at sourceforge..

I finally got round to fixing (in CVS) this problem reported by Nick Holloway.
(but more conservatively than his patch...) It seems to have crept in by an
earlier "code cleanup".....

Are there any advantages to Nick's
fix that I havent appreciated? (see his patch posted in August).

I've been feeding updates from CVS to the official
kernel via Alan Cox.  Some will be in 2.4.20.

P.S. Is the cpia list still working?  (Peter, can you check ,if this email
doesnt
get resent to the list).



diff -uNr module/cpia.h module-fixed/cpia.h
--- module/cpia.h       Sat May 11 14:51:02 2002
+++ module-fixed/cpia.h Fri Oct 18 02:41:48 2002
@@ -419,16 +419,20 @@
       (p)&0x80?1:0, (p)&0x40?1:0, (p)&0x20?1:0, (p)&0x10?1:0,\
         (p)&0x08?1:0, (p)&0x04?1:0, (p)&0x02?1:0, (p)&0x01?1:0);
 
-static inline void cpia_add_to_list(struct cam_data* l, struct cam_data* drv)
+static inline void cpia_add_to_list(struct cam_data** l, struct cam_data**
drv_p)
 {
-       drv->next = l;
-       drv->previous = &l;
-       l = drv;
+       struct cam_data* drv;
+       drv = *drv_p;
+       drv->next = *l;
+       drv->previous = l;
+       *l = drv;
 }
 
 
-static inline void cpia_remove_from_list(struct cam_data* drv)
+static inline void cpia_remove_from_list(struct cam_data** drv_p)
 {
+       struct cam_data* drv;
+       drv = *drv_p;
        if (drv->previous != NULL) {
                if (drv->next != NULL)
                        drv->next->previous = drv->previous;
diff -uNr module/cpia_pp.c module-fixed/cpia_pp.c
--- module/cpia_pp.c    Thu May  9 20:36:11 2002
+++ module-fixed/cpia_pp.c      Fri Oct 18 02:42:00 2002
@@ -1507,7 +1507,7 @@
                return -ENXIO;
        }
        spin_lock( &cam_list_lock_pp );
-       cpia_add_to_list(cam_list, cpia);
+       cpia_add_to_list(&cam_list, &cpia);
        spin_unlock( &cam_list_lock_pp );
 
        return 0;
@@ -1521,7 +1521,7 @@
        for(cpia = cam_list; cpia != NULL; cpia = cpia->next) {
                struct pp_cam_entry *cam = cpia->lowlevel_data;
                if (cam && cam->port->number == port->number) {
-                       cpia_remove_from_list(cpia);
+                       cpia_remove_from_list(&cpia);
                        spin_unlock( &cam_list_lock_pp );
                        
 #ifdef CONFIG_VIDEO_CPIA_PP_DMA
diff -uNr module/cpia_usb.c module-fixed/cpia_usb.c
--- module/cpia_usb.c   Thu May  9 20:00:50 2002
+++ module-fixed/cpia_usb.c     Fri Oct 18 02:41:56 2002
@@ -565,7 +565,7 @@
        }
 
        spin_lock( &cam_list_lock_usb );
-       cpia_add_to_list(cam_list, cam);
+       cpia_add_to_list(&cam_list, &cam);
        spin_unlock( &cam_list_lock_usb );
 
        return cam;
@@ -617,7 +617,7 @@
        struct usb_cpia *ucpia = (struct usb_cpia *) cam->lowlevel_data;
   
        spin_lock( &cam_list_lock_usb );
-       cpia_remove_from_list(cam);
+       cpia_remove_from_list(&cam);
        spin_unlock( &cam_list_lock_usb );
        
        /* Don't even try to reset the altsetting if we're disconnected */



On 07-Aug-2002 Nick Holloway wrote:
> I've been using a parport cpia camera, with the driver compiled as
> modules.  I found that if the camera had been used, and the modules
> unloaded, the next attempt to load caused an oops.
> 
> I discovered that this was due to the camera not getting deregistered
> when the module was unloaded.
> 
> Several DBGs and recompiles later, I tracked this down to "cam_list"
> never containing any entries, because "cpia_add_to_list" doesn't manage
> to add the camera to the list (code looks OK at first glance, but doesn't
> actually modify "cam_list", but just its local copy).
> 
> Here is a patch to use the double-linked list implementation from
> "linux/list.h".  This patch is against the current CVS tree.
> 
> I've tested cpia_pp with a single camera with kernel 2.4.18.  I've updated
> the 2.2.x style deregistration, but I can't test it, as my parport needs
> 2.4 to be used with the camera.  I've updated cpia_usb, but I also can't
> test this.
> 
> -- 
>  `O O'  | Nick.Holloway@pyrites.org.uk
> // ^ \\ | http://www.pyrites.org.uk/

----------------------------------
E-Mail: Duncan Haldane <f.duncan.m.haldane@worldnet.att.net>
Date: 18-Oct-2002
Time: 02:48:39

This message was sent by XFMail
----------------------------------