Date: Sun, 17 Aug 2008 13:23:02 GMT From: Jacek Wikiera <jacek@wikiera.net> To: freebsd-gnats-submit@FreeBSD.org Subject: docs/126590: Write routine called forever in Sample Echo Pseudo-Device Driver Message-ID: <200808171323.m7HDN2Ha087622@www.freebsd.org> Resent-Message-ID: <200808171330.m7HDU1HD067362@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 126590 >Category: docs >Synopsis: Write routine called forever in Sample Echo Pseudo-Device Driver >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-doc >State: open >Quarter: >Keywords: >Date-Required: >Class: doc-bug >Submitter-Id: current-users >Arrival-Date: Sun Aug 17 13:30:01 UTC 2008 >Closed-Date: >Last-Modified: >Originator: Jacek Wikiera >Release: n/a >Organization: n/a >Environment: n/a >Description: Location: FreeBSD Architecture Handbook, 9.4 Character Devices, example driver code. http://www.freebsd.org/doc/en_US.ISO8859-1/books/arch-handbook/driverbasics-char.html Description: The function echo_write() is incorrect - it does not zero an important variable and makes the example a bad example. If code is built from the example, the function echo_write() does not zeroe uio->uio_resid and thus fails to tell the OS that all the data has been consumed. The function is called again and again forever (until the caller is terminated, I guess). >How-To-Repeat: Build the example code, and type at the command prompt: cat > /dev/echo Next type a line followed by return. This will cause the file /dev/echo to be open, and continuous calls to echo_write subroutine. The cat program will hang now and not able to read Ctrl-D from the terminal. Ctrl-C is needed. >Fix: In the function echo_write() add the following line: uio->uio_resid = 0; This will tell the OS that all the data has been consumed. See the source of the null device for this hint. Patch attached with submission follows: --- driverbasics-char.html 2008-08-16 06:08:26.000000000 +0200 +++ driverbasics-char_fix.html 2008-08-17 15:10:37.531250000 +0200 @@ -200,6 +200,8 @@ *(echomsg->msg + MIN(uio->uio_iov->iov_len, BUFFERSIZE - 1)) = 0; echomsg->len = MIN(uio->uio_iov->iov_len, BUFFERSIZE); + uio->uio_resid = 0; /* signall that all data is consumed */ + if (err != 0) { uprintf("Write failed: bad address!\n"); } >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200808171323.m7HDN2Ha087622>