[2.5][CHECKER] i2c-core locking

[2.5][CHECKER] i2c-core locking

Post by Zwane Mwaikamb » Tue, 04 Mar 2003 06:40:04



This one looks like it wasn't dropping the driver mutex on some exit
paths.

Index: linux-2.5.62-numaq/drivers/i2c/i2c-core.c
===================================================================
RCS file: /build/cvsroot/linux-2.5.62/drivers/i2c/i2c-core.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 i2c-core.c
--- linux-2.5.62-numaq/drivers/i2c/i2c-core.c   18 Feb 2003 00:15:36 -0000      1.1.1.1

 {
        int i,j,k,res;

+       ADAP_LOCK();
        DRV_LOCK();
        for (i = 0; i < I2C_DRIVER_MAX; i++)

                                    "[%s] not found\n",
                        driver->name);
                DRV_UNLOCK();
+               ADAP_UNLOCK();
                return -ENODEV;
        }

         * invalid operation might (will!) result, when using stale client
         * pointers.
         */
-       ADAP_LOCK(); /* should be moved inside the if statement... */
        for (k=0;k<I2C_ADAP_MAX;k++) {
                struct i2c_adapter *adap = adapters[k];

                                       "not be detached properly; driver "
                                       "not unloaded!",driver->name,
                                       adap->name);
+                               DRV_UNLOCK();
                                ADAP_UNLOCK();
                                return res;

                                                       driver->name,
                                                       client->addr,
                                                       adap->name);
+                                               DRV_UNLOCK();
                                                ADAP_UNLOCK();
                                                return res;

                        }
                }
        }
-       ADAP_UNLOCK();
        drivers[i] = NULL;
        driver_count--;
        DRV_UNLOCK();
-      
+       ADAP_UNLOCK();  
        DEB(printk(KERN_DEBUG "i2c-core.o: driver unregistered: %s\n",driver->name));
        return 0;
 }
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

[2.5][CHECKER] i2c-core locking

Post by Christoph Hellwi » Tue, 04 Mar 2003 09:50:06



> This one looks like it wasn't dropping the driver mutex on some exit
> paths.

Please leave this as-is for now.  lm_sensors CVS has replaced the two
with a single semaphore and I plan to bring their changes over to
mainline soon.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

1. [I2C] fix unsafe usage of list_for_each in i2c-core

Hi,

i2c-core.c contains 2 loops that iterate over the list of the clients attached
to an adapter and detaches them. Detaching the clients will actually remove
them from the list the loop is iterating over. Therefore the
list_for_each_safe() method has to be used.

Andreas

===== i2c-core.c 1.38 vs edited =====
--- 1.38/drivers/i2c/i2c-core.c Mon May 26 02:00:00 2003

 int i2c_del_adapter(struct i2c_adapter *adap)
 {
-       struct list_head  *item;
+       struct list_head  *item, *_n;
        struct i2c_driver *driver;
        struct i2c_client *client;

        /* detach any active clients. This must be done first, because
         * it can fail; in which case we give upp. */
-       list_for_each(item,&adap->clients) {
+       list_for_each_safe(item, _n, &adap->clients) {
                client = list_entry(item, struct i2c_client, list);


 int i2c_del_driver(struct i2c_driver *driver)
 {
-       struct list_head   *item1;
-       struct list_head   *item2;
+       struct list_head   *item1, *item2, *_n;
        struct i2c_client  *client;
        struct i2c_adapter *adap;

                                goto out_unlock;
                        }
                } else {
-                       list_for_each(item2,&adap->clients) {
+                       list_for_each_safe(item2, _n, &adap->clients) {
                                client = list_entry(item2, struct i2c_client, list);
                                if (client->driver != driver)
                                        continue;

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

2. xmh-pop-1.2

3. [2.5][CHECKER] rtc locking

4. ips.c remove tqueue.h

5. i2c #1/3: listify i2c core

6. Writing TCP server.

7. Error on i2c-core.o

8. Newbie Question: How to install openwin....

9. [2.5] fix most obvious i2c driver flaws

10. remove i2c-old.c from 2.5.x tree?

11. [2.5][RESEND] fix i2c-drivers in drivers/media/video

12. driver core support for i2c bus and drivers