From: Jiri Olsa <jolsa@redhat.com>
To: gregkh@suse.de
Cc: linux-kernel@vger.kernel.org, Jiri Olsa <jolsa@redhat.com>
Subject: [PATCH] tty: getting rid of __GFP_NOFAIL in tty_add_file
Date: Thu, 2 Sep 2010 18:17:56 +0200 [thread overview]
Message-ID: <1283444276-19355-1-git-send-email-jolsa@redhat.com> (raw)
hi,
added error handling for struct tty_file_private allocation,
Fixed error paths in tty_open and ptmx_open.
wbr,
jirka
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
---
drivers/char/pty.c | 9 ++++++++-
drivers/char/tty_io.c | 26 +++++++++++++++++++-------
include/linux/tty.h | 4 +++-
3 files changed, 30 insertions(+), 9 deletions(-)
diff --git a/drivers/char/pty.c b/drivers/char/pty.c
index c350d01..cc4f861 100644
--- a/drivers/char/pty.c
+++ b/drivers/char/pty.c
@@ -652,6 +652,7 @@ static const struct tty_operations pty_unix98_ops = {
static int ptmx_open(struct inode *inode, struct file *filp)
{
struct tty_struct *tty;
+ struct tty_file_private *priv;
int retval;
int index;
@@ -664,6 +665,12 @@ static int ptmx_open(struct inode *inode, struct file *filp)
if (index < 0)
return index;
+ priv = alloc_tty_priv();
+ if (!priv)
+ return -ENOMEM;
+
+ filp->private_data = priv;
+
mutex_lock(&tty_mutex);
tty_lock();
tty = tty_init_dev(ptm_driver, index, 1);
@@ -676,7 +683,7 @@ static int ptmx_open(struct inode *inode, struct file *filp)
set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */
- tty_add_file(tty, filp);
+ tty_set_priv(priv, tty, filp);
retval = devpts_pty_new(inode, tty->link);
if (retval)
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 949067a..99d8bcb 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -193,17 +193,19 @@ static inline struct tty_struct *file_tty(struct file *file)
return ((struct tty_file_private *)file->private_data)->tty;
}
-/* Associate a new file with the tty structure */
-void tty_add_file(struct tty_struct *tty, struct file *file)
+
+struct tty_file_private *alloc_tty_priv(void)
{
- struct tty_file_private *priv;
+ return kzalloc(sizeof(struct tty_file_private), GFP_KERNEL);
+}
- /* XXX: must implement proper error handling in callers */
- priv = kmalloc(sizeof(*priv), GFP_KERNEL|__GFP_NOFAIL);
+/* Associate a new file with the tty structure */
+void tty_set_priv(struct tty_file_private *priv, struct tty_struct *tty,
+ struct file *file)
+{
priv->tty = tty;
priv->file = file;
- file->private_data = priv;
spin_lock(&tty_files_lock);
list_add(&priv->list, &tty->tty_files);
@@ -1787,6 +1789,7 @@ int tty_release(struct inode *inode, struct file *filp)
static int tty_open(struct inode *inode, struct file *filp)
{
struct tty_struct *tty = NULL;
+ struct tty_file_private *priv;
int noctty, retval;
struct tty_driver *driver;
int index;
@@ -1861,6 +1864,15 @@ got_driver:
}
}
+ priv = alloc_tty_priv();
+ if (!priv) {
+ tty_unlock();
+ mutex_unlock(&tty_mutex);
+ return -ENOMEM;
+ }
+
+ filp->private_data = priv;
+
if (tty) {
retval = tty_reopen(tty);
if (retval)
@@ -1875,7 +1887,7 @@ got_driver:
return PTR_ERR(tty);
}
- tty_add_file(tty, filp);
+ tty_set_priv(priv, tty, filp);
check_tty_count(tty, "tty_open");
if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 67d64e6..48705aa 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -465,7 +465,9 @@ extern void proc_clear_tty(struct task_struct *p);
extern struct tty_struct *get_current_tty(void);
extern void tty_default_fops(struct file_operations *fops);
extern struct tty_struct *alloc_tty_struct(void);
-extern void tty_add_file(struct tty_struct *tty, struct file *file);
+struct tty_file_private *alloc_tty_priv(void);
+void tty_set_priv(struct tty_file_private *priv, struct tty_struct *tty,
+ struct file *file);
extern void free_tty_struct(struct tty_struct *tty);
extern void initialize_tty_struct(struct tty_struct *tty,
struct tty_driver *driver, int idx);
--
1.7.1
next reply other threads:[~2010-09-02 16:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-02 16:17 Jiri Olsa [this message]
2010-09-02 20:09 ` Greg KH
2010-09-03 13:15 ` Jiri Olsa
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=1283444276-19355-1-git-send-email-jolsa@redhat.com \
--to=jolsa@redhat.com \
--cc=gregkh@suse.de \
--cc=linux-kernel@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome