Skip to content

Commit c39191f

Browse files
YueHaibingdanvet
authored andcommitted
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: 6296814 ("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
1 parent 227ad6d commit c39191f

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

‎drivers/gpu/drm/drm_context.c‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,23 +361,26 @@ int drm_legacy_addctx(struct drm_device *dev, void *data,
361361
{
362362
struct drm_ctx_list *ctx_entry;
363363
struct drm_ctx *ctx = data;
364+
int tmp_handle;
364365

365366
if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) &&
366367
!drm_core_check_feature(dev, DRIVER_LEGACY))
367368
return -EOPNOTSUPP;
368369

369-
ctx->handle = drm_legacy_ctxbitmap_next(dev);
370-
if (ctx->handle == DRM_KERNEL_CONTEXT) {
370+
tmp_handle = drm_legacy_ctxbitmap_next(dev);
371+
if (tmp_handle == DRM_KERNEL_CONTEXT) {
371372
/* Skip kernel's context and get a new one. */
372-
ctx->handle = drm_legacy_ctxbitmap_next(dev);
373+
tmp_handle = drm_legacy_ctxbitmap_next(dev);
373374
}
374-
DRM_DEBUG("%d\n", ctx->handle);
375-
if (ctx->handle < 0) {
375+
DRM_DEBUG("%d\n", tmp_handle);
376+
if (tmp_handle < 0) {
376377
DRM_DEBUG("Not enough free contexts.\n");
377378
/* Should this return -EBUSY instead? */
378-
return -ENOMEM;
379+
return tmp_handle;
379380
}
380381

382+
ctx->handle = tmp_handle;
383+
381384
ctx_entry = kmalloc(sizeof(*ctx_entry), GFP_KERNEL);
382385
if (!ctx_entry) {
383386
DRM_DEBUG("out of memory\n");

0 commit comments

Comments
 (0)