Commit c39191fe authored by YueHaibing's avatar YueHaibing Committed by Daniel Vetter

drm: Fix error handling in drm_legacy_addctx

'ctx->handle' is unsigned, it never less than zero.
This patch use int 'tmp_handle' to handle the err condition.

Fixes: 62968144 ("drm: convert drm context code to use Linux idr")
Signed-off-by: default avatarYueHaibing <yuehaibing@huawei.com>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20181229024907.12852-1-yuehaibing@huawei.com
parent 227ad6d9
...@@ -361,23 +361,26 @@ int drm_legacy_addctx(struct drm_device *dev, void *data, ...@@ -361,23 +361,26 @@ int drm_legacy_addctx(struct drm_device *dev, void *data,
{ {
struct drm_ctx_list *ctx_entry; struct drm_ctx_list *ctx_entry;
struct drm_ctx *ctx = data; struct drm_ctx *ctx = data;
int tmp_handle;
if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) && if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
!drm_core_check_feature(dev, DRIVER_LEGACY)) !drm_core_check_feature(dev, DRIVER_LEGACY))
return -EOPNOTSUPP; return -EOPNOTSUPP;
ctx->handle = drm_legacy_ctxbitmap_next(dev); tmp_handle = drm_legacy_ctxbitmap_next(dev);
if (ctx->handle == DRM_KERNEL_CONTEXT) { if (tmp_handle == DRM_KERNEL_CONTEXT) {
/* Skip kernel's context and get a new one. */ /* Skip kernel's context and get a new one. */
ctx->handle = drm_legacy_ctxbitmap_next(dev); tmp_handle = drm_legacy_ctxbitmap_next(dev);
} }
DRM_DEBUG("%d\n", ctx->handle); DRM_DEBUG("%d\n", tmp_handle);
if (ctx->handle < 0) { if (tmp_handle < 0) {
DRM_DEBUG("Not enough free contexts.\n"); DRM_DEBUG("Not enough free contexts.\n");
/* Should this return -EBUSY instead? */ /* Should this return -EBUSY instead? */
return -ENOMEM; return tmp_handle;
} }
ctx->handle = tmp_handle;
ctx_entry = kmalloc(sizeof(*ctx_entry), GFP_KERNEL); ctx_entry = kmalloc(sizeof(*ctx_entry), GFP_KERNEL);
if (!ctx_entry) { if (!ctx_entry) {
DRM_DEBUG("out of memory\n"); DRM_DEBUG("out of memory\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment