Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3540815imm; Tue, 17 Jul 2018 06:34:20 -0700 (PDT) X-Google-Smtp-Source: AAOMgpebe4uJhvMdsc5RKPVCJfhgIkfHqEJg2q/DX6meWElNv/twdG5DagFK6fbh+SfKoR2KS8nX X-Received: by 2002:a63:2dc1:: with SMTP id t184-v6mr1650670pgt.62.1531834460078; Tue, 17 Jul 2018 06:34:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531834460; cv=none; d=google.com; s=arc-20160816; b=ZPf1Tisl4tasMHwWLgSoTqRytsBz3eAHcsuG3GyBPMNyCFcS4Iszh+cnCRIckIzE6T oopExwaE2ai35xCC7Tc4wfDhZjTWPHxoM39mfoo5S6hY/e72tWjTZZLyxox2uucjobvY mj2yhuPgD6uTHXb57mCjMAVZq40SGd46BbxA6CEgxe4s41EKIb28wBDmnl+rVpoQAAlw mxXvX4Q9NKTjdkuaiNvtDQr4WuGldJPLymA42cTHRX1Asf0H65XoVujdCNUPKzyhmrP1 hoaj88r9IQBdS91t2JCI8RDMb0pQgWkyYWJegE2dlrz7yYjXan85gGi48wVQnH4JFbk5 i4cA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=OP8dl866kPhXlxu1Ej720XfGDHpnxMhlZwowmT8Txwk=; b=ybWpKOC7js7gVQ+TDbVYdcmqcKL7MofbMSloRcGNM9+LU/gR2S23Nfl9TjJHGtWLgB o8TKlju2PVahoZEsEOkCvVLpTngMRzkOG2QTgqv26C/n2kJpfmq/r/M3PWihEehkTNrO P5bB+QurXUvvVzW6oPslwJsygtRZe0JnAXuPQLS/DSwObEX5KiKRWqzPD+Tqdl+gq/Yi yMORuDYJK/BfewPN3XZkz3ydoK2koNsqmDFC5jt8HuLtFQ7bj0TJ3SITe/5vMaPG2qzm QtztRGIMUzz70ZU1wxYGmK8Tvwg9hWphU+QB8WNrCRjbDMN1fjX2eJX3IL6jByu/pjB1 1YLw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b8-v6si771483pls.392.2018.07.17.06.34.04; Tue, 17 Jul 2018 06:34:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731603AbeGQOGL (ORCPT + 99 others); Tue, 17 Jul 2018 10:06:11 -0400 Received: from www.osadl.org ([62.245.132.105]:34963 "EHLO www.osadl.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731523AbeGQOGL (ORCPT ); Tue, 17 Jul 2018 10:06:11 -0400 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 w6HDTADC024377; Tue, 17 Jul 2018 15:29:10 +0200 From: Nicholas Mc Guire To: Gustavo Padovan Cc: Li Philip , Maarten Lankhorst , Sean Paul , David Airlie , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Nicholas Mc Guire Subject: [PATCH V2] drm: handle error values properly Date: Tue, 17 Jul 2018 15:28:21 +0200 Message-Id: <1531834101-6018-1-git-send-email-hofrat@osadl.org> X-Mailer: git-send-email 2.1.4 X-Spam-Status: No, score=-4.2 required=6.0 tests=BAYES_00,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on www.osadl.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Fixes: d530b5f1ca0b ("drm: re-enable error handling") Fixes: 62968144e673 ("drm: convert drm context code to use Linux idr") --- kbuild test robot reported: tree: git://anongit.freedesktop.org/drm/drm-misc for-linux-next-fixes head: d530b5f1ca0bb66958a2b714bebe40a1248b9c15 commit: d530b5f1ca0bb66958a2b714bebe40a1248b9c15 [2/2] drm: re-enable error +handling smatch warnings: drivers/gpu/drm/drm_context.c:375 drm_legacy_addctx() warn: unsigned +'ctx->handle' is never less than zero. 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-rc4 (localversion-next is next-20180717) drivers/gpu/drm/drm_context.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/drm_context.c b/drivers/gpu/drm/drm_context.c index 3c4000f..78f32a3 100644 --- a/drivers/gpu/drm/drm_context.c +++ b/drivers/gpu/drm/drm_context.c @@ -361,22 +361,26 @@ 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) { -- 2.1.4