Use size_t cast instead of fixed-length integer cast
authorRobert Tivy <rtivy@ti.com>
Mon, 4 Nov 2013 23:55:44 +0000 (15:55 -0800)
committerChris Ring <cring@ti.com>
Thu, 7 Nov 2013 01:50:06 +0000 (17:50 -0800)
When using fixed-length integer-based cast (unsigned int or unsigned long)
to or from a pointer type, errors/warnings are thrown from one compiler
or another, depending on the integer size vs. the pointer size.  The
size_t type adjusts based on pointer size, so it allows a clean compile.

Also had to add a cast after existing cast, creating an ugly double-cast.

Signed-off-by: Robert Tivy <rtivy@ti.com>
packages/ti/ipc/rpmsg/virtio_ring.h

index cc0a7e06f73174f8e348df3a05725474293f921e..a9d47c54bc3f341d5f28a7165de70ea260f8ce47 100644 (file)
@@ -130,15 +130,16 @@ static inline void vring_init(struct vring *vr, unsigned int num, void *p,
 {
     vr->num = num;
     vr->desc = p;
-    vr->avail = (struct vring_avail *)
-                    ((unsigned)p + (num * sizeof(struct vring_desc)));
+    vr->avail = (struct vring_avail *)(size_t)
+                    ((size_t)p + (num * sizeof(struct vring_desc)));
     /*
      * Suppress Coverity Error: Indexing "vr->avail->ring" with "num".
      * This should be OK, because this is just address calculation:
      */
     /* coverity[index_parm] */
-    vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + pagesize-1)
-                & ~(pagesize - 1));
+    vr->used = (struct vring_used *)(size_t)
+                   (((size_t)&vr->avail->ring[num] + pagesize-1) &
+                   ~(pagesize - 1));
 }
 
 static inline unsigned vring_size(unsigned int num, unsigned long pagesize)