Update /proc/can implementation to compile with 3.10+ kernels with dummy chip_info...
authorPavel Pisa <pisa@cmp.felk.cvut.cz>
Sat, 30 Nov 2013 12:16:50 +0000 (13:16 +0100)
committerPavel Pisa <pisa@cmp.felk.cvut.cz>
Sat, 30 Nov 2013 12:16:50 +0000 (13:16 +0100)
/proc/can/channelX/chip_info support needs to be updated to use seq_file.

Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
lincan/src/proc.c

index 7cb69c3..16dda35 100644 (file)
@@ -111,10 +111,23 @@ static struct proc_dir_entry * can_create_proc_entry(const char *name, mode_t mo
        return new_entry;
 }
 
-static int can_remove_proc_entry(struct proc_dir_entry *del, struct proc_dir_entry *parent)
+struct proc_dir_entry *can_create_proc_read_entry(const char *name,
+       mode_t mode, struct proc_dir_entry *parent,
+       read_proc_t *read_proc, void * data)
+{
+       return create_proc_read_entry(name, mode, parent, read_proc, data);
+}
+
+struct proc_dir_entry *can_proc_mkdir_mode(const char *name, umode_t mode,
+                                       struct proc_dir_entry *parent)
+{
+       return can_create_proc_entry(name, S_IFDIR | mode, parent);
+}
+
+static int can_proc_remove(struct proc_dir_entry *del)
 {
        if (del != NULL) {
-               proc_unregister(parent, del->low_ino);
+               proc_unregister(del->parent, del->low_ino);
                can_checked_free(del);
                return 0;
        }
@@ -147,21 +160,77 @@ static inline struct proc_dir_entry *can_proc_symlink(const char *name,
        return entry;
 }
 
-#else /* Functions forwarded for kernel 2.4 and above */
+#elif (LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0))
 
-static inline struct proc_dir_entry * can_create_proc_entry(const char *name, mode_t mode,
-                                       struct proc_dir_entry *parent)
+struct proc_dir_entry *can_create_proc_read_entry(const char *name,
+       mode_t mode, struct proc_dir_entry *parent,
+       read_proc_t *read_proc, void * data)
 {
-       return create_proc_entry(name, mode, parent);
+       return create_proc_read_entry(name, mode, parent, read_proc, data);
 }
 
+struct proc_dir_entry *can_proc_mkdir_mode(const char *name, umode_t mode,
+                                       struct proc_dir_entry *parent)
+{
+       return create_proc_entry(name, S_IFDIR | mode, parent);
+}
 
 /* This does not fully follow linux 2.4 and 2.6 prototype to simplify 2.2.x compatibility */
 /* The newer kernels use entry name instead of pointer to the entry */
-static int can_remove_proc_entry(struct proc_dir_entry *del, struct proc_dir_entry *parent)
+static int can_proc_remove(struct proc_dir_entry *del)
+{
+       if(!del) return -ENODEV;
+       remove_proc_entry(del->name, del->parent);
+       return 0;
+}
+
+static inline struct proc_dir_entry *can_proc_symlink(const char *name,
+                struct proc_dir_entry *parent, const char *dest)
+{
+       return proc_symlink(name, parent, dest);
+}
+
+#else /* Linux kernel 3.10+ */
+
+#include <linux/seq_file.h>
+
+static int can_status_proc_show(struct seq_file *m, void *v)
+{
+       seq_printf(m, "dummy CAN can_create_proc_read_entry implementation\n");
+       return 0;
+}
+
+static int can_status_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, can_status_proc_show, PDE_DATA(inode));
+}
+
+static const struct file_operations can_status_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = can_status_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+
+struct proc_dir_entry *can_create_proc_read_entry(const char *name,
+       mode_t mode, struct proc_dir_entry *parent,
+       void *read_proc, void * data)
+{
+       /*return proc_read_entry(name, mode, parent, read_proc, data);*/
+       return proc_create_data(name, mode, parent, &can_status_proc_fops, data);
+}
+
+struct proc_dir_entry *can_proc_mkdir_mode(const char *name, umode_t mode,
+                                       struct proc_dir_entry *parent)
+{
+       return proc_mkdir_mode(name, mode, parent);
+}
+
+static int can_proc_remove(struct proc_dir_entry *del)
 {
        if(!del) return -ENODEV;
-       remove_proc_entry(del->name,parent);
+       proc_remove(del);
        return 0;
 }
 
