Commit 8561c44c9e8baf02a9e3018f76c53aa99038a499
Committed by
Linus Torvalds
1 parent
87687144b4
Exists in
master
and in
7 other branches
proc tty: switch stallion to ->proc_fops
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com> Cc: Alan Cox <alan@lxorguk.ukuu.org.uk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 1 changed file with 50 additions and 76 deletions Side-by-side Diff
drivers/char/stallion.c
... | ... | @@ -32,6 +32,7 @@ |
32 | 32 | #include <linux/tty.h> |
33 | 33 | #include <linux/tty_flip.h> |
34 | 34 | #include <linux/serial.h> |
35 | +#include <linux/seq_file.h> | |
35 | 36 | #include <linux/cd1400.h> |
36 | 37 | #include <linux/sc26198.h> |
37 | 38 | #include <linux/comstats.h> |
38 | 39 | |
39 | 40 | |
40 | 41 | |
41 | 42 | |
42 | 43 | |
43 | 44 | |
44 | 45 | |
... | ... | @@ -1379,52 +1380,47 @@ |
1379 | 1380 | stl_putchar(tty, ch); |
1380 | 1381 | } |
1381 | 1382 | |
1382 | -/*****************************************************************************/ | |
1383 | - | |
1384 | -#define MAXLINE 80 | |
1385 | - | |
1386 | -/* | |
1387 | - * Format info for a specified port. The line is deliberately limited | |
1388 | - * to 80 characters. (If it is too long it will be truncated, if too | |
1389 | - * short then padded with spaces). | |
1390 | - */ | |
1391 | - | |
1392 | -static int stl_portinfo(struct stlport *portp, int portnr, char *pos) | |
1383 | +static void stl_portinfo(struct seq_file *m, struct stlport *portp, int portnr) | |
1393 | 1384 | { |
1394 | - char *sp; | |
1395 | - int sigs, cnt; | |
1385 | + int sigs; | |
1386 | + char sep; | |
1396 | 1387 | |
1397 | - sp = pos; | |
1398 | - sp += sprintf(sp, "%d: uart:%s tx:%d rx:%d", | |
1388 | + seq_printf(m, "%d: uart:%s tx:%d rx:%d", | |
1399 | 1389 | portnr, (portp->hwid == 1) ? "SC26198" : "CD1400", |
1400 | 1390 | (int) portp->stats.txtotal, (int) portp->stats.rxtotal); |
1401 | 1391 | |
1402 | 1392 | if (portp->stats.rxframing) |
1403 | - sp += sprintf(sp, " fe:%d", (int) portp->stats.rxframing); | |
1393 | + seq_printf(m, " fe:%d", (int) portp->stats.rxframing); | |
1404 | 1394 | if (portp->stats.rxparity) |
1405 | - sp += sprintf(sp, " pe:%d", (int) portp->stats.rxparity); | |
1395 | + seq_printf(m, " pe:%d", (int) portp->stats.rxparity); | |
1406 | 1396 | if (portp->stats.rxbreaks) |
1407 | - sp += sprintf(sp, " brk:%d", (int) portp->stats.rxbreaks); | |
1397 | + seq_printf(m, " brk:%d", (int) portp->stats.rxbreaks); | |
1408 | 1398 | if (portp->stats.rxoverrun) |
1409 | - sp += sprintf(sp, " oe:%d", (int) portp->stats.rxoverrun); | |
1399 | + seq_printf(m, " oe:%d", (int) portp->stats.rxoverrun); | |
1410 | 1400 | |
1411 | 1401 | sigs = stl_getsignals(portp); |
1412 | - cnt = sprintf(sp, "%s%s%s%s%s ", | |
1413 | - (sigs & TIOCM_RTS) ? "|RTS" : "", | |
1414 | - (sigs & TIOCM_CTS) ? "|CTS" : "", | |
1415 | - (sigs & TIOCM_DTR) ? "|DTR" : "", | |
1416 | - (sigs & TIOCM_CD) ? "|DCD" : "", | |
1417 | - (sigs & TIOCM_DSR) ? "|DSR" : ""); | |
1418 | - *sp = ' '; | |
1419 | - sp += cnt; | |
1420 | - | |
1421 | - for (cnt = sp - pos; cnt < (MAXLINE - 1); cnt++) | |
1422 | - *sp++ = ' '; | |
1423 | - if (cnt >= MAXLINE) | |
1424 | - pos[(MAXLINE - 2)] = '+'; | |
1425 | - pos[(MAXLINE - 1)] = '\n'; | |
1426 | - | |
1427 | - return MAXLINE; | |
1402 | + sep = ' '; | |
1403 | + if (sigs & TIOCM_RTS) { | |
1404 | + seq_printf(m, "%c%s", sep, "RTS"); | |
1405 | + sep = '|'; | |
1406 | + } | |
1407 | + if (sigs & TIOCM_CTS) { | |
1408 | + seq_printf(m, "%c%s", sep, "CTS"); | |
1409 | + sep = '|'; | |
1410 | + } | |
1411 | + if (sigs & TIOCM_DTR) { | |
1412 | + seq_printf(m, "%c%s", sep, "DTR"); | |
1413 | + sep = '|'; | |
1414 | + } | |
1415 | + if (sigs & TIOCM_CD) { | |
1416 | + seq_printf(m, "%c%s", sep, "DCD"); | |
1417 | + sep = '|'; | |
1418 | + } | |
1419 | + if (sigs & TIOCM_DSR) { | |
1420 | + seq_printf(m, "%c%s", sep, "DSR"); | |
1421 | + sep = '|'; | |
1422 | + } | |
1423 | + seq_putc(m, '\n'); | |
1428 | 1424 | } |
1429 | 1425 | |
1430 | 1426 | /*****************************************************************************/ |
1431 | 1427 | |
1432 | 1428 | |
1433 | 1429 | |
1434 | 1430 | |
... | ... | @@ -1433,30 +1429,17 @@ |
1433 | 1429 | * Port info, read from the /proc file system. |
1434 | 1430 | */ |
1435 | 1431 | |
1436 | -static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data) | |
1432 | +static int stl_proc_show(struct seq_file *m, void *v) | |
1437 | 1433 | { |
1438 | 1434 | struct stlbrd *brdp; |
1439 | 1435 | struct stlpanel *panelp; |
1440 | 1436 | struct stlport *portp; |
1441 | 1437 | unsigned int brdnr, panelnr, portnr; |
1442 | - int totalport, curoff, maxoff; | |
1443 | - char *pos; | |
1438 | + int totalport; | |
1444 | 1439 | |
1445 | - pr_debug("stl_readproc(page=%p,start=%p,off=%lx,count=%d,eof=%p," | |
1446 | - "data=%p\n", page, start, off, count, eof, data); | |
1447 | - | |
1448 | - pos = page; | |
1449 | 1440 | totalport = 0; |
1450 | - curoff = 0; | |
1451 | 1441 | |
1452 | - if (off == 0) { | |
1453 | - pos += sprintf(pos, "%s: version %s", stl_drvtitle, | |
1454 | - stl_drvversion); | |
1455 | - while (pos < (page + MAXLINE - 1)) | |
1456 | - *pos++ = ' '; | |
1457 | - *pos++ = '\n'; | |
1458 | - } | |
1459 | - curoff = MAXLINE; | |
1442 | + seq_printf(m, "%s: version %s\n", stl_drvtitle, stl_drvversion); | |
1460 | 1443 | |
1461 | 1444 | /* |
1462 | 1445 | * We scan through for each board, panel and port. The offset is |
1463 | 1446 | |
1464 | 1447 | |
1465 | 1448 | |
1466 | 1449 | |
1467 | 1450 | |
... | ... | @@ -1469,46 +1452,37 @@ |
1469 | 1452 | if (brdp->state == 0) |
1470 | 1453 | continue; |
1471 | 1454 | |
1472 | - maxoff = curoff + (brdp->nrports * MAXLINE); | |
1473 | - if (off >= maxoff) { | |
1474 | - curoff = maxoff; | |
1475 | - continue; | |
1476 | - } | |
1477 | - | |
1478 | 1455 | totalport = brdnr * STL_MAXPORTS; |
1479 | 1456 | for (panelnr = 0; panelnr < brdp->nrpanels; panelnr++) { |
1480 | 1457 | panelp = brdp->panels[panelnr]; |
1481 | 1458 | if (panelp == NULL) |
1482 | 1459 | continue; |
1483 | 1460 | |
1484 | - maxoff = curoff + (panelp->nrports * MAXLINE); | |
1485 | - if (off >= maxoff) { | |
1486 | - curoff = maxoff; | |
1487 | - totalport += panelp->nrports; | |
1488 | - continue; | |
1489 | - } | |
1490 | - | |
1491 | 1461 | for (portnr = 0; portnr < panelp->nrports; portnr++, |
1492 | 1462 | totalport++) { |
1493 | 1463 | portp = panelp->ports[portnr]; |
1494 | 1464 | if (portp == NULL) |
1495 | 1465 | continue; |
1496 | - if (off >= (curoff += MAXLINE)) | |
1497 | - continue; | |
1498 | - if ((pos - page + MAXLINE) > count) | |
1499 | - goto stl_readdone; | |
1500 | - pos += stl_portinfo(portp, totalport, pos); | |
1466 | + stl_portinfo(m, portp, totalport); | |
1501 | 1467 | } |
1502 | 1468 | } |
1503 | 1469 | } |
1470 | + return 0; | |
1471 | +} | |
1504 | 1472 | |
1505 | - *eof = 1; | |
1506 | - | |
1507 | -stl_readdone: | |
1508 | - *start = page; | |
1509 | - return pos - page; | |
1473 | +static int stl_proc_open(struct inode *inode, struct file *file) | |
1474 | +{ | |
1475 | + return single_open(file, stl_proc_show, NULL); | |
1510 | 1476 | } |
1511 | 1477 | |
1478 | +static const struct file_operations stl_proc_fops = { | |
1479 | + .owner = THIS_MODULE, | |
1480 | + .open = stl_proc_open, | |
1481 | + .read = seq_read, | |
1482 | + .llseek = seq_lseek, | |
1483 | + .release = single_release, | |
1484 | +}; | |
1485 | + | |
1512 | 1486 | /*****************************************************************************/ |
1513 | 1487 | |
1514 | 1488 | /* |
1515 | 1489 | |
... | ... | @@ -2566,9 +2540,9 @@ |
2566 | 2540 | .break_ctl = stl_breakctl, |
2567 | 2541 | .wait_until_sent = stl_waituntilsent, |
2568 | 2542 | .send_xchar = stl_sendxchar, |
2569 | - .read_proc = stl_readproc, | |
2570 | 2543 | .tiocmget = stl_tiocmget, |
2571 | 2544 | .tiocmset = stl_tiocmset, |
2545 | + .proc_fops = &stl_proc_fops, | |
2572 | 2546 | }; |
2573 | 2547 | |
2574 | 2548 | static const struct tty_port_operations stl_port_ops = { |