Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp133113imm; Tue, 17 Jul 2018 22:39:27 -0700 (PDT) X-Google-Smtp-Source: AAOMgpekBVIPZlvlJtLeGaLMbwro/p4IhQnI7bTsuF7DJ2jzNnPLA5hLu/mimARwJrrq8ZP5cwPX X-Received: by 2002:a63:ae02:: with SMTP id q2-v6mr4353895pgf.189.1531892367885; Tue, 17 Jul 2018 22:39:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531892367; cv=none; d=google.com; s=arc-20160816; b=wDmB5xe/MPqllQhODR/j6BDyIg6hk/xEtk4o0iXJLR9DI1Kz+6ZJU86336vMYZ2oTk 2gK0keoYP+yk7kOZDF4YSzvYyu0nRgc2oWSk2OiaIXJkzZcm3Isph4SxMLUgtqp2lCg7 pku5Le+9LQsJAIVKOAc3B3MP/8GhvZKq+pHA6/OD8f7jbxJjLF2GyC0kdBbfdDhCjBef jAc2r8OU+17xpEdL+zt/BCzr1npIT/Y0ZEK2+ObbcinUOS9vlZ93kg7L8wkJZQw49wfu P4/pg6SUbsQEleGKYibLk6huoPjmT7oCGR0YoJ1dxRzbXJ3Umf7Gm4cMa5Fp98MXb1jM Lesg== 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:arc-authentication-results; bh=HRQUmxhQCS4uwCSwcPRNsDwHf82IEeRprH1JdizqFhc=; b=esA513fRAezSEfXlzGSFBRJjQEEhyuu27CZ3We81+LHHOuE2FNj1GBOL1z/ByG8WVZ Wgxrvxy2s1ZZyq+1oqrNT0P5rkdatTkvO+GaTxPyEfjNZoM7jm3lYRjzUHrYqCMYiZ7H wFEPiHimyQ7+YjvlfMSYC3FFJv+tMjCjqL5Lp2l/d2YOq7G22YNBZ00tqi01QzKnRIGW rnQWOS4xskizQ1DMO+kJ5QP+hj5ZTSbbtN+6TqhPliht7d6/16oUdlGW2o0WoNG5XRvI lfOlS9pXdmeYsyb6zVi4lysHpvE6SYqsehQHZZaOB+ERW+bPdSoy1sBlaMg/MzeVIe1f 7RMw== 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 u27-v6si2481403pgo.676.2018.07.17.22.39.13; Tue, 17 Jul 2018 22:39:27 -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 S1726699AbeGRGOk (ORCPT + 99 others); Wed, 18 Jul 2018 02:14:40 -0400 Received: from 178.115.242.59.static.drei.at ([178.115.242.59]:47237 "EHLO mail.osadl.at" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1726110AbeGRGOj (ORCPT ); Wed, 18 Jul 2018 02:14:39 -0400 Received: by mail.osadl.at (Postfix, from userid 1001) id 790065C02FA; Wed, 18 Jul 2018 05:36:58 +0000 (UTC) Date: Wed, 18 Jul 2018 05:36:58 +0000 From: Nicholas Mc Guire To: Sean Paul Cc: Nicholas Mc Guire , Gustavo Padovan , Li Philip , Maarten Lankhorst , David Airlie , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH V2] drm: handle error values properly Message-ID: <20180718053658.GA10618@osadl.at> References: <1531834101-6018-1-git-send-email-hofrat@osadl.org> <20180717201416.GZ20303@art_vandelay> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180717201416.GZ20303@art_vandelay> User-Agent: Mutt/1.5.23 (2014-03-12) 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 04:14:16PM -0400, Sean Paul wrote: > 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? yup - forgot to remove that line after copying The modified block should be: int ret; ... ret = drm_legacy_ctxbitmap_next(dev); if (ret == DRM_KERNEL_CONTEXT) { /* Skip kernel's context and get a new one. */ ret = drm_legacy_ctxbitmap_next(dev); } 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; thanks for cathcing that - will resend thx! hofrat > > > - 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