diff options
author | YueHaibing <yuehaibing@huawei.com> | 2018-12-29 10:49:07 +0800 |
---|---|---|
committer | Ben Hutchings <ben@decadent.org.uk> | 2019-07-09 22:03:44 +0100 |
commit | b429b68647312be7823b6eb17b40ad2f3fdca3f8 (patch) | |
tree | f9d4b055efd89e8b37c8c703dec05066653bb1e2 | |
parent | b9e04b7c6288f1022f66b3f2c177db0c7d59ec47 (diff) | |
download | linux-stable-b429b68647312be7823b6eb17b40ad2f3fdca3f8.tar.gz linux-stable-b429b68647312be7823b6eb17b40ad2f3fdca3f8.tar.bz2 linux-stable-b429b68647312be7823b6eb17b40ad2f3fdca3f8.zip |
drm: Fix error handling in drm_legacy_addctx
commit c39191feed4540fed98badeb484833dcf659bb96 upstream.
'ctx->handle' is unsigned, it never less than zero.
This patch use int 'tmp_handle' to handle the err condition.
Fixes: 62968144e673 ("drm: convert drm context code to use Linux idr")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20181229024907.12852-1-yuehaibing@huawei.com
[bwh: Backported to 3.16: We only have the "legacy" driver type here]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
-rw-r--r-- | drivers/gpu/drm/drm_context.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/drivers/gpu/drm/drm_context.c b/drivers/gpu/drm/drm_context.c index d2376911c541..6e1a8420b3fc 100644 --- a/drivers/gpu/drm/drm_context.c +++ b/drivers/gpu/drm/drm_context.c @@ -309,19 +309,22 @@ int drm_addctx(struct drm_device *dev, void *data, { struct drm_ctx_list *ctx_entry; struct drm_ctx *ctx = data; + int tmp_handle; - ctx->handle = drm_ctxbitmap_next(dev); - if (ctx->handle == DRM_KERNEL_CONTEXT) { + tmp_handle = drm_ctxbitmap_next(dev); + if (tmp_handle == DRM_KERNEL_CONTEXT) { /* Skip kernel's context and get a new one. */ - ctx->handle = drm_ctxbitmap_next(dev); + tmp_handle = drm_ctxbitmap_next(dev); } - DRM_DEBUG("%d\n", ctx->handle); - if (ctx->handle < 0) { + DRM_DEBUG("%d\n", tmp_handle); + if (tmp_handle < 0) { DRM_DEBUG("Not enough free contexts.\n"); /* Should this return -EBUSY instead? */ - return -ENOMEM; + return tmp_handle; } + ctx->handle = tmp_handle; + ctx_entry = kmalloc(sizeof(*ctx_entry), GFP_KERNEL); if (!ctx_entry) { DRM_DEBUG("out of memory\n"); |