Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp10727384rwl; Mon, 2 Jan 2023 07:16:42 -0800 (PST) X-Google-Smtp-Source: AMrXdXvMix7KivNjbNd82MzjWmG1kBL7eyOOMkZFipYwkCDbyzUtXhNv4rbCgCoNt0M3zo7Vm6Au X-Received: by 2002:a05:6a00:1d1f:b0:581:ad48:d480 with SMTP id a31-20020a056a001d1f00b00581ad48d480mr17451371pfx.34.1672672602351; Mon, 02 Jan 2023 07:16:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672672602; cv=none; d=google.com; s=arc-20160816; b=T74pWl95kbdG0Y1PNtq/scReFgqwwBRu2yhzYRxkVD++2Is5jjH6jZEgDm1zOkHuq4 6Nd/A+/XtFNkx09c5J1GdiuqcWPjkBniNzHorbaFYopwWBbuwsC047bk1MYvniXmhzbo Pw7Piu2mUbjIkCYXWH33Bve/nyXR0kG724IqnAlHp9yGWpKsFHmMiXJJ4honB7S1mGPR KvN5U0bsJMyHRpiy4DRZ+TdC78ARXflu/hk3vIXFm0GvCNIhtdDrvMZCkOR+0fD0tDrR 0ZrUFI8v3zhIUcBszeorvUg2UhQhY7u9lA/2ekMuBkkXYt/1Ao3BMEG6xpLzn86TSnxw rqPA== 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 :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=4A3Hhfz7RoCaCQ6MQY090KxrvZ+mJw2v9+f7RV6qwZM=; b=KX0etEET6VSKMwfrwA7h/UhWXzeRuEupl0uhOGZSqxb+PTJES5sTbn2RBpRZPRPqu3 Xc+ZRuIlkvBQulL/j572nkpiNJN0c5LPVIra3Ig1voiV5EyzzDjo8DGBlDdUQk6roQHX 0yrwLbhcYPgaAPn4T6ElQmypulveFeoGeKa1ytpnqj+l9NM6RGKChMmIZf+0xkNV/mQP cmViv6vvux+62miKOOyDKu8n29tfzMIuCYRP0ohSFd47j4Jli/zKanlYY1/pt5nrbvDE 0r5ZFLzQpsNG7s5ZY4K7U2aDdzMfiocOZKstdc7xxDdu3e6QlDT44XrAAyQVOSU2P6X5 zmxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=CgxebuPv; 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 u62-20020a638541000000b0047886bf1542si30008893pgd.14.2023.01.02.07.16.34; Mon, 02 Jan 2023 07:16:42 -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=CgxebuPv; 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 S235946AbjABO75 (ORCPT + 61 others); Mon, 2 Jan 2023 09:59:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236019AbjABO7x (ORCPT ); Mon, 2 Jan 2023 09:59:53 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13C0B7659 for ; Mon, 2 Jan 2023 06:59:52 -0800 (PST) Received: from [192.168.2.142] (109-252-113-89.nat.spd-mgts.ru [109.252.113.89]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: dmitry.osipenko) by madras.collabora.co.uk (Postfix) with ESMTPSA id 3985C660036F; Mon, 2 Jan 2023 14:59:50 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1672671590; bh=pr7QKqvU3i2MW8VtEHvkS2Xid3lfTdkU/ArV8Cnv7Tg=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=CgxebuPvia7ztEmuvxa409ukvvV3j/jxgT026sGBSp+chqnhVCB9FVIFIPTmm92Xi Q7oGavLGyhS+Sxc3IV4oKT3j1VDvflDmF+3+OR0zLJsXrt6t+yXBSpgaNzm6PH1Jqm K74Tn0xCa2uhq/mmaD55g36lx4/GiPJYOyCuaswRO8rsV+qXiiB/RAlZsEPU0HxVzr +TeTk3eoD4s6EdJyBsKUovK2Hps64KQEWe2XNPqwrPZCBaCLHs6rtJMDrndAWpWjsS os66iGBzALJwdYiMdrnq2pvQcljSTpdhr+mRNxgzw0k66/JH+1QFlzajkKdkn5Lc9G BXlsujBUl1DaQ== Message-ID: <6ca8b461-c481-bb18-699a-f4671bd773f2@collabora.com> Date: Mon, 2 Jan 2023 17:59:47 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: [PATCH] drm/virtio: Fix memory leak in virtio_gpu_object_create() Content-Language: en-US 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> 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=-5.2 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: Applied to drm-misc-fixes -- Best regards, Dmitry