aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/i2c/writing-clients
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2005-10-17 17:16:25 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2005-10-28 17:02:12 -0400
commit2445eb62e98250f1ec8cbc8cf7c4be9cfafe88e5 (patch)
treed378cbfddb05c37d09cf03c71f070b02aed7a9cc /Documentation/i2c/writing-clients
parentdeb875c7ff2ef417a2daff41ee4b357098b7ab10 (diff)
[PATCH] i2c: Documentation update
Update the i2c documentation: kzalloc should be used instead of kmalloc. I also fixed a couple other things nearby in writing-clients, as several past changes had never been reported there. Signed-off-by: Jean Delvare <khali@linux-fr.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'Documentation/i2c/writing-clients')
-rw-r--r--Documentation/i2c/writing-clients16
1 files changed, 5 insertions, 11 deletions
diff --git a/Documentation/i2c/writing-clients b/Documentation/i2c/writing-clients
index 1882811c7f5d..e94d9c6cc522 100644
--- a/Documentation/i2c/writing-clients
+++ b/Documentation/i2c/writing-clients
@@ -55,6 +55,7 @@ be very useful.
55An example structure is below. 55An example structure is below.
56 56
57 struct foo_data { 57 struct foo_data {
58 struct i2c_client client;
58 struct semaphore lock; /* For ISA access in `sensors' drivers. */ 59 struct semaphore lock; /* For ISA access in `sensors' drivers. */
59 int sysctl_id; /* To keep the /proc directory entry for 60 int sysctl_id; /* To keep the /proc directory entry for
60 `sensors' drivers. */ 61 `sensors' drivers. */
@@ -307,22 +308,15 @@ For now, you can ignore the `flags' parameter. It is there for future use.
307 client structure, even though we cannot fill it completely yet. 308 client structure, even though we cannot fill it completely yet.
308 But it allows us to access several i2c functions safely */ 309 But it allows us to access several i2c functions safely */
309 310
310 /* Note that we reserve some space for foo_data too. If you don't 311 if (!(data = kzalloc(sizeof(struct foo_data), GFP_KERNEL))) {
311 need it, remove it. We do it here to help to lessen memory
312 fragmentation. */
313 if (! (new_client = kmalloc(sizeof(struct i2c_client) +
314 sizeof(struct foo_data),
315 GFP_KERNEL))) {
316 err = -ENOMEM; 312 err = -ENOMEM;
317 goto ERROR0; 313 goto ERROR0;
318 } 314 }
319 315
320 /* This is tricky, but it will set the data to the right value. */ 316 new_client = &data->client;
321 client->data = new_client + 1; 317 i2c_set_clientdata(new_client, data);
322 data = (struct foo_data *) (client->data);
323 318
324 new_client->addr = address; 319 new_client->addr = address;
325 new_client->data = data;
326 new_client->adapter = adapter; 320 new_client->adapter = adapter;
327 new_client->driver = &foo_driver; 321 new_client->driver = &foo_driver;
328 new_client->flags = 0; 322 new_client->flags = 0;
@@ -448,7 +442,7 @@ much simpler than the attachment code, fortunately!
448 release_region(client->addr,LM78_EXTENT); 442 release_region(client->addr,LM78_EXTENT);
449 /* HYBRID SENSORS CHIP ONLY END */ 443 /* HYBRID SENSORS CHIP ONLY END */
450 444
451 kfree(client); /* Frees client data too, if allocated at the same time */ 445 kfree(data);
452 return 0; 446 return 0;
453 } 447 }
454 448