diff options
author | Jean Delvare <khali@linux-fr.org> | 2005-10-17 17:16:25 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2005-10-28 17:02:12 -0400 |
commit | 2445eb62e98250f1ec8cbc8cf7c4be9cfafe88e5 (patch) | |
tree | d378cbfddb05c37d09cf03c71f070b02aed7a9cc /Documentation/i2c | |
parent | deb875c7ff2ef417a2daff41ee4b357098b7ab10 (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')
-rw-r--r-- | Documentation/i2c/porting-clients | 2 | ||||
-rw-r--r-- | Documentation/i2c/writing-clients | 16 |
2 files changed, 6 insertions, 12 deletions
diff --git a/Documentation/i2c/porting-clients b/Documentation/i2c/porting-clients index 4849dfd6961c..184fac2377aa 100644 --- a/Documentation/i2c/porting-clients +++ b/Documentation/i2c/porting-clients | |||
@@ -82,7 +82,7 @@ Technical changes: | |||
82 | exit and exit_free. For i2c+isa drivers, labels should be named | 82 | exit and exit_free. For i2c+isa drivers, labels should be named |
83 | ERROR0, ERROR1 and ERROR2. Don't forget to properly set err before | 83 | ERROR0, ERROR1 and ERROR2. Don't forget to properly set err before |
84 | jumping to error labels. By the way, labels should be left-aligned. | 84 | jumping to error labels. By the way, labels should be left-aligned. |
85 | Use memset to fill the client and data area with 0x00. | 85 | Use kzalloc instead of kmalloc. |
86 | Use i2c_set_clientdata to set the client data (as opposed to | 86 | Use i2c_set_clientdata to set the client data (as opposed to |
87 | a direct access to client->data). | 87 | a direct access to client->data). |
88 | Use strlcpy instead of strcpy to copy the client name. | 88 | Use strlcpy instead of strcpy to copy the client name. |
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. | |||
55 | An example structure is below. | 55 | An 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 | ||