[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] drm/xen: fix potential memleak in error branch


  • To: Bernard Zhao <bernard@xxxxxxxx>, David Airlie <airlied@xxxxxxxx>, Daniel Vetter <daniel@xxxxxxxx>, "dri-devel@xxxxxxxxxxxxxxxxxxxxx" <dri-devel@xxxxxxxxxxxxxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, "linux-kernel@xxxxxxxxxxxxxxx" <linux-kernel@xxxxxxxxxxxxxxx>
  • From: Oleksandr Andrushchenko <Oleksandr_Andrushchenko@xxxxxxxx>
  • Date: Mon, 15 Nov 2021 14:04:44 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=YdvDzg0gK7ltXilC9ZV43mCJsJxkkgJAV7gwTIy6P5I=; b=jJbO1bTVcD4ZO67UPj5z9pcFhpo0SJm3mT7KQZ6vbmsJeY2QOBn/KxSE63C9Nn1MMy6orZFzmpbdWrVKRM619eDSIpviWhu1UUTQhbGDEg/3aik2zmVIa4WWec56nrkrzwzFowbRlSykGCpS5WOxnnQfLsKrbASKePtwe5QGdmvbSbgN8yrLSP8pt8cwWzPPt/dPviX/ah+GfuRVMaB5iJahcRo6NsJk3ohXIDwbLFm/QMlGg71rllrTjYWOfRvT4pN9mf9a0AAx43IkW5pC4Jntb4CMFB9ktxmIo2/vS7jIu1mBHBzrdyuDrXbp9LpQXyjMgvDE//FbfNPc+ajmEw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UvdlkRrvbuGwe5qU0dU0G3oZ0mpTJdur+WZl6RgcDGlBPZGDdFIi6G8NKtDvSi29z2eXVt/WcuPSbuvLE53Zwy3KvjFjkFqXtkhdjeMiWzFaVC0HHkEQAZKjPZoTAi2lmdO3rKLflhY3JDeLhm38CPxkR/0pmmW6dx1IBluVDGpS3RrvrWxSGjno4h44Ch9rjIbGXqdRes2WXq7B6qoGuOzmuUNDgpI1chQ2qANrnM8H8oBhxDg53PXbZAvuxPzvqPMP5RgP1JaJqj7Qv6Jv0tLb7w65cd1/bQgoIOStDOEM6vBk8VF8DotMjXeomPh5J7vnui68XffKFiJDOKEgBg==
  • Delivery-date: Mon, 15 Nov 2021 14:05:07 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHX2dM/C7peAofhs0mLDS2TsBGiLKwEn9OA
  • Thread-topic: [PATCH] drm/xen: fix potential memleak in error branch

Hi, Bernard!

On 15.11.21 05:45, Bernard Zhao wrote:
> In function xen_drm_front_gem_import_sg_table, if in error branch,
> there maybe potential memleak if not call gem_free_pages_array.
>
> Signed-off-by: Bernard Zhao <bernard@xxxxxxxx>
> ---
>   drivers/gpu/drm/xen/xen_drm_front_gem.c | 8 ++++++--
>   1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/xen/xen_drm_front_gem.c 
> b/drivers/gpu/drm/xen/xen_drm_front_gem.c
> index b293c67230ef..732c3eec0666 100644
> --- a/drivers/gpu/drm/xen/xen_drm_front_gem.c
> +++ b/drivers/gpu/drm/xen/xen_drm_front_gem.c
> @@ -222,15 +222,19 @@ xen_drm_front_gem_import_sg_table(struct drm_device 
> *dev,
>   
>       ret = drm_prime_sg_to_page_array(sgt, xen_obj->pages,
>                                        xen_obj->num_pages);
> -     if (ret < 0)
> +     if (ret < 0) {
> +             gem_free_pages_array(xen_obj);
>               return ERR_PTR(ret);
> +     }
This will be deleted on the fail path of the import by removing the GEM
object, so xen_drm_front_gem_free_object_unlocked will take care of this
>   
>       ret = xen_drm_front_dbuf_create(drm_info->front_info,
>                                       
> xen_drm_front_dbuf_to_cookie(&xen_obj->base),
>                                       0, 0, 0, size, sgt->sgl->offset,
>                                       xen_obj->pages);
> -     if (ret < 0)
> +     if (ret < 0) {
> +             gem_free_pages_array(xen_obj);
>               return ERR_PTR(ret);
> +     }
>   
>       DRM_DEBUG("Imported buffer of size %zu with nents %u\n",
>                 size, sgt->orig_nents);
Thank you,
Oleksandr

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.