From patchwork Fri Nov 24 22:04:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Khoroshilov X-Patchwork-Id: 10074659 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D530260375 for ; Fri, 24 Nov 2017 22:05:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8B0D2A141 for ; Fri, 24 Nov 2017 22:05:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BCDB12A1C4; Fri, 24 Nov 2017 22:05:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 74B362A140 for ; Fri, 24 Nov 2017 22:05:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753840AbdKXWEr (ORCPT ); Fri, 24 Nov 2017 17:04:47 -0500 Received: from mail.ispras.ru ([83.149.199.45]:41040 "EHLO mail.ispras.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753813AbdKXWEq (ORCPT ); Fri, 24 Nov 2017 17:04:46 -0500 Received: from localhost.localdomain (ppp85-140-182-168.pppoe.mtu-net.ru [85.140.182.168]) by mail.ispras.ru (Postfix) with ESMTPSA id 473E254006D; Sat, 25 Nov 2017 01:04:44 +0300 (MSK) From: Alexey Khoroshilov To: Laurent Pinchart , Mauro Carvalho Chehab Cc: Alexey Khoroshilov , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org Subject: [PATCH] [media] v4l: mt9v032: Disable clock on error paths Date: Sat, 25 Nov 2017 01:04:37 +0300 Message-Id: <1511561077-25192-1-git-send-email-khoroshilov@ispras.ru> X-Mailer: git-send-email 2.7.4 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP mt9v032_power_on() leaves clk enabled in case of errors, but it is not expected by its callers. There is a similar problem in mt9v032_registered(). Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Alexey Khoroshilov --- drivers/media/i2c/mt9v032.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/media/i2c/mt9v032.c b/drivers/media/i2c/mt9v032.c index 8a430640c85d..4de63b2df334 100644 --- a/drivers/media/i2c/mt9v032.c +++ b/drivers/media/i2c/mt9v032.c @@ -294,14 +294,22 @@ static int mt9v032_power_on(struct mt9v032 *mt9v032) /* Reset the chip and stop data read out */ ret = regmap_write(map, MT9V032_RESET, 1); if (ret < 0) - return ret; + goto err; ret = regmap_write(map, MT9V032_RESET, 0); if (ret < 0) - return ret; + goto err; + + ret = regmap_write(map, MT9V032_CHIP_CONTROL, + MT9V032_CHIP_CONTROL_MASTER_MODE); + if (ret < 0) + goto err; + + return 0; - return regmap_write(map, MT9V032_CHIP_CONTROL, - MT9V032_CHIP_CONTROL_MASTER_MODE); +err: + clk_disable_unprepare(mt9v032->clk); + return ret; } static void mt9v032_power_off(struct mt9v032 *mt9v032) @@ -876,6 +884,9 @@ static int mt9v032_registered(struct v4l2_subdev *subdev) /* Read and check the sensor version */ ret = regmap_read(mt9v032->regmap, MT9V032_CHIP_VERSION, &version); + + mt9v032_power_off(mt9v032); + if (ret < 0) { dev_err(&client->dev, "Failed reading chip version\n"); return ret; @@ -894,8 +905,6 @@ static int mt9v032_registered(struct v4l2_subdev *subdev) return -ENODEV; } - mt9v032_power_off(mt9v032); - dev_info(&client->dev, "%s detected at address 0x%02x\n", mt9v032->version->name, client->addr);