diff mbox series

[net-next,2/2] nfc: s3fwrn5: use devm_clk_get_optional_enabled() helper

Message ID 20220929050426.955139-2-dmitry.torokhov@gmail.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net-next,1/2] nfc: s3fwrn5: fix order of freeing resources | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/apply fail Patch does not apply to net-next

Commit Message

Dmitry Torokhov Sept. 29, 2022, 5:04 a.m. UTC
Because we enable the clock immediately after acquiring it in probe,
we can combine the 2 operations and use devm_clk_get_optional_enabled()
helper.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/nfc/s3fwrn5/i2c.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

Comments

Dmitry Torokhov Sept. 29, 2022, 2:58 p.m. UTC | #1
On Wed, Sep 28, 2022 at 10:04:26PM -0700, Dmitry Torokhov wrote:
> Because we enable the clock immediately after acquiring it in probe,
> we can combine the 2 operations and use devm_clk_get_optional_enabled()
> helper.
> 
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
>  drivers/nfc/s3fwrn5/i2c.c | 14 ++++----------
>  1 file changed, 4 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/nfc/s3fwrn5/i2c.c b/drivers/nfc/s3fwrn5/i2c.c
> index fb36860df81c..2aaee2a8ff1c 100644
> --- a/drivers/nfc/s3fwrn5/i2c.c
> +++ b/drivers/nfc/s3fwrn5/i2c.c
> @@ -209,22 +209,16 @@ static int s3fwrn5_i2c_probe(struct i2c_client *client,
>  	if (ret < 0)
>  		return ret;
>  
> -	phy->clk = devm_clk_get_optional(&client->dev, NULL);
> -	if (IS_ERR(phy->clk))
> -		return dev_err_probe(&client->dev, PTR_ERR(phy->clk),
> -				     "failed to get clock\n");
> -
>  	/*
>  	 * S3FWRN5 depends on a clock input ("XI" pin) to function properly.
>  	 * Depending on the hardware configuration this could be an always-on
>  	 * oscillator or some external clock that must be explicitly enabled.
>  	 * Make sure the clock is running before starting S3FWRN5.
>  	 */
> -	ret = clk_prepare_enable(phy->clk);
> -	if (ret < 0) {
> -		dev_err(&client->dev, "failed to enable clock: %d\n", ret);
> -		return ret;
> -	}
> +	phy->clk = devm_clk_get_optional_enabled(&client->dev, NULL);
> +	if (IS_ERR(phy->clk))
> +		return dev_err_probe(&client->dev, PTR_ERR(phy->clk),
> +				     "failed to get clock\n");

I forgot to remove clk_disable_unprepare() in remove method, I will
resubmit.

Thanks.
diff mbox series

Patch

diff --git a/drivers/nfc/s3fwrn5/i2c.c b/drivers/nfc/s3fwrn5/i2c.c
index fb36860df81c..2aaee2a8ff1c 100644
--- a/drivers/nfc/s3fwrn5/i2c.c
+++ b/drivers/nfc/s3fwrn5/i2c.c
@@ -209,22 +209,16 @@  static int s3fwrn5_i2c_probe(struct i2c_client *client,
 	if (ret < 0)
 		return ret;
 
-	phy->clk = devm_clk_get_optional(&client->dev, NULL);
-	if (IS_ERR(phy->clk))
-		return dev_err_probe(&client->dev, PTR_ERR(phy->clk),
-				     "failed to get clock\n");
-
 	/*
 	 * S3FWRN5 depends on a clock input ("XI" pin) to function properly.
 	 * Depending on the hardware configuration this could be an always-on
 	 * oscillator or some external clock that must be explicitly enabled.
 	 * Make sure the clock is running before starting S3FWRN5.
 	 */
-	ret = clk_prepare_enable(phy->clk);
-	if (ret < 0) {
-		dev_err(&client->dev, "failed to enable clock: %d\n", ret);
-		return ret;
-	}
+	phy->clk = devm_clk_get_optional_enabled(&client->dev, NULL);
+	if (IS_ERR(phy->clk))
+		return dev_err_probe(&client->dev, PTR_ERR(phy->clk),
+				     "failed to get clock\n");
 
 	ret = s3fwrn5_probe(&phy->common.ndev, phy, &phy->i2c_dev->dev,
 			    &i2c_phy_ops);