Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp85596pxb; Mon, 13 Sep 2021 13:38:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyrIC6+mRnlJjK3/Xm3W9yQtpP/WM9Xji4OPW2pWmRwJLMSQUZBP2OHUODPvT0U/HyoJIa X-Received: by 2002:a17:906:4994:: with SMTP id p20mr14737551eju.38.1631565499390; Mon, 13 Sep 2021 13:38:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631565499; cv=none; d=google.com; s=arc-20160816; b=DSVEAsjNkaThHQUsfSDIbDBCi3yFRDuXKhs4gSrJCbuSEh8XAmNY6yeysgRlVNYol8 /3yPQn1CIBzNwcSMnO3XYseh62urKvbyI821sBIFP/vpc2bqfOsv5OvJmxnkCE6VWV1V Fs/FqQz0wLzhUd5NqPFNMoc1ErXDOvWl3mZ/+iZ5HJslWBSarnAsgy2hXNoVXKS4gTy9 9fzb1bTbZQ8PTB3BaljQrw7HQC3Ej5pt6qnLs8jj0Vi/g9CRKyIxBbHMH8pTqYizjsqY YUX027UgL6cIhPbaNA7InOUwnAu6gonF9KdbbfQNEPlnd2Zwz4mcK+W+ymqTLJUO9LQ6 5fQA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=DRdA0RVA5nCMSK9xJGEMtkpcgXw9gE1NWNjJQtxzsss=; b=o+FAEboxhrA+7VdRavnQ76YFBeWW93830mM2Zr4br8VFmLdix3ngsRfXLtksoqEue+ 9kk2Mr3fMSOYsza2uv3ir3G9v+1E5Z5JS7FIH9imXDh3VxRJMGTmBVnPVakqcSk/bHFW LlwYWx6EBKTYICST+bteBG7n7eiMYkiBXl+oXKbMF2YkbEvs7sdhvdm6YuEfRE09T6Sj rvvuUYOd+KRHQqeBAhXkG6+8fha0kcdbMUL+NgeDcNY4Bm7jR3JaQ5DJoFwb96Bfh4gY +TQe5NgDUEozjnRVXgRrpXcZD3E0fKRUycvduGRs0ApzOOARUkxUJBUiQLnZBkG0Rb/m j1lQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iCJUxSVl; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z2si1581615ejl.182.2021.09.13.13.37.55; Mon, 13 Sep 2021 13:38:19 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iCJUxSVl; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242296AbhIMNpe (ORCPT + 99 others); Mon, 13 Sep 2021 09:45:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:39122 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241424AbhIMNjM (ORCPT ); Mon, 13 Sep 2021 09:39:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 27A1A61279; Mon, 13 Sep 2021 13:28:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539733; bh=0eVmFigmvePfK0NtKm7EzbzuJ3ya/9SnuQww5F3AvfQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iCJUxSVldPC4b5PaUkWzH9gxcRRzwHgX8x0p9uNUnV4KCBqRI429E4uJgwP0j0ifg d9Vx08/shStdmDGNYbCVxEp1zddkCeE23Up+c80MCdc+8Pva1hSLujf976Irtp+C7c mSbgXVS+n4qNSG2i2xvSj+l4EvWlP2vm/fvetyCQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dongliang Mu , Dan Carpenter , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 5.10 097/236] media: rockchip/rga: fix error handling in probe Date: Mon, 13 Sep 2021 15:13:22 +0200 Message-Id: <20210913131103.653472896@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131100.316353015@linuxfoundation.org> References: <20210913131100.316353015@linuxfoundation.org> User-Agent: quilt/0.66 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: Dan Carpenter [ Upstream commit e58430e1d4fd01b74475d2fbe2e25b5817b729a9 ] There are a few bugs in this code. 1) No checks for whether dma_alloc_attrs() or __get_free_pages() failed. 2) If video_register_device() fails it doesn't clean up the dma attrs or the free pages. 3) The video_device_release() function frees "vfd" which leads to a use after free on the next line. The call to video_unregister_device() is not required so I have just removed that. Fixes: f7e7b48e6d79 ("[media] rockchip/rga: v4l2 m2m support") Reported-by: Dongliang Mu Signed-off-by: Dan Carpenter Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/platform/rockchip/rga/rga.c | 27 ++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/platform/rockchip/rga/rga.c index bf3fd71ec3af..6759091b15e0 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -863,12 +863,12 @@ static int rga_probe(struct platform_device *pdev) if (IS_ERR(rga->m2m_dev)) { v4l2_err(&rga->v4l2_dev, "Failed to init mem2mem device\n"); ret = PTR_ERR(rga->m2m_dev); - goto unreg_video_dev; + goto rel_vdev; } ret = pm_runtime_resume_and_get(rga->dev); if (ret < 0) - goto unreg_video_dev; + goto rel_vdev; rga->version.major = (rga_read(rga, RGA_VERSION_INFO) >> 24) & 0xFF; rga->version.minor = (rga_read(rga, RGA_VERSION_INFO) >> 20) & 0x0F; @@ -882,11 +882,23 @@ static int rga_probe(struct platform_device *pdev) rga->cmdbuf_virt = dma_alloc_attrs(rga->dev, RGA_CMDBUF_SIZE, &rga->cmdbuf_phy, GFP_KERNEL, DMA_ATTR_WRITE_COMBINE); + if (!rga->cmdbuf_virt) { + ret = -ENOMEM; + goto rel_vdev; + } rga->src_mmu_pages = (unsigned int *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, 3); + if (!rga->src_mmu_pages) { + ret = -ENOMEM; + goto free_dma; + } rga->dst_mmu_pages = (unsigned int *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, 3); + if (rga->dst_mmu_pages) { + ret = -ENOMEM; + goto free_src_pages; + } def_frame.stride = (def_frame.width * def_frame.fmt->depth) >> 3; def_frame.size = def_frame.stride * def_frame.height; @@ -894,7 +906,7 @@ static int rga_probe(struct platform_device *pdev) ret = video_register_device(vfd, VFL_TYPE_VIDEO, -1); if (ret) { v4l2_err(&rga->v4l2_dev, "Failed to register video device\n"); - goto rel_vdev; + goto free_dst_pages; } v4l2_info(&rga->v4l2_dev, "Registered %s as /dev/%s\n", @@ -902,10 +914,15 @@ static int rga_probe(struct platform_device *pdev) return 0; +free_dst_pages: + free_pages((unsigned long)rga->dst_mmu_pages, 3); +free_src_pages: + free_pages((unsigned long)rga->src_mmu_pages, 3); +free_dma: + dma_free_attrs(rga->dev, RGA_CMDBUF_SIZE, rga->cmdbuf_virt, + rga->cmdbuf_phy, DMA_ATTR_WRITE_COMBINE); rel_vdev: video_device_release(vfd); -unreg_video_dev: - video_unregister_device(rga->vfd); unreg_v4l2_dev: v4l2_device_unregister(&rga->v4l2_dev); err_put_clk: -- 2.30.2