Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1413770 > unrolled thread
| Started by | Jyoti Singh <jssengar92@gmail.com> |
|---|---|
| First post | 2016-06-04 16:50 +0200 |
| Last post | 2016-06-06 17:30 +0200 |
| Articles | 5 — 4 participants |
Back to article view | Back to linux.kernel
[PATCH] char: Prefer pr_* instead of printk Jyoti Singh <jssengar92@gmail.com> - 2016-06-04 16:50 +0200
Re: [PATCH] char: Prefer pr_* instead of printk Greg KH <gregkh@linuxfoundation.org> - 2016-06-04 18:40 +0200
Re: [PATCH] char: Prefer pr_* instead of printk jyoti singh <jssengar92@gmail.com> - 2016-06-06 08:20 +0200
Re: [PATCH] char: Prefer pr_* instead of printk Greg KH <gregkh@linuxfoundation.org> - 2016-06-06 16:40 +0200
Re: [PATCH] char: Prefer pr_* instead of printk Joe Perches <joe@perches.com> - 2016-06-06 17:30 +0200
| From | Jyoti Singh <jssengar92@gmail.com> |
|---|---|
| Date | 2016-06-04 16:50 +0200 |
| Subject | [PATCH] char: Prefer pr_* instead of printk |
| Message-ID | <rGl3H-2ms-7@gated-at.bofh.it> |
This patch replaces all the printk[KERN_INFO] with pr_* in the file
"ttyprintk.c" addressing the following warning:
WARNING:Prefer [subsystem eg: netdev]_info([subsystem]dev, ...
then dev_info(dev,... then pr_info(... to printk(KERN_INFO ...
Found with checkpatch
Signed-off-by: Jyoti Singh <jssengar@gmail.com>
---
drivers/char/ttyprintk.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/char/ttyprintk.c b/drivers/char/ttyprintk.c
index b098d2d..ca14f3e 100644
--- a/drivers/char/ttyprintk.c
+++ b/drivers/char/ttyprintk.c
@@ -51,7 +51,7 @@ static int tpk_printk(const unsigned char *buf, int count)
/* non nl or cr terminated message - add nl */
tmp[tpk_curr + 0] = '\n';
tmp[tpk_curr + 1] = '\0';
- printk(KERN_INFO "%s%s", tpk_tag, tmp);
+ pr_info("%s%s", tpk_tag, tmp);
tpk_curr = 0;
}
return i;
@@ -65,14 +65,14 @@ static int tpk_printk(const unsigned char *buf, int count)
/* replace cr with nl */
tmp[tpk_curr + 0] = '\n';
tmp[tpk_curr + 1] = '\0';
- printk(KERN_INFO "%s%s", tpk_tag, tmp);
+ pr_info("%s%s", tpk_tag, tmp);
tpk_curr = 0;
if ((i + 1) < count && buf[i + 1] == '\n')
i++;
break;
case '\n':
tmp[tpk_curr + 1] = '\0';
- printk(KERN_INFO "%s%s", tpk_tag, tmp);
+ pr_info("%s%s", tpk_tag, tmp);
tpk_curr = 0;
break;
default:
@@ -83,7 +83,7 @@ static int tpk_printk(const unsigned char *buf, int count)
tmp[tpk_curr + 1] = '\\';
tmp[tpk_curr + 2] = '\n';
tmp[tpk_curr + 3] = '\0';
- printk(KERN_INFO "%s%s", tpk_tag, tmp);
+ pr_info("%s%s", tpk_tag, tmp);
tpk_curr = 0;
}
}
@@ -203,7 +203,7 @@ static int __init ttyprintk_init(void)
ret = tty_register_driver(ttyprintk_driver);
if (ret < 0) {
- printk(KERN_ERR "Couldn't register ttyprintk driver\n");
+ pr_err("Couldn't register ttyprintk driver\n");
goto error;
}
--
1.9.3
[toc] | [next] | [standalone]
| From | Greg KH <gregkh@linuxfoundation.org> |
|---|---|
| Date | 2016-06-04 18:40 +0200 |
| Message-ID | <rGmM9-3qZ-13@gated-at.bofh.it> |
| In reply to | #1413770 |
On Sat, Jun 04, 2016 at 08:15:11PM +0530, Jyoti Singh wrote: > This patch replaces all the printk[KERN_INFO] with pr_* in the file > "ttyprintk.c" addressing the following warning: > > WARNING:Prefer [subsystem eg: netdev]_info([subsystem]dev, ... > then dev_info(dev,... then pr_info(... to printk(KERN_INFO ... > Found with checkpatch Sometimes checkpatch tells you to do things that are incorrect :) Are you _sure_ the code works the same before and after this? The ttyprintk driver is a bit "special". Did you test these changes? thanks, greg k-h
[toc] | [prev] | [next] | [standalone]
| From | jyoti singh <jssengar92@gmail.com> |
|---|---|
| Date | 2016-06-06 08:20 +0200 |
| Message-ID | <rGW3g-17P-11@gated-at.bofh.it> |
| In reply to | #1413792 |
yes sir, I have written a tty driver module there i had used printk and pr_*. it is working fine with both. Thanks, Jyoti Singh On Mon, Jun 6, 2016 at 11:08 AM, jyoti singh <jssengar92@gmail.com> wrote: > Really sorry sir,As this is my first patch i m new to these thing. > will take care of this now onwards. > and i m sending the mail again to everyone on the mailing list. > > Thanks, > Jyoti singh > > On Sun, Jun 5, 2016 at 8:33 PM, Greg KH <gregkh@linuxfoundation.org> wrote: >> >> On Sun, Jun 05, 2016 at 06:41:00PM +0530, jyoti singh wrote: >> > yes sir, >> >> <snip> >> >> For some reason you sent this only to me, which is a bit rude to >> everyone else on the mailing list. I'll be glad to respond if you >> resend it to everyone. >> >> thanks, >> >> greg k-h > >
[toc] | [prev] | [next] | [standalone]
| From | Greg KH <gregkh@linuxfoundation.org> |
|---|---|
| Date | 2016-06-06 16:40 +0200 |
| Message-ID | <rH3R9-68Z-59@gated-at.bofh.it> |
| In reply to | #1414666 |
On Mon, Jun 06, 2016 at 11:44:07AM +0530, jyoti singh wrote: > yes sir, > I have written a tty driver module there i had used printk and pr_*. > it is working fine with both. That's not the answer to my question, did you test _this_ driver with _these_ changes? Or at least I think that was what my question was, I don't see it here in the context so I don't remember... greg k-h
[toc] | [prev] | [next] | [standalone]
| From | Joe Perches <joe@perches.com> |
|---|---|
| Date | 2016-06-06 17:30 +0200 |
| Message-ID | <rH4Dw-6Hq-27@gated-at.bofh.it> |
| In reply to | #1413792 |
On Sat, 2016-06-04 at 09:36 -0700, Greg KH wrote:
> On Sat, Jun 04, 2016 at 08:15:11PM +0530, Jyoti Singh wrote:
> >
> > This patch replaces all the printk[KERN_INFO] with pr_* in the file
> > "ttyprintk.c" addressing the following warning:
> >
> > WARNING:Prefer [subsystem eg: netdev]_info([subsystem]dev, ...
> > then dev_info(dev,... then pr_info(... to printk(KERN_INFO ...
> > Found with checkpatch
> Sometimes checkpatch tells you to do things that are incorrect :)
>
> Are you _sure_ the code works the same before and after this? The
> ttyprintk driver is a bit "special".
when pr_fmt is not defined (and ttyprint doesn't use pr_fmt),
pr_<level> uses are printks.
#define pr_info(fmt, ...) \
printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
The only one that is not a printk is pr_debug.
It'd be simpler code if all the printks in this file were
consolidated into something like a single tpk_flush function
and the tpk_tag removed.
Something like (completely untested, just typed and compiled
with a couple typos fixed)
---
drivers/char/ttyprintk.c | 69 ++++++++++++++++++++++--------------------------
1 file changed, 31 insertions(+), 38 deletions(-)
diff --git a/drivers/char/ttyprintk.c b/drivers/char/ttyprintk.c
index b098d2d..67549ce 100644
--- a/drivers/char/ttyprintk.c
+++ b/drivers/char/ttyprintk.c
@@ -31,60 +31,53 @@ static struct ttyprintk_port tpk_port;
* printk messages (also suitable for logging service):
* - any cr is replaced by nl
* - adds a ttyprintk source tag in front of each line
- * - too long message is fragmeted, with '\'nl between fragments
- * - TPK_STR_SIZE isn't really the write_room limiting factor, bcause
+ * - too long message is fragmented, with '\'nl between fragments
+ * - TPK_STR_SIZE isn't really the write_room limiting factor, because
* it is emptied on the fly during preformatting.
*/
#define TPK_STR_SIZE 508 /* should be bigger then max expected line length */
#define TPK_MAX_ROOM 4096 /* we could assume 4K for instance */
-static const char *tpk_tag = "[U] "; /* U for User */
static int tpk_curr;
+static char tpk_buffer[TPK_STR_SIZE + 4];
+
+static void tpk_flush(void)
+{
+ if (tpk_curr > 0) {
+ tpk_buffer[tpk_curr] = '\0';
+ pr_info("[U] %s\n", tpk_buffer);
+ tpk_curr = 0;
+ }
+}
+
static int tpk_printk(const unsigned char *buf, int count)
{
- static char tmp[TPK_STR_SIZE + 4];
int i = tpk_curr;
if (buf == NULL) {
- /* flush tmp[] */
- if (tpk_curr > 0) {
- /* non nl or cr terminated message - add nl */
- tmp[tpk_curr + 0] = '\n';
- tmp[tpk_curr + 1] = '\0';
- printk(KERN_INFO "%s%s", tpk_tag, tmp);
- tpk_curr = 0;
- }
+ tpk_flush();
return i;
}
for (i = 0; i < count; i++) {
- tmp[tpk_curr] = buf[i];
- if (tpk_curr < TPK_STR_SIZE) {
- switch (buf[i]) {
- case '\r':
- /* replace cr with nl */
- tmp[tpk_curr + 0] = '\n';
- tmp[tpk_curr + 1] = '\0';
- printk(KERN_INFO "%s%s", tpk_tag, tmp);
- tpk_curr = 0;
- if ((i + 1) < count && buf[i + 1] == '\n')
- i++;
- break;
- case '\n':
- tmp[tpk_curr + 1] = '\0';
- printk(KERN_INFO "%s%s", tpk_tag, tmp);
- tpk_curr = 0;
- break;
- default:
- tpk_curr++;
- }
- } else {
+ if (tpk_curr >= TPK_STR_SIZE) {
/* end of tmp buffer reached: cut the message in two */
- tmp[tpk_curr + 1] = '\\';
- tmp[tpk_curr + 2] = '\n';
- tmp[tpk_curr + 3] = '\0';
- printk(KERN_INFO "%s%s", tpk_tag, tmp);
- tpk_curr = 0;
+ tpk_buffer[tpk_curr++] = '\\';
+ tpk_flush();
+ }
+
+ switch (buf[i]) {
+ case '\r':
+ tpk_flush();
+ if ((i + 1) < count && buf[i + 1] == '\n')
+ i++;
+ break;
+ case '\n':
+ tpk_flush();
+ break;
+ default:
+ tpk_buffer[tpk_curr++] = buf[i];
+ break;
}
}
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web