Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp987314rdb; Sun, 18 Feb 2024 23:44:33 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXN/nDzzWqMGzAhK6FLpK8uQFF0dCgKMxO3bQ+2MpBSzJRjtRm2r2ASXJoXKOYtcDbIrV8jKN2aIPrM45m9w1+AK3laqBo8vLZvDBy9OQ== X-Google-Smtp-Source: AGHT+IFNGFAh6o4jxmci7HUJqUMzaVkM3tRkLOwYoNTvZXVD5qUkk8lfJDt302JsgcWCzuynE1tt X-Received: by 2002:a05:620a:531a:b0:783:bd16:e46a with SMTP id oo26-20020a05620a531a00b00783bd16e46amr11952497qkn.58.1708328672802; Sun, 18 Feb 2024 23:44:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708328672; cv=pass; d=google.com; s=arc-20160816; b=Ix2vicrEsZKMU6QIIlay/TlXyKCPqKvzi6AF6YSoQ3KcxEd6Wr0l1XjyhbQCGFDnC/ AyEs0fFHJtzEmY4+tAaaGfKuMJgTtaTcduszmqLv7Vi8HVCECohO++iwgmS86YPAyGZd bkNUB2vVYI3UrtUWuEGFHeUX0iHsd2L5St9Vjy0s1h8ykD3Fa+IMzIqsMbon9Cdl+bfh K2AOmYEJMELbCI8j/Av1VatQfqIpWi8hn5AlY+VXJ1WxByLLk3wP9piQQG41wxo6i+Lh D+N+cBkyOYeWNvMLA8B0WDOYnLn8OyuCgMq+V26zH2tDXWWyLRhOd0500e+z+juO57NL Gw7g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=NWRB34m7daMDprm8NGoyhlWPNl7PmR3a1A52zijhYzY=; fh=TFLxKJqalARk+xoSOnDZPlCfDev1CII5wRKDPeNNinE=; b=DxKzd8HSLPJwDIj0ABOxNUbumZSu3Supbs5AT2aPp39Wk9F0P4GL1NV/cq2Cd+DHJ+ DIAq9GhJ0bnKbYRSu5KMZVQ5nSGevWDTrpKIFrY5R6d3pV3AYge7aBsllPzvTwLzfpXM I/djrntIw91qB9pH2BS8gtDpIc9ZGCIZuuKw4olC+tFDUvpf2kJm/0QKqYshwB+WfkSc kywJxyrgJqDosr5Yp9AlK8ErrhGpMOFFN439GcaaxfTm49UJTq/rahu4mvtxEHehIQ0D fFwXg4Gvrk2jNQ+z7ASIc+xDeXvnIQ58pY5EtDs0cxBaItXWN7q3KuqOicmNU2l/F8op S/pw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="Msv/k5sx"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-70848-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70848-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id vq7-20020a05620a558700b007872d315cd7si5549524qkn.301.2024.02.18.23.44.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 23:44:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70848-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="Msv/k5sx"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-70848-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70848-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 803831C219A3 for ; Mon, 19 Feb 2024 07:44:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 14ED021103; Mon, 19 Feb 2024 07:44:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Msv/k5sx" Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5A8220DF4; Mon, 19 Feb 2024 07:44:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708328652; cv=none; b=Bqb1Getw8UDn7/2d/R0lQI2ZjfYHq48/400Sx2F7WmWpxB5ydupc0mROAhkGab/9DWyUucb9NbEoMfmbWJqo8P6m9f/OWSY4bbvC4umSDVDHKUP9JOZl0WiCYmQbpTDJFlzBNFSPgAUn/Xnh2/m9lS9t/1neTFNtbf5oMSuo5ew= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708328652; c=relaxed/simple; bh=0cPDHhNi8bYSx15AbJNOmGn2pNvsKEpiuV1I2zmlnwY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=XgzCrxKiZT4diEO5+6WPMeU7d1ln2i+GJc33qlwjHla9m8Z5PmpyXa083C1pD0xazIpR6hBronpcn3/k55u+F6/KxPMaqMk6Nuv7gVQtn1+TTwIn7ZLj/QuSWZc58Vs9xtbAhBA9zRURA8lAm2LHpxL3APacj+QADQsopeSgeS4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Msv/k5sx; arc=none smtp.client-ip=209.85.167.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-512a96e44e2so1582155e87.2; Sun, 18 Feb 2024 23:44:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708328649; x=1708933449; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=NWRB34m7daMDprm8NGoyhlWPNl7PmR3a1A52zijhYzY=; b=Msv/k5sxoRnCL4mkL5twCE9KD6+WOikyOO/4VftT+8mppfg/Z4YFljtmxP8WSmZ8L6 5nbk7yhwDG8A22BW2odqJ9lHZg7UKHD96IGGkZdn0MU575ITAqvD+1dw9ziXJBpOc2pv ymKOKo2fPwgr28M8gc2TCMkx0i4s5bKjr8jUjYIUXHaQ7d8SXkkZ47TeLBnkz19c344E BDnGzN97I9UBO3JU+8p0zWhRPTwkQ7+gc3nvE4iD9JKtZOqqmSeVkXYGTn8uq129vJ/J vQELhTSZ4hHV/GWMxyp6oIsGfIeVrrad+vFF+fIaSi91rrbUiDAwjIqO7qRNG6p9rML4 i1JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708328649; x=1708933449; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=NWRB34m7daMDprm8NGoyhlWPNl7PmR3a1A52zijhYzY=; b=WhQpE/dkBxEW1JqdNdLRhXQjmPYUVztllxRDX6tHksrLSkOsey2hpSYLxVIV9RDJ34 UM7jQqb/39blLTB32yshfSbnE4ZIL+5oP5eIXVVNIZE5rq7YsqSwRpcKpLLBr2wy+72C DmInpCB+muj2PWCnSYBGaK/IZmPq84mJRVEpYT4dOoK4jIGMtjGtxmnGI0xIXTle6UJg N0SeazCUo1IqcGIsebbC5A+k3Rp66ezb86IaDn9P9IFyeeWcbcXg6QB8+GWZpMWoEv7Q AZXZSJIte0TGGlIyaNfOwvqQoP4FFlCyOk0Io8RopxXgOeE6lbuc4crxlN665gtlTh7H AROA== X-Forwarded-Encrypted: i=1; AJvYcCUu+hXNgDruy3ioRr696cw+klhh7JcaddjJoKvxxDLv6QoEsiPP864bpiOWIzoq7CZqnzX60oHhn3+Ns85grfWUdodKWT+DtAnG8RMs X-Gm-Message-State: AOJu0YzFnUXy5NtzyIJYUKIANqLuo+PykFxwguvWKbpnZH2qsl0rW3GD WqilghbkQesBIByqXyrSEupA2XP7/DlF4l5DytjvvczlR9uuptJh X-Received: by 2002:a05:6512:12c7:b0:512:bc14:6b80 with SMTP id p7-20020a05651212c700b00512bc146b80mr395625lfg.25.1708328648730; Sun, 18 Feb 2024 23:44:08 -0800 (PST) Received: from localhost.localdomain ([86.38.153.174]) by smtp.gmail.com with ESMTPSA id qw23-20020a170906fcb700b00a3e426149a1sm1886019ejb.50.2024.02.18.23.44.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 23:44:08 -0800 (PST) From: Arturas Moskvinas To: jic23@kernel.org, Jonathan.Cameron@huawei.com, oskar.andero@gmail.com, lars@metafoo.de, lukas@wunner.de Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Arturas Moskvinas Subject: [PATCH v2] iio: adc: mcp320x: Simplify device removal logic Date: Mon, 19 Feb 2024 09:41:40 +0200 Message-ID: <20240219074139.193464-2-arturas.moskvinas@gmail.com> X-Mailer: git-send-email 2.43.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Use devm_* APIs to enable/disable regulator and to register in IIO infrastructure. Signed-off-by: Arturas Moskvinas --- v1 -> v2: - Use devm_add_action_or_reset instead of devm_regulator_get_enable to automate disabling regulator - Remove empty mcp320x_remove function --- drivers/iio/adc/mcp320x.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/drivers/iio/adc/mcp320x.c b/drivers/iio/adc/mcp320x.c index f3b81798b3c9..da1421bd7b62 100644 --- a/drivers/iio/adc/mcp320x.c +++ b/drivers/iio/adc/mcp320x.c @@ -371,6 +371,11 @@ static const struct mcp320x_chip_info mcp320x_chip_infos[] = { }, }; +static void mcp320x_regulator_disable(void *reg) +{ + regulator_disable(reg); +} + static int mcp320x_probe(struct spi_device *spi) { struct iio_dev *indio_dev; @@ -388,7 +393,6 @@ static int mcp320x_probe(struct spi_device *spi) indio_dev->name = spi_get_device_id(spi)->name; indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->info = &mcp320x_info; - spi_set_drvdata(spi, indio_dev); device_index = spi_get_device_id(spi)->driver_data; chip_info = &mcp320x_chip_infos[device_index]; @@ -445,27 +449,13 @@ static int mcp320x_probe(struct spi_device *spi) if (ret < 0) return ret; - mutex_init(&adc->lock); - - ret = iio_device_register(indio_dev); + ret = devm_add_action_or_reset(&spi->dev, mcp320x_regulator_disable, adc->reg); if (ret < 0) - goto reg_disable; - - return 0; - -reg_disable: - regulator_disable(adc->reg); - - return ret; -} + return ret; -static void mcp320x_remove(struct spi_device *spi) -{ - struct iio_dev *indio_dev = spi_get_drvdata(spi); - struct mcp320x *adc = iio_priv(indio_dev); + mutex_init(&adc->lock); - iio_device_unregister(indio_dev); - regulator_disable(adc->reg); + return devm_iio_device_register(&spi->dev, indio_dev); } static const struct of_device_id mcp320x_dt_ids[] = { @@ -520,7 +510,6 @@ static struct spi_driver mcp320x_driver = { .of_match_table = mcp320x_dt_ids, }, .probe = mcp320x_probe, - .remove = mcp320x_remove, .id_table = mcp320x_id, }; module_spi_driver(mcp320x_driver); base-commit: 8d3dea210042f54b952b481838c1e7dfc4ec751d -- 2.43.2