From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 824223C07A for ; Sat, 18 Jul 2026 21:55:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784411739; cv=none; b=tEseZ4E2g5ewrFor1ZK8Uk2Ngb3FJT/Wp8YgbD/1Z68UuGR7ub/DLmS+6GsEHBu8XAxTO+yD1Oi9heaFw0vMTjz34XBxbEcqF9fUWqKfZS3L0u00TklyjW/zeyglOIOnQRsxIOdYFpKRaqGJcj2vp2xIMgQU49U4eDJHDam4zac= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784411739; c=relaxed/simple; bh=7d4SD29H4eCm2+c+O28KnjY1ObN+/d9GJbsZkR3a8YE=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=po79zOR9LkSfFOR3NFw6U4hC6gfkJPwqcgQkhRSbKe3AQBE7DVBm0FS3NmsYHkR2WSe9a9/pgkEIIe96zoJC7qdKTd2n7ARmQDNte1V9g8wJa+kmDUFW4FLo1gqSQ5e4kmh8SGScsOtS7kzgzrVlyne5CP64ruNq+kRKYCMh1ec= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=HKKXIDJ/; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=c09ZDnW7; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="HKKXIDJ/"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="c09ZDnW7" Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 66IJrC7A1692542 for ; Sat, 18 Jul 2026 21:55:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= ASHWcBJN/1ikBOiz3cdVY+T9vPEaHVJ/+JaXYaW0mgU=; b=HKKXIDJ/bkTaw1yM KASYOGh0YRG2eg7qJMzLT8zUIkNBObT2MHEgq/djypfnro/KSGCg08FYXEZxDyUP kqewM/S4/vXw+6fCzQgwpKx3JzgiRFqPDRQD9lwdST0RiRVFNKYKO1lF0asOCOOT XrfpQr88JEv0t+tl7Cd2ROuNV+I7uiQxgpYjMrUNkdC5ENAb8CL4RXclC7tDB2NU VQ3EyCqK8B2IK5uhM7xn84IErKkv2JhL1lnaHdEdHEKQYtTvHMlmtyxph5eBithf oGu4lzu0WUWWAjrgvo5ly0NrTFc0YgHdCVaibE0Wx0uMOj6fCHPGTKPxBouB9919 81Y84A== Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4fg2c69muf-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Sat, 18 Jul 2026 21:55:37 +0000 (GMT) Received: by mail-pf1-f200.google.com with SMTP id d2e1a72fcca58-8486c3411c8so12256085b3a.2 for ; Sat, 18 Jul 2026 14:55:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1784411736; x=1785016536; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=ASHWcBJN/1ikBOiz3cdVY+T9vPEaHVJ/+JaXYaW0mgU=; b=c09ZDnW7baTaj7L7BuAb2/vm58+t7hHSuNumOh9m+Hydwq3miPWVlZSdkM/nirzALX XrNVQl3TN3jQ441cjThpYnb7UoxyKla/xHJTDBQQfMSB3eHJncomYTSgLCZlwjoBwBrT j9QKhLtA2FyjtrwvuwMGqAZcg7Tesm5xXZ0AKw9n4S0ckHJ64rnVisbSBNlLp6kyBK3w zGx+6IxBWiD9/UB2H/jAapg4I57zyiC+XxrJ5YpWmE8hEz59ME96PGkQB9bBSZyxss5A wgkMKWc3yQvQccg9pZszcP4M4zuKGzWXrWe4UJUdkM+NpkezmxZV6hfdc+hVpYLTLSuG /7QQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784411736; x=1785016536; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ASHWcBJN/1ikBOiz3cdVY+T9vPEaHVJ/+JaXYaW0mgU=; b=XoSwlpH+SrtBXUsmi9kci+HJcCkgrzaNE2rJ5JoTyDbArCj34TgxsE9dUx9ALh4zPQ J+jnhJLF0VrxMohGLZhVJK6l0y86eZVXXIHjWmlwCyxzrlh9VmIRXSRIfkr0m/tgF5nN ZFiB2YQ/iWOJ7x8fZ8l+AmKwbPI2xXYZZPnwFtpxUfX5YLb2pNlB476CMQD2uD/gSV0C H2iHbCTqcx/W8dQq4Dsw4HpqWIop1eeVMevouaiUKaspLUscCZtk3Hcivq2Loa56ufm+ wVe+z5Vsw6w84OVzmT7U3RVisGFB7A0GLW6qNy9TOPzl63WVw65iwIwa3sfzmRKpd/IM PhGw== X-Forwarded-Encrypted: i=1; AHgh+RpCm6kInpsg0SBDyMWWQh5/TkzgaZSh/YzbqQIEwi0fyokil+SwXpXHTnFneEUoq1pTipD2CqsWyv9wP+o=@vger.kernel.org X-Gm-Message-State: AOJu0Ywc361f811ZpkAAkz/7YPkBW+A/LcdhCYq1Oj9ttZTWEWF6M0bi BNLJZ5+t1j55B6pKVuOVn9NlhGguvks/vTsYFdiYmUC1WaAqKlVaSjf+qtI4a99LwewsqKekroC Dtu/Ut0+u+oK1u1W750zgjdCT0ZENxeiyxmuVPYODVYorI2qnS6j7EP14A8xgWh/qTX4= X-Gm-Gg: AfdE7ckx+6jb79i3k+d2SXOGAPBXWpZ/qSkAhsH7pDKc22xu0RFgWsnW4qK4tcLKlVh /m9HZS4EH9rfnw78suwUhjwtOU9kPJ2uVU50pOf6gqDTvSDDc/kYexHZZo//XGMlwW76hwj0PP7 QUJ/0RfeVp4byeEqQo27/63VYl6eHompTUAPJz0JVLAq0QsAphlw5ACGk98mUJ4QwfuCCiHH5qm 0n/sPVWS8+h5BJohjRNLQLzwHRQDQI543ViJKaxfftfQJgx2+rqU9K3vhG0/wo+VKN7ZrCOzId/ nLRdig8JdpMlxfTvtZVLALqvb4kcDWh0uS8cnLHm1aUSqO2RhvgUznpnc06pcn7F5jypw9NWCGj 9VBlF1EUn9+e62whI X-Received: by 2002:a05:6a00:aa0b:b0:842:2a81:4c63 with SMTP id d2e1a72fcca58-84c292ac538mr8112256b3a.25.1784411736005; Sat, 18 Jul 2026 14:55:36 -0700 (PDT) X-Received: by 2002:a05:6a00:aa0b:b0:842:2a81:4c63 with SMTP id d2e1a72fcca58-84c292ac538mr8112235b3a.25.1784411735542; Sat, 18 Jul 2026 14:55:35 -0700 (PDT) Received: from jic23-huawei ([50.35.46.84]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84c2f1601d6sm3060523b3a.50.2026.07.18.14.55.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Jul 2026 14:55:34 -0700 (PDT) Date: Sat, 18 Jul 2026 22:55:30 +0100 From: Jonathan Cameron To: Archit Anant Cc: dlechner@baylibre.com, andy@kernel.org, nuno.sa@analog.com, u.kleine-koenig@baylibre.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/3] iio: adc: ti-ads1015: convert to fully managed resources Message-ID: <20260718225515.7e49a458@jic23-huawei> In-Reply-To: <20260718075016.27750-4-architanant5@gmail.com> References: <20260718075016.27750-1-architanant5@gmail.com> <20260718075016.27750-4-architanant5@gmail.com> X-Mailer: Claws Mail 4.4.0 (GTK 3.24.52; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Proofpoint-GUID: Ydv4NZoJIidkjzVg-Ce5I7dlYfTSrlLs X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzE4MDIzMCBTYWx0ZWRfXy2mjXXmL9ojN eKJWnzGrjb7fpfQcoAMsJyYYTbpPnw8aAIbw5/Ok3HnEW6Pat3cw15GaaLQZGdveRNMtIS6mmhx 4bD8GajfREMvlbmbHbz9KgHG+4Jj5YulPr/wOOwLSGELIF+S5dVEfXJjE97jekaBwjwoL/oF5pM Tmj/k7vjHxTTBw6l9QCn0LduG4ghO43JYdtPdyvTMs5mZFaXG4cZbuVbdwV+Rok2g3KAJOvFMNp 8jVfsIaGkF9/s1dEXhSZ/03rGOQdEq9eeCfbX9lQvsQutKRT6Kpo5RQBap7Vnns29B+eDhkDqv7 /xltlKq2pqBzSbPN3K3Mu3+D7QVuYYstVXER8ZLo0OG+QDM2jW2NNiK+yNkEwbRE2Pvf2zXrzoa sNdcbC1QjaEJzVB93V6y831Zlom/uWH334sDMDA++4OxgbjyYmOmsZrYgJrtxSJXPgwAnuqrtGl d30S58VGrX4Ue/lrw/g== X-Proofpoint-ORIG-GUID: Ydv4NZoJIidkjzVg-Ce5I7dlYfTSrlLs X-Proofpoint-Spam-Info: AW1haW4tMjYwNzE4MDIzMCBTYWx0ZWRfX6XkHRlatMNIy xfASZAGcnoRwCZaTX9JUBF01yrMZFQexmAfA5yUykZ5kbiyxO7BUBGPV+SxlV1DxpEVVnq0gJUD z945WMcoiFLrgit8mC7vBVh8W38CanE= X-Authority-Analysis: v=2.4 cv=CJQamxrD c=1 sm=1 tr=0 ts=6a5bf659 cx=c_pps a=mDZGXZTwRPZaeRUbqKGCBw==:117 a=qC1CW/w66vtJz1P9yTJxNA==:17 a=kj9zAlcOel0A:10 a=RAioF0-LDSMA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=_glEPmIy2e8OvE2BGh3C:22 a=c92rfblmAAAA:8 a=pGLkceISAAAA:8 a=0kWMRCPL9c4H5K_DkQwA:9 a=CjuIK1q_8ugA:10 a=zc0IvFSfCIW2DFIPzwfm:22 a=GvGzcOZaWPEFPQC_NcjD:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-07-18_06,2026-07-17_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 adultscore=0 impostorscore=0 lowpriorityscore=0 malwarescore=0 suspectscore=0 phishscore=0 priorityscore=1501 spamscore=0 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607180230 On Sat, 18 Jul 2026 13:20:16 +0530 Archit Anant wrote: > Refactor the driver to use devm_ allocations and power > management, allowing for the complete removal of the > ads1015_remove() > > Key changes: > - Use devm_add_action_or_reset() to ensure the ADC is safely powered > down upon driver removal. > - Move to devm_pm_runtime_set_active_enabled() to manage the runtime > PM lifecycle. > - Update the PM operations to use DEFINE_RUNTIME_DEV_PM_OPS and > pm_ptr() for modern compiler saftey. > - Convert iio_device_register() and mutex_init() to their devm_ > variants. > - Remove the thus obsolete ads1015_remove() function. See below. I'm fairly sure this is also fixing a bug. Ideally you'd fix that first at the start of the series then refactor it later. Jonathan > > Signed-off-by: Archit Anant > --- > drivers/iio/adc/ti-ads1015.c | 58 ++++++++++++++++-------------------- > 1 file changed, 26 insertions(+), 32 deletions(-) > > diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c > index 0232a4ca2d77..57e5fa593b31 100644 > --- a/drivers/iio/adc/ti-ads1015.c > +++ b/drivers/iio/adc/ti-ads1015.c > @@ -930,6 +930,14 @@ static int ads1015_set_conv_mode(struct ads1015_data *data, int mode) > mode << ADS1015_CFG_MOD_SHIFT); > } > > +static void ads1015_power_off(void *data) > +{ > + struct ads1015_data *st = data; > + > + /* power down single shot mode */ > + ads1015_set_conv_mode(st, ADS1015_SINGLESHOT); > +} > + > static int ads1015_probe(struct i2c_client *client) > { > const struct ads1015_chip_data *chip; > @@ -950,7 +958,9 @@ static int ads1015_probe(struct i2c_client *client) > data = iio_priv(indio_dev); > i2c_set_clientdata(client, indio_dev); > > - mutex_init(&data->lock); > + ret = devm_mutex_init(dev, &data->lock); > + if (ret) > + return ret; > > indio_dev->name = ADS1015_DRV_NAME; > indio_dev->modes = INDIO_DIRECT_MODE; > @@ -1033,38 +1043,23 @@ static int ads1015_probe(struct i2c_client *client) > > data->conv_invalid = true; > > - ret = pm_runtime_set_active(dev); > + ret = devm_add_action_or_reset(dev, ads1015_power_off, data); > if (ret) > return ret; > - pm_runtime_set_autosuspend_delay(dev, ADS1015_SLEEP_DELAY_MS); > - pm_runtime_use_autosuspend(dev); > - pm_runtime_enable(dev); > > - ret = iio_device_register(indio_dev); > - if (ret < 0) { > - dev_err(dev, "Failed to register IIO device\n"); > + ret = devm_pm_runtime_set_active_enabled(dev); > + if (ret) > return ret; Worth noting this was a bug as noting turned off the runtime pm if we got an error in iio_device_register(). That is fixed by this patch I think. > - } > > - return 0; > -} > - > -static void ads1015_remove(struct i2c_client *client) > -{ > - struct iio_dev *indio_dev = i2c_get_clientdata(client); > - struct ads1015_data *data = iio_priv(indio_dev); > - int ret; > - > - iio_device_unregister(indio_dev); > - > - pm_runtime_disable(&client->dev); > - pm_runtime_set_suspended(&client->dev); > + pm_runtime_set_autosuspend_delay(dev, ADS1015_SLEEP_DELAY_MS); > + pm_runtime_use_autosuspend(dev); > > - /* power down single shot mode */ > - ret = ads1015_set_conv_mode(data, ADS1015_SINGLESHOT); > + ret = devm_iio_device_register(dev, indio_dev); > if (ret) > - dev_warn(&client->dev, "Failed to power down (%pe)\n", > - ERR_PTR(ret)); > + return dev_err_probe(dev, ret, > + "Failed to register IIO device\n"); > + > + return 0; > } > > #ifdef CONFIG_PM > @@ -1090,10 +1085,10 @@ static int ads1015_runtime_resume(struct device *dev) > } > #endif > > -static const struct dev_pm_ops ads1015_pm_ops = { > - SET_RUNTIME_PM_OPS(ads1015_runtime_suspend, > - ads1015_runtime_resume, NULL) > -}; > +static DEFINE_RUNTIME_DEV_PM_OPS(ads1015_pm_ops, Sashiko points this out. Switching to this and leaving the CONFIG_PM ifdef above is a bug. https://sashiko.dev/#/patchset/20260718075016.27750-1-architanant5%40gmail.com I didn't chase through whether you can also safely remove the other one further up in the code. > + ads1015_runtime_suspend, > + ads1015_runtime_resume, > + NULL); > > static const struct ads1015_chip_data ads1015_data = { > .channels = ads1015_channels, > @@ -1148,10 +1143,9 @@ static struct i2c_driver ads1015_driver = { > .driver = { > .name = ADS1015_DRV_NAME, > .of_match_table = ads1015_of_match, > - .pm = &ads1015_pm_ops, > + .pm = pm_ptr(&ads1015_pm_ops), > }, > .probe = ads1015_probe, > - .remove = ads1015_remove, > .id_table = ads1015_id, > }; >