cregit-Linux how code gets into the kernel

Release 4.14 arch/mips/lasat/picvue_proc.c

Directory: arch/mips/lasat
/*
 * Picvue PVC160206 display driver
 *
 * Brian Murphy <brian.murphy@eicon.com>
 *
 */
#include <linux/bug.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/errno.h>

#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/interrupt.h>

#include <linux/timer.h>
#include <linux/mutex.h>
#include <linux/uaccess.h>

#include "picvue.h"

static DEFINE_MUTEX(pvc_mutex);

static char pvc_lines[PVC_NLINES][PVC_LINELEN+1];

static int pvc_linedata[PVC_NLINES];

static char *pvc_linename[PVC_NLINES] = {"line1", "line2"};

#define DISPLAY_DIR_NAME "display"


static int scroll_dir, scroll_interval;


static struct timer_list timer;


static void pvc_display(unsigned long data) { int i; pvc_clear(); for (i = 0; i < PVC_NLINES; i++) pvc_write_string(pvc_lines[i], 0, i); }

Contributors

PersonTokensPropCommitsCommitProp
Brian Murphy41100.00%1100.00%
Total41100.00%1100.00%

static DECLARE_TASKLET(pvc_display_tasklet, &pvc_display, 0);
static int pvc_line_proc_show(struct seq_file *m, void *v) { int lineno = *(int *)m->private; if (lineno < 0 || lineno >= PVC_NLINES) { printk(KERN_WARNING "proc_read_line: invalid lineno %d\n", lineno); return 0; } mutex_lock(&pvc_mutex); seq_printf(m, "%s\n", pvc_lines[lineno]); mutex_unlock(&pvc_mutex); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Brian Murphy6179.22%125.00%
Alexey Dobriyan1114.29%125.00%
Daniel Walker45.19%125.00%
Dan Carpenter11.30%125.00%
Total77100.00%4100.00%


static int pvc_line_proc_open(struct inode *inode, struct file *file) { return single_open(file, pvc_line_proc_show, PDE_DATA(inode)); }

Contributors

PersonTokensPropCommitsCommitProp
Alexey Dobriyan2689.66%133.33%
Brian Murphy26.90%133.33%
Al Viro13.45%133.33%
Total29100.00%3100.00%


static ssize_t pvc_line_proc_write(struct file *file, const char __user *buf, size_t count, loff_t *pos) { int lineno = *(int *)PDE_DATA(file_inode(file)); char kbuf[PVC_LINELEN]; size_t len; BUG_ON(lineno < 0 || lineno >= PVC_NLINES); len = min(count, sizeof(kbuf) - 1); if (copy_from_user(kbuf, buf, len)) return -EFAULT; kbuf[len] = '\0'; if (len > 0 && kbuf[len - 1] == '\n') len--; mutex_lock(&pvc_mutex); strncpy(pvc_lines[lineno], kbuf, len); pvc_lines[lineno][len] = '\0'; mutex_unlock(&pvc_mutex); tasklet_schedule(&pvc_display_tasklet); return count; }

Contributors

PersonTokensPropCommitsCommitProp
Brian Murphy8654.78%116.67%
Alexey Dobriyan6239.49%116.67%
Al Viro42.55%233.33%
Daniel Walker42.55%116.67%
Dan Carpenter10.64%116.67%
Total157100.00%6100.00%

static const struct file_operations pvc_line_proc_fops = { .owner = THIS_MODULE, .open = pvc_line_proc_open, .read = seq_read, .llseek = seq_lseek, .release = single_release, .write = pvc_line_proc_write, };
static ssize_t pvc_scroll_proc_write(struct file *file, const char __user *buf, size_t count, loff_t *pos) { char kbuf[42]; size_t len; int cmd; len = min(count, sizeof(kbuf) - 1); if (copy_from_user(kbuf, buf, len)) return -EFAULT; kbuf[len] = '\0'; cmd = simple_strtol(kbuf, NULL, 10); mutex_lock(&pvc_mutex); if (scroll_interval != 0) del_timer(&timer); if (cmd == 0) { scroll_dir = 0; scroll_interval = 0; } else { if (cmd < 0) { scroll_dir = -1; scroll_interval = -cmd; } else { scroll_dir = 1; scroll_interval = cmd; } add_timer(&timer); } mutex_unlock(&pvc_mutex); return count; }

Contributors

PersonTokensPropCommitsCommitProp
Brian Murphy10362.80%133.33%
Alexey Dobriyan5734.76%133.33%
Daniel Walker42.44%133.33%
Total164100.00%3100.00%


static int pvc_scroll_proc_show(struct seq_file *m, void *v) { mutex_lock(&pvc_mutex); seq_printf(m, "%d\n", scroll_dir * scroll_interval); mutex_unlock(&pvc_mutex); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Brian Murphy2765.85%133.33%
Alexey Dobriyan1024.39%133.33%
Daniel Walker49.76%133.33%
Total41100.00%3100.00%


static int pvc_scroll_proc_open(struct inode *inode, struct file *file) { return single_open(file, pvc_scroll_proc_show, NULL); }

Contributors

PersonTokensPropCommitsCommitProp
Alexey Dobriyan2492.31%150.00%
Brian Murphy27.69%150.00%
Total26100.00%2100.00%

static const struct file_operations pvc_scroll_proc_fops = { .owner = THIS_MODULE, .open = pvc_scroll_proc_open, .read = seq_read, .llseek = seq_lseek, .release = single_release, .write = pvc_scroll_proc_write, };
void pvc_proc_timerfunc(unsigned long data) { if (scroll_dir < 0) pvc_move(DISPLAY|RIGHT); else if (scroll_dir > 0) pvc_move(DISPLAY|LEFT); timer.expires = jiffies + scroll_interval; add_timer(&timer); }

Contributors

PersonTokensPropCommitsCommitProp
Brian Murphy50100.00%1100.00%
Total50100.00%1100.00%


static void pvc_proc_cleanup(void) { remove_proc_subtree(DISPLAY_DIR_NAME, NULL); del_timer_sync(&timer); }

Contributors

PersonTokensPropCommitsCommitProp
Brian Murphy1990.48%133.33%
Al Viro14.76%133.33%
Julia Lawall14.76%133.33%
Total21100.00%3100.00%


static int __init pvc_proc_init(void) { struct proc_dir_entry *dir, *proc_entry; int i; dir = proc_mkdir(DISPLAY_DIR_NAME, NULL); if (dir == NULL) goto error; for (i = 0; i < PVC_NLINES; i++) { strcpy(pvc_lines[i], ""); pvc_linedata[i] = i; } for (i = 0; i < PVC_NLINES; i++) { proc_entry = proc_create_data(pvc_linename[i], 0644, dir, &pvc_line_proc_fops, &pvc_linedata[i]); if (proc_entry == NULL) goto error; } proc_entry = proc_create("scroll", 0644, dir, &pvc_scroll_proc_fops); if (proc_entry == NULL) goto error; init_timer(&timer); timer.function = pvc_proc_timerfunc; return 0; error: pvc_proc_cleanup(); return -ENOMEM; }

Contributors

PersonTokensPropCommitsCommitProp
Brian Murphy14387.20%133.33%
Alexey Dobriyan148.54%133.33%
Al Viro74.27%133.33%
Total164100.00%3100.00%

module_init(pvc_proc_init); module_exit(pvc_proc_cleanup); MODULE_LICENSE("GPL");

Overall Contributors

PersonTokensPropCommitsCommitProp
Brian Murphy63365.73%111.11%
Alexey Dobriyan28629.70%111.11%
Daniel Walker252.60%111.11%
Al Viro161.66%444.44%
Dan Carpenter20.21%111.11%
Julia Lawall10.10%111.11%
Total963100.00%9100.00%
Directory: arch/mips/lasat
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.