@@ -180,7 +249,7 @@ int can_init_procdir(void)
 {
        int board;
        struct candevice_t *candev;
-       base->can_proc_entry = can_create_proc_entry("can", S_IFDIR | S_IRUGO |
+       base->can_proc_entry = can_proc_mkdir_mode("can", S_IFDIR | S_IRUGO |
                                        S_IXUGO, CAN_PROC_ROOT);
        if (base->can_proc_entry == NULL)
                return -ENODEV;
@@ -199,7 +268,7 @@ int can_delete_procdir(void)
        if (remove_channel_from_procdir())
                return -ENODEV;
        /* name: "can" */
-       if (can_remove_proc_entry(base->can_proc_entry, CAN_PROC_ROOT))
+       if (can_proc_remove(base->can_proc_entry))
                return -ENODEV;
 
        return 0;
@@ -248,7 +317,7 @@ int add_channel_to_procdir(struct candevice_t *candev)
 
                sprintf(base->channel[cc]->ch_name, "channel%d",cc);
 
-               base->channel[cc]->ch_entry = can_create_proc_entry(
+               base->channel[cc]->ch_entry = can_proc_mkdir_mode(
                                                base->channel[cc]->ch_name,
                                                S_IFDIR | S_IRUGO |S_IXUGO,
                                                base->can_proc_entry);
@@ -258,7 +327,7 @@ int add_channel_to_procdir(struct candevice_t *candev)
 
                add_object_to_procdir(cc);
 
-               create_proc_read_entry("chip_info",        /* proc entry name */
+               can_create_proc_read_entry("chip_info",        /* proc entry name */
                                       0,                  /* protection mask, 0->default */
                                       base->channel[cc]->ch_entry,  /* parent dir, NULL->/proc */
                                       can_chip_procinfo,
@@ -284,8 +353,7 @@ int remove_channel_from_procdir(void)
                        return -ENODEV;
 
                /* name: base->channel[cc]->ch_name */
-               if (can_remove_proc_entry(base->channel[cc]->ch_entry,
-                                                       base->can_proc_entry))
+               if (can_proc_remove(base->channel[cc]->ch_entry))
                        return -ENODEV;
 
                can_checked_free(base->channel[cc]);
@@ -312,7 +380,7 @@ int add_object_to_procdir(int chip_nr)
                sprintf(base->channel[chip_nr]->object[i]->obj_name,"object%d",i);
                sprintf(base->channel[chip_nr]->object[i]->lnk_name,"dev");
 
-               base->channel[chip_nr]->object[i]->obj_entry = can_create_proc_entry(
+               base->channel[chip_nr]->object[i]->obj_entry = can_proc_mkdir_mode(
                                base->channel[chip_nr]->object[i]->obj_name,
                                S_IFDIR | S_IRUGO | S_IXUGO,
                                base->channel[chip_nr]->ch_entry);
@@ -343,13 +411,10 @@ int remove_object_from_procdir(int chip_nr)
                if(!base->channel[chip_nr]->object[i]) continue;
 
                /* name: base->channel[chip_nr]->object[i]->lnk_name */
-               if (can_remove_proc_entry( base->channel[chip_nr]->object[i]->lnk,
-                               base->channel[chip_nr]->object[i]->obj_entry))
+               if (can_proc_remove( base->channel[chip_nr]->object[i]->lnk))
                        return -ENODEV;
                /* name: base->channel[chip_nr]->object[i]->obj_name */
-               if (can_remove_proc_entry(
-                               base->channel[chip_nr]->object[i]->obj_entry,
-                               base->channel[chip_nr]->ch_entry))
+               if (can_proc_remove(base->channel[chip_nr]->object[i]->obj_entry))
                        return -ENODEV;
 
                can_checked_free(base->channel[chip_nr]->object[i]);