linux-renesas-soc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v8 0/3] i2c: improve i2c_new_{device|dummy}
@ 2019-05-16 21:13 Wolfram Sang
  2019-05-16 21:13 ` [PATCH v8 1/3] i2c: core: improve return value handling of i2c_new_device and i2c_new_dummy Wolfram Sang
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Wolfram Sang @ 2019-05-16 21:13 UTC (permalink / raw)
  To: linux-i2c
  Cc: linux-renesas-soc, Heiner Kallweit, Bartosz Golaszewski,
	Kieran Bingham, Peter Rosin, Wolfram Sang

Hiya,

so, here is a new version as a result of the discussion.

Changes since V7:

* dropped the 'errptr' suffix and renamed the functions to
  'i2c_new_client_device' and 'i2c_new_dummy_device'

* add EXPORT_SYMBOL_GPL to these new functions

I decided to convert the users of i2c_new_device and i2c_new_dummy to
the new functions after these functions are available. So, we can get
rid of the old functions somewhen. To speed this up, I'd like to send
them this merge window to Linus. Yeah, this is short notice, but I
simply couldn't work earlier on this because of my illness. So, if you
can support me with immediate (but still thorough!) reviews, that would
be much appreciated. If we can get it upstream this cycle, then I can
already start fixing the users.

Patch 3 is only for demonstration purposes, of course. I will send it to
the MFD list once the dependencies are upstream.

Tested on a Renesas Lager board (R-Car Gen2).

Looking forward to comments,

   Wolfram


Heiner Kallweit (2):
  i2c: core: improve return value handling of i2c_new_device and
    i2c_new_dummy
  i2c: core: add device-managed version of i2c_new_dummy

Wolfram Sang (1):
  mfd: da9063: occupy second I2C address, too

 Documentation/driver-model/devres.txt |   3 +
 drivers/i2c/i2c-core-base.c           | 118 +++++++++++++++++++++++---
 drivers/mfd/da9063-i2c.c              |   2 +
 include/linux/i2c.h                   |   3 +
 4 files changed, 113 insertions(+), 13 deletions(-)

-- 
2.19.1


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

* [PATCH v8 1/3] i2c: core: improve return value handling of i2c_new_device and i2c_new_dummy
  2019-05-16 21:13 [PATCH v8 0/3] i2c: improve i2c_new_{device|dummy} Wolfram Sang
@ 2019-05-16 21:13 ` Wolfram Sang
  2019-05-17  7:16   ` Peter Rosin
                     ` (3 more replies)
  2019-05-16 21:13 ` [PATCH v8 2/3] i2c: core: add device-managed version of i2c_new_dummy Wolfram Sang
  2019-05-16 21:13 ` [PATCH v8 3/3] mfd: da9063: occupy second I2C address, too Wolfram Sang
  2 siblings, 4 replies; 16+ messages in thread
From: Wolfram Sang @ 2019-05-16 21:13 UTC (permalink / raw)
  To: linux-i2c
  Cc: linux-renesas-soc, Heiner Kallweit, Bartosz Golaszewski,
	Kieran Bingham, Peter Rosin, Wolfram Sang

From: Heiner Kallweit <hkallweit1@gmail.com>

Currently i2c_new_device and i2c_new_dummy return just NULL in error
case although they have more error details internally. Therefore move
the functionality into new functions returning detailed errors and
add wrappers for compatibility with the current API.

This allows to use these functions with detailed error codes within
the i2c core or for API extensions.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
[wsa: rename new functions and fix minor kdoc issues]
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
 drivers/i2c/i2c-core-base.c | 74 ++++++++++++++++++++++++++++++-------
 1 file changed, 61 insertions(+), 13 deletions(-)

diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 9732a81bb7dd..9c38dde73366 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -714,7 +714,7 @@ static int i2c_dev_irq_from_resources(const struct resource *resources,
 }
 
 /**
- * i2c_new_device - instantiate an i2c device
+ * i2c_new_client_device - instantiate an i2c device
  * @adap: the adapter managing the device
  * @info: describes one I2C device; bus_num is ignored
  * Context: can sleep
@@ -727,17 +727,17 @@ static int i2c_dev_irq_from_resources(const struct resource *resources,
  * before any i2c_adapter could exist.
  *
  * This returns the new i2c client, which may be saved for later use with
- * i2c_unregister_device(); or NULL to indicate an error.
+ * i2c_unregister_device(); or an ERR_PTR to describe the error.
  */
-struct i2c_client *
-i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
+static struct i2c_client *
+i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
 {
 	struct i2c_client	*client;
 	int			status;
 
 	client = kzalloc(sizeof *client, GFP_KERNEL);
 	if (!client)
-		return NULL;
+		return ERR_PTR(-ENOMEM);
 
 	client->adapter = adap;
 
@@ -803,7 +803,31 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
 		client->name, client->addr, status);
 out_err_silent:
 	kfree(client);
-	return NULL;
+	return ERR_PTR(status);
+}
+EXPORT_SYMBOL_GPL(i2c_new_client_device);
+
+/**
+ * i2c_new_device - instantiate an i2c device
+ * @adap: the adapter managing the device
+ * @info: describes one I2C device; bus_num is ignored
+ * Context: can sleep
+ *
+ * This deprecated function has the same functionality as
+ * @i2c_new_client_device, it just returns NULL instead of an ERR_PTR in case of
+ * an error for compatibility with current I2C API. It will be removed once all
+ * users are converted.
+ *
+ * This returns the new i2c client, which may be saved for later use with
+ * i2c_unregister_device(); or NULL to indicate an error.
+ */
+struct i2c_client *
+i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
+{
+	struct i2c_client *ret;
+
+	ret = i2c_new_client_device(adap, info);
+	return IS_ERR(ret) ? NULL : ret;
 }
 EXPORT_SYMBOL_GPL(i2c_new_device);
 
