Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp5892323ybi; Sun, 7 Jul 2019 15:40:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqyl1MObtHbF+OHvOoyU8+xsUvdCIoNJNZ2fUPuAFJ1vCrm++BJzLGHglXevBgp+AeHklfF5 X-Received: by 2002:a65:5b8e:: with SMTP id i14mr19175427pgr.188.1562539232493; Sun, 07 Jul 2019 15:40:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562539232; cv=none; d=google.com; s=arc-20160816; b=r1wdUA32L4TFcncVaxKUelcDSXKOa2l3lU+Iy+yYwgzGaUeL0G5Mu4CX3H9sthtiVF yATvD2S0Aqh2m21Xq6Al4LsiVVHZEUXKCyWS7+U0sleFUSe9xBHEsGVh6KGjRc3i3z8D 4mJFgiWNrOfifbiILD/GpIN80JRK2YZEP80kUVplycy7oXAyi2FXmG8GOw9BQRwnu03j jZ8I2UBYKsx5ZAwQrAzvXro/2Hml50Zyivo8fN/R+K9dv6PIy9VEGfBfkSpNpP2a5o71 mfSuSKlymHf+pCk4NSEu+z5LCIEqWFfVyzfaWPkCoDh5cmV57zdvdRrm8uxa/+6wTlbV STEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=rDg/qBoBhx5UD32JkIvZQ9LyEzfGuQletqKglBiQBWE=; b=IMDdqCPhNiHczZnTrtGfQPtr2dW7S8sogKmf4FygFX02rO5XL2+A9KPVZ54SEXRYsB 6f6ziqhnQD82OkSQb+bR5jCr7LVtbDQtPTPq8fQkg04Y4ucH4eS6xPpdyjSzjujFVsaF Q0IOibmVaSQ97DICpjmrQ8Umj7ihZludotdRx15vWgDecwc1pVLHjiWYmFzjEk1LdShw 8up2FGaYLalhZ+17yeagk2p3WVV7Iclyey6LFD1YqPlzFxtZW77gPrtj4j95iBITjnQR OXjSfw4MZfTA/whsPaC2lPIQZbwSr3QOjHdb6NIvtU0jG+kVlGHGgN8njekNir1YGx5v 4eFg== 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 f5si16719623pgq.564.2019.07.07.15.40.17; Sun, 07 Jul 2019 15:40:32 -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 S1728466AbfGGTqq (ORCPT + 99 others); Sun, 7 Jul 2019 15:46:46 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:56892 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727466AbfGGTiB (ORCPT ); Sun, 7 Jul 2019 15:38:01 -0400 Received: from 94.197.121.43.threembb.co.uk ([94.197.121.43] helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hkCz1-0006di-Ku; Sun, 07 Jul 2019 20:37:59 +0100 Received: from ben by deadeye with local (Exim 4.92) (envelope-from ) id 1hkCz0-0005Xi-HK; Sun, 07 Jul 2019 20:37:58 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, Denis Kirjanov , "Daniel Vetter" , "YueHaibing" Date: Sun, 07 Jul 2019 17:54:17 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 018/129] drm: Fix error handling in drm_legacy_addctx In-Reply-To: X-SA-Exim-Connect-IP: 94.197.121.43 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.70-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: YueHaibing commit c39191feed4540fed98badeb484833dcf659bb96 upstream. 'ctx->handle' is unsigned, it never less than zero. This patch use int 'tmp_handle' to handle the err condition. Fixes: 62968144e673 ("drm: convert drm context code to use Linux idr") Signed-off-by: YueHaibing Signed-off-by: Daniel Vetter Link: https://patchwork.freedesktop.org/patch/msgid/20181229024907.12852-1-yuehaibing@huawei.com [bwh: Backported to 3.16: We only have the "legacy" driver type here] Signed-off-by: Ben Hutchings --- drivers/gpu/drm/drm_context.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) --- a/drivers/gpu/drm/drm_context.c +++ b/drivers/gpu/drm/drm_context.c @@ -309,19 +309,22 @@ int drm_addctx(struct drm_device *dev, v { struct drm_ctx_list *ctx_entry; struct drm_ctx *ctx = data; + int tmp_handle; - ctx->handle = drm_ctxbitmap_next(dev); - if (ctx->handle == DRM_KERNEL_CONTEXT) { + tmp_handle = drm_ctxbitmap_next(dev); + if (tmp_handle == DRM_KERNEL_CONTEXT) { /* Skip kernel's context and get a new one. */ - ctx->handle = drm_ctxbitmap_next(dev); + tmp_handle = drm_ctxbitmap_next(dev); } - DRM_DEBUG("%d\n", ctx->handle); - if (ctx->handle < 0) { + DRM_DEBUG("%d\n", tmp_handle); + if (tmp_handle < 0) { DRM_DEBUG("Not enough free contexts.\n"); /* Should this return -EBUSY instead? */ - return -ENOMEM; + return tmp_handle; } + ctx->handle = tmp_handle; + ctx_entry = kmalloc(sizeof(*ctx_entry), GFP_KERNEL); if (!ctx_entry) { DRM_DEBUG("out of memory\n");