Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp3359546pxb; Sun, 26 Sep 2021 12:44:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1WHsaeM149fS14Q4KEwM3U13w0he6a2K8ZT62EQ8G5DB3psGARt97hh00PxuquvMZTena X-Received: by 2002:a17:902:7613:b0:13d:c6f0:1ecf with SMTP id k19-20020a170902761300b0013dc6f01ecfmr19575701pll.16.1632685459788; Sun, 26 Sep 2021 12:44:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632685459; cv=none; d=google.com; s=arc-20160816; b=d5Rm25bONyXs2mBOPaaK158/9a0CJtX6jmT8pLu7hgrudWIInO971f/91u72/mNMh8 7lkEoEaBrsIbOJXF2W2I0eXg5WPuFNS9qNFE7/4T7K7Q/cCNqVjpbfnxyXLpzis+ZzqR QQDJCYdqFHSwhqxtXXLRWgHaQv9lO9XOp17mvzwqS1xa68hER8XZYjwMyrKT8ejBB3Ss 53hVpRbNwRqDFSrNZyDQJ508hIb3pfaMhrMUTYYfGXWkof5EGlryiI/mYHpNtAzTNcQM yClKS2XXwEb8B4sqqsLzUdINmKKNEXNNekM+NCYaXtKZ2qMZDQgnXpV1Ombt7flkziEj 9nvg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=+FqvCf5osAEwUJvV00eWIuuRwW5rXLzyPiLGVp8SKng=; b=VzHxRs1ty6QWpbkD7YmjF1vf6G3OWnlHMLTmGiKsXrCpM5fG5FxRpwd7yh/slpuSwa KM2O4m/KftpCvOAtnw/DiRNGjWajdJP6Kt2tCn2rrPUElcdX2l+3MZu5GcgQnAb4T8Sj ACCh5GME4d+18mlVFOJ2ZyrtTZoxqTzoYU4kjVqxN8zfvNuAxfGO7ijLIOlATid9RTkK Pap8mVFLzntzabffa92DbGHjlqVE+AhzmuisRJMQSU6fsKb1cqhNwpq0cIbfU0LTyaFT Qc1LcFHO+0fNnj7ze5XOQKAQHB8pnSgnT67ashtaFNhtiJjh77BGENyQF4a9yoPE68eS tw/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deviqon.com header.s=google header.b=Kanj6in+; 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 gi1si18062360pjb.187.2021.09.26.12.44.06; Sun, 26 Sep 2021 12:44:19 -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=Kanj6in+; 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 S229932AbhIZTo5 (ORCPT + 99 others); Sun, 26 Sep 2021 15:44:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229894AbhIZTo5 (ORCPT ); Sun, 26 Sep 2021 15:44:57 -0400 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48910C061575 for ; Sun, 26 Sep 2021 12:43:20 -0700 (PDT) Received: by mail-ed1-x536.google.com with SMTP id g7so454275edv.1 for ; Sun, 26 Sep 2021 12:43:20 -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:mime-version :content-transfer-encoding; bh=+FqvCf5osAEwUJvV00eWIuuRwW5rXLzyPiLGVp8SKng=; b=Kanj6in+B0Fx4dH3EbYTaDVlFJEkWXI9oRKfdTyxjT+G3+wnkaB3BYqts832OVWmxq CS2GhnE91NBJYFNloXrDmvZcVwgTyKKFyYqaQDAtJ/fozrn2PJdwy9qJgoEm0eMAUYBL qNyQOYJ2t0yrF2lt6wCi9aFkSd24gHaTH80A/nUizYD0pkOlOQtix2xSNZMS/ciuaePH /0AW7uofgqydthYM94ISTZm/avcEDI7vWp4IHKOAiABW/wxXNP8KJAu3PPkRtDT+MGaK EczlOWeLMss8vpAHXiCrmsJwW2ZTB/02D/9u2gmZxb6v0DQ4xsGSAjBD444f3jpw+Ykt 6Q1w== 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=+FqvCf5osAEwUJvV00eWIuuRwW5rXLzyPiLGVp8SKng=; b=BEs+VqDin7jXqr5yA2ckoQqC21CJ6wl79+FX4jkLttr845cOxz27w0CAdKSSHCUumw q4aN/0yhwY7ZQOgEq7o1UdVvnlm7Nb8huFID1LleB3MzJ/WYuQkvgju0+33PHBMDyQ0G n5gFrz4C7XGOqcPsoC5Kvg7JX1Hz0wRf14+a0p/5KKk1xAq0B2P6TY7RXssNkQPjGBjC SHnvFTeWp2nYgNa2ElS8evQH01x/S53jAobsgo9Nb7sMrE5E6pjHMyu5WS5E+q+kGOSq F2comhnMp315bUfsJGZV9GMjND5V2G9bL/XV+w9sND7DMHuOsLrsurvGPkYaHNtp+zsr Bxtw== X-Gm-Message-State: AOAM532BIKd5Ly4+NfZOJudSfmYy7mAHk2iuTBSRky8mnL71+IFRJpgD BmxAwougN5CRatae7LTMwpexNK/QKODZ6C/A X-Received: by 2002:a05:6402:1808:: with SMTP id g8mr19068079edy.188.1632685398682; Sun, 26 Sep 2021 12:43:18 -0700 (PDT) Received: from neptune.. ([188.27.128.17]) by smtp.gmail.com with ESMTPSA id a23sm1872347edx.69.2021.09.26.12.43.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Sep 2021 12:43:18 -0700 (PDT) From: Alexandru Ardelean To: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org Cc: jic23@kernel.org, Alexandru Ardelean Subject: [PATCH] iio: adc: ad7291: convert probe to device-managed only Date: Sun, 26 Sep 2021 22:43:15 +0300 Message-Id: <20210926194315.7742-1-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a simple conversion for to device-managed with using devm_request_threaded_irq(), disabling the regulator via a devm_add_action_or_reset() hook and finally using devm_iio_device_register(). The i2c_set_clientdata() call is removed as it becomes redundant after this change. Signed-off-by: Alexandru Ardelean --- drivers/iio/adc/ad7291.c | 70 +++++++++++++--------------------------- 1 file changed, 22 insertions(+), 48 deletions(-) diff --git a/drivers/iio/adc/ad7291.c b/drivers/iio/adc/ad7291.c index 2301a0e27f23..e9129dac762f 100644 --- a/drivers/iio/adc/ad7291.c +++ b/drivers/iio/adc/ad7291.c @@ -460,6 +460,11 @@ static const struct iio_info ad7291_info = { .write_event_value = &ad7291_write_event_value, }; +static void ad7291_reg_disable(void *reg) +{ + regulator_disable(reg); +} + static int ad7291_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -473,8 +478,6 @@ static int ad7291_probe(struct i2c_client *client, chip = iio_priv(indio_dev); mutex_init(&chip->state_lock); - /* this is only used for device removal purposes */ - i2c_set_clientdata(client, indio_dev); chip->client = client; @@ -495,6 +498,11 @@ static int ad7291_probe(struct i2c_client *client, if (ret) return ret; + ret = devm_add_action_or_reset(&client->dev, ad7291_reg_disable, + chip->reg); + if (ret) + return ret; + chip->command |= AD7291_EXT_REF; } @@ -506,58 +514,25 @@ static int ad7291_probe(struct i2c_client *client, indio_dev->modes = INDIO_DIRECT_MODE; ret = ad7291_i2c_write(chip, AD7291_COMMAND, AD7291_RESET); - if (ret) { - ret = -EIO; - goto error_disable_reg; - } + if (ret) + return -EIO; ret = ad7291_i2c_write(chip, AD7291_COMMAND, chip->command); - if (ret) { - ret = -EIO; - goto error_disable_reg; - } + if (ret) + return -EIO; if (client->irq > 0) { - ret = request_threaded_irq(client->irq, - NULL, - &ad7291_event_handler, - IRQF_TRIGGER_LOW | IRQF_ONESHOT, - id->name, - indio_dev); + ret = devm_request_threaded_irq(&client->dev, client->irq, + NULL, + &ad7291_event_handler, + IRQF_TRIGGER_LOW | IRQF_ONESHOT, + id->name, + indio_dev); if (ret) - goto error_disable_reg; + return ret; } - ret = iio_device_register(indio_dev); - if (ret) - goto error_unreg_irq; - - return 0; - -error_unreg_irq: - if (client->irq) - free_irq(client->irq, indio_dev); -error_disable_reg: - if (chip->reg) - regulator_disable(chip->reg); - - return ret; -} - -static int ad7291_remove(struct i2c_client *client) -{ - struct iio_dev *indio_dev = i2c_get_clientdata(client); - struct ad7291_chip_info *chip = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - - if (client->irq) - free_irq(client->irq, indio_dev); - - if (chip->reg) - regulator_disable(chip->reg); - - return 0; + return devm_iio_device_register(&client->dev, indio_dev); } static const struct i2c_device_id ad7291_id[] = { @@ -579,7 +554,6 @@ static struct i2c_driver ad7291_driver = { .of_match_table = ad7291_of_match, }, .probe = ad7291_probe, - .remove = ad7291_remove, .id_table = ad7291_id, }; module_i2c_driver(ad7291_driver); -- 2.31.1