@@ -854,7 +878,7 @@ static struct i2c_driver dummy_driver = {
 };
 
 /**
- * i2c_new_dummy - return a new i2c device bound to a dummy driver
+ * i2c_new_dummy_device - return a new i2c device bound to a dummy driver
  * @adapter: the adapter managing the device
  * @address: seven bit address to be used
  * Context: can sleep
@@ -869,15 +893,39 @@ static struct i2c_driver dummy_driver = {
  * different driver.
  *
  * This returns the new i2c client, which should be saved for later use with
- * i2c_unregister_device(); or NULL to indicate an error.
+ * i2c_unregister_device(); or an ERR_PTR to describe the error.
  */
-struct i2c_client *i2c_new_dummy(struct i2c_adapter *adapter, u16 address)
+static struct i2c_client *
+i2c_new_dummy_device(struct i2c_adapter *adapter, u16 address)
 {
 	struct i2c_board_info info = {
 		I2C_BOARD_INFO("dummy", address),
 	};
 
-	return i2c_new_device(adapter, &info);
+	return i2c_new_client_device(adapter, &info);
+}
+EXPORT_SYMBOL_GPL(i2c_new_dummy_device);
+
+/**
+ * i2c_new_dummy - return a new i2c device bound to a dummy driver
+ * @adapter: the adapter managing the device
+ * @address: seven bit address to be used
+ * Context: can sleep
+ *
+ * This deprecated function has the same functionality as @i2c_new_dummy_device,
+ * it just returns NULL instead of an ERR_PTR in case of an error for
+ * compatibility with current I2C API. It will be removed once all users are
+ * converted.
+ *
+ * This returns the new i2c client, which should be saved for later use with
+ * i2c_unregister_device(); or NULL to indicate an error.
+ */
+struct i2c_client *i2c_new_dummy(struct i2c_adapter *adapter, u16 address)
+{
+	struct i2c_client *ret;
+
+	ret = i2c_new_dummy_device(adapter, address);
+	return IS_ERR(ret) ? NULL : ret;
 }
 EXPORT_SYMBOL_GPL(i2c_new_dummy);
 
@@ -1000,9 +1048,9 @@ i2c_sysfs_new_device(struct device *dev, struct device_attribute *attr,
 		info.flags |= I2C_CLIENT_SLAVE;
 	}
 
-	client = i2c_new_device(adap, &info);
-	if (!client)
-		return -EINVAL;
+	client = i2c_new_client_device(adap, &info);
+	if (IS_ERR(client))
+		return PTR_ERR(client);
 
 	/* Keep track of the added device */
 	mutex_lock(&adap->userspace_clients_lock);
-- 
2.19.1


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

* [PATCH v8 2/3] i2c: core: add device-managed version of i2c_new_dummy
  2019-05-16 21:13 [PATCH v8 0/3] i2c: improve i2c_new_{device|dummy} Wolfram Sang
  2019-05-16 21:13 ` [PATCH v8 1/3] i2c: core: improve return value handling of i2c_new_device and i2c_new_dummy Wolfram Sang
@ 2019-05-16 21:13 ` Wolfram Sang
  2019-05-17  7:17   ` Peter Rosin
                     ` (3 more replies)
  2019-05-16 21:13 ` [PATCH v8 3/3] mfd: da9063: occupy second I2C address, too Wolfram Sang
  2 siblings, 4 replies; 16+ messages in thread
From: Wolfram Sang @ 2019-05-16 21:13 UTC (permalink / raw)
  To: linux-i2c
  Cc: linux-renesas-soc, Heiner Kallweit, Bartosz Golaszewski,
	Kieran Bingham, Peter Rosin, Wolfram Sang

From: Heiner Kallweit <hkallweit1@gmail.com>

i2c_new_dummy is typically called from the probe function of the
driver for the primary i2c client. It requires calls to
i2c_unregister_device in the error path of the probe function and
in the remove function.
This can be simplified by introducing a device-managed version.

Note the changed error case return value type: i2c_new_dummy returns
NULL whilst devm_i2c_new_dummy_device returns an ERR_PTR.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
[wsa: rename new functions and fix minor kdoc issues]
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
 Documentation/driver-model/devres.txt |  3 ++
 drivers/i2c/i2c-core-base.c           | 44 +++++++++++++++++++++++++++
 include/linux/i2c.h                   |  3 ++
 3 files changed, 50 insertions(+)

diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt
index 99994a461359..69c7fa7f616c 100644
--- a/Documentation/driver-model/devres.txt
+++ b/Documentation/driver-model/devres.txt
@@ -271,6 +271,9 @@ GPIO
   devm_gpio_request_one()
   devm_gpio_free()
 
+I2C
+  devm_i2c_new_dummy_device()
+
 IIO
   devm_iio_device_alloc()
   devm_iio_device_free()
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 9c38dde73366..d389d4fb0623 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -929,6 +929,50 @@ struct i2c_client *i2c_new_dummy(struct i2c_adapter *adapter, u16 address)
 }
 EXPORT_SYMBOL_GPL(i2c_new_dummy);
 
+struct i2c_dummy_devres {
+	struct i2c_client *client;
+};
+
+static void devm_i2c_release_dummy(struct device *dev, void *res)
+{
+	struct i2c_dummy_devres *this = res;
+
+	i2c_unregister_device(this->client);
+}
+
+/**
+ * devm_i2c_new_dummy_device - return a new i2c device bound to a dummy driver
+ * @dev: device the managed resource is bound to
+ * @adapter: the adapter managing the device
+ * @address: seven bit address to be used
+ * Context: can sleep
+ *
+ * This is the device-managed version of @i2c_new_dummy_device. It returns the
+ * new i2c client or an ERR_PTR in case of an error.
+ */
+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);
+
+	client = i2c_new_dummy_device(adapter, address);
+	if (IS_ERR(client)) {
+		devres_free(dr);
+	} else {
+		dr->client = client;
+		devres_add(dev, dr);
+	}
+
+	return client;
+}
+EXPORT_SYMBOL_GPL(devm_i2c_new_dummy_device);
+
 /**
  * i2c_new_secondary_device - Helper to get the instantiated secondary address
  * and create the associated device
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index be27062f8ed1..6c4db54714f6 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -469,6 +469,9 @@ extern int i2c_probe_func_quick_read(struct i2c_adapter *, unsigned short addr);
 extern struct i2c_client *
 i2c_new_dummy(struct i2c_adapter *adap, u16 address);
 
+extern struct i2c_client *
+devm_i2c_new_dummy_device(struct device *dev, struct i2c_adapter *adap, u16 address);
+
 extern struct i2c_client *
 i2c_new_secondary_device(struct i2c_client *client,
 				const char *name,
-- 
2.19.1


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

* [PATCH v8 3/3] mfd: da9063: occupy second I2C address, too
  2019-05-16 21:13 [PATCH v8 0/3] i2c: improve i2c_new_{device|dummy} Wolfram Sang
  2019-05-16 21:13 ` [PATCH v8 1/3] i2c: core: improve return value handling of i2c_new_device and i2c_new_dummy Wolfram Sang
  2019-05-16 21:13 ` [PATCH v8 2/3] i2c: core: add device-managed version of i2c_new_dummy Wolfram Sang
@ 2019-05-16 21:13 ` Wolfram Sang
  2019-05-17  7:17   ` Peter Rosin
                     ` (2 more replies)
  2 siblings, 3 replies; 16+ messages in thread
