Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp200445imm; Thu, 30 Aug 2018 11:49:38 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYwtV+LRECGfTkf82sbUCSuqe/FcYGzQAj5T5wbSDMe9R+LNgo6yz0mRQJhaEGf0vFtqFx9 X-Received: by 2002:a62:e08b:: with SMTP id d11-v6mr11751149pfm.214.1535654978350; Thu, 30 Aug 2018 11:49:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535654978; cv=none; d=google.com; s=arc-20160816; b=JC4Xz/29zvthCHRSCGdrZj3RStqxjPr+ayfzuf4EmGxWIhKHtouH5Igw7IG0iFyjkU tNVMG+m6PTnveQsNFV4/XmsyWRQ2CrOfamrU6N9mBfBh5qFboD9N3KqISWVDHcfSaUF0 DyoPevQmSTANmogjpB2yE+/qgair3aZg9tkNE5Yc0NLMpoXgwH/+VdCzoFAZDhKpf3HH KfRH1HaNnKyNhobDjbmRkwYIqEvXEkamOqZkoy0g3Z1IjyJClAchnJzRhhEbJfnRiPgi jH7lJKqcTKZd7w/Tpu4fUeCNeNom8PVvl6BdErLBxx4gSu48ACN63c5GKVy2U2/71pIB urRg== 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=PraEuvb9LSfwlFNr8UCeNyLmnSq/V8Hep4UBv0/LdUs=; b=TUPce63LqDJ4fbuU54nUbmas8PSO/wxBpHF2Fu2UbW0+UpDKItqupZu3vUZuJVUOea euY7GJwyuRXDzicJ7zozj55EoDAt3lmT8nCAjie8XaE9F7Mw+Pog3bS4oWTZWKK72RSn QC8b2Y1p8W30AAROfWBgFAtPsii45VzG9/JPVL+NQ5WZn57nxH8iI80nEW9zS8Tc4x2p dGf9F5DEJWfuoLjPtblD5UoqEiDrK0NkLCxdHAimQMd2muBmaE7Fd75yK9BZ5VnYbJFJ 9Yxugp4RFnFR1+OE6CjGYPccwjCDUWFqp8KwfTkB2Bu9982//N+2rVHfnolaic1kr35w VAjQ== 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 t16-v6si7218195pgi.457.2018.08.30.11.49.23; Thu, 30 Aug 2018 11:49:38 -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 S1727599AbeH3WvM (ORCPT + 99 others); Thu, 30 Aug 2018 18:51:12 -0400 Received: from 178.115.242.59.static.drei.at ([178.115.242.59]:40278 "EHLO mail.osadl.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725836AbeH3WvM (ORCPT ); Thu, 30 Aug 2018 18:51:12 -0400 Received: by mail.osadl.at (Postfix, from userid 1001) id 5CDE75C0B55; Thu, 30 Aug 2018 18:45:45 +0000 (UTC) Date: Thu, 30 Aug 2018 18:45:45 +0000 From: Nicholas Mc Guire 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 V3] drm: handle error values properly Message-ID: <20180830184545.GA5617@osadl.at> References: <1531905244-18044-1-git-send-email-hofrat@osadl.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1531905244-18044-1-git-send-email-hofrat@osadl.org> 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 Wed, Jul 18, 2018 at 11:14:04AM +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. As the first version made it into -stable unfortunately I would ask for a review on this V3 so that a correct fix could go into -stabele ASAP. thx! hofrat > > 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) { > -- > 2.1.4 >