[PATCH 14/14] i2c: Documentation update

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Content-Disposition: inline; filename=kzalloc-06-i2c-documentation-update.patch

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 at linux-fr.org>

---
 Documentation/i2c/porting-clients |    2 +-
 Documentation/i2c/writing-clients |   16 +++++-----------
 2 files changed, 6 insertions(+), 12 deletions(-)

--- linux-2.6.14-rc4.orig/Documentation/i2c/writing-clients	2005-10-13 23:14:21.000000000 +0200
+++ linux-2.6.14-rc4/Documentation/i2c/writing-clients	2005-10-13 23:15:45.000000000 +0200
@@ -55,6 +55,7 @@
 An example structure is below.
 
   struct foo_data {
+    struct i2c_client client;
     struct semaphore lock; /* For ISA access in `sensors' drivers. */
     int sysctl_id;         /* To keep the /proc directory entry for 
                               `sensors' drivers. */
@@ -307,22 +308,15 @@
        client structure, even though we cannot fill it completely yet.
        But it allows us to access several i2c functions safely */
     
-    /* Note that we reserve some space for foo_data too. If you don't
-       need it, remove it. We do it here to help to lessen memory
-       fragmentation. */
-    if (! (new_client = kmalloc(sizeof(struct i2c_client) + 
-                                sizeof(struct foo_data),
-                                GFP_KERNEL))) {
+    if (!(data = kzalloc(sizeof(struct foo_data), GFP_KERNEL))) {
       err = -ENOMEM;
       goto ERROR0;
     }
 
-    /* This is tricky, but it will set the data to the right value. */
-    client->data = new_client + 1;
-    data = (struct foo_data *) (client->data);
+    new_client = &data->client;
+    i2c_set_clientdata(new_client, data);
 
     new_client->addr = address;
-    new_client->data = data;
     new_client->adapter = adapter;
     new_client->driver = &foo_driver;
     new_client->flags = 0;
@@ -448,7 +442,7 @@
       release_region(client->addr,LM78_EXTENT);
     /* HYBRID SENSORS CHIP ONLY END */
 
-    kfree(client); /* Frees client data too, if allocated at the same time */
+    kfree(data);
     return 0;
   }
 
--- linux-2.6.14-rc4.orig/Documentation/i2c/porting-clients	2005-09-13 21:20:58.000000000 +0200
+++ linux-2.6.14-rc4/Documentation/i2c/porting-clients	2005-10-13 23:16:28.000000000 +0200
@@ -82,7 +82,7 @@
   exit and exit_free. For i2c+isa drivers, labels should be named
   ERROR0, ERROR1 and ERROR2. Don't forget to properly set err before
   jumping to error labels. By the way, labels should be left-aligned.
-  Use memset to fill the client and data area with 0x00.
+  Use kzalloc instead of kmalloc.
   Use i2c_set_clientdata to set the client data (as opposed to
   a direct access to client->data).
   Use strlcpy instead of strcpy to copy the client name.

-- 
Jean Delvare




[Index of Archives]     [Linux Kernel]     [Linux Hardware Monitoring]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux