Commit ea00b8e2 authored by Alexey Dobriyan's avatar Alexey Dobriyan Committed by David S. Miller

can: switch to seq_file

create_proc_read_entry() is going to be removed soon.
Signed-off-by: default avatarAlexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4923576b
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#include <linux/hrtimer.h> #include <linux/hrtimer.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/proc_fs.h> #include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/uio.h> #include <linux/uio.h>
#include <linux/net.h> #include <linux/net.h>
#include <linux/netdevice.h> #include <linux/netdevice.h>
...@@ -146,23 +147,18 @@ static char *bcm_proc_getifname(int ifindex) ...@@ -146,23 +147,18 @@ static char *bcm_proc_getifname(int ifindex)
return "???"; return "???";
} }
static int bcm_read_proc(char *page, char **start, off_t off, static int bcm_proc_show(struct seq_file *m, void *v)
int count, int *eof, void *data)
{ {
int len = 0; struct sock *sk = (struct sock *)m->private;
struct sock *sk = (struct sock *)data;
struct bcm_sock *bo = bcm_sk(sk); struct bcm_sock *bo = bcm_sk(sk);
struct bcm_op *op; struct bcm_op *op;
len += snprintf(page + len, PAGE_SIZE - len, ">>> socket %p", seq_printf(m, ">>> socket %p", sk->sk_socket);
sk->sk_socket); seq_printf(m, " / sk %p", sk);
len += snprintf(page + len, PAGE_SIZE - len, " / sk %p", sk); seq_printf(m, " / bo %p", bo);
len += snprintf(page + len, PAGE_SIZE - len, " / bo %p", bo); seq_printf(m, " / dropped %lu", bo->dropped_usr_msgs);
len += snprintf(page + len, PAGE_SIZE - len, " / dropped %lu", seq_printf(m, " / bound %s", bcm_proc_getifname(bo->ifindex));
bo->dropped_usr_msgs); seq_printf(m, " <<<\n");
len += snprintf(page + len, PAGE_SIZE - len, " / bound %s",
bcm_proc_getifname(bo->ifindex));
len += snprintf(page + len, PAGE_SIZE - len, " <<<\n");
list_for_each_entry(op, &bo->rx_ops, list) { list_for_each_entry(op, &bo->rx_ops, list) {
...@@ -172,71 +168,62 @@ static int bcm_read_proc(char *page, char **start, off_t off, ...@@ -172,71 +168,62 @@ static int bcm_read_proc(char *page, char **start, off_t off,
if (!op->frames_abs) if (!op->frames_abs)
continue; continue;
len += snprintf(page + len, PAGE_SIZE - len, seq_printf(m, "rx_op: %03X %-5s ",
"rx_op: %03X %-5s ",
op->can_id, bcm_proc_getifname(op->ifindex)); op->can_id, bcm_proc_getifname(op->ifindex));
len += snprintf(page + len, PAGE_SIZE - len, "[%d]%c ", seq_printf(m, "[%d]%c ", op->nframes,
op->nframes,
(op->flags & RX_CHECK_DLC)?'d':' '); (op->flags & RX_CHECK_DLC)?'d':' ');
if (op->kt_ival1.tv64) if (op->kt_ival1.tv64)
len += snprintf(page + len, PAGE_SIZE - len, seq_printf(m, "timeo=%lld ",
"timeo=%lld ",
(long long) (long long)
ktime_to_us(op->kt_ival1)); ktime_to_us(op->kt_ival1));
if (op->kt_ival2.tv64) if (op->kt_ival2.tv64)
len += snprintf(page + len, PAGE_SIZE - len, seq_printf(m, "thr=%lld ",
"thr=%lld ",
(long long) (long long)
ktime_to_us(op->kt_ival2)); ktime_to_us(op->kt_ival2));
len += snprintf(page + len, PAGE_SIZE - len, seq_printf(m, "# recv %ld (%ld) => reduction: ",
"# recv %ld (%ld) => reduction: ",
op->frames_filtered, op->frames_abs); op->frames_filtered, op->frames_abs);
reduction = 100 - (op->frames_filtered * 100) / op->frames_abs; reduction = 100 - (op->frames_filtered * 100) / op->frames_abs;
len += snprintf(page + len, PAGE_SIZE - len, "%s%ld%%\n", seq_printf(m, "%s%ld%%\n",
(reduction == 100)?"near ":"", reduction); (reduction == 100)?"near ":"", reduction);
if (len > PAGE_SIZE - 200) {
/* mark output cut off */
len += snprintf(page + len, PAGE_SIZE - len, "(..)\n");
break;
}
} }
list_for_each_entry(op, &bo->tx_ops, list) { list_for_each_entry(op, &bo->tx_ops, list) {
len += snprintf(page + len, PAGE_SIZE - len, seq_printf(m, "tx_op: %03X %s [%d] ",
"tx_op: %03X %s [%d] ",
op->can_id, bcm_proc_getifname(op->ifindex), op->can_id, bcm_proc_getifname(op->ifindex),
op->nframes); op->nframes);
if (op->kt_ival1.tv64) if (op->kt_ival1.tv64)
len += snprintf(page + len, PAGE_SIZE - len, "t1=%lld ", seq_printf(m, "t1=%lld ",
(long long) ktime_to_us(op->kt_ival1)); (long long) ktime_to_us(op->kt_ival1));
if (op->kt_ival2.tv64) if (op->kt_ival2.tv64)
len += snprintf(page + len, PAGE_SIZE - len, "t2=%lld ", seq_printf(m, "t2=%lld ",
(long long) ktime_to_us(op->kt_ival2)); (long long) ktime_to_us(op->kt_ival2));
len += snprintf(page + len, PAGE_SIZE - len, "# sent %ld\n", seq_printf(m, "# sent %ld\n", op->frames_abs);
op->frames_abs);
if (len > PAGE_SIZE - 100) {
/* mark output cut off */
len += snprintf(page + len, PAGE_SIZE - len, "(..)\n");
break;
}
} }
seq_putc(m, '\n');
return 0;
}
len += snprintf(page + len, PAGE_SIZE - len, "\n"); static int bcm_proc_open(struct inode *inode, struct file *file)
{
*eof = 1; return single_open(file, bcm_proc_show, PDE(inode)->data);
return len;
} }
static const struct file_operations bcm_proc_fops = {
.owner = THIS_MODULE,
.open = bcm_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
/* /*
* bcm_can_tx - send the (next) CAN frame to the appropriate CAN interface * bcm_can_tx - send the (next) CAN frame to the appropriate CAN interface
* of the given bcm tx op * of the given bcm tx op
...@@ -1515,9 +1502,9 @@ static int bcm_connect(struct socket *sock, struct sockaddr *uaddr, int len, ...@@ -1515,9 +1502,9 @@ static int bcm_connect(struct socket *sock, struct sockaddr *uaddr, int len,
if (proc_dir) { if (proc_dir) {
/* unique socket address as filename */ /* unique socket address as filename */
sprintf(bo->procname, "%p", sock); sprintf(bo->procname, "%p", sock);
bo->bcm_proc_read = create_proc_read_entry(bo->procname, 0644, bo->bcm_proc_read = proc_create_data(bo->procname, 0644,
proc_dir, proc_dir,
bcm_read_proc, sk); &bcm_proc_fops, sk);
} }
return 0; return 0;
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment