From patchwork Tue Sep 24 18:42:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 277599 Return-Path: X-Original-To: incoming-imx@patchwork.ozlabs.org Delivered-To: patchwork-incoming-imx@bilbo.ozlabs.org Received: from casper.infradead.org (unknown [IPv6:2001:770:15f::2]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BC3562C00C3 for ; Wed, 25 Sep 2013 04:43:34 +1000 (EST) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VOXa1-0000Ah-Cn; Tue, 24 Sep 2013 18:43:25 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VOXZy-0001P0-Ll; Tue, 24 Sep 2013 18:43:22 +0000 Received: from metis.ext.pengutronix.de ([2001:6f8:1178:4:290:27ff:fe1d:cc33]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VOXZu-0001O9-PU for linux-arm-kernel@lists.infradead.org; Tue, 24 Sep 2013 18:43:19 +0000 Received: from dude.hi.pengutronix.de ([2001:6f8:1178:2:21e:67ff:fe11:9c5c]) by metis.ext.pengutronix.de with esmtp (Exim 4.72) (envelope-from ) id 1VOXZT-0003dy-D6; Tue, 24 Sep 2013 20:42:51 +0200 Received: from ukl by dude.hi.pengutronix.de with local (Exim 4.80) (envelope-from ) id 1VOXZR-0003a2-5f; Tue, 24 Sep 2013 20:42:49 +0200 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= To: Jonathan Corbet , Mauro Carvalho Chehab Subject: [PATCH] [media] marvell-ccic: simplify and fix clk handling (a bit) Date: Tue, 24 Sep 2013 20:42:47 +0200 Message-Id: <1380048167-13729-1-git-send-email-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 1.8.4.rc3 In-Reply-To: <1379951159-8294-1-git-send-email-u.kleine-koenig@pengutronix.de> References: <1379951159-8294-1-git-send-email-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:6f8:1178:2:21e:67ff:fe11:9c5c X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130924_144319_216880_55BDDBB9 X-CRM114-Status: GOOD ( 19.20 ) X-Spam-Score: -4.2 (----) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-4.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Libin Yang , Russell King , kernel@pengutronix.de, linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org List-Id: linux-imx-kernel.lists.patchwork.ozlabs.org The marvell-ccic does several things wrong or ineffectively in the clock handling and it's usage of the devm_* stuff - it assumes clk_get doesn't return NULL - it explicitly calls devm_clk_put instead just keeping the reference during it's lifetime and let the driver core call it - it calls kfree, gpio_free and free_irq for resources it requested using devm_kzalloc, devm_gpio_request and devm_request_irq respectively. - it mixes devm_ and unmanaged resources which probably results in a race condition during remove This patch fixes all but the last issue in this list. This patch doesn't introduce new reasons for not building, but there are already several bulid problems. Signed-off-by: Uwe Kleine-König --- Cc: Libin Yang --- drivers/media/platform/marvell-ccic/mmp-driver.c | 26 ++---------------------- 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/drivers/media/platform/marvell-ccic/mmp-driver.c b/drivers/media/platform/marvell-ccic/mmp-driver.c index b5a19af..49ff52e 100644 --- a/drivers/media/platform/marvell-ccic/mmp-driver.c +++ b/drivers/media/platform/marvell-ccic/mmp-driver.c @@ -143,7 +143,6 @@ static int mmpcam_power_up(struct mcam_camera *mcam) struct mmp_camera_platform_data *pdata; if (mcam->bus_type == V4L2_MBUS_CSI2) { - cam->mipi_clk = devm_clk_get(mcam->dev, "mipi"); if ((IS_ERR(cam->mipi_clk) && mcam->dphy[2] == 0)) return PTR_ERR(cam->mipi_clk); } @@ -186,12 +185,6 @@ static void mmpcam_power_down(struct mcam_camera *mcam) gpio_set_value(pdata->sensor_power_gpio, 0); gpio_set_value(pdata->sensor_reset_gpio, 0); - if (mcam->bus_type == V4L2_MBUS_CSI2 && !IS_ERR(cam->mipi_clk)) { - if (cam->mipi_clk) - devm_clk_put(mcam->dev, cam->mipi_clk); - cam->mipi_clk = NULL; - } - mcam_clk_disable(mcam); } @@ -325,19 +318,6 @@ static irqreturn_t mmpcam_irq(int irq, void *data) return IRQ_RETVAL(handled); } -static void mcam_deinit_clk(struct mcam_camera *mcam) -{ - unsigned int i; - - for (i = 0; i < NR_MCAM_CLK; i++) { - if (!IS_ERR(mcam->clk[i])) { - if (mcam->clk[i]) - devm_clk_put(mcam->dev, mcam->clk[i]); - } - mcam->clk[i] = NULL; - } -} - static void mcam_init_clk(struct mcam_camera *mcam) { unsigned int i; @@ -371,7 +351,7 @@ static int mmpcam_probe(struct platform_device *pdev) if (cam == NULL) return -ENOMEM; cam->pdev = pdev; - cam->mipi_clk = NULL; + cam->mipi_clk = devm_clk_get(&pdev->dev, "mipi"); INIT_LIST_HEAD(&cam->devlist); mcam = &cam->mcam; @@ -442,6 +422,7 @@ static int mmpcam_probe(struct platform_device *pdev) /* * Power the device up and hand it off to the core. */ + ret = mmpcam_power_up(mcam); if (ret) goto out_deinit_clk; @@ -470,7 +451,6 @@ out_unregister: out_power_down: mmpcam_power_down(mcam); out_deinit_clk: - mcam_deinit_clk(mcam); return ret; } @@ -487,10 +467,8 @@ static int mmpcam_remove(struct mmp_camera *cam) pdata = cam->pdev->dev.platform_data; gpio_free(pdata->sensor_reset_gpio); gpio_free(pdata->sensor_power_gpio); - mcam_deinit_clk(mcam); iounmap(cam->power_regs); iounmap(mcam->regs); - kfree(cam); return 0; }