From: Wolfram Sang @ 2019-05-16 21:13 UTC (permalink / raw)
  To: linux-i2c
  Cc: linux-renesas-soc, Heiner Kallweit, Bartosz Golaszewski,
	Kieran Bingham, Peter Rosin, Wolfram Sang

Even though we don't use it yet, we should mark the second I2C address
this device is listening to as used.

Not yet for upstream until all dependencies are merged!

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
 drivers/mfd/da9063-i2c.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/mfd/da9063-i2c.c b/drivers/mfd/da9063-i2c.c
index 455de74c0dd2..2133b09f6e7a 100644
--- a/drivers/mfd/da9063-i2c.c
+++ b/drivers/mfd/da9063-i2c.c
@@ -221,6 +221,8 @@ static int da9063_i2c_probe(struct i2c_client *i2c,
 		return ret;
 	}
 
+	devm_i2c_new_dummy_device(&i2c->dev, i2c->adapter, i2c->addr + 1);
+
 	return da9063_device_init(da9063, i2c->irq);
 }
 
-- 
2.19.1


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

* Re: [PATCH v8 1/3] i2c: core: improve return value handling of i2c_new_device and i2c_new_dummy
  2019-05-16 21:13 ` [PATCH v8 1/3] i2c: core: improve return value handling of i2c_new_device and i2c_new_dummy Wolfram Sang
@ 2019-05-17  7:16   ` Peter Rosin
  2019-05-17 17:35     ` Wolfram Sang
  2019-05-17  8:02   ` Kieran Bingham
                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 16+ messages in thread
From: Peter Rosin @ 2019-05-17  7:16 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c
  Cc: linux-renesas-soc, Heiner Kallweit, Bartosz Golaszewski, Kieran Bingham

On 2019-05-16 23:13, Wolfram Sang wrote:
> From: Heiner Kallweit <hkallweit1@gmail.com>
> 
> Currently i2c_new_device and i2c_new_dummy return just NULL in error
> case although they have more error details internally. Therefore move
> the functionality into new functions returning detailed errors and
> add wrappers for compatibility with the current API.
> 
> This allows to use these functions with detailed error codes within
> the i2c core or for API extensions.
> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> [wsa: rename new functions and fix minor kdoc issues]
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

The only nit I can find is that you could perhaps sweep the patches
with sed 's/i2c /I2C /'. But that is indeed a nit, so if you're in
a hurry...

Reviewed-by: Peter Rosin <peda@axentia.se>

Cheers,
Peter

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

* Re: [PATCH v8 2/3] i2c: core: add device-managed version of i2c_new_dummy
  2019-05-16 21:13 ` [PATCH v8 2/3] i2c: core: add device-managed version of i2c_new_dummy Wolfram Sang
@ 2019-05-17  7:17   ` Peter Rosin
  2019-05-17  8:21   ` Kieran Bingham
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 16+ messages in thread
From: Peter Rosin @ 2019-05-17  7:17 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c
  Cc: linux-renesas-soc, Heiner Kallweit, Bartosz Golaszewski, Kieran Bingham

On 2019-05-16 23:13, Wolfram Sang wrote:
> From: Heiner Kallweit <hkallweit1@gmail.com>
> 
> i2c_new_dummy is typically called from the probe function of the
> driver for the primary i2c client. It requires calls to
> i2c_unregister_device in the error path of the probe function and
> in the remove function.
> This can be simplified by introducing a device-managed version.
> 
> Note the changed error case return value type: i2c_new_dummy returns
> NULL whilst devm_i2c_new_dummy_device returns an ERR_PTR.
> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> [wsa: rename new functions and fix minor kdoc issues]
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

Reviewed-by: Peter Rosin <peda@axentia.se>

Cheers,
Peter


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

* Re: [PATCH v8 3/3] mfd: da9063: occupy second I2C address, too
  2019-05-16 21:13 ` [PATCH v8 3/3] mfd: da9063: occupy second I2C address, too Wolfram Sang
@ 2019-05-17  7:17   ` Peter Rosin
  2019-05-17  8:57   ` Bartosz Golaszewski
  2019-05-17 14:56   ` Kieran Bingham
  2 siblings, 0 replies; 16+ messages in thread
From: Peter Rosin @ 2019-05-17  7:17 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c
  Cc: linux-renesas-soc, Heiner Kallweit, Bartosz Golaszewski, Kieran Bingham

On 2019-05-16 23:13, Wolfram Sang wrote:
> Even though we don't use it yet, we should mark the second I2C address
> this device is listening to as used.
> 
> Not yet for upstream until all dependencies are merged!
> 
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

Reviewed-by: Peter Rosin <peda@axentia.se>

Cheers,
Peter


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

* Re: [PATCH v8 1/3] i2c: core: improve return value handling of i2c_new_device and i2c_new_dummy
  2019-05-16 21:13 ` [PATCH v8 1/3] i2c: core: improve return value handling of i2c_new_device and i2c_new_dummy Wolfram Sang
  2019-05-17  7:16   ` Peter Rosin
@ 2019-05-17  8:02   ` Kieran Bingham
  2019-05-17  8:56   ` Bartosz Golaszewski
  2019-05-17 17:35   ` Wolfram Sang
  3 siblings, 0 replies; 16+ messages in thread
