[PATCH] xfree86: Fix null pointer dereference

Kyle Guinn elyk03 at gmail.com
Tue Jan 12 21:47:52 PST 2016


Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=93675

Signed-off-by: Kyle Guinn <elyk03 at gmail.com>
---
 hw/xfree86/i2c/xf86i2c.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/hw/xfree86/i2c/xf86i2c.c b/hw/xfree86/i2c/xf86i2c.c
index 2a8b8df..62b647c 100644
--- a/hw/xfree86/i2c/xf86i2c.c
+++ b/hw/xfree86/i2c/xf86i2c.c
@@ -615,19 +615,21 @@ void
 xf86DestroyI2CDevRec(I2CDevPtr d, Bool unalloc)
 {
     if (d) {
-        I2CDevPtr *p;
+        if (d->pI2CBus) {
+            I2CDevPtr *p;
 
-        /* Remove this from the list of active I2C devices. */
+            /* Remove this from the list of active I2C devices. */
 
-        for (p = &d->pI2CBus->FirstDev; *p != NULL; p = &(*p)->NextDev)
-            if (*p == d) {
-                *p = (*p)->NextDev;
-                break;
-            }
+            for (p = &d->pI2CBus->FirstDev; *p != NULL; p = &(*p)->NextDev)
+                if (*p == d) {
+                    *p = (*p)->NextDev;
+                    break;
+                }
 
-        xf86DrvMsg(d->pI2CBus->scrnIndex, X_INFO,
-                   "I2C device \"%s:%s\" removed.\n",
-                   d->pI2CBus->BusName, d->DevName);
+            xf86DrvMsg(d->pI2CBus->scrnIndex, X_INFO,
+                       "I2C device \"%s:%s\" removed.\n",
+                       d->pI2CBus->BusName, d->DevName);
+        }
 
         if (unalloc)
             free(d);
-- 
1.8.4



More information about the xorg-devel mailing list