[PATCH 0/2] Small tasks

33 views
Skip to first unread message

Somya Anand

unread,
Oct 12, 2014, 3:35:22 AM10/12/14
to ar...@arndb.de, opw-k...@googlegroups.com, somyaa...@gmail.com
[PATCH 1] Staging: dgnc: replace timeval with ktime_t
* Small task for y2038 project.

[PATCH 2] Staging: dgnc: Remove sniff code
* Small task for kernel tinification project.

Somya Anand (2):
Staging: dgnc: replace timeval with ktime_t
Staging: dgnc: Remove sniff code

drivers/staging/dgnc/dgnc_cls.c | 4 --
drivers/staging/dgnc/dgnc_driver.h | 14 ----
drivers/staging/dgnc/dgnc_neo.c | 3 -
drivers/staging/dgnc/dgnc_tty.c | 128 +------------------------------------
drivers/staging/dgnc/dgnc_tty.h | 2 -
5 files changed, 1 insertion(+), 150 deletions(-)

--
1.9.1

Somya Anand

unread,
Oct 12, 2014, 3:35:33 AM10/12/14
to ar...@arndb.de, opw-k...@googlegroups.com, somyaa...@gmail.com
'timeval' is used to create header timestamps for the data dump.

32-bit systems using 'struct timeval' will break in the year 2038,
So we have to replace that code with more appropriate types.
This patch changes the dgnc driver to use ktime_t instead of timeval.

It uses ktime_get() to get current timestamp. It is better than
do_gettimeofday() as it uses the monotonic clock.