From: Kieran Bingham @ 2019-05-17  8:02 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c
  Cc: linux-renesas-soc, Heiner Kallweit, Bartosz Golaszewski, Peter Rosin

Hi Wolfram,

On 16/05/2019 22:13, Wolfram Sang wrote:
> From: Heiner Kallweit <hkallweit1@gmail.com>
> 
> Currently i2c_new_device and i2c_new_dummy return just NULL in error
> case although they have more error details internally. Therefore move
> the functionality into new functions returning detailed errors and
> add wrappers for compatibility with the current API.
> 
> This allows to use these functions with detailed error codes within
> the i2c core or for API extensions.
> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> [wsa: rename new functions and fix minor kdoc issues]
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>


I like the new naming a lot more this time :-)

Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>

> ---
>  drivers/i2c/i2c-core-base.c | 74 ++++++++++++++++++++++++++++++-------
>  1 file changed, 61 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
> index 9732a81bb7dd..9c38dde73366 100644
> --- a/drivers/i2c/i2c-core-base.c
> +++ b/drivers/i2c/i2c-core-base.c
> @@ -714,7 +714,7 @@ static int i2c_dev_irq_from_resources(const struct resource *resources,
>  }
>  
>  /**
> - * i2c_new_device - instantiate an i2c device
> + * i2c_new_client_device - instantiate an i2c device
>   * @adap: the adapter managing the device
>   * @info: describes one I2C device; bus_num is ignored
>   * Context: can sleep
> @@ -727,17 +727,17 @@ static int i2c_dev_irq_from_resources(const struct resource *resources,
>   * before any i2c_adapter could exist.
>   *
>   * This returns the new i2c client, which may be saved for later use with
> - * i2c_unregister_device(); or NULL to indicate an error.
> + * i2c_unregister_device(); or an ERR_PTR to describe the error.
>   */
> -struct i2c_client *
> -i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
> +static struct i2c_client *
> +i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
>  {
>  	struct i2c_client	*client;
>  	int			status;
>  
>  	client = kzalloc(sizeof *client, GFP_KERNEL);
>  	if (!client)
> -		return NULL;
> +		return ERR_PTR(-ENOMEM);
>  
>  	client->adapter = adap;
>  
> @@ -803,7 +803,31 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
>  		client->name, client->addr, status);
>  out_err_silent:
>  	kfree(client);
> -	return NULL;
> +	return ERR_PTR(status);
> +}
> +EXPORT_SYMBOL_GPL(i2c_new_client_device);
> +
> +/**
> + * i2c_new_device - instantiate an i2c device
> + * @adap: the adapter managing the device
> + * @info: describes one I2C device; bus_num is ignored
> + * Context: can sleep
> + *
> + * This deprecated function has the same functionality as
> + * @i2c_new_client_device, it just returns NULL instead of an ERR_PTR in case of
> + * an error for compatibility with current I2C API. It will be removed once all
> + * users are converted.
> + *
> + * This returns the new i2c client, which may be saved for later use with
> + * i2c_unregister_device(); or NULL to indicate an error.
> + */
> +struct i2c_client *
> +i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
> +{
> +	struct i2c_client *ret;
> +
> +	ret = i2c_new_client_device(adap, info);
> +	return IS_ERR(ret) ? NULL : ret;
>  }
>  EXPORT_SYMBOL_GPL(i2c_new_device);
>  
> @@ -854,7 +878,7 @@ static struct i2c_driver dummy_driver = {
>  };
>  
>  /**
> - * i2c_new_dummy - return a new i2c device bound to a dummy driver
> + * i2c_new_dummy_device - return a new i2c device bound to a dummy driver
>   * @adapter: the adapter managing the device
>   * @address: seven bit address to be used
>   * Context: can sleep
> @@ -869,15 +893,39 @@ static struct i2c_driver dummy_driver = {
>   * different driver.
>   *
>   * This returns the new i2c client, which should be saved for later use with
> - * i2c_unregister_device(); or NULL to indicate an error.
> + * i2c_unregister_device(); or an ERR_PTR to describe the error.
>   */
> -struct i2c_client *i2c_new_dummy(struct i2c_adapter *adapter, u16 address)
> +static struct i2c_client *
> +i2c_new_dummy_device(struct i2c_adapter *adapter, u16 address)
>  {
>  	struct i2c_board_info info = {
>  		I2C_BOARD_INFO("dummy", address),

I wonder if in the future we could find an easy way to propagate a
device name into this 'dummy' info field for dummy devices.

Then it would be much easier to identify all of the rogue dummys that
appear in my system (ok, not rogue - I've put them there - but I've put
in sooo many :D)

Anyway - just musings - not a topic for this patch.

>  	};
>  
> -	return i2c_new_device(adapter, &info);
> +	return i2c_new_client_device(adapter, &info);
> +}
> +EXPORT_SYMBOL_GPL(i2c_new_dummy_device);
> +
> +/**
> + * i2c_new_dummy - return a new i2c device bound to a dummy driver
> + * @adapter: the adapter managing the device
> + * @address: seven bit address to be used
> + * Context: can sleep
> + *
> + * This deprecated function has the same functionality as @i2c_new_dummy_device,
> + * it just returns NULL instead of an ERR_PTR in case of an error for
> + * compatibility with current I2C API. It will be removed once all users are
> + * converted.
> + *
> + * This returns the new i2c client, which should be saved for later use with
> + * i2c_unregister_device(); or NULL to indicate an error.
> + */
> +struct i2c_client *i2c_new_dummy(struct i2c_adapter *adapter, u16 address)
> +{
> +	struct i2c_client *ret;
> +
> +	ret = i2c_new_dummy_device(adapter, address);
> +	return IS_ERR(ret) ? NULL : ret;
>  }
>  EXPORT_SYMBOL_GPL(i2c_new_dummy);
>  
> @@ -1000,9 +1048,9 @@ i2c_sysfs_new_device(struct device *dev, struct device_attribute *attr,
>  		info.flags |= I2C_CLIENT_SLAVE;
>  	}
>  
> -	client = i2c_new_device(adap, &info);
> -	if (!client)
> -		return -EINVAL;
> +	client = i2c_new_client_device(adap, &info);
> +	if (IS_ERR(client))
> +		return PTR_ERR(client);
>  
>  	/* Keep track of the added device */
>  	mutex_lock(&adap->userspace_clients_lock);
> 


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

