]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - arch/um/drivers/pty.c
sparc32: pass -m32 when building vmlinux.lds
[linux-2.6-omap-h63xx.git] / arch / um / drivers / pty.c
index 1e3fd619a83732f53244f1b025661557bc020955..1113911dcb2bfb70696785ac194089705c9c8693 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
  * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Licensed under the GPL
  */
@@ -6,16 +6,16 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
 #include <errno.h>
+#include <fcntl.h>
+#include <string.h>
 #include <termios.h>
 #include <sys/stat.h>
 #include "chan_user.h"
-#include "os.h"
-#include "user.h"
 #include "kern_constants.h"
+#include "os.h"
 #include "um_malloc.h"
+#include "user.h"
 
 struct pty_chan {
        void (*announce)(char *dev_name, int dev);
@@ -29,11 +29,11 @@ static void *pty_chan_init(char *str, int device, const struct chan_opts *opts)
 {
        struct pty_chan *data;
 
-       data = kmalloc(sizeof(*data), UM_GFP_KERNEL);
+       data = uml_kmalloc(sizeof(*data), UM_GFP_KERNEL);
        if (data == NULL)
                return NULL;
 
-       *data = ((struct pty_chan) { .announce          = opts->announce, 
+       *data = ((struct pty_chan) { .announce          = opts->announce,
                                     .dev               = device,
                                     .raw               = opts->raw });
        return data;
@@ -56,11 +56,11 @@ static int pts_open(int input, int output, int primary, void *d,
        if (data->raw) {
                CATCH_EINTR(err = tcgetattr(fd, &data->tt));
                if (err)
-                       return err;
+                       goto out_close;
 
                err = raw(fd);
                if (err)
-                       return err;
+                       goto out_close;
        }
 
        dev = ptsname(fd);
@@ -71,6 +71,10 @@ static int pts_open(int input, int output, int primary, void *d,
                (*data->announce)(dev, data->dev);
 
        return fd;
+
+out_close:
+       close(fd);
+       return err;
 }
 
 static int getmaster(char *line)
@@ -97,7 +101,7 @@ static int getmaster(char *line)
                                *tp = 't';
                                err = access(line, R_OK | W_OK);
                                *tp = 'p';
-                               if(!err)
+                               if (!err)
                                        return master;
                                close(master);
                        }
@@ -119,12 +123,14 @@ static int pty_open(int input, int output, int primary, void *d,
        if (fd < 0)
                return fd;
 
-       if(data->raw){
+       if (data->raw) {
                err = raw(fd);
-               if (err)
+               if (err) {
+                       close(fd);
                        return err;
+               }
        }
-       
+
        if (data->announce)
                (*data->announce)(dev, data->dev);