linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/2] i2c: dev: Define pr_fmt() and drop duplication substrings
@ 2021-07-12 14:23 Andy Shevchenko
  2021-07-12 14:23 ` [PATCH v1 2/2] i2c: dev: Use sysfs_emit() in "show" functions Andy Shevchenko
  2021-08-11 14:47 ` [PATCH v1 1/2] i2c: dev: Define pr_fmt() and drop duplication substrings Wolfram Sang
  0 siblings, 2 replies; 4+ messages in thread
From: Andy Shevchenko @ 2021-07-12 14:23 UTC (permalink / raw)
  To: Andy Shevchenko, linux-i2c, linux-kernel; +Cc: Wolfram Sang

Define pr_fmt() to print module name as prefix and at the same time
drop duplication substrings in the messages.

While at it, convert printk(<LEVEL>) to pr_<level>().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/i2c-dev.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index cb64fe649390..6cf98c06653a 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -14,6 +14,8 @@
 
 /* The I2C_RDWR ioctl code is written by Kolja Waschk <waschk@telos.de> */
 
+#define pr_fmt(fmt)	KBUILD_MODNAME ": " fmt
+
 #include <linux/cdev.h>
 #include <linux/compat.h>
 #include <linux/device.h>
@@ -68,8 +70,7 @@ static struct i2c_dev *get_free_i2c_dev(struct i2c_adapter *adap)
 	struct i2c_dev *i2c_dev;
 
 	if (adap->nr >= I2C_MINORS) {
-		printk(KERN_ERR "i2c-dev: Out of device minors (%d)\n",
-		       adap->nr);
+		pr_err("Out of device minors (%d)\n", adap->nr);
 		return ERR_PTR(-ENODEV);
 	}
 
@@ -145,8 +146,7 @@ static ssize_t i2cdev_read(struct file *file, char __user *buf, size_t count,
 	if (tmp == NULL)
 		return -ENOMEM;
 
-	pr_debug("i2c-dev: i2c-%d reading %zu bytes.\n",
-		iminor(file_inode(file)), count);
+	pr_debug("i2c-%d reading %zu bytes.\n", iminor(file_inode(file)), count);
 
 	ret = i2c_master_recv(client, tmp, count);
 	if (ret >= 0)
@@ -169,8 +169,7 @@ static ssize_t i2cdev_write(struct file *file, const char __user *buf,
 	if (IS_ERR(tmp))
 		return PTR_ERR(tmp);
 
-	pr_debug("i2c-dev: i2c-%d writing %zu bytes.\n",
-		iminor(file_inode(file)), count);
+	pr_debug("i2c-%d writing %zu bytes.\n", iminor(file_inode(file)), count);
 
 	ret = i2c_master_send(client, tmp, count);
 	kfree(tmp);
@@ -673,8 +672,7 @@ static int i2cdev_attach_adapter(struct device *dev, void *dummy)
 		return res;
 	}
 
-	pr_debug("i2c-dev: adapter [%s] registered as minor %d\n",
-		 adap->name, adap->nr);
+	pr_debug("adapter [%s] registered as minor %d\n", adap->name, adap->nr);
 	return 0;
 }
 
@@ -693,7 +691,7 @@ static int i2cdev_detach_adapter(struct device *dev, void *dummy)
 
 	put_i2c_dev(i2c_dev, true);
 
-	pr_debug("i2c-dev: adapter [%s] unregistered\n", adap->name);
+	pr_debug("adapter [%s] unregistered\n", adap->name);
 	return 0;
 }
 
@@ -726,7 +724,7 @@ static int __init i2c_dev_init(void)
 {
 	int res;
 
-	printk(KERN_INFO "i2c /dev entries driver\n");
+	pr_info("i2c /dev entries driver\n");
 
 	res = register_chrdev_region(MKDEV(I2C_MAJOR, 0), I2C_MINORS, "i2c");
 	if (res)
@@ -754,7 +752,7 @@ static int __init i2c_dev_init(void)
 out_unreg_chrdev:
 	unregister_chrdev_region(MKDEV(I2C_MAJOR, 0), I2C_MINORS);
 out:
-	printk(KERN_ERR "%s: Driver Initialisation failed\n", __FILE__);
+	pr_err("Driver Initialisation failed\n");
 	return res;
 }
 