* Re: [PATCH v8 2/3] i2c: core: add device-managed version of i2c_new_dummy
  2019-05-16 21:13 ` [PATCH v8 2/3] i2c: core: add device-managed version of i2c_new_dummy Wolfram Sang
  2019-05-17  7:17   ` Peter Rosin
@ 2019-05-17  8:21   ` Kieran Bingham
  2019-05-17  8:57   ` Bartosz Golaszewski
  2019-05-17 17:35   ` Wolfram Sang
  3 siblings, 0 replies; 16+ messages in thread
From: Kieran Bingham @ 2019-05-17  8:21 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c
  Cc: linux-renesas-soc, Heiner Kallweit, Bartosz Golaszewski, Peter Rosin

Hi Wolfram,

On 16/05/2019 22:13, Wolfram Sang wrote:
> From: Heiner Kallweit <hkallweit1@gmail.com>
> 
> i2c_new_dummy is typically called from the probe function of the
> driver for the primary i2c client. It requires calls to
> i2c_unregister_device in the error path of the probe function and
> in the remove function.
> This can be simplified by introducing a device-managed version.
> 
> Note the changed error case return value type: i2c_new_dummy returns
> NULL whilst devm_i2c_new_dummy_device returns an ERR_PTR.
> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> [wsa: rename new functions and fix minor kdoc issues]
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

This looks good to me.

Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>

> ---
>  Documentation/driver-model/devres.txt |  3 ++
>  drivers/i2c/i2c-core-base.c           | 44 +++++++++++++++++++++++++++
>  include/linux/i2c.h                   |  3 ++
>  3 files changed, 50 insertions(+)
> 
> diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt
> index 99994a461359..69c7fa7f616c 100644
> --- a/Documentation/driver-model/devres.txt
> +++ b/Documentation/driver-model/devres.txt
> @@ -271,6 +271,9 @@ GPIO
>    devm_gpio_request_one()
>    devm_gpio_free()
>  
> +I2C
> +  devm_i2c_new_dummy_device()
> +
>  IIO
>    devm_iio_device_alloc()
>    devm_iio_device_free()
> diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
> index 9c38dde73366..d389d4fb0623 100644
> --- a/drivers/i2c/i2c-core-base.c
> +++ b/drivers/i2c/i2c-core-base.c
> @@ -929,6 +929,50 @@ struct i2c_client *i2c_new_dummy(struct i2c_adapter *adapter, u16 address)
>  }
>  EXPORT_SYMBOL_GPL(i2c_new_dummy);
>  
> +struct i2c_dummy_devres {
> +	struct i2c_client *client;
> +};
> +
> +static void devm_i2c_release_dummy(struct device *dev, void *res)
> +{
> +	struct i2c_dummy_devres *this = res;
> +
> +	i2c_unregister_device(this->client);
> +}
> +
> +/**
> + * devm_i2c_new_dummy_device - return a new i2c device bound to a dummy driver
> + * @dev: device the managed resource is bound to
> + * @adapter: the adapter managing the device
> + * @address: seven bit address to be used
> + * Context: can sleep
> + *
> + * This is the device-managed version of @i2c_new_dummy_device. It returns the
> + * new i2c client or an ERR_PTR in case of an error.
> + */
> +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);
> +
> +	client = i2c_new_dummy_device(adapter, address);
> +	if (IS_ERR(client)) {
> +		devres_free(dr);
> +	} else {
> +		dr->client = client;
> +		devres_add(dev, dr);
> +	}
> +
> +	return client;
> +}
> +EXPORT_SYMBOL_GPL(devm_i2c_new_dummy_device);
> +
>  /**
>   * i2c_new_secondary_device - Helper to get the instantiated secondary address
>   * and create the associated device
> diff --git a/include/linux/i2c.h b/include/linux/i2c.h
> index be27062f8ed1..6c4db54714f6 100644
> --- a/include/linux/i2c.h
> +++ b/include/linux/i2c.h
> @@ -469,6 +469,9 @@ extern int i2c_probe_func_quick_read(struct i2c_adapter *, unsigned short addr);
>  extern struct i2c_client *
>  i2c_new_dummy(struct i2c_adapter *adap, u16 address);
>  
> +extern struct i2c_client *
> +devm_i2c_new_dummy_device(struct device *dev, struct i2c_adapter *adap, u16 address);
> +
>  extern struct i2c_client *
>  i2c_new_secondary_device(struct i2c_client *client,
>  				const char *name,
> 


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

* Re: [PATCH v8 1/3] i2c: core: improve return value handling of i2c_new_device and i2c_new_dummy
  2019-05-16 21:13 ` [PATCH v8 1/3] i2c: core: improve return value handling of i2c_new_device and i2c_new_dummy Wolfram Sang
  2019-05-17  7:16   ` Peter Rosin
  2019-05-17  8:02   ` Kieran Bingham
@ 2019-05-17  8:56   ` Bartosz Golaszewski
  2019-05-17 17:35   ` Wolfram Sang
  3 siblings, 0 replies; 16+ messages in thread
From: Bartosz Golaszewski @ 2019-05-17  8:56 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: linux-i2c, Linux-Renesas, Heiner Kallweit, Kieran Bingham, Peter Rosin

