Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp661857pxj; Fri, 14 May 2021 12:25:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydruT5/0jDp4EvWeNgfrq8+ffpQfdkD6GKgV2HXGeTuJzhN5brtv68COVvbKw7quF+tmTd X-Received: by 2002:a05:6402:2064:: with SMTP id bd4mr21168340edb.96.1621020323014; Fri, 14 May 2021 12:25:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621020323; cv=none; d=google.com; s=arc-20160816; b=s3A7ZjoKgig9dpMmE32tW/kx7/YnBuWdBk3o6fsnRKyn3EUr76Vluci8IZoIEnvN6J s4bC8ha56Ah823OcPHRgxwqbB6P5RdXJTELWHWdk+2pwUfq5Fwhqdc862yMUBHbFL2SR Ziqmc7WxYz0f57v7wL8ngyigS+J5gnWyzykevhGTKtiTL/Zd/qGeC3VXQUoVuPBlDiyU gFn4vYyGGiBZXhjy9vGRlRAuVEZo/jqO3VZpnlnglndZLZ00A+9JwZOOgAm2kV9vVr8X yW8Zz34fThwpWpXiVHPIyNiY6c7+ydSDY3KwQthoyWeNeR3iRbz3+qF5ceqqAQSfClmo +WBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=b105tiDbnWmTUVBq0/2fMno82vTx+NY6GQ7045vj76Q=; b=hxgK1hDzcmPuDrb//UOcx5Kt2KEBJQoq6sd61PATQcqSgqNn95AslK/uLmEFJovKZX 7td00T14z2Ikf7eEDxeyybNLlWUDwq9sCiZkCVXc0uMMMo4ld9EB2wZWNILsGxy3augP epZ5XHiaiA46Sv1xtgS/d1rW/xwXQGZ8IS55Ipfu8Qkv/7Ls0INC4JiuIzfenUDKO4BU xZqozZfWlqrecqIkBYrQ9ip4xav76AxVgVSRgqG8aODNCbcalGPilAlVded+yirHySUF ljr7/10uwmeNz2BUvnK48iYGtv92w3kowPbno0gvkb+OLfnLq7wIqEbsJLPo8ejKoO+h 9RjQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h14si174775eje.92.2021.05.14.12.24.59; Fri, 14 May 2021 12:25:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231539AbhENOur (ORCPT + 99 others); Fri, 14 May 2021 10:50:47 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:45038 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233044AbhENOup (ORCPT ); Fri, 14 May 2021 10:50:45 -0400 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1lhZ87-0006J9-0E; Fri, 14 May 2021 14:49:31 +0000 From: Colin King To: VMware Graphics , Roland Scheidegger , Zack Rusin , David Airlie , Daniel Vetter , dri-devel@lists.freedesktop.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][V2][next] drm/vmwgfx: Fix memory allocation check and a leak of object fifo Date: Fri, 14 May 2021 15:49:30 +0100 Message-Id: <20210514144930.89813-1-colin.king@canonical.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King The allocation of fifo is lacking an allocation failure check, so fix this by adding one. In the case where fifo->static_buffer fails to be allocated the error return path neglects to kfree the fifo object. Fix this by adding in the missing kfree. Kudos to Dan Carpenter for spotting the missing kzalloc failure check. Addresses-Coverity: ("Resource leak") Fixes: 2cd80dbd3551 ("drm/vmwgfx: Add basic support for SVGA3") Signed-off-by: Colin Ian King --- V2: Add missing allocation failure check Update $SUBJECT to reflect this extra change --- drivers/gpu/drm/vmwgfx/vmwgfx_cmd.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_cmd.c b/drivers/gpu/drm/vmwgfx/vmwgfx_cmd.c index 027d7d504e78..d9acd2f3f673 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_cmd.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_cmd.c @@ -105,10 +105,14 @@ struct vmw_fifo_state *vmw_fifo_create(struct vmw_private *dev_priv) return NULL; fifo = kzalloc(sizeof(*fifo), GFP_KERNEL); + if (!fifo) + return ERR_PTR(-ENOMEM); fifo->static_buffer_size = VMWGFX_FIFO_STATIC_SIZE; fifo->static_buffer = vmalloc(fifo->static_buffer_size); - if (unlikely(fifo->static_buffer == NULL)) + if (unlikely(fifo->static_buffer == NULL)) { + kfree(fifo); return ERR_PTR(-ENOMEM); + } fifo->dynamic_buffer = NULL; fifo->reserved_size = 0; -- 2.30.2