From patchwork Thu Apr 7 11:56:21 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: 12805127 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 7C080C433F5 for ; Thu, 7 Apr 2022 11:56:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238840AbiDGL6f (ORCPT ); Thu, 7 Apr 2022 07:58:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233421AbiDGL6e (ORCPT ); Thu, 7 Apr 2022 07:58:34 -0400 Received: from mail-oa1-x35.google.com (mail-oa1-x35.google.com [IPv6:2001:4860:4864:20::35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BA4A44A06 for ; Thu, 7 Apr 2022 04:56:30 -0700 (PDT) Received: by mail-oa1-x35.google.com with SMTP id 586e51a60fabf-de3ca1efbaso6053911fac.9 for ; Thu, 07 Apr 2022 04:56:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp.br; s=usp-google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=LoNJyQ9i7p9EmUWA3T7gto6j9HpcpbaFgL9mxYK2vi0=; b=c59uRjC89onHqXp7pfqBNuJzt16ZqqwD3qw108yHuG0zwUe7z+kEyAQ6kAKT/sANRk 8B5R6JpfKscpAlwdIqvR8mmLmj5KoRQDwwtZ0ZcTVd1wNNhbpBprPL0PqThG1qRONVK4 DFlMiIJME/azHjdAPBtMo6tc3UVzXnKcInPQwOSYGW030sbFLze4PcIbmaH3tSrbPbqD 7grKCWsOdEc862M7yxsL6AlOtreITnSnCfWFl20LUMJH9puWt/2drEUDrhkLwJ0m47Rj OoaGT2loAeV8ESZjCKo6f+MEO2s1hQCFSp6wBwSgH0xnc6HugFOTsmFW6mnEiMYleizR hv8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=LoNJyQ9i7p9EmUWA3T7gto6j9HpcpbaFgL9mxYK2vi0=; b=1ptI7Zr7BRV7oUqWVfpsAIGVqaRCJWpe8dNkpp+em5M13kUo9ubxtLPvS1U7w7D+gU 9Th3seUASvHbUwXRocuoVUM9y1FhuFI0BN3yiTIT3vBXSklNFarmcubDAzDj/XTtFeVe z1I6zbK1b4ckZ0TndPUA0kT/nUh0fOcF1vKD8lmtL/t7nNWG512m6zT+ClYMaX5f6ZFv J0Nmq+Gx0xvQYuDmV80dMDXaNl/V5bH9s6WKNj/m4tqykWdO3p49mfYYwTN7ULar30pt oEJ6iEiWq4zdbFY2E+ehHc50WnY84zdb/xK2BanIg5ai4vFqonGryY/QoyrofGE5E17K Rmww== X-Gm-Message-State: AOAM530l8BxLcIzaIRDWDHwiZQTpCPmcIHEbthdLoPDkw9335VZaDBpH SW+Y6t6iMMhwzpBIdGEWzNHV9Q== X-Google-Smtp-Source: ABdhPJzzS0lc63FgTUKSt/2ZASb12eQDkWyoVdMJsqKvtCIJHsNLKrKxpg8TERXrzzOC7j5iRBZ1bw== X-Received: by 2002:a05:6870:6192:b0:e1:dcc4:e0e8 with SMTP id a18-20020a056870619200b000e1dcc4e0e8mr6298605oah.58.1649332589872; Thu, 07 Apr 2022 04:56:29 -0700 (PDT) Received: from fedora.. ([2804:14d:8084:84c6:2e13:8e30:84f7:1597]) by smtp.gmail.com with ESMTPSA id m2-20020a9d4002000000b005e6b6ed9001sm151420ote.60.2022.04.07.04.56.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 04:56:29 -0700 (PDT) From: =?utf-8?q?Ma=C3=ADra_Canal?= To: lars@metafoo.de, michael.hennerich@analog.com, jic23@kernel.org Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Ma?= =?utf-8?q?=C3=ADra_Canal?= , Marcelo Schmitt , =?utf-8?q?Nuno_S=C3=A1?= Subject: [PATCH v2] iio: ad7266: convert probe to full device-managed Date: Thu, 7 Apr 2022 08:56:21 -0300 Message-Id: <20220407115621.10781-1-maira.canal@usp.br> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 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. Reviewed-by: Marcelo Schmitt Reviewed-by: Nuno Sá Signed-off-by: Maíra Canal --- drivers/iio/adc/ad7266.c | 44 +++++++++++++--------------------------- 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/drivers/iio/adc/ad7266.c b/drivers/iio/adc/ad7266.c index c17d9b5fbaf6..f20d39f0bc01 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; } } } @@ -433,7 +442,6 @@ static int ad7266_probe(struct spi_device *spi) st->mode = AD7266_MODE_DIFF; } - spi_set_drvdata(spi, indio_dev); st->spi = spi; indio_dev->name = spi_get_device_id(spi)->name; @@ -459,35 +467,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 +487,6 @@ static struct spi_driver ad7266_driver = { .name = "ad7266", }, .probe = ad7266_probe, - .remove = ad7266_remove, .id_table = ad7266_id, }; module_spi_driver(ad7266_driver);