All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] i2c: core: simplify devm_i2c_new_dummy_device()
@ 2021-04-08 12:17 Yicong Yang
  2021-04-08 13:32 ` Andy Shevchenko
  2021-04-08 21:02 ` Wolfram Sang
  0 siblings, 2 replies; 3+ messages in thread
From: Yicong Yang @ 2021-04-08 12:17 UTC (permalink / raw)
  To: wsa, linux-i2c
  Cc: digetx, andriy.shevchenko, prime.zeng, tiantao6, yangyicong, linuxarm

Use devm_add_action_or_reset() instead of devres_alloc() and
devres_add(), which works the same. This will simplify the
code. There is no functional change.

Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
---
 drivers/i2c/i2c-core-base.c | 28 +++++++++-------------------
 1 file changed, 9 insertions(+), 19 deletions(-)

diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 63ebf72..b883a59 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -1016,15 +1016,9 @@ struct i2c_client *i2c_new_dummy_device(struct i2c_adapter *adapter, u16 address
 }
 EXPORT_SYMBOL_GPL(i2c_new_dummy_device);

-struct i2c_dummy_devres {
-	struct i2c_client *client;
-};
-
-static void devm_i2c_release_dummy(struct device *dev, void *res)
+static void devm_i2c_release_dummy(void *client)
 {
-	struct i2c_dummy_devres *this = res;
-
-	i2c_unregister_device(this->client);
+	i2c_unregister_device(client);
 }

 /**
@@ -1041,20 +1035,16 @@ struct i2c_client *devm_i2c_new_dummy_device(struct device *dev,
 					     struct i2c_adapter *adapter,
 					     u16 address)
 {
-	struct i2c_dummy_devres *dr;
 	struct i2c_client *client;
-
-	dr = devres_alloc(devm_i2c_release_dummy, sizeof(*dr), GFP_KERNEL);
-	if (!dr)
-		return ERR_PTR(-ENOMEM);
+	int ret;

 	client = i2c_new_dummy_device(adapter, address);
-	if (IS_ERR(client)) {
-		devres_free(dr);
-	} else {
-		dr->client = client;
-		devres_add(dev, dr);
-	}
+	if (IS_ERR(client))
+		return client;
+
+	ret = devm_add_action_or_reset(dev, devm_i2c_release_dummy, client);
+	if (ret)
+		return ERR_PTR(ret);

 	return client;
 }
--
2.8.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] i2c: core: simplify devm_i2c_new_dummy_device()
  2021-04-08 12:17 [PATCH] i2c: core: simplify devm_i2c_new_dummy_device() Yicong Yang
@ 2021-04-08 13:32 ` Andy Shevchenko
  2021-04-08 21:02 ` Wolfram Sang
  1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2021-04-08 13:32 UTC (permalink / raw)
  To: Yicong Yang; +Cc: wsa, linux-i2c, digetx, prime.zeng, tiantao6, linuxarm

On Thu, Apr 08, 2021 at 08:17:40PM +0800, Yicong Yang wrote:
> Use devm_add_action_or_reset() instead of devres_alloc() and
> devres_add(), which works the same. This will simplify the
> code. There is no functional change.

Nice!
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

> Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
> ---
>  drivers/i2c/i2c-core-base.c | 28 +++++++++-------------------
>  1 file changed, 9 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
> index 63ebf72..b883a59 100644
> --- a/drivers/i2c/i2c-core-base.c
> +++ b/drivers/i2c/i2c-core-base.c
> @@ -1016,15 +1016,9 @@ struct i2c_client *i2c_new_dummy_device(struct i2c_adapter *adapter, u16 address
>  }
>  EXPORT_SYMBOL_GPL(i2c_new_dummy_device);
> 
> -struct i2c_dummy_devres {
> -	struct i2c_client *client;
> -};
> -
> -static void devm_i2c_release_dummy(struct device *dev, void *res)
> +static void devm_i2c_release_dummy(void *client)
>  {
> -	struct i2c_dummy_devres *this = res;
> -
> -	i2c_unregister_device(this->client);
> +	i2c_unregister_device(client);
>  }
> 
>  /**
> @@ -1041,20 +1035,16 @@ struct i2c_client *devm_i2c_new_dummy_device(struct device *dev,
>  					     struct i2c_adapter *adapter,
>  					     u16 address)
>  {
> -	struct i2c_dummy_devres *dr;
>  	struct i2c_client *client;
> -
> -	dr = devres_alloc(devm_i2c_release_dummy, sizeof(*dr), GFP_KERNEL);
> -	if (!dr)
> -		return ERR_PTR(-ENOMEM);
> +	int ret;
> 
>  	client = i2c_new_dummy_device(adapter, address);
> -	if (IS_ERR(client)) {
> -		devres_free(dr);
> -	} else {
> -		dr->client = client;
> -		devres_add(dev, dr);
> -	}
> +	if (IS_ERR(client))
> +		return client;
> +
> +	ret = devm_add_action_or_reset(dev, devm_i2c_release_dummy, client);
> +	if (ret)
> +		return ERR_PTR(ret);
> 
>  	return client;
>  }
> --
> 2.8.1
> 

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] i2c: core: simplify devm_i2c_new_dummy_device()
  2021-04-08 12:17 [PATCH] i2c: core: simplify devm_i2c_new_dummy_device() Yicong Yang
  2021-04-08 13:32 ` Andy Shevchenko
@ 2021-04-08 21:02 ` Wolfram Sang
  1 sibling, 0 replies; 3+ messages in thread
From: Wolfram Sang @ 2021-04-08 21:02 UTC (permalink / raw)
  To: Yicong Yang
  Cc: linux-i2c, digetx, andriy.shevchenko, prime.zeng, tiantao6, linuxarm

[-- Attachment #1: Type: text/plain, Size: 341 bytes --]

On Thu, Apr 08, 2021 at 08:17:40PM +0800, Yicong Yang wrote:
> Use devm_add_action_or_reset() instead of devres_alloc() and
> devres_add(), which works the same. This will simplify the
> code. There is no functional change.
> 
> Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>

Yes, really nice! Applied to for-next, thanks!


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-04-08 21:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-08 12:17 [PATCH] i2c: core: simplify devm_i2c_new_dummy_device() Yicong Yang
2021-04-08 13:32 ` Andy Shevchenko
2021-04-08 21:02 ` Wolfram Sang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.