diff options
author | David Herrmann <dh.herrmann@gmail.com> | 2014-08-29 14:12:41 +0400 |
---|---|---|
committer | Dave Airlie <airlied@redhat.com> | 2014-09-10 11:42:14 +0400 |
commit | d0a39164b6adad0cec5046b6aad6b590cc9466cc (patch) | |
tree | 84ed1ba6ab36604fa2783f93a91229637e2c9b16 /drivers/gpu/drm/drm_platform.c | |
parent | d7d2c48e5cfe27dc7378e48d4f22efcf417317d9 (diff) | |
download | linux-d0a39164b6adad0cec5046b6aad6b590cc9466cc.tar.xz |
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/drm/drm_platform.c')
-rw-r--r-- | drivers/gpu/drm/drm_platform.c | 31 |
1 files changed, 8 insertions, 23 deletions
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: static int drm_platform_set_busid(struct drm_device *dev, struct drm_master *master) { - int len, ret, id; - - master->unique_len = 13 + strlen(dev->platformdev->name); - master->unique_size = master->unique_len; - master->unique = kmalloc(master->unique_len + 1, GFP_KERNEL); - - if (master->unique == NULL) - return -ENOMEM; + int id; id = dev->platformdev->id; - - /* if only a single instance of the platform device, id will be - * set to -1.. use 0 instead to avoid a funny looking bus-id: - */ - if (id == -1) + if (id < 0) id = 0; - len = snprintf(master->unique, master->unique_len, - "platform:%s:%02d", dev->platformdev->name, id); - - if (len > master->unique_len) { - DRM_ERROR("Unique buffer overflowed\n"); - ret = -EINVAL; - goto err; - } + master->unique = kasprintf(GFP_KERNEL, "platform:%s:%02d", + dev->platformdev->name, id); + if (!master->unique) + return -ENOMEM; + master->unique_len = strlen(master->unique); + master->unique_size = master->unique_len; return 0; -err: - return ret; } static struct drm_bus drm_platform_bus = { |