Changeset 4011
- Timestamp:
- 10/30/05 14:52:51 (3 years ago)
- Files:
-
- i2c/trunk/doc/writing-clients (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
i2c/trunk/doc/writing-clients
r4008 r4011 107 107 108 108 struct foo_data { 109 struct i2c_client client; 109 110 struct semaphore lock; /* For ISA access in `sensors' drivers. */ 110 111 int sysctl_id; /* To keep the /proc directory entry for … … 449 450 But it allows us to access several i2c functions safely */ 450 451 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))) { 457 453 err = -ENOMEM; 458 454 goto ERROR0; 459 455 } 460 456 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; 465 458 new_client->addr = address; 466 459 new_client->data = data; … … 559 552 /* SENSORS ONLY END */ 560 553 ERROR1: 561 kfree( new_client);554 kfree(data); 562 555 ERROR0: 563 556 return err; … … 592 585 /* SENSORS ONLY END */ 593 586 594 kfree(client ); /* Frees client data too, if allocated at the same time */587 kfree(client->data); 595 588 return 0; 596 589 }