czw., 16 maj 2019 o 23:13 Wolfram Sang
<wsa+renesas@sang-engineering.com> napisał(a):
>
> From: Heiner Kallweit <hkallweit1@gmail.com>
>
> Currently i2c_new_device and i2c_new_dummy return just NULL in error
> case although they have more error details internally. Therefore move
> the functionality into new functions returning detailed errors and
> add wrappers for compatibility with the current API.
>
> This allows to use these functions with detailed error codes within
> the i2c core or for API extensions.
>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> [wsa: rename new functions and fix minor kdoc issues]
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> ---
>  drivers/i2c/i2c-core-base.c | 74 ++++++++++++++++++++++++++++++-------
>  1 file changed, 61 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
> index 9732a81bb7dd..9c38dde73366 100644
> --- a/drivers/i2c/i2c-core-base.c
> +++ b/drivers/i2c/i2c-core-base.c
> @@ -714,7 +714,7 @@ static int i2c_dev_irq_from_resources(const struct resource *resources,
>  }
>
>  /**
> - * i2c_new_device - instantiate an i2c device
> + * i2c_new_client_device - instantiate an i2c device
>   * @adap: the adapter managing the device
>   * @info: describes one I2C device; bus_num is ignored
>   * Context: can sleep
> @@ -727,17 +727,17 @@ static int i2c_dev_irq_from_resources(const struct resource *resources,
>   * before any i2c_adapter could exist.
>   *
>   * This returns the new i2c client, which may be saved for later use with
> - * i2c_unregister_device(); or NULL to indicate an error.
> + * i2c_unregister_device(); or an ERR_PTR to describe the error.
>   */
> -struct i2c_client *
> -i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
> +static struct i2c_client *
> +i2c_new_client_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
>  {
>         struct i2c_client       *client;
>         int                     status;
>
>         client = kzalloc(sizeof *client, GFP_KERNEL);
>         if (!client)
> -               return NULL;
> +               return ERR_PTR(-ENOMEM);
>
>         client->adapter = adap;
>
> @@ -803,7 +803,31 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
>                 client->name, client->addr, status);
>  out_err_silent:
>         kfree(client);
> -       return NULL;
> +       return ERR_PTR(status);
> +}
> +EXPORT_SYMBOL_GPL(i2c_new_client_device);
> +
> +/**
> + * i2c_new_device - instantiate an i2c device
> + * @adap: the adapter managing the device
> + * @info: describes one I2C device; bus_num is ignored
> + * Context: can sleep
> + *
> + * This deprecated function has the same functionality as
> + * @i2c_new_client_device, it just returns NULL instead of an ERR_PTR in case of
> + * an error for compatibility with current I2C API. It will be removed once all
> + * users are converted.
> + *
> + * This returns the new i2c client, which may be saved for later use with
> + * i2c_unregister_device(); or NULL to indicate an error.
> + */
> +struct i2c_client *
> +i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
> +{
> +       struct i2c_client *ret;
> +
> +       ret = i2c_new_client_device(adap, info);
> +       return IS_ERR(ret) ? NULL : ret;
>  }
>  EXPORT_SYMBOL_GPL(i2c_new_device);
>
> @@ -854,7 +878,7 @@ static struct i2c_driver dummy_driver = {
>  };
>
>  /**
> - * i2c_new_dummy - return a new i2c device bound to a dummy driver
> + * i2c_new_dummy_device - return a new i2c device bound to a dummy driver
>   * @adapter: the adapter managing the device
>   * @address: seven bit address to be used
>   * Context: can sleep
> @@ -869,15 +893,39 @@ static struct i2c_driver dummy_driver = {
>   * different driver.
>   *
>   * This returns the new i2c client, which should be saved for later use with
> - * i2c_unregister_device(); or NULL to indicate an error.
> + * i2c_unregister_device(); or an ERR_PTR to describe the error.
>   */
> -struct i2c_client *i2c_new_dummy(struct i2c_adapter *adapter, u16 address)
> +static struct i2c_client *
> +i2c_new_dummy_device(struct i2c_adapter *adapter, u16 address)
>  {
>         struct i2c_board_info info = {
>                 I2C_BOARD_INFO("dummy", address),
>         };
>
> -       return i2c_new_device(adapter, &info);
> +       return i2c_new_client_device(adapter, &info);
> +}
> +EXPORT_SYMBOL_GPL(i2c_new_dummy_device);
> +
> +/**
> + * i2c_new_dummy - return a new i2c device bound to a dummy driver
> + * @adapter: the adapter managing the device
> + * @address: seven bit address to be used
> + * Context: can sleep
> + *
> + * This deprecated function has the same functionality as @i2c_new_dummy_device,
> + * it just returns NULL instead of an ERR_PTR in case of an error for
> + * compatibility with current I2C API. It will be removed once all users are
> + * converted.
> + *
> + * This returns the new i2c client, which should be saved for later use with
> + * i2c_unregister_device(); or NULL to indicate an error.
> + */
> +struct i2c_client *i2c_new_dummy(struct i2c_adapter *adapter, u16 address)
> +{
> +       struct i2c_client *ret;
> +
> +       ret = i2c_new_dummy_device(adapter, address);
> +       return IS_ERR(ret) ? NULL : ret;
>  }
>  EXPORT_SYMBOL_GPL(i2c_new_dummy);
>
> @@ -1000,9 +1048,9 @@ i2c_sysfs_new_device(struct device *dev, struct device_attribute *attr,
>                 info.flags |= I2C_CLIENT_SLAVE;
>         }
>
> -       client = i2c_new_device(adap, &info);
> -       if (!client)
> -               return -EINVAL;
> +       client = i2c_new_client_device(adap, &info);
> +       if (IS_ERR(client))
> +               return PTR_ERR(client);
>
>         /* Keep track of the added device */
>         mutex_lock(&adap->userspace_clients_lock);
> --
> 2.19.1
>

Reviewed-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>

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

