aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2014-08-29 06:12:41 -0400
committerDave Airlie <airlied@redhat.com>2014-09-10 03:42:14 -0400
commitd0a39164b6adad0cec5046b6aad6b590cc9466cc (patch)
tree84ed1ba6ab36604fa2783f93a91229637e2c9b16 /drivers/gpu
parentd7d2c48e5cfe27dc7378e48d4f22efcf417317d9 (diff)
drm: simplify drm_*_set_unique()
Lets use kasprintf() to avoid pre-allocating the buffer. This is really nothing to optimize for speed and the input is trusted, so kasprintf() is just fine. Signed-off-by: David Herrmann <dh.herrmann@gmail.com> Reviewed-by: Thierry Reding <treding@nvidia.com> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: Dave Airlie <airlied@redhat.com>
Diffstat (limited to 'drivers/gpu')
-rw-r--r--drivers/gpu/drm/drm_pci.c30
-rw-r--r--drivers/gpu/drm/drm_platform.c31
2 files changed, 16 insertions, 45 deletions
diff --git a/drivers/gpu/drm/drm_pci.c b/drivers/gpu/drm/drm_pci.c
index 020cfd934854..8efea6b4602b 100644
--- a/drivers/gpu/drm/drm_pci.c
+++ b/drivers/gpu/drm/drm_pci.c
@@ -129,31 +129,17 @@ static int drm_get_pci_domain(struct drm_device *dev)
129 129
130static int drm_pci_set_busid(struct drm_device *dev, struct drm_master *master) 130static int drm_pci_set_busid(struct drm_device *dev, struct drm_master *master)
131{ 131{
132 int len, ret; 132 master->unique = kasprintf(GFP_KERNEL, "pci:%04x:%02x:%02x.%d",
133 master->unique_len = 40; 133 drm_get_pci_domain(dev),
134 master->unique_size = master->unique_len; 134 dev->pdev->bus->number,
135 master->unique = kmalloc(master->unique_size, GFP_KERNEL); 135 PCI_SLOT(dev->pdev->devfn),
136 if (master->unique == NULL) 136 PCI_FUNC(dev->pdev->devfn));
137 if (!master->unique)
137 return -ENOMEM; 138 return -ENOMEM;
138 139
139 140 master->unique_len = strlen(master->unique);
140 len = snprintf(master->unique, master->unique_len, 141 master->unique_size = master->unique_len + 1;
141 "pci:%04x:%02x:%02x.%d",
142 drm_get_pci_domain(dev),
143 dev->pdev->bus->number,
144 PCI_SLOT(dev->pdev->devfn),
145 PCI_FUNC(dev->pdev->devfn));
146
147 if (len >= master->unique_len) {
148 DRM_ERROR("buffer overflow");
149 ret = -EINVAL;
150 goto err;
151 } else
152 master->unique_len = len;
153
154 return 0; 142 return 0;
155err:
156 return ret;
157} 143}
158 144
159int drm_pci_set_unique(struct drm_device *dev, 145int drm_pci_set_unique(struct drm_device *dev,
diff --git a/drivers/gpu/drm/drm_platform.c b/drivers/gpu/drm/drm_platform.c
index d5b76f148c12..0c09ddd50c15 100644
--- a/drivers/gpu/drm/drm_platform.c
+++ b/drivers/gpu/drm/drm_platform.c
@@ -70,35 +70,20 @@ err_free:
70 70
71static int drm_platform_set_busid(struct drm_device *dev, struct drm_master *master) 71static int drm_platform_set_busid(struct drm_device *dev, struct drm_master *master)
72{ 72{
73 int len, ret, id; 73 int id;
74
75 master->unique_len = 13 + strlen(dev->platformdev->name);
76 master->unique_size = master->unique_len;
77 master->unique = kmalloc(master->unique_len + 1, GFP_KERNEL);
78
79 if (master->unique == NULL)
80 return -ENOMEM;
81 74
82 id = dev->platformdev->id; 75 id = dev->platformdev->id;
83 76 if (id < 0)
84 /* if only a single instance of the platform device, id will be
85 * set to -1.. use 0 instead to avoid a funny looking bus-id:
86 */
87 if (id == -1)
88 id = 0; 77 id = 0;
89 78
90 len = snprintf(master->unique, master->unique_len, 79 master->unique = kasprintf(GFP_KERNEL, "platform:%s:%02d",
91 "platform:%s:%02d", dev->platformdev->name, id); 80 dev->platformdev->name, id);
92 81 if (!master->unique)
93 if (len > master->unique_len) { 82 return -ENOMEM;
94 DRM_ERROR("Unique buffer overflowed\n");
95 ret = -EINVAL;
96 goto err;
97 }
98 83
84 master->unique_len = strlen(master->unique);
85 master->unique_size = master->unique_len;
99 return 0; 86 return 0;
100err:
101 return ret;
102} 87}
103 88
104static struct drm_bus drm_platform_bus = { 89static struct drm_bus drm_platform_bus = {