From patchwork Wed Apr 6 12:29:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ma=C3=ADra_Canal?= X-Patchwork-Id: 12803619 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 44501C433F5 for ; Wed, 6 Apr 2022 15:27:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236131AbiDFP3m (ORCPT ); Wed, 6 Apr 2022 11:29:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235682AbiDFP3P (ORCPT ); Wed, 6 Apr 2022 11:29:15 -0400 Received: from mail-oa1-x32.google.com (mail-oa1-x32.google.com [IPv6:2001:4860:4864:20::32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D6D156122D for ; Wed, 6 Apr 2022 05:29:09 -0700 (PDT) Received: by mail-oa1-x32.google.com with SMTP id 586e51a60fabf-d6e29fb3d7so2689628fac.7 for ; Wed, 06 Apr 2022 05:29:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp.br; s=usp-google; h=date:from:to:subject:message-id:mime-version:content-disposition :content-transfer-encoding; bh=f9uUO1j3Pv/5fo7aHMxUGqKZLMa4C4Cbm+pCSR0pZdg=; b=Jgn1UZ4t04iIJsvgNJOclG2gtp7Az/+qysNdFnh3eLRkCs+8SzZAHC/1WjOVLWQMh/ PzmtRz7Wuv1otNj2iwwR/t8RxAWBwq/SL24Pq2pJJZUqURusxQwV1J3DCX5o9Cp0OY1e OjBqIMZ2PfAS2qXVbVSQbAj79dZrvfnx9WJujiLQ0uZP8KHzcs3siWWFRujYH+Cp3KHx 9p4L3rozr4sl9jwpP0MLavEy3LFOc6pQnGLgNCVExt5n9kgB2YWZEzu/MCG88B0nlUYy PxxJbJ+hI15qzgqJ2shzKQ3An7yVR5UKdqr1VI72+5z2umJ7jpddHjn/7Nos+V6ZGxIM LGPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:content-transfer-encoding; bh=f9uUO1j3Pv/5fo7aHMxUGqKZLMa4C4Cbm+pCSR0pZdg=; b=JHgnGNWgWqa1ES4dbJyYtT8HrRSMW6JES+UXnd/dWaJnYJvMonXXWe6Xx7O3xSMp5B OUH9pYqs4WoP09uBlywdouH+LYy6U0H75YcGzuBgOPFMb7IlWsNZ2Zu0xcp8+JgyxIk1 toJ+qDKIBEB6DsTxElJ0RivRfUyO7yVCDw2UyBCNHVPTvK5LQNyY5eUQg3NiRFNHI0wv E/vJKsOrPauHBOpKpP3kPqUvcDIE853yYA1qHvwibIrKmt18ZPKIRBG+AnRhYqzmZeoZ xOrvlHmuv7KfPyZGOgUPa84eEhmPs6UrrSXPE3nQArcxyvmxWCZqM6k70iLpQprf8Qn3 CCyQ== X-Gm-Message-State: AOAM530b/f1JyvHPj0mBiolXwd3ILeX5cN0PUBq7eFISj5+2/wJK0BLM ndcEZN8urn8pUmTlOyNivYFPqg== X-Google-Smtp-Source: ABdhPJxQAh7U7BTJOVmhbyWXNLrCv5Youq0bLX6t3zA8GC5zw7+zx9Xbj6Cz7ncvfDCYrPI+MjDeag== X-Received: by 2002:a05:6870:1cc:b0:e1:fabc:6e03 with SMTP id n12-20020a05687001cc00b000e1fabc6e03mr3753415oad.16.1649248148501; Wed, 06 Apr 2022 05:29:08 -0700 (PDT) Received: from fedora ([2804:14d:8084:84c6:2e13:8e30:84f7:1597]) by smtp.gmail.com with ESMTPSA id t4-20020a0568301e2400b005c9781086d9sm6575055otr.9.2022.04.06.05.29.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 05:29:08 -0700 (PDT) Date: Wed, 6 Apr 2022 09:29:04 -0300 From: =?iso-8859-1?q?Ma=EDra?= Canal To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] iio: ad7266: convert probe to full device-managed Message-ID: MIME-Version: 1.0 Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Convert probe functions to device-managed variants, with exception of the regulator, which required a devm_add_action_or_reset() hook registration. Signed-off-by: MaĆ­ra Canal --- drivers/iio/adc/ad7266.c | 43 +++++++++++++--------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/drivers/iio/adc/ad7266.c b/drivers/iio/adc/ad7266.c index c17d9b5fbaf6..4f8f07d5c1a3 100644 --- a/drivers/iio/adc/ad7266.c +++ b/drivers/iio/adc/ad7266.c @@ -378,6 +378,11 @@ static const char * const ad7266_gpio_labels[] = { "ad0", "ad1", "ad2", }; +static void ad7266_reg_disable(void *reg) +{ + regulator_disable(reg); +} + static int ad7266_probe(struct spi_device *spi) { struct ad7266_platform_data *pdata = spi->dev.platform_data; @@ -398,9 +403,13 @@ static int ad7266_probe(struct spi_device *spi) if (ret) return ret; + ret = devm_add_action_or_reset(&spi->dev, ad7266_reg_disable, st->reg); + if (ret) + return ret; + ret = regulator_get_voltage(st->reg); if (ret < 0) - goto error_disable_reg; + return ret; st->vref_mv = ret / 1000; } else { @@ -423,7 +432,7 @@ static int ad7266_probe(struct spi_device *spi) GPIOD_OUT_LOW); if (IS_ERR(st->gpios[i])) { ret = PTR_ERR(st->gpios[i]); - goto error_disable_reg; + return ret; } } } @@ -459,35 +468,12 @@ static int ad7266_probe(struct spi_device *spi) spi_message_add_tail(&st->single_xfer[1], &st->single_msg); spi_message_add_tail(&st->single_xfer[2], &st->single_msg); - ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time, + ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, &iio_pollfunc_store_time, &ad7266_trigger_handler, &iio_triggered_buffer_setup_ops); if (ret) - goto error_disable_reg; - - ret = iio_device_register(indio_dev); - if (ret) - goto error_buffer_cleanup; - - return 0; - -error_buffer_cleanup: - iio_triggered_buffer_cleanup(indio_dev); -error_disable_reg: - if (!IS_ERR(st->reg)) - regulator_disable(st->reg); - - return ret; -} - -static void ad7266_remove(struct spi_device *spi) -{ - struct iio_dev *indio_dev = spi_get_drvdata(spi); - struct ad7266_state *st = iio_priv(indio_dev); + return ret; - iio_device_unregister(indio_dev); - iio_triggered_buffer_cleanup(indio_dev); - if (!IS_ERR(st->reg)) - regulator_disable(st->reg); + return devm_iio_device_register(&spi->dev, indio_dev); } static const struct spi_device_id ad7266_id[] = { @@ -502,7 +488,6 @@ static struct spi_driver ad7266_driver = { .name = "ad7266", }, .probe = ad7266_probe, - .remove = ad7266_remove, .id_table = ad7266_id, }; module_spi_driver(ad7266_driver);