* Re: [PATCH v8 2/3] i2c: core: add device-managed version of i2c_new_dummy
  2019-05-16 21:13 ` [PATCH v8 2/3] i2c: core: add device-managed version of i2c_new_dummy Wolfram Sang
  2019-05-17  7:17   ` Peter Rosin
  2019-05-17  8:21   ` Kieran Bingham
@ 2019-05-17  8:57   ` Bartosz Golaszewski
  2019-05-17 17:35   ` Wolfram Sang
  3 siblings, 0 replies; 16+ messages in thread
From: Bartosz Golaszewski @ 2019-05-17  8:57 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: linux-i2c, Linux-Renesas, Heiner Kallweit, Kieran Bingham, Peter Rosin

czw., 16 maj 2019 o 23:13 Wolfram Sang
<wsa+renesas@sang-engineering.com> napisał(a):
>
> From: Heiner Kallweit <hkallweit1@gmail.com>
>
> i2c_new_dummy is typically called from the probe function of the
> driver for the primary i2c client. It requires calls to
> i2c_unregister_device in the error path of the probe function and
> in the remove function.
> This can be simplified by introducing a device-managed version.
>
> Note the changed error case return value type: i2c_new_dummy returns
> NULL whilst devm_i2c_new_dummy_device returns an ERR_PTR.
>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> [wsa: rename new functions and fix minor kdoc issues]
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> ---
>  Documentation/driver-model/devres.txt |  3 ++
>  drivers/i2c/i2c-core-base.c           | 44 +++++++++++++++++++++++++++
>  include/linux/i2c.h                   |  3 ++
>  3 files changed, 50 insertions(+)
>
> diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt
> index 99994a461359..69c7fa7f616c 100644
> --- a/Documentation/driver-model/devres.txt
> +++ b/Documentation/driver-model/devres.txt
> @@ -271,6 +271,9 @@ GPIO
>    devm_gpio_request_one()
>    devm_gpio_free()
>
> +I2C
> +  devm_i2c_new_dummy_device()
> +
>  IIO
>    devm_iio_device_alloc()
>    devm_iio_device_free()
> diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
> index 9c38dde73366..d389d4fb0623 100644
> --- a/drivers/i2c/i2c-core-base.c
> +++ b/drivers/i2c/i2c-core-base.c
> @@ -929,6 +929,50 @@ struct i2c_client *i2c_new_dummy(struct i2c_adapter *adapter, u16 address)
>  }
>  EXPORT_SYMBOL_GPL(i2c_new_dummy);
>
> +struct i2c_dummy_devres {
> +       struct i2c_client *client;
> +};
> +
> +static void devm_i2c_release_dummy(struct device *dev, void *res)
> +{
> +       struct i2c_dummy_devres *this = res;
> +
> +       i2c_unregister_device(this->client);
> +}
> +
> +/**
> + * devm_i2c_new_dummy_device - return a new i2c device bound to a dummy driver
> + * @dev: device the managed resource is bound to
> + * @adapter: the adapter managing the device
> + * @address: seven bit address to be used
> + * Context: can sleep
> + *
> + * This is the device-managed version of @i2c_new_dummy_device. It returns the
> + * new i2c client or an ERR_PTR in case of an error.
> + */
> +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);
> +
> +       client = i2c_new_dummy_device(adapter, address);
> +       if (IS_ERR(client)) {
> +               devres_free(dr);
> +       } else {
> +               dr->client = client;
> +               devres_add(dev, dr);
> +       }
> +
> +       return client;
> +}
> +EXPORT_SYMBOL_GPL(devm_i2c_new_dummy_device);
> +
>  /**
>   * i2c_new_secondary_device - Helper to get the instantiated secondary address
>   * and create the associated device
> diff --git a/include/linux/i2c.h b/include/linux/i2c.h
> index be27062f8ed1..6c4db54714f6 100644
> --- a/include/linux/i2c.h
> +++ b/include/linux/i2c.h
> @@ -469,6 +469,9 @@ extern int i2c_probe_func_quick_read(struct i2c_adapter *, unsigned short addr);
>  extern struct i2c_client *
>  i2c_new_dummy(struct i2c_adapter *adap, u16 address);
>
> +extern struct i2c_client *
> +devm_i2c_new_dummy_device(struct device *dev, struct i2c_adapter *adap, u16 address);
> +
>  extern struct i2c_client *
>  i2c_new_secondary_device(struct i2c_client *client,
>                                 const char *name,
> --
> 2.19.1
>

Reviewed-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>

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

* Re: [PATCH v8 3/3] mfd: da9063: occupy second I2C address, too
  2019-05-16 21:13 ` [PATCH v8 3/3] mfd: da9063: occupy second I2C address, too Wolfram Sang
  2019-05-17  7:17   ` Peter Rosin
@ 2019-05-17  8:57   ` Bartosz Golaszewski
  2019-05-17 14:56   ` Kieran Bingham
  2 siblings, 0 replies; 16+ messages in thread
From: Bartosz Golaszewski @ 2019-05-17  8:57 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: linux-i2c, Linux-Renesas, Heiner Kallweit, Kieran Bingham, Peter Rosin

czw., 16 maj 2019 o 23:13 Wolfram Sang
<wsa+renesas@sang-engineering.com> napisał(a):
>
> Even though we don't use it yet, we should mark the second I2C address
> this device is listening to as used.
>
> Not yet for upstream until all dependencies are merged!
>
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> ---
>  drivers/mfd/da9063-i2c.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/mfd/da9063-i2c.c b/drivers/mfd/da9063-i2c.c
> index 455de74c0dd2..2133b09f6e7a 100644
> --- a/drivers/mfd/da9063-i2c.c
> +++ b/drivers/mfd/da9063-i2c.c
> @@ -221,6 +221,8 @@ static int da9063_i2c_probe(struct i2c_client *i2c,
>                 return ret;
>         }
>
> +       devm_i2c_new_dummy_device(&i2c->dev, i2c->adapter, i2c->addr + 1);
> +
>         return da9063_device_init(da9063, i2c->irq);
>  }
>
> --
> 2.19.1
>

Reviewed-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>

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

* Re: [PATCH v8 3/3] mfd: da9063: occupy second I2C address, too
  2019-05-16 21:13 ` [PATCH v8 3/3] mfd: da9063: occupy second I2C address, too Wolfram Sang
  2019-05-17  7:17   ` Peter Rosin
  2019-05-17  8:57   ` Bartosz Golaszewski
