Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1498487ybt; Thu, 9 Jul 2020 08:26:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGyNlQKXD7JQ8pZ+1OeqwXqJtWiKuE+/BVvlJ1BtXuMNiR8tAyy24O0gy+znZp13X4Ujcm X-Received: by 2002:a05:6402:1d0b:: with SMTP id dg11mr40095629edb.212.1594308390281; Thu, 09 Jul 2020 08:26:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594308390; cv=none; d=google.com; s=arc-20160816; b=nN7KkM/QSBtqzF6m2+TI+c+w6K6qdzgr8Pc+YOL/jqXJ+HkKaYDTzTPwmDj2KCADOD CZP35V8x4+akOYdwROW0WO85fdw4D7bj96Pm8Jy7aDo9agAQkYIam+mcsOIJmHUuTcZt BLbHneHTb7xzmXdfrfSm/3az3+JQ5S7ei2s065+HZGUsN/QZfWfvU2N393ksH3Zc1CoB 75w6l/Lm/lJ35dAksyKGkNPyxWGySjXGuGPlmjpf48zJhGPjJHD7swY3Zw9cMqt3kmMa k/K5Sym37L2YLwnf7kKu0alo6WO4O+tU5+E15gn/mc0lvcUUNG9ZgPYT5ONUIByZHOsl 2PMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=UxLrnCHHx6JzxNzrQImAKW6dPzQ/bThYZvGTl49P+GM=; b=0SOahfldascklNyXfyBrz8BfpIIEbbjEkIJAbWVEyxx7w4qcuOU7Nhx5KMpod6SG0w SYiaReWUBKhlmA1tsjvVS+2Qov2f2W7WHmFoQoznFoLCmLGirwY7HmBuKkWl5NoQOMNu 5PllsxNFMFE0GR02frMbE2wLLIG3jZyzUlQkOHdPdN3mKFgHbMLoSYKW5RTWQiSRAOBY wxg6yHuCd1GsyYQB6wvKkqJ8ZDlJt/Gf8Hr0mo4HOPeLDDO8y56p+46yZlj1RtQDap7o 9soI6KVDG3lgyq7Thq9yzxHrrYn/gUkWGdl9dmtD7ZBbYeF9vVaZPOdh4IlsXm/9huXM jphA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m15si2033854ejr.38.2020.07.09.08.26.07; Thu, 09 Jul 2020 08:26:30 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728467AbgGIPXH (ORCPT + 99 others); Thu, 9 Jul 2020 11:23:07 -0400 Received: from relay6-d.mail.gandi.net ([217.70.183.198]:32927 "EHLO relay6-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728239AbgGIPWq (ORCPT ); Thu, 9 Jul 2020 11:22:46 -0400 X-Originating-IP: 195.189.32.242 Received: from pc.localdomain (unknown [195.189.32.242]) (Authenticated sender: contact@artur-rojek.eu) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 396F8C0010; Thu, 9 Jul 2020 15:22:42 +0000 (UTC) From: Artur Rojek To: Dmitry Torokhov , Rob Herring , Mark Rutland , Jonathan Cameron , Paul Cercueil , Andy Shevchenko Cc: Heiko Stuebner , Ezequiel Garcia , devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Artur Rojek Subject: [PATCH v8 2/6] IIO: Ingenic JZ47xx: Error check clk_enable calls. Date: Thu, 9 Jul 2020 17:21:56 +0200 Message-Id: <20200709152200.10039-3-contact@artur-rojek.eu> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200709152200.10039-1-contact@artur-rojek.eu> References: <20200709152200.10039-1-contact@artur-rojek.eu> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce error checks for the clk_enable calls used in this driver. As part of the changes, move clk_enable/clk_disable calls out of ingenic_adc_set_config and into respective logic of its callers. Signed-off-by: Artur Rojek Tested-by: Paul Cercueil --- Changes: v6: new patch v7: no change v8: move `clk_disable` outside the lock drivers/iio/adc/ingenic-adc.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/drivers/iio/adc/ingenic-adc.c b/drivers/iio/adc/ingenic-adc.c index 39c0a609fc94..c1946a9f1cca 100644 --- a/drivers/iio/adc/ingenic-adc.c +++ b/drivers/iio/adc/ingenic-adc.c @@ -73,7 +73,6 @@ static void ingenic_adc_set_config(struct ingenic_adc *adc, { uint32_t cfg; - clk_enable(adc->clk); mutex_lock(&adc->lock); cfg = readl(adc->base + JZ_ADC_REG_CFG) & ~mask; @@ -81,7 +80,6 @@ static void ingenic_adc_set_config(struct ingenic_adc *adc, writel(cfg, adc->base + JZ_ADC_REG_CFG); mutex_unlock(&adc->lock); - clk_disable(adc->clk); } static void ingenic_adc_enable(struct ingenic_adc *adc, @@ -124,6 +122,8 @@ static int ingenic_adc_write_raw(struct iio_dev *iio_dev, long m) { struct ingenic_adc *adc = iio_priv(iio_dev); + struct device *dev = iio_dev->dev.parent; + int ret; switch (m) { case IIO_CHAN_INFO_SCALE: @@ -131,6 +131,14 @@ static int ingenic_adc_write_raw(struct iio_dev *iio_dev, case INGENIC_ADC_BATTERY: if (!adc->soc_data->battery_vref_mode) return -EINVAL; + + ret = clk_enable(adc->clk); + if (ret) { + dev_err(dev, "Failed to enable clock: %d\n", + ret); + return ret; + } + if (val > JZ_ADC_BATTERY_LOW_VREF) { ingenic_adc_set_config(adc, JZ_ADC_REG_CFG_BAT_MD, @@ -142,6 +150,9 @@ static int ingenic_adc_write_raw(struct iio_dev *iio_dev, JZ_ADC_REG_CFG_BAT_MD); adc->low_vref_mode = true; } + + clk_disable(adc->clk); + return 0; default: return -EINVAL; @@ -317,6 +328,13 @@ static int ingenic_adc_read_chan_info_raw(struct ingenic_adc *adc, int *val) { int bit, ret, engine = (chan->channel == INGENIC_ADC_BATTERY); + struct device *dev = iio_priv_to_dev(adc)->dev.parent; + + ret = clk_enable(adc->clk); + if (ret) { + dev_err(dev, "Failed to enable clock: %d\n", ret); + return ret; + } /* We cannot sample AUX/AUX2 in parallel. */ mutex_lock(&adc->aux_lock); @@ -325,7 +343,6 @@ static int ingenic_adc_read_chan_info_raw(struct ingenic_adc *adc, ingenic_adc_set_config(adc, JZ_ADC_REG_CFG_AUX_MD, bit); } - clk_enable(adc->clk); ret = ingenic_adc_capture(adc, engine); if (ret) goto out; @@ -342,8 +359,8 @@ static int ingenic_adc_read_chan_info_raw(struct ingenic_adc *adc, ret = IIO_VAL_INT; out: - clk_disable(adc->clk); mutex_unlock(&adc->aux_lock); + clk_disable(adc->clk); return ret; } -- 2.27.0