kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drivers/tty: Use get_user instead of dereferencing user pointer
@ 2012-04-20 15:52 Emil Goode
  2012-04-20 20:59 ` Alan Cox
  0 siblings, 1 reply; 5+ messages in thread
From: Emil Goode @ 2012-04-20 15:52 UTC (permalink / raw)
  To: gregkh; +Cc: kernel-janitors, linux-kernel, Emil Goode

We should use the get_user macro instead of dereferencing user
pointers directly.

This patch fixes the following sparse warning:
drivers/tty/n_tty.c:1648:51: warning:
	dereference of noderef expression

Signed-off-by: Emil Goode <emilgoode@gmail.com>
---
I'm a newbie so please review carefully.
Not sure if I should add error handling for the get_user call here.

 drivers/tty/n_tty.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 94b6eda..5ff63cc 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -1630,6 +1630,7 @@ static int copy_from_read_buf(struct tty_struct *tty,
 	int retval;
 	size_t n;
 	unsigned long flags;
+	unsigned char ch;
 
 	retval = 0;
 	spin_lock_irqsave(&tty->read_lock, flags);
@@ -1645,7 +1646,8 @@ static int copy_from_read_buf(struct tty_struct *tty,
 		tty->read_cnt -= n;
 		/* Turn single EOF into zero-length read */
 		if (L_EXTPROC(tty) && tty->icanon && n = 1) {
-			if (!tty->read_cnt && (*b)[n-1] = EOF_CHAR(tty))
+			get_user(ch, b[n-1]);
+			if (!tty->read_cnt && ch = EOF_CHAR(tty))
 				n--;
 		}
 		spin_unlock_irqrestore(&tty->read_lock, flags);
-- 
1.7.9.5


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

end of thread, other threads:[~2012-04-21 14:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-20 15:52 [PATCH] drivers/tty: Use get_user instead of dereferencing user pointer Emil Goode
2012-04-20 20:59 ` Alan Cox
2012-04-21  9:04   ` Jiri Slaby
2012-04-21 14:04     ` Howard Chu
2012-04-21 14:25       ` Howard Chu

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