Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp27759imm; Tue, 17 Jul 2018 13:16:17 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfgtqsdZMoetGbmF6+dHxWEzHmpmfyL5GcigCO34uhVCxtJ53Fds3YpGAqqgTehDBfIsLT2 X-Received: by 2002:a65:5144:: with SMTP id g4-v6mr2952244pgq.21.1531858576967; Tue, 17 Jul 2018 13:16:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531858576; cv=none; d=google.com; s=arc-20160816; b=SfpV3cT95r3ulmxLySdHxzxJf+BBY4fqqxjcGMSfG6u3wDxJOVDBU29k6yo70Nw6MY PcstwJ2JqK4WnFmcPNSQazwQOkcEICcnESLNPUPEaMVSkt/xEZOAWYzQ4mgDqEzbU3Se DlXmz/iFfG4JqBBhLjVw5Lo8pNG+tXqesxhWQ0srTr3LHz7I6uggIE1mbChEzCq7+hX8 y5ez+zXB77sLP0T2Xp7Q0vzhSPIV55z+yCfchzQNeWk+nXdD8+Lh9K0zHg9j9LOb6OOB Pxq89KTHh+/Q0NxaJq+QL9yPUcNGCSdbzmXR0NZlrXAt5qYQXnd/KKE2nDwXMaWDr9Ie iPHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=mu99MLzTa/RgV55rKC/mAxnmvv4YfuC72J29XjCEt4k=; b=v0JPBdWc1Tf8+GORDDfhGcauj1Gj7G/CVwe+qSslMIx4YfQUOb6cVkUyxkywjdPTjF XYWFeFJCAv5GoehEbcaLHlg17HzITxvrPQXGYcfi15SxA2r1LQVUM42UaU5y1nQ0wt2I 56ujg4zgMBh69BPGE3t/gh2cgQgGp9gslY4tRxuqv6WB+zJnM8aE1nz1YkxEa981LJa5 Un82eaAF39zPjIbs0APfvZW4pIQb346E19G8z38qB+1nBavQ4TOlSF48xCBiMoVyv36T A4Nt8NotWiz3bD0YJaZBltu0jDZrVQUk2FVsd12mTlTDrjHtNRTDlZwp5YOZdJqV+CPn oZUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FoDh8Rx0; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h1-v6si1590576pll.416.2018.07.17.13.16.01; Tue, 17 Jul 2018 13:16:16 -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; dkim=pass header.i=@chromium.org header.s=google header.b=FoDh8Rx0; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730869AbeGQUse (ORCPT + 99 others); Tue, 17 Jul 2018 16:48:34 -0400 Received: from mail-yw0-f195.google.com ([209.85.161.195]:39149 "EHLO mail-yw0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729728AbeGQUsd (ORCPT ); Tue, 17 Jul 2018 16:48:33 -0400 Received: by mail-yw0-f195.google.com with SMTP id r184-v6so864690ywg.6 for ; Tue, 17 Jul 2018 13:14:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=mu99MLzTa/RgV55rKC/mAxnmvv4YfuC72J29XjCEt4k=; b=FoDh8Rx08ow3FLXrHwNyIhp6eWuJUal7Py73YGVhhglnAV7Fk9uC9TLq67AujdNklO HxUTTVaBdeYe+GGDvbAOd75GEXImdVPkarg4DKVkTUmUN+XuFJkoXRTt73GYRPwIryV1 F4kwpXlrZcV/g7dOmi4/XpI7wbmW6+LhGrXC8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=mu99MLzTa/RgV55rKC/mAxnmvv4YfuC72J29XjCEt4k=; b=Ey4+0XzDfEEPv2IjIw1anjhDVM+8h+3VWRpnRp3H8LR+ERgoSbFqenZG7W7FG5UkZa mQ4mKZx1Q3ZhqycFfked4zF0ohEEABT7l0zKvWbSuazTNlW5wRV5wPRQzdvwcniahcE4 qNxV83DfsPJi2v3d2b66wd+63Fc0swOyrTtzeUrcip5QUJ4SwYbCYfC3jP4i5b29Sp/r kk/ZiNvlFttrEMZxj1THwIRn31tOSmtez2xf1UFWVTHsHxFCwflAMIf9k/QNo/JtCOB3 gLVMmp/F0yAV9y+6mu/61rj01GSZypwFC/qHWCx2qqcgszz+rpxpbIsbC3TgCuOc6YP4 ZPAQ== X-Gm-Message-State: AOUpUlFrJr5TpWd+tPQ2bqzv0dNf7OFBpwPJLq41CfzPYXUk0sCwk8Or QHAtWlZjaLVNRAjwuIn8tWwKNA== X-Received: by 2002:a0d:cac5:: with SMTP id m188-v6mr1603195ywd.307.1531858457418; Tue, 17 Jul 2018 13:14:17 -0700 (PDT) Received: from localhost ([2620:0:1013:11:ad55:b1db:adfe:3b9f]) by smtp.gmail.com with ESMTPSA id u64-v6sm2346171ywu.107.2018.07.17.13.14.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 17 Jul 2018 13:14:16 -0700 (PDT) Date: Tue, 17 Jul 2018 16:14:16 -0400 From: Sean Paul To: Nicholas Mc Guire Cc: Gustavo Padovan , Li Philip , Maarten Lankhorst , Sean Paul , David Airlie , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH V2] drm: handle error values properly Message-ID: <20180717201416.GZ20303@art_vandelay> References: <1531834101-6018-1-git-send-email-hofrat@osadl.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1531834101-6018-1-git-send-email-hofrat@osadl.org> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 17, 2018 at 03:28:21PM +0200, Nicholas Mc Guire wrote: > 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); Remove this call? Sean > - 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 > -- Sean Paul, Software Engineer, Google / Chromium OS