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 99828C678D5 for ; Sat, 4 Mar 2023 17:20:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229556AbjCDRUC (ORCPT ); Sat, 4 Mar 2023 12:20:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229447AbjCDRUA (ORCPT ); Sat, 4 Mar 2023 12:20:00 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12771E073; Sat, 4 Mar 2023 09:19:58 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4DA59B808CA; Sat, 4 Mar 2023 17:19:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95A2BC433EF; Sat, 4 Mar 2023 17:19:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1677950395; bh=SK7Kwhhi/uD/G7RidXbseM1UAmXNuUfv51NQ/U3YKJg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=rh0wM4+Ml+ReF6Qhs2k32vLNSULLA70mmDWbx2mUMySoqjawNnGB6mX7xaL7UJNso mqkwU+LxrRIp5w8IfkL4768a6u+APrr1D6l/5qxoq6LozxY5VprzAZhMFT/VL8FhpA PAYFZEByZkw6niCsNA3xbg1dVe/7nZM4dfQS2J+jW9DnOZVYs9HZhu7yUWTSmOJEVM QNS/vTiYNF2OZ1967KViRQ8JdNJEu0vV3ezLPVQl9D9u3oMW+8J4nn0vmaHbr4FxtZ UqDGrBPuOhxpVkCmqo+a0TTgxJdSp3ci3LaXNYEJI/iC/P7F4WMnuwmJgxj7CFLknd Wtl6i1BVuZenw== Date: Sat, 4 Mar 2023 17:19:50 +0000 From: Jonathan Cameron To: Lars-Peter Clausen Cc: Mike Looijmans , Andy Shevchenko , devicetree@vger.kernel.org, linux-iio@vger.kernel.org, Caleb Connolly , ChiYuan Huang , ChiaEn Wu , Cosmin Tanislav , Ibrahim Tilki , Ramona Bolboaca , William Breathitt Gray , linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 2/2] iio: adc: Add TI ADS1100 and ADS1000 Message-ID: <20230304171950.5a411037@jic23-huawei> In-Reply-To: References: <20230228063151.17598-1-mike.looijmans@topic.nl> <20230228063151.17598-2-mike.looijmans@topic.nl> <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.0685d97e-4a28-499e-a9e3-3bafec126832@emailsignatures365.codetwo.com> <87bc192e-45ae-9480-5e84-8fe0adfc12e7@metafoo.de> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.37; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2 Mar 2023 05:20:38 -0800 Lars-Peter Clausen wrote: > On 3/2/23 05:16, Lars-Peter Clausen wrote: > > On 3/1/23 23:49, Mike Looijmans wrote: =20 > >> > >> =20 > >>> ... > >>> ... > >>> =20 > >>>> +static int ads1100_runtime_suspend(struct device *dev) > >>>> +{ > >>>> +=C2=A0=C2=A0=C2=A0 struct iio_dev *indio_dev =3D=20 > >>>> i2c_get_clientdata(to_i2c_client(dev)); > >>>> +=C2=A0=C2=A0=C2=A0 struct ads1100_data *data =3D iio_priv(indio_dev= ); > >>>> + > >>>> +=C2=A0=C2=A0=C2=A0 ads1100_set_config_bits(data, ADS1100_CFG_SC,=20 > >>>> ADS1100_SINGLESHOT); > >>>> +=C2=A0=C2=A0=C2=A0 regulator_disable(data->reg_vdd); =20 > >>> Wrong devm / non-devm ordering. =20 > >> > >> Don't understand your remark, can you explain further please? > >> > >> devm / non-devm ordering would be related to the "probe" function. As= =20 > >> far as I can tell, I'm not allocating resources after the devm calls.= =20 > >> And the "remove" is empty. =20 > > > > Strictly speaking we need to unregister the IIO device before=20 > > disabling the regulator, otherwise there is a small window where the=20 > > IIO device still exists, but doesn't work anymore. This is a very=20 > > theoretical scenario though. > > > > You are lucky :) There is a new function=20 > > `devm_regulator_get_enable()`[1], which will manage the=20 > > regulator_disable() for you. Using that will also reduce the=20 > > boilerplate in `probe()` a bit > > > > - Lars > > > > [1] https://lwn.net/Articles/904383/ > > =20 > Sorry, just saw that Andy's comment was on the suspend() function, not=20 > remove(). In that case there is of course no need for any devm things.=20 > But still a good idea to use `devm_regulator_get_enable()` in probe for=20 > the boiler plate. >=20 You can't because (annoyingly) devem_regulator_get_enable() doesn't provide you access to the struct regulator that you need to be able to turn it of for power management. That case only works for the leave the power on all the time cases. Jonathan