linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] i2c: core: Use DEVICE_ATTR_*() helper macros
@ 2019-11-13 15:23 Geert Uytterhoeven
  2019-11-26 12:57 ` Kieran Bingham
  2019-12-17 15:58 ` Wolfram Sang
  0 siblings, 2 replies; 3+ messages in thread
From: Geert Uytterhoeven @ 2019-11-13 15:23 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linux-i2c, linux-kernel, Geert Uytterhoeven

Convert the i2c core sysfs attributes from DEVICE_ATTR() to
DEVICE_ATTR_*(), to reduce boilerplate.
This requires renaming some functions.

Although no suitable macro exists for the delete_device attribute,
rename i2c_sysfs_delete_device() to delete_device_store() for
consistency.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Luca Ceresoli <luca@lucaceresoli.net>
---
v2:
  - s/DEVICE_ATTR_RW/DEVICE_ATTR_*/ in summary and description,
  - Add Reviewed-by.
---
 drivers/i2c/i2c-core-base.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 6a5183cffdfc3e82..c87bf5bcab3f1349 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -449,15 +449,15 @@ static void i2c_client_dev_release(struct device *dev)
 }
 
 static ssize_t
-show_name(struct device *dev, struct device_attribute *attr, char *buf)
+name_show(struct device *dev, struct device_attribute *attr, char *buf)
 {
 	return sprintf(buf, "%s\n", dev->type == &i2c_client_type ?
 		       to_i2c_client(dev)->name : to_i2c_adapter(dev)->name);
 }
-static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
+static DEVICE_ATTR_RO(name);
 
 static ssize_t
-show_modalias(struct device *dev, struct device_attribute *attr, char *buf)
+modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
 {
 	struct i2c_client *client = to_i2c_client(dev);
 	int len;
@@ -472,7 +472,7 @@ show_modalias(struct device *dev, struct device_attribute *attr, char *buf)
 
 	return sprintf(buf, "%s%s\n", I2C_MODULE_PREFIX, client->name);
 }
