All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guillaume Chazarain <guichaz@yahoo.fr>
To: Andrew Morton <akpm@osdl.org>
Cc: linux-kernel@vger.kernel.org, tim.bird@am.sony.com
Subject: [PATCH 2/2] kmsg_write: don't return printk return value
Date: Tue, 15 Nov 2005 13:18:39 +0100	[thread overview]
Message-ID: <4379D21F.3050500@yahoo.fr> (raw)
In-Reply-To: <430CA2CE.4070403@am.sony.com>

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

kmsg_write returns with printk, so some programs may be confused by
a successful write() with a return value different than the buffer length.

# /bin/echo something > /dev/kmsg
/bin/echo: write error: Inappropriate ioctl for device

The drawbacks is that the printk return value can no more be quickly checked
from userspace.

Signed-off-by: Guillaume Chazarain <guichaz@yahoo.fr>

---
  mem.c |    5 ++++-
  1 files changed, 4 insertions(+), 1 deletion(-)

-- 
Guillaume



[-- Attachment #2: kmsg_write.diff --]
[-- Type: text/x-patch, Size: 522 bytes --]

diff -r d18e06f9c571 drivers/char/mem.c
--- a/drivers/char/mem.c	Mon Nov 14 10:22:49 2005 +0800
+++ b/drivers/char/mem.c	Mon Nov 14 15:03:06 2005 +0100
@@ -817,7 +817,7 @@
 			  size_t count, loff_t *ppos)
 {
 	char *tmp;
-	int ret;
+	ssize_t ret;
 
 	tmp = kmalloc(count + 1, GFP_KERNEL);
 	if (tmp == NULL)
@@ -826,6 +826,9 @@
 	if (!copy_from_user(tmp, buf, count)) {
 		tmp[count] = 0;
 		ret = printk("%s", tmp);
+		if (ret > count)
+			/* printk can add a prefix */
+			ret = count;
 	}
 	kfree(tmp);
 	return ret;


      parent reply	other threads:[~2005-11-15 12:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-03  9:35 [PATCH] Wrong printk return value Guillaume Chazarain
2005-08-24 16:39 ` Tim Bird
2005-11-15 12:17   ` [-mm PATCH 1/2] printk return value: fix it Guillaume Chazarain
2005-11-15 23:23     ` Tim Bird
2005-11-15 12:18   ` Guillaume Chazarain [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4379D21F.3050500@yahoo.fr \
    --to=guichaz@yahoo.fr \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tim.bird@am.sony.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.