From patchwork Wed Jul 18 09:14:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Mc Guire X-Patchwork-Id: 10531643 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E31E16020A for ; Wed, 18 Jul 2018 09:18:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA8E529067 for ; Wed, 18 Jul 2018 09:18:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CEE2229176; Wed, 18 Jul 2018 09:18:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 59B8229067 for ; Wed, 18 Jul 2018 09:18:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2F1806E972; Wed, 18 Jul 2018 09:18:21 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from www.osadl.org (www.osadl.org [62.245.132.105]) by gabe.freedesktop.org (Postfix) with ESMTPS id 96E456E972 for ; Wed, 18 Jul 2018 09:18:20 +0000 (UTC) Received: from debian01.hofrr.at (178.115.242.59.static.drei.at [178.115.242.59] (may be forged)) by www.osadl.org (8.13.8/8.13.8/OSADL-2007092901) with ESMTP id w6I9ErR8002397; Wed, 18 Jul 2018 11:14:53 +0200 From: Nicholas Mc Guire To: Gustavo Padovan Subject: [PATCH V3] drm: handle error values properly Date: Wed, 18 Jul 2018 11:14:04 +0200 Message-Id: <1531905244-18044-1-git-send-email-hofrat@osadl.org> X-Mailer: git-send-email 2.1.4 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Airlie , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Li Philip , Nicholas Mc Guire MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP drm_legacy_ctxbitmap_next() returns idr_alloc() which can return -ENOMEM, -EINVAL or -ENOSPC none of which are -1. since drm_context_t is an unsigned int an intermediate variable is used to handle the error cases, and then cast to drm_context_t after ensuring that the value is >= 0. The explicit cast is to mark the type conversion as intentional. Signed-off-by: Nicholas Mc Guire Reported-by: kbuild test robot Reported-by: Sean Paul Fixes: d530b5f1ca0b ("drm: re-enable error handling") Fixes: 62968144e673 ("drm: convert drm context code to use Linux idr") --- V3: bug in patch - omission to remove old code properly - V3 fixes the original problem as proposed in V2 and drops the excess line. reported by Sean Paul - thanks! V2: The proposed fix in d530b5f1ca0b ("drm: re-enable error handling") actually was ineffective as the negative return value check was against a unsigned int and thus always false as reported by kbuild test robot . The below patch removes that warning and fixes the original problem of missed error handling. drm_context_t is actually just used in a few placed so the type could be changed but it is also exported via tools/include/uapi/drm/drm.h so changing the typedef of drm_context_t could break applications and thus this is not an option. Patch was compile tested with: x86_64_defconfig Patch is against 4.18-rc5 (localversion-next is next-20180718) drivers/gpu/drm/drm_context.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/drm_context.c b/drivers/gpu/drm/drm_context.c index f973d28..ad268c8 100644 --- a/drivers/gpu/drm/drm_context.c +++ b/drivers/gpu/drm/drm_context.c @@ -361,22 +361,25 @@ int drm_legacy_addctx(struct drm_device *dev, void *data, { struct drm_ctx_list *ctx_entry; struct drm_ctx *ctx = data; + int ret; if (!drm_core_check_feature(dev, DRIVER_KMS_LEGACY_CONTEXT) && !drm_core_check_feature(dev, DRIVER_LEGACY)) return -EINVAL; - ctx->handle = drm_legacy_ctxbitmap_next(dev); - if (ctx->handle == DRM_KERNEL_CONTEXT) { + ret = drm_legacy_ctxbitmap_next(dev); + if (ret == DRM_KERNEL_CONTEXT) { /* Skip kernel's context and get a new one. */ - ctx->handle = drm_legacy_ctxbitmap_next(dev); + ret = drm_legacy_ctxbitmap_next(dev); } - DRM_DEBUG("%d\n", ctx->handle); - if (ctx->handle < 0) { + DRM_DEBUG("ctxbitmap is error code %d\n", ret); + if (ret < 0) { DRM_DEBUG("Not enough free contexts.\n"); /* Should this return -EBUSY instead? */ return -ENOMEM; } + /* valid context is >= 0 */ + ctx->handle = (drm_context_t)ret; ctx_entry = kmalloc(sizeof(*ctx_entry), GFP_KERNEL); if (!ctx_entry) {