Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp247005ybh; Sun, 12 Jul 2020 05:06:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxW+Wq1Ee9GxPvKWWXujODCMj7lOhgiBnibe/s9i0doSQLSGaWN3IY5QBUWu4EVyGsEgx/c X-Received: by 2002:aa7:cfc8:: with SMTP id r8mr52385062edy.125.1594555609973; Sun, 12 Jul 2020 05:06:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594555609; cv=none; d=google.com; s=arc-20160816; b=ulYsdbnbBQ9yfD2UfGVrSua3O8BNiUJOrgiJIRz25Md49wCljgkCAdV+73/zmwPkZg 98UV5id/fbPthjJSPF20MD2CEWgmorf8L6hY4wgaX8+bBsFh+dUcVVilKJVNNxaRUG4d p1YIozKCwaYhCrZ2P4biP8KNm1R1WeG7ip7lBIb9BoZMIemW1qiOdPBsfK/cCRwaMkT6 DEij1RdF2F0qC5OFR3CtHl/Va2OQDraIe7RhuFqb9V2Z40hYCLgDTNdpjJgLAsccPN0D ye3WpIp7o39uerwhK33BSMtOY7YNyxysly24MGPT4kq/7T8N2WTiZGJYBTu4laLl0sVN 3hgA== 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:subject:cc:to:from:date :dkim-signature; bh=xB87LZqmMTWRJzI929qdXOjcQgUPE+352SysKJfJCms=; b=dsLXxop/+Acx+93KXB0TXUDEcyx0tJ/0llqQG8Gncx3XbFvsjs5PsUUskb0TI7MqeW bu1u4ffnOCw6+HsEXTarLJ7sTNG7QGDx2B9CpBa1yLLy+E98weMJuefttIlylY5ovkGP AWENknGosQKH1HdSYg1GKDJ3hZyAZ3h2ts2tGR0CLlT2lQF3/jlY8/zjlGD//eF+xCNH 5svfQS5yOctnnaLtgO56DGnWXiXBQnsvA0TOzMUPmgW4WGcyPUEzWR+T+AI0hI9vGLpJ Ur39NJNDbskeOoSonPeClkYW9OtjhbEYOQGgdem0mLUrpwhcJaoaUfHFYASKFQRwjHK0 IO8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DZYWlI9x; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l15si7197182eji.501.2020.07.12.05.06.27; Sun, 12 Jul 2020 05:06:49 -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; dkim=pass header.i=@kernel.org header.s=default header.b=DZYWlI9x; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728786AbgGLMC2 (ORCPT + 99 others); Sun, 12 Jul 2020 08:02:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:50426 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725765AbgGLMC2 (ORCPT ); Sun, 12 Jul 2020 08:02:28 -0400 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A98D7206E2; Sun, 12 Jul 2020 12:02:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594555347; bh=Y6o64oPzXqnkmkO5D5vSu68cq6MMV4hGP4lea6hgEco=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=DZYWlI9x1G3c2Y3/38BcyufUw/DWeM42v2JWmqSr0gj4zdO3STakd7DHta2+gk+/X 9hpUxcALSbsxZvzS0Av/nbEPrfDO7ClqXAC8EDyhxA/CIP9LDJoKDVnTICYroGXFge MfQ42fXtlvx18GIb7vnkJQ7ZT6JeShZqDzSv5NB4= Date: Sun, 12 Jul 2020 13:02:22 +0100 From: Jonathan Cameron To: Artur Rojek Cc: Dmitry Torokhov , Rob Herring , Mark Rutland , Paul Cercueil , Andy Shevchenko , Heiko Stuebner , Ezequiel Garcia , devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v8 2/6] IIO: Ingenic JZ47xx: Error check clk_enable calls. Message-ID: <20200712130222.76bf32ed@archlinux> In-Reply-To: <20200709152200.10039-3-contact@artur-rojek.eu> References: <20200709152200.10039-1-contact@artur-rojek.eu> <20200709152200.10039-3-contact@artur-rojek.eu> X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 9 Jul 2020 17:21:56 +0200 Artur Rojek wrote: > 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 Applied. Thanks, Jonathan > --- > > 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; > }