[PATCH 1/5] drm/usb: add a busid implementation

Dave Airlie airlied at gmail.com
Mon Feb 20 08:13:45 PST 2012


From: Dave Airlie <airlied at redhat.com>

This adds an implementation for the busid callback so userspace can distinguish
usb devices better.

Signed-off-by: Dave Airlie <airlied at redhat.com>
---
 drivers/gpu/drm/drm_usb.c |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/drivers/gpu/drm/drm_usb.c b/drivers/gpu/drm/drm_usb.c
index 445003f..ca77aa6 100644
--- a/drivers/gpu/drm/drm_usb.c
+++ b/drivers/gpu/drm/drm_usb.c
@@ -85,7 +85,39 @@ static const char *drm_usb_get_name(struct drm_device *dev)
 static int drm_usb_set_busid(struct drm_device *dev,
 			       struct drm_master *master)
 {
+	struct usb_driver *udriver = dev->driver->kdriver.usb;
+	int len, ret;
+
+	master->unique_len = 40;
+	master->unique_size = master->unique_len;
+	master->unique = kmalloc(master->unique_size, GFP_KERNEL);
+	if (master->unique == NULL)
+		return -ENOMEM;
+
+	len = snprintf(master->unique, master->unique_len,
+		       "usb:%s", dev_name(&dev->usbdev->dev));
+
+	if (len >= master->unique_len) {
+		DRM_ERROR("buffer overflow");
+		ret = -EINVAL;
+		goto err;
+	} else
+		master->unique_len = len;
+
+	dev->devname = kmalloc(strlen(udriver->name) +
+			       master->unique_len + 2, GFP_KERNEL);
+
+	if (dev->devname == NULL) {
+		ret = -ENOMEM;
+		goto err;
+	}
+
+	sprintf(dev->devname, "%s@%s", udriver->name,
+		master->unique);
+
 	return 0;
+err:
+	return ret;
 }
 
 static struct drm_bus drm_usb_bus = {
-- 
1.7.6



More information about the dri-devel mailing list