From patchwork Thu Jun 25 20:19:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 11627325 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 36DED6C1 for ; Fri, 26 Jun 2020 11:58:59 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D41432078D for ; Fri, 26 Jun 2020 11:58:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Bnh0pHUe"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="ZydIj9bp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D41432078D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=wanadoo.fr Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=zIzTdOhPlaqXU4pd6507EhOguyRYVlljrUNIf9r/ZvM=; b=Bnh0pHUe3sJRrpe463EEee7TT izBbHmR34EpCLd4IAanJ/NlhbQheKSEsjOorlHYjoJfSnQleuu/UNiOueu2kSzTqNo6/BkBiG2WXZ 6T8axWzzzP9h6pM8XcvdWsuXy53xYBIlqLplOpArtfAe0HdQWn2AkJgyyU3oIdjTvUoMoY9oh4uV0 KmwFHx+CJKbI5+njG9M6SwH1JuZ/sbr6z132g4MhrnOe5egVD3WyEwckSouSdkGVfS2S4q/cH25LL 7mYyGEXx3x25Qw+cP8ztQoUDsQHULaeWE6X2hcfaD/S1+m74p2bPipii5I/8STr1I8biWay16TFsb OA3T1MA7g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jomyu-0008Vy-Jg; Fri, 26 Jun 2020 11:57:21 +0000 Received: from casper.infradead.org ([90.155.50.34]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jolPT-0001jR-6M for linux-arm-kernel@merlin.infradead.org; Fri, 26 Jun 2020 10:16:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=VzTXRQ2JRlOwOpBq17t1uIjpRYRP4UED47lOocWZycQ=; b=ZydIj9bpRoS5O/B1eackjFG150 4hQwM9nILYuC/xC4ooPEg7eEhsjnY8PZIzAPA/xJH7phQOVzuBgAUC5qhhHxXuQjKMwBVaf0x00mT WAWOyfgKEveEXB5a5smJ6vbM1UwHnxjNA5zT8sNs68ccamP50V+nq8OCNGg2Gne9shv+h6owTyud9 vBZ+7ab0i7263DUR+0zx/qeTUtqZUIYei9ptuGczqi9qIc+EnD7o6L3S3YhTD9tUf4IZKXiH2zAV2 vS0VmG7ZfQLgVkv4wyPMGUwj8qUOkZSKRSu9NuWyTUQddxaEuaETnacAA5cXAUKOR6e+Ny7CQstED 0ixVZAlA==; Received: from smtp09.smtpout.orange.fr ([80.12.242.131] helo=smtp.smtpout.orange.fr) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1joYLm-0003k8-4i for linux-arm-kernel@lists.infradead.org; Thu, 25 Jun 2020 20:20:01 +0000 Received: from localhost.localdomain ([93.22.134.133]) by mwinf5d69 with ME id vYKo2200P2sr5ud03YKpeA; Thu, 25 Jun 2020 22:19:55 +0200 X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Thu, 25 Jun 2020 22:19:55 +0200 X-ME-IP: 93.22.134.133 From: Christophe JAILLET To: hverkuil@xs4all.nl, kyungmin.park@samsung.com, kamil@wypas.org, a.hajda@samsung.com, mchehab@kernel.org Subject: [PATCH] media: s5p-g2d: Fix a memory leak in an error handling path in 'g2d_probe()' Date: Thu, 25 Jun 2020 22:19:47 +0200 Message-Id: <20200625201947.943043-1-christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200426200631.42497-1-christophe.jaillet@wanadoo.fr> References: <20200426200631.42497-1-christophe.jaillet@wanadoo.fr> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200625_211958_431386_435E7154 X-CRM114-Status: GOOD ( 14.07 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.4 on casper.infradead.org summary: Content analysis details: (-1.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [80.12.242.131 listed in wl.mailspike.net] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [80.12.242.131 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Christophe JAILLET , kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Memory allocated with 'v4l2_m2m_init()' must be freed by a corresponding call to 'v4l2_m2m_release()' Also reorder the code at the end of the probe function so that 'video_register_device()' is called last. Update the error handling path accordingly. Fixes: 5ce60d790a24 ("[media] s5p-g2d: Add DT based discovery support") Fixes: 918847341af0 ("[media] v4l: add G2D driver for s5p device family") Signed-off-by: Christophe JAILLET --- V2: Call 'video_register_device()' as required by Hans Verkuil Compile tested only. --- drivers/media/platform/s5p-g2d/g2d.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/drivers/media/platform/s5p-g2d/g2d.c b/drivers/media/platform/s5p-g2d/g2d.c index 6932fd47071b..fb2e48dbabd4 100644 --- a/drivers/media/platform/s5p-g2d/g2d.c +++ b/drivers/media/platform/s5p-g2d/g2d.c @@ -695,21 +695,13 @@ static int g2d_probe(struct platform_device *pdev) vfd->lock = &dev->mutex; vfd->v4l2_dev = &dev->v4l2_dev; vfd->device_caps = V4L2_CAP_VIDEO_M2M | V4L2_CAP_STREAMING; - ret = video_register_device(vfd, VFL_TYPE_VIDEO, 0); - if (ret) { - v4l2_err(&dev->v4l2_dev, "Failed to register video device\n"); - goto rel_vdev; - } - video_set_drvdata(vfd, dev); - dev->vfd = vfd; - v4l2_info(&dev->v4l2_dev, "device registered as /dev/video%d\n", - vfd->num); + platform_set_drvdata(pdev, dev); dev->m2m_dev = v4l2_m2m_init(&g2d_m2m_ops); if (IS_ERR(dev->m2m_dev)) { v4l2_err(&dev->v4l2_dev, "Failed to init mem2mem device\n"); ret = PTR_ERR(dev->m2m_dev); - goto unreg_video_dev; + goto rel_vdev; } def_frame.stride = (def_frame.width * def_frame.fmt->depth) >> 3; @@ -717,14 +709,24 @@ static int g2d_probe(struct platform_device *pdev) of_id = of_match_node(exynos_g2d_match, pdev->dev.of_node); if (!of_id) { ret = -ENODEV; - goto unreg_video_dev; + goto free_m2m; } dev->variant = (struct g2d_variant *)of_id->data; + ret = video_register_device(vfd, VFL_TYPE_VIDEO, 0); + if (ret) { + v4l2_err(&dev->v4l2_dev, "Failed to register video device\n"); + goto free_m2m; + } + video_set_drvdata(vfd, dev); + dev->vfd = vfd; + v4l2_info(&dev->v4l2_dev, "device registered as /dev/video%d\n", + vfd->num); + return 0; -unreg_video_dev: - video_unregister_device(dev->vfd); +free_m2m: + v4l2_m2m_release(dev->m2m_dev); rel_vdev: video_device_release(vfd); unreg_v4l2_dev: