From patchwork Sat May 3 16:13:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guennadi Liakhovetski X-Patchwork-Id: 4106221 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E4629C0ACC for ; Sat, 3 May 2014 16:13:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 204102020F for ; Sat, 3 May 2014 16:13:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 005532028D for ; Sat, 3 May 2014 16:13:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752837AbaECQNJ (ORCPT ); Sat, 3 May 2014 12:13:09 -0400 Received: from mout.kundenserver.de ([212.227.126.187]:60883 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752790AbaECQNI (ORCPT ); Sat, 3 May 2014 12:13:08 -0400 Received: from axis700.grange (dslb-178-009-254-245.pools.arcor-ip.net [178.9.254.245]) by mrelayeu.kundenserver.de (node=mreue004) with ESMTP (Nemesis) id 0MYrHb-1WKz6v0BU3-00Vgci; Sat, 03 May 2014 18:13:06 +0200 Received: by axis700.grange (Postfix, from userid 1000) id 8D50440BDB; Sat, 3 May 2014 18:13:05 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by axis700.grange (Postfix) with ESMTP id 8466740BD9 for ; Sat, 3 May 2014 18:13:05 +0200 (CEST) Date: Sat, 3 May 2014 18:13:05 +0200 (CEST) From: Guennadi Liakhovetski X-X-Sender: lyakh@axis700.grange To: Linux Media Mailing List Subject: [PATCH] V4L: soc-camera: wxplicitly free allocated managed memory on error Message-ID: MIME-Version: 1.0 X-Provags-ID: V02:K0:EgFV0bwQp7jqL7W1Pw1qO5qQkYCDYTjatysnasgMX9K lkGrx4k0+OmLtoGyRWDXh3jXrjAc6x0rf2teAqzuDLw6KClpvL cZG+44E0LR11h3/BeHv8Lk4z7qn9hFjrAoUgIERCZO20tkohSX wD8D5vL4b/X5u5kvhpWcFVACbrPwqQy7GByqeUKIiUhpNamzg4 QqO9vwvzIxe651SFFYIsJ2IaXhLHpEFR5Aiuk86WoLjU7CQs2S bZCQrh7YKBAoPmJQpyuZ/2qRgkhUwlnq8d93e1RoJyGxB5KYVd ZWBXXGxPh/q9XOdB/3dcrrZIY2DoNvKsV12ejGQbxBLPpilavS 4pbaQhuS/MeQ3choFsEnudRYAz/Lsojru9MhyC0HlvRD437pF7 vJddPTpCyOosw== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP devm_kzalloc() allocations are freed when the device is unbound. But if a certain path fails and the allocated memory cannot be used anyway it is better to free it explicitly immediately. This patch does exactly this if asynchronous group probing in scan_async_group() fails after memory has been allocated. Signed-off-by: Guennadi Liakhovetski --- drivers/media/platform/soc_camera/soc_camera.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/soc_camera/soc_camera.c b/drivers/media/platform/soc_camera/soc_camera.c index 4b8c024..ef5e197 100644 --- a/drivers/media/platform/soc_camera/soc_camera.c +++ b/drivers/media/platform/soc_camera/soc_camera.c @@ -1522,14 +1522,14 @@ static int scan_async_group(struct soc_camera_host *ici, ret = soc_camera_dyn_pdev(&sdesc, sasc); if (ret < 0) - return ret; + goto eallocpdev; sasc->sensor = &sasd->asd; icd = soc_camera_add_pdev(sasc); if (!icd) { - platform_device_put(sasc->pdev); - return -ENOMEM; + ret = -ENOMEM; + goto eaddpdev; } sasc->notifier.subdevs = asd; @@ -1557,7 +1557,11 @@ static int scan_async_group(struct soc_camera_host *ici, v4l2_clk_unregister(icd->clk); eclkreg: icd->clk = NULL; - platform_device_unregister(sasc->pdev); + platform_device_del(sasc->pdev); +eaddpdev: + platform_device_put(sasc->pdev); +eallocpdev: + devm_kfree(ici->v4l2_dev.dev, sasc); dev_err(ici->v4l2_dev.dev, "group probe failed: %d\n", ret); return ret;