[libdrm] Fix void pointer arithmetic in drmProcessPciDevice
diff mbox

Message ID 1444794948-29135-1-git-send-email-michel@daenzer.net
State New
Headers show

Commit Message

Michel Dänzer Oct. 14, 2015, 3:55 a.m. UTC
From: Michel Dänzer <michel.daenzer@amd.com>

Arithmetic on void pointers is a GCC extension.

  CC       libdrm_la-xf86drm.lo
../xf86drm.c: In function 'drmProcessPciDevice':
../xf86drm.c:3017:10: warning: pointer of type 'void *' used in arithmetic [-Wpointer-arith]
     addr += sizeof(drmDevice);
          ^
../xf86drm.c:3020:10: warning: pointer of type 'void *' used in arithmetic [-Wpointer-arith]
     addr += DRM_NODE_MAX * sizeof(void *);
          ^
../xf86drm.c:3023:14: warning: pointer of type 'void *' used in arithmetic [-Wpointer-arith]
         addr += max_node_str;
              ^
../xf86drm.c:3035:14: warning: pointer of type 'void *' used in arithmetic [-Wpointer-arith]
         addr += sizeof(drmPciBusInfo);
              ^

Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
---
 xf86drm.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

Comments

Alex Deucher Oct. 14, 2015, 3:44 p.m. UTC | #1
On Tue, Oct 13, 2015 at 11:55 PM, Michel Dänzer <michel@daenzer.net> wrote:
> From: Michel Dänzer <michel.daenzer@amd.com>
>
> Arithmetic on void pointers is a GCC extension.
>
>   CC       libdrm_la-xf86drm.lo
> ../xf86drm.c: In function 'drmProcessPciDevice':
> ../xf86drm.c:3017:10: warning: pointer of type 'void *' used in arithmetic [-Wpointer-arith]
>      addr += sizeof(drmDevice);
>           ^
> ../xf86drm.c:3020:10: warning: pointer of type 'void *' used in arithmetic [-Wpointer-arith]
>      addr += DRM_NODE_MAX * sizeof(void *);
>           ^
> ../xf86drm.c:3023:14: warning: pointer of type 'void *' used in arithmetic [-Wpointer-arith]
>          addr += max_node_str;
>               ^
> ../xf86drm.c:3035:14: warning: pointer of type 'void *' used in arithmetic [-Wpointer-arith]
>          addr += sizeof(drmPciBusInfo);
>               ^
>
> Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

> ---
>  xf86drm.c | 19 ++++++++++---------
>  1 file changed, 10 insertions(+), 9 deletions(-)
>
> diff --git a/xf86drm.c b/xf86drm.c
> index 27313cc..a29db42 100644
> --- a/xf86drm.c
> +++ b/xf86drm.c
> @@ -3001,21 +3001,22 @@ static int drmProcessPciDevice(drmDevicePtr *device, const char *d_name,
>  {
>      const int max_node_str = drmGetMaxNodeName();
>      int ret, i;
> -    void *addr;
> +    char *addr;
>
> -    addr = *device = calloc(1, sizeof(drmDevice) +
> -                               (DRM_NODE_MAX *
> -                                (sizeof(void *) + max_node_str)) +
> -                               sizeof(drmPciBusInfo) +
> -                               sizeof(drmPciDeviceInfo));
> +    *device = calloc(1, sizeof(drmDevice) +
> +                    (DRM_NODE_MAX * (sizeof(void *) + max_node_str)) +
> +                    sizeof(drmPciBusInfo) +
> +                    sizeof(drmPciDeviceInfo));
>      if (!*device)
>          return -ENOMEM;
>
> +    addr = (char*)*device;
> +
>      (*device)->bustype = DRM_BUS_PCI;
>      (*device)->available_nodes = 1 << node_type;
>
>      addr += sizeof(drmDevice);
> -    (*device)->nodes = addr;
> +    (*device)->nodes = (char**)addr;
>
>      addr += DRM_NODE_MAX * sizeof(void *);
>      for (i = 0; i < DRM_NODE_MAX; i++) {
> @@ -3024,7 +3025,7 @@ static int drmProcessPciDevice(drmDevicePtr *device, const char *d_name,
>      }
>      memcpy((*device)->nodes[node_type], node, max_node_str);
>
> -    (*device)->businfo.pci = addr;
> +    (*device)->businfo.pci = (drmPciBusInfoPtr)addr;
>
>      ret = drmParsePciBusInfo(maj, min, (*device)->businfo.pci);
>      if (ret)
> @@ -3033,7 +3034,7 @@ static int drmProcessPciDevice(drmDevicePtr *device, const char *d_name,
>      // Fetch the device info if the user has requested it
>      if (fetch_deviceinfo) {
>          addr += sizeof(drmPciBusInfo);
> -        (*device)->deviceinfo.pci = addr;
> +        (*device)->deviceinfo.pci = (drmPciDeviceInfoPtr)addr;
>
>          ret = drmParsePciDeviceInfo(d_name, (*device)->deviceinfo.pci);
>          if (ret)
> --
> 2.6.0
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel

Patch
diff mbox

diff --git a/xf86drm.c b/xf86drm.c
index 27313cc..a29db42 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -3001,21 +3001,22 @@  static int drmProcessPciDevice(drmDevicePtr *device, const char *d_name,
 {
     const int max_node_str = drmGetMaxNodeName();
     int ret, i;
-    void *addr;
+    char *addr;
 
-    addr = *device = calloc(1, sizeof(drmDevice) +
-                               (DRM_NODE_MAX *
-                                (sizeof(void *) + max_node_str)) +
-                               sizeof(drmPciBusInfo) +
-                               sizeof(drmPciDeviceInfo));
+    *device = calloc(1, sizeof(drmDevice) +
+		     (DRM_NODE_MAX * (sizeof(void *) + max_node_str)) +
+		     sizeof(drmPciBusInfo) +
+		     sizeof(drmPciDeviceInfo));
     if (!*device)
         return -ENOMEM;
 
+    addr = (char*)*device;
+  
     (*device)->bustype = DRM_BUS_PCI;
     (*device)->available_nodes = 1 << node_type;
 
     addr += sizeof(drmDevice);
-    (*device)->nodes = addr;
+    (*device)->nodes = (char**)addr;
 
     addr += DRM_NODE_MAX * sizeof(void *);
     for (i = 0; i < DRM_NODE_MAX; i++) {
@@ -3024,7 +3025,7 @@  static int drmProcessPciDevice(drmDevicePtr *device, const char *d_name,
     }
     memcpy((*device)->nodes[node_type], node, max_node_str);
 
-    (*device)->businfo.pci = addr;
+    (*device)->businfo.pci = (drmPciBusInfoPtr)addr;
 
     ret = drmParsePciBusInfo(maj, min, (*device)->businfo.pci);
     if (ret)
@@ -3033,7 +3034,7 @@  static int drmProcessPciDevice(drmDevicePtr *device, const char *d_name,
     // Fetch the device info if the user has requested it
     if (fetch_deviceinfo) {
         addr += sizeof(drmPciBusInfo);
-        (*device)->deviceinfo.pci = addr;
+        (*device)->deviceinfo.pci = (drmPciDeviceInfoPtr)addr;
 
         ret = drmParsePciDeviceInfo(d_name, (*device)->deviceinfo.pci);
         if (ret)