@ 2019-05-17 14:56   ` Kieran Bingham
  2 siblings, 0 replies; 16+ messages in thread
From: Kieran Bingham @ 2019-05-17 14:56 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c
  Cc: linux-renesas-soc, Heiner Kallweit, Bartosz Golaszewski, Peter Rosin

Hi Wolfram,

On 16/05/2019 22:13, Wolfram Sang wrote:
> Even though we don't use it yet, we should mark the second I2C address
> this device is listening to as used.
> 
> Not yet for upstream until all dependencies are merged!
> 
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

As I reviewed the other two anyway, it seems silly not to add this here :D

Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>


> ---
>  drivers/mfd/da9063-i2c.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/mfd/da9063-i2c.c b/drivers/mfd/da9063-i2c.c
> index 455de74c0dd2..2133b09f6e7a 100644
> --- a/drivers/mfd/da9063-i2c.c
> +++ b/drivers/mfd/da9063-i2c.c
> @@ -221,6 +221,8 @@ static int da9063_i2c_probe(struct i2c_client *i2c,
>  		return ret;
>  	}
>  
> +	devm_i2c_new_dummy_device(&i2c->dev, i2c->adapter, i2c->addr + 1);
> +
>  	return da9063_device_init(da9063, i2c->irq);
>  }
>  
> 


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

* Re: [PATCH v8 1/3] i2c: core: improve return value handling of i2c_new_device and i2c_new_dummy
  2019-05-17  7:16   ` Peter Rosin
@ 2019-05-17 17:35     ` Wolfram Sang
  0 siblings, 0 replies; 16+ messages in thread
From: Wolfram Sang @ 2019-05-17 17:35 UTC (permalink / raw)
  To: Peter Rosin
  Cc: Wolfram Sang, linux-i2c, linux-renesas-soc, Heiner Kallweit,
	Bartosz Golaszewski, Kieran Bingham

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


> The only nit I can find is that you could perhaps sweep the patches
> with sed 's/i2c /I2C /'. But that is indeed a nit, so if you're in
> a hurry...

Valid point. I'd like to fix it as a seperate patch, though. One reason
is that it is needed in far more places in this file, too. The main
reason is that I don't want to introduce some stupid last minute typo
after all these reviews.

> Reviewed-by: Peter Rosin <peda@axentia.se>

Thanks!


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

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

* Re: [PATCH v8 1/3] i2c: core: improve return value handling of i2c_new_device and i2c_new_dummy
  2019-05-16 21:13 ` [PATCH v8 1/3] i2c: core: improve return value handling of i2c_new_device and i2c_new_dummy Wolfram Sang
                     ` (2 preceding siblings ...)
  2019-05-17  8:56   ` Bartosz Golaszewski
@ 2019-05-17 17:35   ` Wolfram Sang
  3 siblings, 0 replies; 16+ messages in thread
From: Wolfram Sang @ 2019-05-17 17:35 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: linux-i2c, linux-renesas-soc, Heiner Kallweit,
	Bartosz Golaszewski, Kieran Bingham, Peter Rosin

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

On Thu, May 16, 2019 at 11:13:08PM +0200, Wolfram Sang wrote:
> From: Heiner Kallweit <hkallweit1@gmail.com>
> 
> Currently i2c_new_device and i2c_new_dummy return just NULL in error
> case although they have more error details internally. Therefore move
> the functionality into new functions returning detailed errors and
> add wrappers for compatibility with the current API.
> 
> This allows to use these functions with detailed error codes within
> the i2c core or for API extensions.
> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> [wsa: rename new functions and fix minor kdoc issues]
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

Applied to for-current, thanks everyone!


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

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

* Re: [PATCH v8 2/3] i2c: core: add device-managed version of i2c_new_dummy
  2019-05-16 21:13 ` [PATCH v8 2/3] i2c: core: add device-managed version of i2c_new_dummy Wolfram Sang
                     ` (2 preceding siblings ...)
  2019-05-17  8:57   ` Bartosz Golaszewski
@ 2019-05-17 17:35   ` Wolfram Sang
  3 siblings, 0 replies; 16+ messages in thread
From: Wolfram Sang @ 2019-05-17 17:35 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: linux-i2c, linux-renesas-soc, Heiner Kallweit,
	Bartosz Golaszewski, Kieran Bingham, Peter Rosin

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

On Thu, May 16, 2019 at 11:13:09PM +0200, Wolfram Sang wrote:
> From: Heiner Kallweit <hkallweit1@gmail.com>
> 
> i2c_new_dummy is typically called from the probe function of the
> driver for the primary i2c client. It requires calls to
> i2c_unregister_device in the error path of the probe function and
> in the remove function.
> This can be simplified by introducing a device-managed version.
> 
> Note the changed error case return value type: i2c_new_dummy returns
> NULL whilst devm_i2c_new_dummy_device returns an ERR_PTR.
> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> [wsa: rename new functions and fix minor kdoc issues]
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

Applied to for-current, thanks everyone!


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

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

end of thread, other threads:[~2019-05-17 17:35 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-16 21:13 [PATCH v8 0/3] i2c: improve i2c_new_{device|dummy} Wolfram Sang
2019-05-16 21:13 ` [PATCH v8 1/3] i2c: core: improve return value handling of i2c_new_device and i2c_new_dummy Wolfram Sang
2019-05-17  7:16   ` Peter Rosin
2019-05-17 17:35     ` Wolfram Sang
2019-05-17  8:02   ` Kieran Bingham
2019-05-17  8:56   ` Bartosz Golaszewski
2019-05-17 17:35   ` Wolfram Sang
2019-05-16 21:13 ` [PATCH v8 2/3] i2c: core: add device-managed version of i2c_new_dummy Wolfram Sang
2019-05-17  7:17   ` Peter Rosin
2019-05-17  8:21   ` Kieran Bingham
2019-05-17  8:57   ` Bartosz Golaszewski
2019-05-17 17:35   ` Wolfram Sang
2019-05-16 21:13 ` [PATCH v8 3/3] mfd: da9063: occupy second I2C address, too Wolfram Sang
2019-05-17  7:17   ` Peter Rosin
2019-05-17  8:57   ` Bartosz Golaszewski
2019-05-17 14:56   ` Kieran Bingham

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).