drm: Prevent NULL deref in drm_name_info()
authorChris Wilson <chris@chris-wilson.co.uk>
Mon, 20 Jun 2016 18:53:33 +0000 (19:53 +0100)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Mon, 20 Jun 2016 19:20:16 +0000 (21:20 +0200)
If a driver does not have a parent, or never sets the unique name for
itself, then we may proceed to chase a NULL dereference through
debugfs/.../name.

Testcase: igt/vgem_basic/debugfs
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1466448813-23340-1-git-send-email-chris@chris-wilson.co.uk
drivers/gpu/drm/drm_info.c

index 0090d598780189f46b424e096760f7cb64d7349a..e2d2543d5bd0e171b4ca4da14637872f8a82664a 100644 (file)
@@ -51,17 +51,16 @@ int drm_name_info(struct seq_file *m, void *data)
        struct drm_minor *minor = node->minor;
        struct drm_device *dev = minor->dev;
        struct drm_master *master = minor->master;
-       if (!master)
-               return 0;
-
-       if (master->unique) {
-               seq_printf(m, "%s %s %s\n",
-                          dev->driver->name,
-                          dev_name(dev->dev), master->unique);
-       } else {
-               seq_printf(m, "%s %s\n",
-                          dev->driver->name, dev_name(dev->dev));
-       }
+
+       seq_printf(m, "%s", dev->driver->name);
+       if (dev->dev)
+               seq_printf(m, " dev=%s", dev_name(dev->dev));
+       if (master && master->unique)
+               seq_printf(m, " master=%s", master->unique);
+       if (dev->unique)
+               seq_printf(m, " unique=%s", dev->unique);
+       seq_printf(m, "\n");
+
        return 0;
 }