include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / drivers / isdn / hysdn / hysdn_procconf.c
index 639582f..8096646 100644 (file)
  *
  */
 
+#include <linux/cred.h>
 #include <linux/module.h>
-#include <linux/version.h>
 #include <linux/poll.h>
 #include <linux/proc_fs.h>
 #include <linux/pci.h>
+#include <linux/slab.h>
 #include <linux/smp_lock.h>
+#include <net/net_namespace.h>
 
 #include "hysdn_defs.h"
 
@@ -37,9 +39,9 @@ struct conf_writedata {
        int buf_size;           /* actual number of bytes in the buffer */
        int needed_size;        /* needed size when reading pof */
        int state;              /* actual interface states from above constants */
-       uchar conf_line[CONF_LINE_LEN];         /* buffered conf line */
-       word channel;           /* active channel number */
-       uchar *pof_buffer;      /* buffer when writing pof */
+       unsigned char conf_line[CONF_LINE_LEN]; /* buffered conf line */
+       unsigned short channel;         /* active channel number */
+       unsigned char *pof_buffer;      /* buffer when writing pof */
 };
 
 /***********************************************************************/
@@ -50,7 +52,7 @@ struct conf_writedata {
 static int
 process_line(struct conf_writedata *cnf)
 {
-       uchar *cp = cnf->conf_line;
+       unsigned char *cp = cnf->conf_line;
        int i;
 
        if (cnf->card->debug_flags & LOG_CNF_LINE)
@@ -93,7 +95,7 @@ hysdn_conf_write(struct file *file, const char __user *buf, size_t count, loff_t
 {
        struct conf_writedata *cnf;
        int i;
-       uchar ch, *cp;
+       unsigned char ch, *cp;
 
        if (!count)
                return (0);     /* nothing to handle */
@@ -207,30 +209,17 @@ hysdn_conf_write(struct file *file, const char __user *buf, size_t count, loff_t
 /* read conf file -> output card info data */
 /*******************************************/
 static ssize_t
-hysdn_conf_read(struct file *file, char __user *buf, size_t count, loff_t * off)
+hysdn_conf_read(struct file *file, char __user *buf, size_t count, loff_t *off)
 {
        char *cp;
-       int i;
 
-       if (file->f_mode & FMODE_READ) {
-               if (!(cp = file->private_data))
-                       return (-EFAULT);       /* should never happen */
-               i = strlen(cp); /* get total string length */
-               if (*off < i) {
-                       /* still bytes to transfer */
-                       cp += *off;     /* point to desired data offset */
-                       i -= *off;      /* remaining length */
-                       if (i > count)
-                               i = count;      /* limit length to transfer */
-                       if (copy_to_user(buf, cp, i))
-                               return (-EFAULT);       /* copy error */
-                       *off += i;      /* adjust offset */
-               } else
-                       return (0);
-       } else
-               return (-EPERM);        /* no permission to read */
-
-       return (i);
+       if (!(file->f_mode & FMODE_READ))
+               return -EPERM;  /* no permission to read */
+
+       if (!(cp = file->private_data))
+               return -EFAULT; /* should never happen */
+
+       return simple_read_from_buffer(buf, count, off, cp, strlen(cp));
 }                              /* hysdn_conf_read */
 
 /******************/
@@ -259,7 +248,8 @@ hysdn_conf_open(struct inode *ino, struct file *filep)
        }
        if (card->debug_flags & (LOG_PROC_OPEN | LOG_PROC_ALL))
                hysdn_addlog(card, "config open for uid=%d gid=%d mode=0x%x",
-                            filep->f_uid, filep->f_gid, filep->f_mode);
+                            filep->f_cred->fsuid, filep->f_cred->fsgid,
+                            filep->f_mode);
 
        if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_WRITE) {
                /* write only access -> write boot file or conf line */
@@ -276,7 +266,7 @@ hysdn_conf_open(struct inode *ino, struct file *filep)
        } else if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) {
                /* read access -> output card info data */
 
-               if (!(tmp = (char *) kmalloc(INFO_OUT_LEN * 2 + 2, GFP_KERNEL))) {
+               if (!(tmp = kmalloc(INFO_OUT_LEN * 2 + 2, GFP_KERNEL))) {
                        unlock_kernel();
                        return (-EFAULT);       /* out of memory */
                }
@@ -344,7 +334,8 @@ hysdn_conf_close(struct inode *ino, struct file *filep)
        }
        if (card->debug_flags & (LOG_PROC_OPEN | LOG_PROC_ALL))
                hysdn_addlog(card, "config close for uid=%d gid=%d mode=0x%x",
-                            filep->f_uid, filep->f_gid, filep->f_mode);
+                            filep->f_cred->fsuid, filep->f_cred->fsgid,
+                            filep->f_mode);
 
        if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_WRITE) {
                /* write only access -> write boot file or conf line */
@@ -359,8 +350,7 @@ hysdn_conf_close(struct inode *ino, struct file *filep)
        } else if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) {
                /* read access -> output card info data */
 
-               if (filep->private_data)
-                       kfree(filep->private_data);     /* release memory */
+               kfree(filep->private_data);     /* release memory */
        }
        unlock_kernel();
        return (retval);
@@ -369,8 +359,9 @@ hysdn_conf_close(struct inode *ino, struct file *filep)
 /******************************************************/
 /* table for conf filesystem functions defined above. */
 /******************************************************/
-static struct file_operations conf_fops =
+static const struct file_operations conf_fops =
 {
+       .owner          = THIS_MODULE,
        .llseek         = no_llseek,
        .read           = hysdn_conf_read,
        .write          = hysdn_conf_write,
@@ -392,9 +383,9 @@ int
 hysdn_procconf_init(void)
 {
        hysdn_card *card;
-       uchar conf_name[20];
+       unsigned char conf_name[20];
 
-       hysdn_proc_entry = proc_mkdir(PROC_SUBDIR_NAME, proc_net);
+       hysdn_proc_entry = proc_mkdir(PROC_SUBDIR_NAME, init_net.proc_net);
        if (!hysdn_proc_entry) {
                printk(KERN_ERR "HYSDN: unable to create hysdn subdir\n");
                return (-1);
@@ -403,11 +394,10 @@ hysdn_procconf_init(void)
        while (card) {
 
                sprintf(conf_name, "%s%d", PROC_CONF_BASENAME, card->myid);
-               if ((card->procconf = (void *) create_proc_entry(conf_name,
-                                            S_IFREG | S_IRUGO | S_IWUSR,
-                                           hysdn_proc_entry)) != NULL) {
-                       ((struct proc_dir_entry *) card->procconf)->proc_fops = &conf_fops;
-                       ((struct proc_dir_entry *) card->procconf)->owner = THIS_MODULE;
+               if ((card->procconf = (void *) proc_create(conf_name,
+                                               S_IFREG | S_IRUGO | S_IWUSR,
+                                               hysdn_proc_entry,
+                                               &conf_fops)) != NULL) {
                        hysdn_proclog_init(card);       /* init the log file entry */
                }
                card = card->next;      /* next entry */
@@ -425,7 +415,7 @@ void
 hysdn_procconf_release(void)
 {
        hysdn_card *card;
-       uchar conf_name[20];
+       unsigned char conf_name[20];
 
        card = card_root;       /* start with first card */
        while (card) {
@@ -439,5 +429,5 @@ hysdn_procconf_release(void)
                card = card->next;      /* point to next card */
        }
 
-       remove_proc_entry(PROC_SUBDIR_NAME, proc_net);
+       remove_proc_entry(PROC_SUBDIR_NAME, init_net.proc_net);
 }