Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp642566pxj; Thu, 13 May 2021 13:21:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxD3kNplBObE8IOsCEGbd5uX9lhSmGs0tTeq1xJiaBprJiVR1D5nnKy3wmh41NOh3MHgI0r X-Received: by 2002:a17:907:3e28:: with SMTP id hp40mr22586750ejc.523.1620937284152; Thu, 13 May 2021 13:21:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620937284; cv=none; d=google.com; s=arc-20160816; b=WiW2IzS6pLctxc1vDA46sjTSsJ7obo7q0tfv3nlD8Oe14AcrMMB6+JIThCQfiF7o9l 5oEpoBIKZVfPC3SVQj+LHIWLQeOyGqoc9oecZfLWacwn8jDKVqIk9SpqDBmiEZCVaotA SzXl9ADnSqiC4ELtUf/YNpeG8j9v4mIZ6Jy5MvXH8OKlxfNn44Z3cArK2t4qAlkjIolA sYeFLio10Ae+OGL+USLou19opqc8w32q0IYkjKQBzLdKticFn/B0noY98lihcmrwlvKR fsuYmuomWICC61Sg1RShKs2pnkxGwGpSFRSkDiQneZ4PKgSzP5tVunxbLEid20FpylPR frFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/XPGApaju6LMGXyrepb+ba3cN9cbtBiZnKqABRzBNdQ=; b=AaT/+lipToLCe50GpyBoFL9IeGP4kgbPQLtEfBeA5oVtCuZjbgqhh/CJb4lifWS5Gy cNc3IHZ1GKhMqJGubNn5ucaNPuZSskwPaMmSCxZiOmtqYMqa5ODis9gWS6HXKk4URx8B ix3GOntMYERaEDCMcw1ravYfsIYrL1oU+LId/7NziFhHpE2Q3h25EfvFs4c/BmkCPgyK dXv7iZWqEB38FtOCjd4e/IISw6ZZSeVgnmQXio7QRZN82QWjX25JAkWFSP6gMuuKkaNL FVWj9gc0U+iljpjRIa6NHWMiIh1dFUJR0VS7uLQrkoFbVefNUOzcZvs0Mo1QLOsm5BY2 ZhbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deviqon.com header.s=google header.b=DEWo68MH; 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=deviqon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rh5si3911599ejb.475.2021.05.13.13.20.33; Thu, 13 May 2021 13:21:24 -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=@deviqon.com header.s=google header.b=DEWo68MH; 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=deviqon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233694AbhEMMK2 (ORCPT + 99 others); Thu, 13 May 2021 08:10:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233690AbhEMMJR (ORCPT ); Thu, 13 May 2021 08:09:17 -0400 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69D78C06138A for ; Thu, 13 May 2021 05:08:06 -0700 (PDT) Received: by mail-ed1-x531.google.com with SMTP id r11so6660121edt.13 for ; Thu, 13 May 2021 05:08:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/XPGApaju6LMGXyrepb+ba3cN9cbtBiZnKqABRzBNdQ=; b=DEWo68MHe8XL0las/rhte0NwwiN0TNv3enDH7m7Np0e/fI3FznpZJGJ+iHvwBINjXP 1yNsCrPtveMW+HenfvW+GHKE75M50BtGjQstRCZTY+HS4qlNcGaXEA5k8B7igZ4WUN/l F0TpJcPcxsrm1xqukr0BH3ZsgDdadt0jcP9mCDm6Ny7K/30seo55gEzvD+ijdSfHUnma JitT7Jajt4xrzfjN65ryKym51fXBalGfRFjcpGhzOp7vui1rU+45Pw+1/VbTBATK/5nh ZzQl0MPzV+I7BqUjOiCwMkqeVrAwC5m2d2CdAW/setauZZNfHJP1OPsLUw73oV9hrA7x nBfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/XPGApaju6LMGXyrepb+ba3cN9cbtBiZnKqABRzBNdQ=; b=tt2J4vxuQCCohlkF3jLQeiMeM3SNMK+TVNADNgXTcfqX6zz5YniaTqabpXjjPl91xK XHwTzzlo2IhO1bY8sRljkmWjUnTndBj4EWS10IhTnOu9KsEV49R8rqf5yUEN/nBO37qr +SGErGDzcQQqLesw4AIpBYNoEP3BsQ1TxJiaRCi+YS4iQN9n1f/kf5SOXw6O9sCPiSqA LAcXA1rZKSYDoeuMUUjudweJusESWexT6f1mIjFMGWnW5ggqqe1XoFF5txfhqUFaPWIU QOTFXDqrqYNui7tv/j91HgWSaTX+bTn0Qfk1GQqurPrUrmnFySw55E7Hsa31Tz2wCMpC xRFQ== X-Gm-Message-State: AOAM531mJ6UKhZC1ajvfSOjQaDChD4XQiZTUWfsH2w9b0xAEW3QO8+6t HxWV69T1Ytrziqv+BWw+IpOUdQ== X-Received: by 2002:a50:a446:: with SMTP id v6mr47242351edb.254.1620907685059; Thu, 13 May 2021 05:08:05 -0700 (PDT) Received: from neptune.. ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id ga28sm1717809ejc.20.2021.05.13.05.08.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 May 2021 05:08:04 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, Jonathan.Cameron@huawei.com, alexandru.tachici@analog.com, linux@deviqon.com, Alexandru Ardelean Subject: [PATCH v4 06/12] iio: adc: ad7793: convert to device-managed functions Date: Thu, 13 May 2021 15:07:46 +0300 Message-Id: <20210513120752.90074-7-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210513120752.90074-1-aardelean@deviqon.com> References: <20210513120752.90074-1-aardelean@deviqon.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With the devm_ad_sd_setup_buffer_and_trigger() helper, it's a bit easier now to convert the probe of the AD7793 driver to use device-managed functions. Only the regulator disable requires a devm_add_action_or_reset() callback. This change does that, cleaning up the driver a bit. Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7793.c | 53 ++++++++++++---------------------------- 1 file changed, 15 insertions(+), 38 deletions(-) diff --git a/drivers/iio/adc/ad7793.c b/drivers/iio/adc/ad7793.c index 5e980a06258e..5dab2e5b5bac 100644 --- a/drivers/iio/adc/ad7793.c +++ b/drivers/iio/adc/ad7793.c @@ -768,6 +768,11 @@ static const struct ad7793_chip_info ad7793_chip_info_tbl[] = { }, }; +static void ad7793_reg_disable(void *reg) +{ + regulator_disable(reg); +} + static int ad7793_probe(struct spi_device *spi) { const struct ad7793_platform_data *pdata = spi->dev.platform_data; @@ -802,11 +807,13 @@ static int ad7793_probe(struct spi_device *spi) if (ret) return ret; + ret = devm_add_action_or_reset(&spi->dev, ad7793_reg_disable, st->reg); + if (ret) + return ret; + vref_mv = regulator_get_voltage(st->reg); - if (vref_mv < 0) { - ret = vref_mv; - goto error_disable_reg; - } + if (vref_mv < 0) + return vref_mv; vref_mv /= 1000; } else { @@ -816,50 +823,21 @@ static int ad7793_probe(struct spi_device *spi) st->chip_info = &ad7793_chip_info_tbl[spi_get_device_id(spi)->driver_data]; - spi_set_drvdata(spi, indio_dev); - indio_dev->name = spi_get_device_id(spi)->name; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->channels = st->chip_info->channels; indio_dev->num_channels = st->chip_info->num_channels; indio_dev->info = st->chip_info->iio_info; - ret = ad_sd_setup_buffer_and_trigger(indio_dev); + ret = devm_ad_sd_setup_buffer_and_trigger(&spi->dev, indio_dev); if (ret) - goto error_disable_reg; + return ret; ret = ad7793_setup(indio_dev, pdata, vref_mv); if (ret) - goto error_remove_trigger; - - ret = iio_device_register(indio_dev); - if (ret) - goto error_remove_trigger; - - return 0; - -error_remove_trigger: - ad_sd_cleanup_buffer_and_trigger(indio_dev); -error_disable_reg: - if (pdata->refsel != AD7793_REFSEL_INTERNAL) - regulator_disable(st->reg); - - return ret; -} - -static int ad7793_remove(struct spi_device *spi) -{ - const struct ad7793_platform_data *pdata = spi->dev.platform_data; - struct iio_dev *indio_dev = spi_get_drvdata(spi); - struct ad7793_state *st = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - ad_sd_cleanup_buffer_and_trigger(indio_dev); - - if (pdata->refsel != AD7793_REFSEL_INTERNAL) - regulator_disable(st->reg); + return ret; - return 0; + return devm_iio_device_register(&spi->dev, indio_dev); } static const struct spi_device_id ad7793_id[] = { @@ -881,7 +859,6 @@ static struct spi_driver ad7793_driver = { .name = "ad7793", }, .probe = ad7793_probe, - .remove = ad7793_remove, .id_table = ad7793_id, }; module_spi_driver(ad7793_driver); -- 2.31.1