Re: UART driver problem

2 messages, 2 authors, 2000-04-05 · open the first message on its own page

Re: UART driver problem

From: Pavel Roskin <hidden>
Date: 2000-02-15 14:41:33

Hello, Marcus!

You have fixed uart.c before me (thanks to everybody who pointed it out
for me!), but your arguments were probably not quite convincing, and this
may be the reason why your patch has not yet been applied.

You write:
Strangely enough drivers/char/serial.c is broken as well in standard
kernels. The only difference is that there the copy_from_user() will
appear to always succeed instead of always failing...
drivers/char/serial.c is not broken!

copy_from_user(to, from, len) returns len if it fails and 0 if it
succeeds. Now let's look into drivers/char/serial.c, function rs_write():

c -= copy_from_user(tmp_buf, buf, c);
if (!c) {
        if (!ret)
                ret = -EFAULT;
        break;
}

If copy_from_user succeeds then it returns 0 and c doesn't change. If
copy_from_user fails then it returns the value equal to c. Then c becomes
zero and the function terminates. If no data have been transferred so far,
the result code becomes -EFAULT

Indeed, this code is written in a confusing way, but it is not broken.
Anyway, I don't think that arch/ppc/8xx_io/uart.c should use this style.

Thus your patch is both correct and complete, i.e. it fixes only broken
things. I believe it should be applied both to the 2.2.x and 2.3.x
branches. It is already applied to the version used by my company.

Pavel Roskin


** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

Re: UART driver problem

From: Graham Stoney <hidden>
Date: 2000-04-05 05:34:43

Hi guys,

Pavel Roskin writes:
drivers/char/serial.c is not broken!
[ explaination of why the code looks correct deleted ]

Sorry to dredge up the past here, but I'm still confused about one thing:
why does write(2) to a tty return successfully when passed an invalid address?

Here's an example:

    #include <unistd.h>

    int main()
    {
	printf("bad write returned %d\n", write(1, 0, 1));
	perror("write");
	return 0;
    }

When run on Linux/PPC or Linux/i386, you get:
    bad write returned 1
    write: Success

I would have expected the SunOS result of:
    bad write returned -1
    write: Bad address

There was a discussion about this on the linux-kernel mailing list, under
the subject "bug in write(2) system call", but I can't see where to fix it.

Any clues?

Thanks,
Graham

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help