From patchwork Fri Aug 19 19:20:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 12949122 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D618EC32773 for ; Fri, 19 Aug 2022 19:20:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351452AbiHSTUp (ORCPT ); Fri, 19 Aug 2022 15:20:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351429AbiHSTU1 (ORCPT ); Fri, 19 Aug 2022 15:20:27 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 880AA4CA39; Fri, 19 Aug 2022 12:20:25 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id d23so2943003lfl.13; Fri, 19 Aug 2022 12:20:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc; bh=FdWk3y+T5Xz7F0ok6QUYuKZuWMUSNYttRlt11tcAS4o=; b=GZxVL7QRvxWWsB/hSG7pqSJMKuQnlrju1SMvDxiWaoMfVBtuJ3S4dmMCdAJQDsI6D7 aEo5jmgCPgWLU5qB17qMeZVJCVcvITK8Fi+PX60t1DCkiLaPkkTVj6cRdiValj58BsRn 1PBAd1QOPVJYxXf5YMO+vc33IAwpBhiNFBeBaiw1DEtgW66QJYzqNpGo9DUOYthYDLa6 MhdATPVcFV+lpi4KckDcKkdLB0vlntgXdbfKjvC7g87aIuW906+yYWuE2IbSjkV51gIx kMYoNcRnoRNKvpa7kvcyDLuhbkLOjzLqrtFgLHxeFDldhceMI0+d6g684fF738oVBJe1 jnfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=FdWk3y+T5Xz7F0ok6QUYuKZuWMUSNYttRlt11tcAS4o=; b=JZRYiHc5toWRHrr744RR5AxXE/eNHTjzuBObp3VkYeDi+hb2OECbUWm8i+c/aq0AP1 y+7lge7xow4B9QGarj32wjL60tQJ09l7/5WRrzLUo3CK+HVm60JDeZBDWgKkT6RSVINJ mbyqgsoylzmZFDsYoMWipeGmOZzJpW0JNhmxqb23PzgC1m1kuLG67mUJRGQg3e+Eq47g uypl0ivOOAQKAJZ9mzFSjPtSwQQg+ed4GstcwNindtXQg2NTW3VrVIlkRyDDAhOQC9Q6 Laov8fzHr7U1MHOT4KDp+Cp187SWIKKiZ4BC2sqwX10DoL7QsN11Js41wm9MxK+5OsN2 6wcA== X-Gm-Message-State: ACgBeo0CqeNd+oc6d6nMyaP8clKb5XaX6boZ67Mjs+xgxLMHT+e6/MkO xx+SF55cNzm6qf79YDcgKa4= X-Google-Smtp-Source: AA6agR6Nm6+xYuT0Cdd/DZvMSYDopH8+KN7zKoa6NqMWE7jDy4ZBgO1w5bvayvM5+eeSUhM4+mjQdg== X-Received: by 2002:a05:6512:358d:b0:48b:37f:dce2 with SMTP id m13-20020a056512358d00b0048b037fdce2mr2608198lfr.267.1660936823571; Fri, 19 Aug 2022 12:20:23 -0700 (PDT) Received: from dc75zzyyyyyyyyyyyyyyt-3.rev.dnainternet.fi (dc75zzyyyyyyyyyyyyyyt-3.rev.dnainternet.fi. [2001:14ba:16f3:4a00::1]) by smtp.gmail.com with ESMTPSA id w16-20020a19c510000000b00491aee1c4a5sm734450lfe.168.2022.08.19.12.20.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Aug 2022 12:20:22 -0700 (PDT) Date: Fri, 19 Aug 2022 22:20:18 +0300 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 11/14] iio: ad7606: simplify using devm_regulator_get_enable() Message-ID: <521c52f5a9bdc2db04d5775b36df4b233ae338da.1660934107.git.mazziesaccount@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Drop open-coded pattern: 'devm_regulator_get(), regulator_enable(), add_action_or_reset(regulator_disable)' and use the devm_regulator_get_enable() and drop the pointer to the regulator. This simplifies code and makes it less tempting to add manual control for the regulator which is also controlled by devm. Signed-off-by: Matti Vaittinen Acked-by: Nuno Sá --- v2 => v3: New patch --- drivers/iio/adc/ad7606.c | 22 +++------------------- drivers/iio/adc/ad7606.h | 1 - 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c index ba24f99523e0..dd6b603f65ea 100644 --- a/drivers/iio/adc/ad7606.c +++ b/drivers/iio/adc/ad7606.c @@ -557,13 +557,6 @@ static const struct iio_trigger_ops ad7606_trigger_ops = { .validate_device = iio_trigger_validate_own_device, }; -static void ad7606_regulator_disable(void *data) -{ - struct ad7606_state *st = data; - - regulator_disable(st->reg); -} - int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, const char *name, unsigned int id, const struct ad7606_bus_ops *bops) @@ -589,19 +582,10 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address, st->scale_avail = ad7606_scale_avail; st->num_scales = ARRAY_SIZE(ad7606_scale_avail); - st->reg = devm_regulator_get(dev, "avcc"); - if (IS_ERR(st->reg)) - return PTR_ERR(st->reg); - - ret = regulator_enable(st->reg); - if (ret) { - dev_err(dev, "Failed to enable specified AVcc supply\n"); - return ret; - } - - ret = devm_add_action_or_reset(dev, ad7606_regulator_disable, st); + ret = devm_regulator_get_enable(dev, "avcc"); if (ret) - return ret; + return dev_err_probe(dev, ret, + "Failed to enable specified AVcc supply\n"); st->chip_info = &ad7606_chip_info_tbl[id]; diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h index 2dc4f599f9df..924a2d1a6d94 100644 --- a/drivers/iio/adc/ad7606.h +++ b/drivers/iio/adc/ad7606.h @@ -92,7 +92,6 @@ struct ad7606_chip_info { struct ad7606_state { struct device *dev; const struct ad7606_chip_info *chip_info; - struct regulator *reg; const struct ad7606_bus_ops *bops; unsigned int range[16]; unsigned int oversampling;