-static DEVICE_ATTR(modalias, S_IRUGO, show_modalias, NULL);
+static DEVICE_ATTR_RO(modalias);
 
 static struct attribute *i2c_dev_attrs[] = {
 	&dev_attr_name.attr,
@@ -1039,8 +1039,8 @@ EXPORT_SYMBOL_GPL(i2c_adapter_depth);
  * the user to provide incorrect parameters.
  */
 static ssize_t
-i2c_sysfs_new_device(struct device *dev, struct device_attribute *attr,
-		     const char *buf, size_t count)
+new_device_store(struct device *dev, struct device_attribute *attr,
+		 const char *buf, size_t count)
 {
 	struct i2c_adapter *adap = to_i2c_adapter(dev);
 	struct i2c_board_info info;
@@ -1095,7 +1095,7 @@ i2c_sysfs_new_device(struct device *dev, struct device_attribute *attr,
 
 	return count;
 }
-static DEVICE_ATTR(new_device, S_IWUSR, NULL, i2c_sysfs_new_device);
+static DEVICE_ATTR_WO(new_device);
 
 /*
  * And of course let the users delete the devices they instantiated, if
@@ -1107,8 +1107,8 @@ static DEVICE_ATTR(new_device, S_IWUSR, NULL, i2c_sysfs_new_device);
  * the user to delete the wrong device.
  */
 static ssize_t
-i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr,
-			const char *buf, size_t count)
+delete_device_store(struct device *dev, struct device_attribute *attr,
+		    const char *buf, size_t count)
 {
 	struct i2c_adapter *adap = to_i2c_adapter(dev);
 	struct i2c_client *client, *next;
@@ -1151,7 +1151,7 @@ i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr,
 	return res;
 }
 static DEVICE_ATTR_IGNORE_LOCKDEP(delete_device, S_IWUSR, NULL,
-				   i2c_sysfs_delete_device);
+				  delete_device_store);
 
 static struct attribute *i2c_adapter_attrs[] = {
 	&dev_attr_name.attr,
-- 
2.17.1


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

* Re: [PATCH v2] i2c: core: Use DEVICE_ATTR_*() helper macros
  2019-11-13 15:23 [PATCH v2] i2c: core: Use DEVICE_ATTR_*() helper macros Geert Uytterhoeven
@ 2019-11-26 12:57 ` Kieran Bingham
  2019-12-17 15:58 ` Wolfram Sang
  1 sibling, 0 replies; 3+ messages in thread
From: Kieran Bingham @ 2019-11-26 12:57 UTC (permalink / raw)
  To: Geert Uytterhoeven, Wolfram Sang; +Cc: linux-i2c, linux-kernel

Hi Geert,

On 13/11/2019 15:23, Geert Uytterhoeven wrote:
> Convert the i2c core sysfs attributes from DEVICE_ATTR() to
> DEVICE_ATTR_*(), to reduce boilerplate.
> This requires renaming some functions.

Seems a nice cleanup.


> Although no suitable macro exists for the delete_device attribute,
> rename i2c_sysfs_delete_device() to delete_device_store() for
> consistency.
> 
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Reviewed-by: Luca Ceresoli <luca@lucaceresoli.net>

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


> ---
> v2:
>   - s/DEVICE_ATTR_RW/DEVICE_ATTR_*/ in summary and description,
>   - Add Reviewed-by.
> ---
>  drivers/i2c/i2c-core-base.c | 20 ++++++++++----------
>  1 file changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
> index 6a5183cffdfc3e82..c87bf5bcab3f1349 100644
> --- a/drivers/i2c/i2c-core-base.c
> +++ b/drivers/i2c/i2c-core-base.c
> @@ -449,15 +449,15 @@ static void i2c_client_dev_release(struct device *dev)
>  }
>  
>  static ssize_t
> -show_name(struct device *dev, struct device_attribute *attr, char *buf)
> +name_show(struct device *dev, struct device_attribute *attr, char *buf)
>  {
>  	return sprintf(buf, "%s\n", dev->type == &i2c_client_type ?
>  		       to_i2c_client(dev)->name : to_i2c_adapter(dev)->name);
>  }
> -static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
> +static DEVICE_ATTR_RO(name);
>  
>  static ssize_t
> -show_modalias(struct device *dev, struct device_attribute *attr, char *buf)
> +modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
>  {
>  	struct i2c_client *client = to_i2c_client(dev);
>  	int len;
> @@ -472,7 +472,7 @@ show_modalias(struct device *dev, struct device_attribute *attr, char *buf)
>  
>  	return sprintf(buf, "%s%s\n", I2C_MODULE_PREFIX, client->name);
>  }
> -static DEVICE_ATTR(modalias, S_IRUGO, show_modalias, NULL);
> +static DEVICE_ATTR_RO(modalias);
>  
>  static struct attribute *i2c_dev_attrs[] = {
>  	&dev_attr_name.attr,
> @@ -1039,8 +1039,8 @@ EXPORT_SYMBOL_GPL(i2c_adapter_depth);
>   * the user to provide incorrect parameters.
>   */
>  static ssize_t
> -i2c_sysfs_new_device(struct device *dev, struct device_attribute *attr,
> -		     const char *buf, size_t count)
> +new_device_store(struct device *dev, struct device_attribute *attr,
> +		 const char *buf, size_t count)
>  {
>  	struct i2c_adapter *adap = to_i2c_adapter(dev);
>  	struct i2c_board_info info;
> @@ -1095,7 +1095,7 @@ i2c_sysfs_new_device(struct device *dev, struct device_attribute *attr,
>  
>  	return count;
>  }
> -static DEVICE_ATTR(new_device, S_IWUSR, NULL, i2c_sysfs_new_device);
> +static DEVICE_ATTR_WO(new_device);
>  
>  /*
>   * And of course let the users delete the devices they instantiated, if
> @@ -1107,8 +1107,8 @@ static DEVICE_ATTR(new_device, S_IWUSR, NULL, i2c_sysfs_new_device);
>   * the user to delete the wrong device.
>   */
>  static ssize_t
> -i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr,
> -			const char *buf, size_t count)
> +delete_device_store(struct device *dev, struct device_attribute *attr,
> +		    const char *buf, size_t count)
>  {
>  	struct i2c_adapter *adap = to_i2c_adapter(dev);
>  	struct i2c_client *client, *next;
> @@ -1151,7 +1151,7 @@ i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr,
>  	return res;
>  }
>  static DEVICE_ATTR_IGNORE_LOCKDEP(delete_device, S_IWUSR, NULL,
> -				   i2c_sysfs_delete_device);
> +				  delete_device_store);
>  
>  static struct attribute *i2c_adapter_attrs[] = {
>  	&dev_attr_name.attr,
> 


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

* Re: [PATCH v2] i2c: core: Use DEVICE_ATTR_*() helper macros
  2019-11-13 15:23 [PATCH v2] i2c: core: Use DEVICE_ATTR_*() helper macros Geert Uytterhoeven
  2019-11-26 12:57 ` Kieran Bingham
@ 2019-12-17 15:58 ` Wolfram Sang
  1 sibling, 0 replies; 3+ messages in thread
From: Wolfram Sang @ 2019-12-17 15:58 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: linux-i2c, linux-kernel

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

On Wed, Nov 13, 2019 at 04:23:06PM +0100, Geert Uytterhoeven wrote:
> Convert the i2c core sysfs attributes from DEVICE_ATTR() to
> DEVICE_ATTR_*(), to reduce boilerplate.
> This requires renaming some functions.
> 
> Although no suitable macro exists for the delete_device attribute,
> rename i2c_sysfs_delete_device() to delete_device_store() for
> consistency.
> 
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Reviewed-by: Luca Ceresoli <luca@lucaceresoli.net>

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:[~2019-12-17 15:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-13 15:23 [PATCH v2] i2c: core: Use DEVICE_ATTR_*() helper macros Geert Uytterhoeven
2019-11-26 12:57 ` Kieran Bingham
2019-12-17 15:58 ` Wolfram Sang

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).