Changeset 4011

Show
Ignore:
Timestamp:
10/30/05 14:52:51 (3 years ago)
Author:
khali
Message:

Update to reflect the "new" memory allocation model. Backport
from Linux 2.6.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • i2c/trunk/doc/writing-clients

    r4008 r4011  
    107107 
    108108  struct foo_data { 
     109    struct i2c_client client; 
    109110    struct semaphore lock; /* For ISA access in `sensors' drivers. */ 
    110111    int sysctl_id;         /* To keep the /proc directory entry for  
     
    449450       But it allows us to access several i2c functions safely */ 
    450451     
    451     /* Note that we reserve some space for foo_data too. If you don't 
    452        need it, remove it. We do it here to help to lessen memory 
    453        fragmentation. */ 
    454     if (! (new_client = kmalloc(sizeof(struct i2c_client) +  
    455                                 sizeof(struct foo_data), 
    456                                 GFP_KERNEL))) { 
     452    if (!(data = kzalloc(sizeof(struct foo_data), GFP_KERNEL))) { 
    457453      err = -ENOMEM; 
    458454      goto ERROR0; 
    459455    } 
    460456 
    461     /* This is tricky, but it will set the data to the right value. */ 
    462     client->data = new_client + 1; 
    463     data = (struct foo_data *) (client->data); 
    464  
     457    new_client = &data->client; 
    465458    new_client->addr = address; 
    466459    new_client->data = data; 
     
    559552    /* SENSORS ONLY END */ 
    560553    ERROR1: 
    561       kfree(new_client); 
     554      kfree(data); 
    562555    ERROR0: 
    563556      return err; 
     
    592585    /* SENSORS ONLY END */ 
    593586 
    594     kfree(client); /* Frees client data too, if allocated at the same time */ 
     587    kfree(client->data); 
    595588    return 0; 
    596589  }