-- 
2.30.2


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

* [PATCH v1 2/2] i2c: dev: Use sysfs_emit() in "show" functions
  2021-07-12 14:23 [PATCH v1 1/2] i2c: dev: Define pr_fmt() and drop duplication substrings Andy Shevchenko
@ 2021-07-12 14:23 ` Andy Shevchenko
  2021-08-11 14:49   ` Wolfram Sang
  2021-08-11 14:47 ` [PATCH v1 1/2] i2c: dev: Define pr_fmt() and drop duplication substrings Wolfram Sang
  1 sibling, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2021-07-12 14:23 UTC (permalink / raw)
  To: Andy Shevchenko, linux-i2c, linux-kernel; +Cc: Wolfram Sang

The sysfs_emit() function was introduced to make it less ambiguous
which function is preferred when writing to the output buffer in
a "show" callback [1].

Convert the I²C device sysfs interface from sprintf() to sysfs_emit()
accordingly, as the latter is aware of the PAGE_SIZE buffer and correctly
returns the number of bytes written into the buffer.

No functional change intended.

[1] Documentation/filesystems/sysfs.rst

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/i2c-dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index 6cf98c06653a..e2b1aba96401 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -102,7 +102,7 @@ static ssize_t name_show(struct device *dev,
 
 	if (!i2c_dev)
 		return -ENODEV;
-	return sprintf(buf, "%s\n", i2c_dev->adap->name);
+	return sysfs_emit(buf, "%s\n", i2c_dev->adap->name);
 }
 static DEVICE_ATTR_RO(name);
 
-- 
2.30.2


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

* Re: [PATCH v1 1/2] i2c: dev: Define pr_fmt() and drop duplication substrings
  2021-07-12 14:23 [PATCH v1 1/2] i2c: dev: Define pr_fmt() and drop duplication substrings Andy Shevchenko
  2021-07-12 14:23 ` [PATCH v1 2/2] i2c: dev: Use sysfs_emit() in "show" functions Andy Shevchenko
@ 2021-08-11 14:47 ` Wolfram Sang
  1 sibling, 0 replies; 4+ messages in thread
From: Wolfram Sang @ 2021-08-11 14:47 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linux-i2c, linux-kernel

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

On Mon, Jul 12, 2021 at 05:23:22PM +0300, Andy Shevchenko wrote:
> Define pr_fmt() to print module name as prefix and at the same time
> drop duplication substrings in the messages.
> 
> While at it, convert printk(<LEVEL>) to pr_<level>().
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Applied to for-next, thanks!


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

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

* Re: [PATCH v1 2/2] i2c: dev: Use sysfs_emit() in "show" functions
  2021-07-12 14:23 ` [PATCH v1 2/2] i2c: dev: Use sysfs_emit() in "show" functions Andy Shevchenko
@ 2021-08-11 14:49   ` Wolfram Sang
  0 siblings, 0 replies; 4+ messages in thread
From: Wolfram Sang @ 2021-08-11 14:49 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linux-i2c, linux-kernel

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

On Mon, Jul 12, 2021 at 05:23:23PM +0300, Andy Shevchenko wrote:
> The sysfs_emit() function was introduced to make it less ambiguous
> which function is preferred when writing to the output buffer in
> a "show" callback [1].
> 
> Convert the I²C device sysfs interface from sprintf() to sysfs_emit()
> accordingly, as the latter is aware of the PAGE_SIZE buffer and correctly
> returns the number of bytes written into the buffer.
> 
> No functional change intended.
> 
> [1] Documentation/filesystems/sysfs.rst
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Applied to for-next, thanks!


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

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

end of thread, other threads:[~2021-08-11 14:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-12 14:23 [PATCH v1 1/2] i2c: dev: Define pr_fmt() and drop duplication substrings Andy Shevchenko
2021-07-12 14:23 ` [PATCH v1 2/2] i2c: dev: Use sysfs_emit() in "show" functions Andy Shevchenko
2021-08-11 14:49   ` Wolfram Sang
2021-08-11 14:47 ` [PATCH v1 1/2] i2c: dev: Define pr_fmt() and drop duplication substrings 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).