Signed-off-by: Somya Anand <somyaa...@gmail.com>
---
drivers/staging/dgnc/dgnc_tty.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c
index 03c1506..bdc12d3 100644
--- a/drivers/staging/dgnc/dgnc_tty.c
+++ b/drivers/staging/dgnc/dgnc_tty.c
@@ -49,7 +49,7 @@
#include <linux/delay.h> /* For udelay */
#include <linux/uaccess.h> /* For copy_from_user/copy_to_user */
#include <linux/pci.h>
-
+#include <linux/ktime.h>
#include "dgnc_driver.h"
#include "dgnc_tty.h"
#include "dgnc_types.h"
@@ -452,7 +452,7 @@ void dgnc_tty_uninit(struct dgnc_board *brd)
*/
void dgnc_sniff_nowait_nolock(struct channel_t *ch, unsigned char *text, unsigned char *buf, int len)
{
- struct timeval tv;
+ ktime_t kt;
int n;
int r;
int nbuf;
@@ -471,10 +471,9 @@ void dgnc_sniff_nowait_nolock(struct channel_t *ch, unsigned char *text, unsigne
if (!(ch->ch_sniff_flags & SNIFF_OPEN))
goto exit;

- do_gettimeofday(&tv);
-
+ kt = ktime_get();
/* Create our header for data dump */
- p += sprintf(p, "<%ld %ld><%s><", tv.tv_sec, tv.tv_usec, text);
+ p += sprintf(p, "<%llu %llu><%s><", ktime_divns(kt, NSEC_PER_SEC), ktime_to_us(kt), text);
tmpbuflen = p - tmpbuf;

do {
--
1.9.1

Somya Anand

unread,
Oct 12, 2014, 3:35:47 AM10/12/14
to ar...@arndb.de, opw-k...@googlegroups.com, somyaa...@gmail.com
The output written by dgnc_sniff_nowait_nolock() is never used
anywhere since commit 35cf9045931 ("staging: dgnc: removes proc code")
deleted the code that used to copy it to user space.

This patch removes dgnc_sniff_nowait_nolock() and all ch_sniff_* members
of struct channel_t defined in "dgnc_driver.h". It also removes their usage
from the driver files.

Signed-off-by: Somya Anand <somyaa...@gmail.com>
---
drivers/staging/dgnc/dgnc_cls.c | 4 --
drivers/staging/dgnc/dgnc_driver.h | 14 -----
drivers/staging/dgnc/dgnc_neo.c | 3 -
drivers/staging/dgnc/dgnc_tty.c | 125 -------------------------------------
drivers/staging/dgnc/dgnc_tty.h | 2 -
5 files changed, 148 deletions(-)

diff --git a/drivers/staging/dgnc/dgnc_cls.c b/drivers/staging/dgnc/dgnc_cls.c
index a17f4f6..1f013ed 100644
--- a/drivers/staging/dgnc/dgnc_cls.c
+++ b/drivers/staging/dgnc/dgnc_cls.c
@@ -928,8 +928,6 @@ static void cls_copy_data_from_uart_to_queue(struct channel_t *ch)
ch->ch_equeue[head] = linestatus & (UART_LSR_BI | UART_LSR_PE
| UART_LSR_FE);
ch->ch_rqueue[head] = readb(&ch->ch_cls_uart->txrx);
- dgnc_sniff_nowait_nolock(ch, "UART READ",
- ch->ch_rqueue + head, 1);

qleft--;

@@ -1098,8 +1096,6 @@ static void cls_copy_data_from_queue_to_uart(struct channel_t *ch)
ch->ch_tun.un_flags |= (UN_EMPTY);
}
writeb(ch->ch_wqueue[ch->ch_w_tail], &ch->ch_cls_uart->txrx);
- dgnc_sniff_nowait_nolock(ch, "UART WRITE",
- ch->ch_wqueue + ch->ch_w_tail, 1);
ch->ch_w_tail++;
ch->ch_w_tail &= WQUEUEMASK;
ch->ch_txcount++;
diff --git a/drivers/staging/dgnc/dgnc_driver.h b/drivers/staging/dgnc/dgnc_driver.h
index f901957c..b52a182 100644
--- a/drivers/staging/dgnc/dgnc_driver.h
+++ b/drivers/staging/dgnc/dgnc_driver.h
@@ -134,8 +134,6 @@
#define _POSIX_VDISABLE '\0'
#endif

-#define SNIFF_MAX 65536 /* Sniff buffer size (2^n) */
-#define SNIFF_MASK (SNIFF_MAX - 1) /* Sniff wrap mask */

/*
* All the possible states the driver can be while being loaded.
@@ -342,13 +340,6 @@ struct un_t {
#define CH_FORCED_STOP 0x20000 /* Output is forcibly stopped */
#define CH_FORCED_STOPI 0x40000 /* Input is forcibly stopped */

-/*
- * Definitions for ch_sniff_flags
- */
-#define SNIFF_OPEN 0x1
-#define SNIFF_WAIT_DATA 0x2
-#define SNIFF_WAIT_SPACE 0x4
-

/* Our Read/Error/Write queue sizes */
#define RQUEUEMASK 0x1FFF /* 8 K - 1 */
@@ -442,11 +433,6 @@ struct channel_t {
struct proc_dir_entry *proc_entry_pointer;
struct dgnc_proc_entry *dgnc_channel_table;

- uint ch_sniff_in;
- uint ch_sniff_out;
- char *ch_sniff_buf; /* Sniff buffer for proc */
- ulong ch_sniff_flags; /* Channel flags */
- wait_queue_head_t ch_sniff_wait;
};

/*
diff --git a/drivers/staging/dgnc/dgnc_neo.c b/drivers/staging/dgnc/dgnc_neo.c
index a5bd08f..e8b9103 100644
--- a/drivers/staging/dgnc/dgnc_neo.c
+++ b/drivers/staging/dgnc/dgnc_neo.c
@@ -1224,7 +1224,6 @@ static void neo_copy_data_from_uart_to_queue(struct channel_t *ch)

/* Copy data from uart to the queue */
memcpy_fromio(ch->ch_rqueue + head, &ch->ch_neo_uart->txrxburst, n);
- dgnc_sniff_nowait_nolock(ch, "UART READ", ch->ch_rqueue + head, n);

/*
* Since RX_FIFO_DATA_ERROR was 0, we are guarenteed
@@ -1310,7 +1309,6 @@ static void neo_copy_data_from_uart_to_queue(struct channel_t *ch)

memcpy_fromio(ch->ch_rqueue + head, &ch->ch_neo_uart->txrxburst, 1);
ch->ch_equeue[head] = (unsigned char) linestatus;
- dgnc_sniff_nowait_nolock(ch, "UART READ", ch->ch_rqueue + head, 1);

/* Ditch any remaining linestatus value. */
linestatus = 0;
@@ -1563,7 +1561,6 @@ static void neo_copy_data_from_queue_to_uart(struct channel_t *ch)
}

memcpy_toio(&ch->ch_neo_uart->txrxburst, ch->ch_wqueue + tail, s);
- dgnc_sniff_nowait_nolock(ch, "UART WRITE", ch->ch_wqueue + tail, s);

/* Add and flip queue if needed */
tail = (tail + s) & WQUEUEMASK;
diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c
index bdc12d3..dc8afa9 100644
--- a/drivers/staging/dgnc/dgnc_tty.c
+++ b/drivers/staging/dgnc/dgnc_tty.c
@@ -371,7 +371,6 @@ int dgnc_tty_init(struct dgnc_board *brd)
init_waitqueue_head(&ch->ch_flags_wait);
init_waitqueue_head(&ch->ch_tun.un_flags_wait);
init_waitqueue_head(&ch->ch_pun.un_flags_wait);
- init_waitqueue_head(&ch->ch_sniff_wait);

{
struct device *classp;
@@ -446,126 +445,6 @@ void dgnc_tty_uninit(struct dgnc_board *brd)

#define TMPBUFLEN (1024)

-/*
- * dgnc_sniff - Dump data out to the "sniff" buffer if the
- * proc sniff file is opened...
- */
-void dgnc_sniff_nowait_nolock(struct channel_t *ch, unsigned char *text, unsigned char *buf, int len)
-{
- ktime_t kt;
- int n;
- int r;
- int nbuf;
- int i;
- int tmpbuflen;
- char *tmpbuf;
- char *p;
- int too_much_data;
-
- tmpbuf = kzalloc(TMPBUFLEN, GFP_ATOMIC);
- if (!tmpbuf)
- return;
- p = tmpbuf;
-
- /* Leave if sniff not open */
- if (!(ch->ch_sniff_flags & SNIFF_OPEN))
- goto exit;
-
- kt = ktime_get();
- /* Create our header for data dump */
- p += sprintf(p, "<%llu %llu><%s><", ktime_divns(kt, NSEC_PER_SEC), ktime_to_us(kt), text);
- tmpbuflen = p - tmpbuf;
-
- do {
- too_much_data = 0;
-
- for (i = 0; i < len && tmpbuflen < (TMPBUFLEN - 4); i++) {
- p += sprintf(p, "%02x ", *buf);
- buf++;
- tmpbuflen = p - tmpbuf;
- }
-
- if (tmpbuflen < (TMPBUFLEN - 4)) {
- if (i > 0)
- p += sprintf(p - 1, "%s\n", ">");
- else
- p += sprintf(p, "%s\n", ">");
- } else {
- too_much_data = 1;
- len -= i;
- }
-
- nbuf = strlen(tmpbuf);
- p = tmpbuf;
-
- /*
- * Loop while data remains.
- */
- while (nbuf > 0 && ch->ch_sniff_buf) {
- /*
- * Determine the amount of available space left in the
- * buffer. If there's none, wait until some appears.
- */
- n = (ch->ch_sniff_out - ch->ch_sniff_in - 1) & SNIFF_MASK;
-
- /*
- * If there is no space left to write to in our sniff buffer,
- * we have no choice but to drop the data.
- * We *cannot* sleep here waiting for space, because this
- * function was probably called by the interrupt/timer routines!
- */
- if (n == 0)
- goto exit;
-
- /*
- * Copy as much data as will fit.
- */
-
- if (n > nbuf)
- n = nbuf;
-
- r = SNIFF_MAX - ch->ch_sniff_in;
-
- if (r <= n) {
- memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, r);
-
- n -= r;
- ch->ch_sniff_in = 0;
- p += r;
- nbuf -= r;
- }
-
- memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, n);
-
- ch->ch_sniff_in += n;
- p += n;
- nbuf -= n;
-
- /*
- * Wakeup any thread waiting for data
- */
- if (ch->ch_sniff_flags & SNIFF_WAIT_DATA) {
- ch->ch_sniff_flags &= ~SNIFF_WAIT_DATA;
- wake_up_interruptible(&ch->ch_sniff_wait);
- }
- }
-
- /*
- * If the user sent us too much data to push into our tmpbuf,
- * we need to keep looping around on all the data.
- */
- if (too_much_data) {
- p = tmpbuf;
- tmpbuflen = 0;
- }
-
- } while (too_much_data);
-
-exit:
- kfree(tmpbuf);
-}
-
-
/*=======================================================================
*
* dgnc_wmove - Write data to transmit queue.
@@ -780,8 +659,6 @@ void dgnc_input(struct channel_t *ch)
tty_insert_flip_string(tp->port, ch->ch_rqueue + tail, s);
}

- dgnc_sniff_nowait_nolock(ch, "USER READ", ch->ch_rqueue + tail, s);
-
tail += s;
n -= s;
/* Flip queue if needed */
@@ -1973,7 +1850,6 @@ static int dgnc_tty_write(struct tty_struct *tty,
if (n >= remain) {
n -= remain;
memcpy(ch->ch_wqueue + head, buf, remain);
- dgnc_sniff_nowait_nolock(ch, "USER WRITE", ch->ch_wqueue + head, remain);
head = 0;
buf += remain;
}
@@ -1984,7 +1860,6 @@ static int dgnc_tty_write(struct tty_struct *tty,
*/
remain = n;
memcpy(ch->ch_wqueue + head, buf, remain);
- dgnc_sniff_nowait_nolock(ch, "USER WRITE", ch->ch_wqueue + head, remain);
head += remain;
}

diff --git a/drivers/staging/dgnc/dgnc_tty.h b/drivers/staging/dgnc/dgnc_tty.h
index 58eef25..3975f04 100644
--- a/drivers/staging/dgnc/dgnc_tty.h
+++ b/drivers/staging/dgnc/dgnc_tty.h
@@ -37,6 +37,4 @@ void dgnc_carrier(struct channel_t *ch);
void dgnc_wakeup_writes(struct channel_t *ch);
void dgnc_check_queue_flow_control(struct channel_t *ch);

-void dgnc_sniff_nowait_nolock(struct channel_t *ch, unsigned char *text, unsigned char *buf, int nbuf);
-
#endif
--
1.9.1

Reply all
Reply to author
Forward
0 new messages