public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Nicholas Mc Guire <der.herr@hofr.at>
To: Nicholas Mc Guire <hofrat@osadl.org>
Cc: Gustavo Padovan <gustavo@padovan.org>,
	Li Philip <philip.li@intel.com>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Sean Paul <seanpaul@chromium.org>,
	David Airlie <airlied@linux.ie>,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH V3] drm: handle error values properly
Date: Thu, 30 Aug 2018 18:45:45 +0000	[thread overview]
Message-ID: <20180830184545.GA5617@osadl.at> (raw)
In-Reply-To: <1531905244-18044-1-git-send-email-hofrat@osadl.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 <hofrat@osadl.org>
> Reported-by: kbuild test robot <lkp@intel.com>
> Reported-by: Sean Paul <seanpaul@chromium.org>
> 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 <seanpaul@chromium.org> - 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 <lkp@intel.com>. 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
> 

      reply	other threads:[~2018-08-30 18:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-18  9:14 [PATCH V3] drm: handle error values properly Nicholas Mc Guire
2018-08-30 18:45 ` Nicholas Mc Guire [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180830184545.GA5617@osadl.at \
    --to=der.herr@hofr.at \
    --cc=airlied@linux.ie \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gustavo@padovan.org \
    --cc=hofrat@osadl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=philip.li@intel.com \
    --cc=seanpaul@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox