Show
Ignore:
Timestamp:
07/18/99 14:40:50 (15 years ago)
Author:
frodo
Message:

Second part of Kyösti Mälkki's patches

MOD_{INC,DEC}_USE_COUNT should now really be fail-safe.

I wrote in email to Kyösti about this:

If I understand it correctly, the scheme you propose is as follows:

  • Each struct i2c_algorithm variable has inc_use and dec_use hooks in it.
  • The hooks should do a MOD_{INC,DEC}_USE_COUNT in the appropriate adapter modules (of course, these can only be done in the module which needs to be locked)
  • The struct i2c_driver had already similar hooks, for locking the client modules
  • The i2c_{inc,dec}_use_client function should *not* be called when a client is (de)registered; instead, it should only be called when a resource is used that makes it impossible to remove the client and its adapter. For example, the opening of a /proc file or the moving into a /proc directory owned by the client driver. I have applied the changes to i2c-core and i2c.h as in your patch, as well as to i2c-algo-bit. I saw you added MOD_INC_USE_COUNT to the algorithm drivers. That means we can't remove an algorithm module if an adapter module is still connected to it. Perhaps we should do the same as the in the case a driver module is deleted: scan for connected adapters and remove them one by one (including their clients, of course). What do you think? As i2c-algo-pcf is structured similar to i2c-algo-bit, I saw no reason not to apply the same patches to it, including the MOD_{INC,DEC}_USE_COUNT patch. If you know of a reason why I should not have done this, please tell me and/or revert the changes. I know this will break PCF adapter drivers; well, too bad :-) All included adapter drivers have been patched to do MOD_{INC,DEV}_USE_COUNT calls.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • i2c/trunk/kernel/i2c-algo-bit.c

    r3315 r3317  
    523523} 
    524524 
     525static void inc_use(struct i2c_adapter *adapter) 
     526{ 
     527        struct bit_adapter *adap = (struct bit_adapter*)adapter->data; 
     528 
     529        if (adap->inc_use != NULL) 
     530                adap->inc_use(adap); 
     531} 
     532 
     533static void dec_use(struct i2c_adapter *adapter) 
     534{ 
     535        struct bit_adapter *adap = (struct bit_adapter*)adapter->data; 
     536 
     537        if (adap->dec_use != NULL) 
     538                adap->dec_use(adap); 
     539} 
     540 
     541 
    525542/* -----exported algorithm data: -------------------------------------  */ 
    526543 
     
    539556        client_register, 
    540557        client_unregister, 
     558        inc_use, 
     559        dec_use 
    541560}; 
    542561 
     
    578597        i2c_adap->retries = 3;          /* be replaced by defines       */ 
    579598        i2c_adaps[i] = i2c_adap; 
    580         i2c_add_adapter(i2c_adap); 
    581599 
    582600        /* scan bus */ 
     
    594612                printk("\n"); 
    595613        } 
     614 
     615#ifdef MODULE 
     616        MOD_INC_USE_COUNT; 
     617#endif 
     618        i2c_add_adapter(i2c_adap); 
     619 
    596620        return 0; 
    597621} 
     
    617641        adap_count--; 
    618642        DEB2(printk("i2c(bit): adapter unregistered: %s\n",adap->name)); 
    619  
     643#ifdef MODULE 
     644        MOD_DEC_USE_COUNT; 
     645#endif 
    620646        return 0; 
    621647}