Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp536873lqh; Thu, 28 Mar 2024 08:56:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXcEzRSVWFNM81MGfaDjjFc6rowIfnNe9FDxfAYNtmCMelFFLShCKz4ZQKzQjGaNnd4QBhheihEx+27PhdbSo/dhox1te9nHppbbah9ug== X-Google-Smtp-Source: AGHT+IFpU2Onxgsq3m6JUH72cKr5tiQFfua//co20WEU2s6MXm0XsMFMDGQp0UFsTkJ+J0FbvGEQ X-Received: by 2002:a05:6a00:1813:b0:6ea:afd1:9023 with SMTP id y19-20020a056a00181300b006eaafd19023mr4078087pfa.0.1711641408588; Thu, 28 Mar 2024 08:56:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711641408; cv=pass; d=google.com; s=arc-20160816; b=F4MsKJEbmA2JYJxW2ixAexMKj6e8pUh1hlVJV3jIjpcAAtMShcPH3etb3UMpUzxLZQ y6FddQd2rouPiJYQ3dgwUlUc9hfBvWeJiY10Y/KbrtLFdDOuU9w0Sdx5bGUfO3R8gGin qQyLJc2qNGlfyhBE/MHnBDYoNG/MuZOwx29+rh0O09+x48+qKVKtQ7ktlyPjrj0YpIOe iEdQOel7NioB6rEDLjLhO8s69iu6kQCZrfQE6BXFULsigSB4hmRfATjRdEPE+JS/hWDU kY3lY6TcqR2I74CJ2xuHyTIOttn212fkhIuxuytB66VUOtQUW60c78wl+Y8+myv3w0bL VXow== 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:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=/wHnRAkmPaW/bmbMJRuKQxxTx35IyOZTMF6ntJj77Q4=; fh=1Y8jvb9NCxMPzeSAK254nnMSlstfVfizDpfRmub3ENU=; b=QirwfIxXh/gciWqpgCY0nwd5HgiJ3cB/ix7RePFvzlAQYIXGheSPwC8Xmz9k1F2NEZ MNXKhNpcjIK0sAYXN39rBnceOohD+K45yNHxTblomL0nV9mt//warOQ434O8f5my64us PFBhAXf7IL1/qgdTdVaSqBebAhKvOiOzrOCS9sa8XgdtAk8RsUba7YKcwzeVdZdrJBtW cN9r1IPWnar/Id7pthXoxtcRvcsLKq02BA02bHk2CJ7ZLEYeqRTCXfVcnz8dLGcDgiAr N6ov+vBsg8u/1kZiNkJK6L2KBbc2XvZBy8clnconwCJk5fjq+l5fYj249oYH3k9Mk9Yb GQGg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PMo3tpdJ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-123188-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123188-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id o24-20020a056a001b5800b006e6b5abf255si1685228pfv.138.2024.03.28.08.56.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 08:56:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-123188-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PMo3tpdJ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-123188-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123188-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id BEA5BB22C01 for ; Thu, 28 Mar 2024 15:53:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 94317130AD2; Thu, 28 Mar 2024 15:53:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PMo3tpdJ" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 A225E7E0E8; Thu, 28 Mar 2024 15:53:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711641224; cv=none; b=lf3r8+sR7Q08IeN9EUA2JjWxL+NToVeo8PFel4fxaFtiaZe7bTydXdzP4hlAqTAV32I9BT3yS4SJqf+b0BKLl5r5bLFxgxjPzyw5Bg5XOsGmDTkt/TXs9SIrGALq6VyE/VM3q0ehOdt52W89Hcej4uAirWRnBl2LrWAdBYLbiBI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711641224; c=relaxed/simple; bh=UQ4ftE4d2wyJQXBRF16WggqiN2pIoTo1vBnMgKGTa20=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=W/xnIOEKTx4hB3wnuKT84H2uJ9lJBM+GK61yfmQ0yssfhSJNz8bX8kVNFjQOW5z1udy6f9lXCyzHUMPmecInbZ0Fxw6y7uJyhrWb0KvtJ0XH7+xoCIRmVQXhJRxuUNd+/PmReg7+Iha88DvmfGSUOfsKeInApD6XbeC+Mn1iank= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PMo3tpdJ; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2DC31C433C7; Thu, 28 Mar 2024 15:53:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711641224; bh=UQ4ftE4d2wyJQXBRF16WggqiN2pIoTo1vBnMgKGTa20=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=PMo3tpdJon9JSWvzLbi3LYD+vJR6aWdM1xxxv4uYiX9pi50ulIvqx9GdLVFmgf/eG y54+FB3f2fVUN7lN24VF9ScRwGE5+nai38XVEFsEY5aGcu/OxmPMo0CRo66VMu641k mdC0z045ZAiJJEfpRO0b9Dj95MNNkN2YcpCv9zrH81OgL69pfoKSG72rxoNnF+ixZE EZKJHXNr8zOTso7/8FjpGQqDLUmz+ExjAsxs8zD+SWgEWTwVed6LVqHLEBYqoP4S62 SoOZq6bJ6d5B7Qr/JjEcmvh3KqQOjAPpY9weBmLgeiFegivskWRvQnn9afckV9PtMn Pd9/b0WisbQDw== Date: Thu, 28 Mar 2024 15:53:28 +0000 From: Jonathan Cameron To: Guenter Roeck Cc: David Lechner , Jonathan Corbet , Liam Girdwood , Mark Brown , Jean Delvare , Support Opensource , Cosmin Tanislav , Lars-Peter Clausen , Michael Hennerich , Antoniu Miclaus , Greg Kroah-Hartman , Dmitry Torokhov , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-iio@vger.kernel.org, linux-staging@lists.linux.dev, linux-input@vger.kernel.org Subject: Re: [PATCH RFC 3/7] hwmon: (da9052) Use devm_regulator_get_enable_get_voltage() Message-ID: <20240328155328.755708bf@jic23-huawei> In-Reply-To: <13405bc9-3c97-4063-87b3-45a7e686fa50@roeck-us.net> References: <20240327-regulator-get-enable-get-votlage-v1-0-5f4517faa059@baylibre.com> <20240327-regulator-get-enable-get-votlage-v1-3-5f4517faa059@baylibre.com> <20240328142038.33ad68bc@jic23-huawei> <13405bc9-3c97-4063-87b3-45a7e686fa50@roeck-us.net> X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; 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 On Thu, 28 Mar 2024 08:20:00 -0700 Guenter Roeck wrote: > On 3/28/24 07:20, Jonathan Cameron wrote: > > On Wed, 27 Mar 2024 18:18:52 -0500 > > David Lechner wrote: > > > >> We can reduce boilerplate code by using > >> devm_regulator_get_enable_get_voltage(). > >> > >> Signed-off-by: David Lechner > > > > A few comments inline, but nothing substantial. > > > > Reviewed-by: Jonathan Cameron > >> --- > >> drivers/hwmon/da9052-hwmon.c | 33 +++++++-------------------------- > >> 1 file changed, 7 insertions(+), 26 deletions(-) > >> > >> diff --git a/drivers/hwmon/da9052-hwmon.c b/drivers/hwmon/da9052-hwmon.c > >> index 2bd7ae8100d7..70e7bc72e980 100644 > >> --- a/drivers/hwmon/da9052-hwmon.c > >> +++ b/drivers/hwmon/da9052-hwmon.c > >> @@ -26,7 +26,6 @@ struct da9052_hwmon { > >> struct mutex hwmon_lock; > >> bool tsi_as_adc; > >> int tsiref_mv; > >> - struct regulator *tsiref; > >> struct completion tsidone; > >> }; > >> > >> @@ -414,32 +413,19 @@ static int da9052_hwmon_probe(struct platform_device *pdev) > >> device_property_read_bool(pdev->dev.parent, "dlg,tsi-as-adc"); > >> > >> if (hwmon->tsi_as_adc) { > >> - hwmon->tsiref = devm_regulator_get(pdev->dev.parent, "tsiref"); > >> - if (IS_ERR(hwmon->tsiref)) { > >> - err = PTR_ERR(hwmon->tsiref); > >> - dev_err(&pdev->dev, "failed to get tsiref: %d", err); > >> + err = devm_regulator_get_enable_get_voltage(pdev->dev.parent, > >> + "tsiref"); > >> + if (err < 0) > >> return err; > >> - } > >> - > >> - err = regulator_enable(hwmon->tsiref); > >> - if (err) > >> - return err; > >> - > >> - hwmon->tsiref_mv = regulator_get_voltage(hwmon->tsiref); > >> - if (hwmon->tsiref_mv < 0) { > >> - err = hwmon->tsiref_mv; > >> - goto exit_regulator; > >> - } > >> > >> /* convert from microvolt (DT) to millivolt (hwmon) */ > >> - hwmon->tsiref_mv /= 1000; > >> + hwmon->tsiref_mv = err / 1000; > >> > > > > Using a variable called err for a good value is a bit ugly but fair enough if that > > is precedence in this driver. > > > > It isn't. The existing code assigns the return value from regulator_get_voltage() > to hwmon->tsiref_mv and then evaluates it. I would not oppose introducing a variable > such as tsiref_uv, but not the misuse of 'err'. I am not going to accept the code > as suggested. It is bad style, and it would invite others to use it as precedent > when trying to introduce similar code. I was too lazy to look and see if there were existing cases :) Local variable indeed the right way to go. > > >> } > >> @@ -483,10 +466,8 @@ static void da9052_hwmon_remove(struct platform_device *pdev) > >> { > >> struct da9052_hwmon *hwmon = platform_get_drvdata(pdev); > >> > >> - if (hwmon->tsi_as_adc) { > >> + if (hwmon->tsi_as_adc) > >> da9052_free_irq(hwmon->da9052, DA9052_IRQ_TSIREADY, hwmon); > > Superficially looks like devm_da9052_request_irq could be added that > > uses devm_request_threaded_irq() to allow dropping this remaining handling. > > > > That should be a separate series of patches. A local solution might be > to use devm_add_action_or_reset(), but that should also be a separate patch. Agreed. Just a passing comment whilst the code was in front of me. Jonathan > > Thanks, > Guenter >