Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2528328rwb; Fri, 11 Nov 2022 10:32:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf6UO/i0VFe1sZ0oPzdkdWBzfNVm70xPpwJ1xxu084etWzxTQyt4ND0sqRNXyT66SPmf537+ X-Received: by 2002:a05:6402:22e5:b0:457:791d:8348 with SMTP id dn5-20020a05640222e500b00457791d8348mr2638145edb.306.1668191534331; Fri, 11 Nov 2022 10:32:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668191534; cv=none; d=google.com; s=arc-20160816; b=01yWSBrbljljZhUDx9Y0gCJBv75m0e0R0SMTBF2Vyo0H5Zf8MP49xB1Gj8bfx68DE/ RAtmzQ4Ahm3GG+ycyWrx9YHDB/p2ug/7tbbU4TTgNY5ljB6JunCWXweImmMDxhKWWQ04 sSBdoJsy46uPPyRUoBJ+pQ2Vw62TeHN+hyQCahK//1xHFZRPJV/JsPYqgTOzGePecfY9 OOTN6L33DZk7bZem17fhJePRazdfzGhLG3h5qsi8wSVW/3eU9rahfnPsT4N+fF1+KMXr Xfd8qY3McmD3Pg333K/nikyFLhvJ7PhqPSbbI7hA0LArBO2+DHqddmyeCxYKh/xwQVcG 1hzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=YEMTD2oDy8i2j7FYxkuPB+Ih6U320F78S0GEoTeP6YI=; b=fAp6IrxuH3LEHNNMyZWgH84siNVfr30M6lxDiRXHWfZVS1U5kL9BRfCCJAM9Z9y1GD OhQT7YoRoBn1gSzGajotpdAWemKmiA7+tMHAr0DJ8d0Hf4DrUhGBgh5vxwncdsDW0cuI SA/7KhN97m6LILEfjNBCWERSY7kJU2DhL9Kw6pFbr25etZlN1AY2vc9ScrwXQcfXKxD/ fpD0TFC5uRXcWPs4XJHPx7I3QX1BUzwnSpktalzXmAfFEDQxsSa2Yj+pV4i+lQVKROKL Nl8Rlk2T6qXcNIZsxSjVJVesxQzofaOtRu622+bBCibX7wO6ah2ClrVB/xgsGen5xyYs aXLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=FMWR7sfU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hq37-20020a1709073f2500b00769d94690fesi2702186ejc.326.2022.11.11.10.31.52; Fri, 11 Nov 2022 10:32:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=FMWR7sfU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234088AbiKKSLN (ORCPT + 90 others); Fri, 11 Nov 2022 13:11:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234085AbiKKSKn (ORCPT ); Fri, 11 Nov 2022 13:10:43 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BBF063BAD for ; Fri, 11 Nov 2022 10:10:42 -0800 (PST) Received: from [192.168.2.108] (unknown [109.252.117.140]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dmitry.osipenko) by madras.collabora.co.uk (Postfix) with ESMTPSA id F13536602A42; Fri, 11 Nov 2022 18:10:39 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1668190240; bh=hCCpAhbEUa8/LLXwnIV87nxTTDpc6b/4kcIs4Wr2NCA=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=FMWR7sfUtjAPriAKjr5fzNysq0wiHmmdmIJbK3fI+sciVImumGHugv0Aaj2x3DJBU evQQjtszZXUsKNMzvEcLxwAO7GtC/wGHv8m8uYLvO5EmTBg8JaDBUyZUNwphTpAEFL T4QqFCVvovGqX72hrk0u9x11/mxsrsRniaQApO4YCFGIvuHuxhjpLzdDrdaXjAajdR ogV8C5gmBLTjUU+tifs8lvulhSCdPzJXxyjhkZ38Yxynf/DSPi4anaOFEvGwPLFrD3 QE/yaB+MkOvPPu9MbFnmH33u2SLrnZL+PtwCP+MDf5mjFSEaYbkCJ5j0eLxuVhlgqw cvebJ1wgapHmg== Message-ID: <9add69a6-9e81-9e5a-b039-fe869c2f3179@collabora.com> Date: Fri, 11 Nov 2022 21:10:36 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.0 Subject: Re: [PATCH] drm/virtio: Fix memory leak in virtio_gpu_object_create() To: Xiu Jianfeng , airlied@redhat.com, kraxel@redhat.com, gurchetansingh@chromium.org, olvaffe@gmail.com, daniel@ffwll.ch Cc: dri-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org References: <20221109091905.55451-1-xiujianfeng@huawei.com> Content-Language: en-US From: Dmitry Osipenko In-Reply-To: <20221109091905.55451-1-xiujianfeng@huawei.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/9/22 12:19, Xiu Jianfeng wrote: > The virtio_gpu_object_shmem_init() will alloc memory and save it in > @ents, so when virtio_gpu_array_alloc() fails, this memory should be > freed, this patch fixes it. > > Fixes: e7fef0923303 ("drm/virtio: Simplify error handling of virtio_gpu_object_create()") > Signed-off-by: Xiu Jianfeng > --- > drivers/gpu/drm/virtio/virtgpu_object.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/virtio/virtgpu_object.c b/drivers/gpu/drm/virtio/virtgpu_object.c > index 8d7728181de0..c7e74cf13022 100644 > --- a/drivers/gpu/drm/virtio/virtgpu_object.c > +++ b/drivers/gpu/drm/virtio/virtgpu_object.c > @@ -184,7 +184,7 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev, > struct virtio_gpu_object_array *objs = NULL; > struct drm_gem_shmem_object *shmem_obj; > struct virtio_gpu_object *bo; > - struct virtio_gpu_mem_entry *ents; > + struct virtio_gpu_mem_entry *ents = NULL; > unsigned int nents; > int ret; > > @@ -210,7 +210,7 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev, > ret = -ENOMEM; > objs = virtio_gpu_array_alloc(1); > if (!objs) > - goto err_put_id; > + goto err_free_entry; > virtio_gpu_array_add_obj(objs, &bo->base.base); > > ret = virtio_gpu_array_lock_resv(objs); > @@ -239,6 +239,8 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev, > > err_put_objs: > virtio_gpu_array_put_free(objs); > +err_free_entry: > + kvfree(ents); > err_put_id: > virtio_gpu_resource_id_put(vgdev, bo->hw_res_handle); > err_free_gem: Reviewed-by: Dmitry Osipenko -- Best regards, Dmitry