[Top] [All Lists]

Re: [PATCH V2 05/10] MIPS: lantiq: add watchdog support

To: Ralf Baechle <>
Subject: Re: [PATCH V2 05/10] MIPS: lantiq: add watchdog support
From: Sergei Shtylyov <>
Date: Wed, 02 Mar 2011 20:34:52 +0300
Cc: John Crispin <>, Ralph Hempel <>, Wim Van Sebroeck <>,,
In-reply-to: <>
Original-recipient: rfc822;
References: <> <> <> <>
User-agent: Thunderbird (X11/20090320)

Ralf Baechle wrote:

+       switch (cmd) {
+       case WDIOC_GETSUPPORT:
+               ret = copy_to_user((struct watchdog_info __user *)arg, &ident,
+                               sizeof(ident)) ? -EFAULT : 0;

   Doesn't copy_to_user() return 0 or -EFAULT?

No and that's a common cause of bugs.  copy_{from,to}_user returns the
number of characters that could be be copied so the conversion to an
error code is needed here.

But then the code above would be wrong. Actually, it returns the number of bytes that could NOT be copied as I now see.

The function takes a void argument and there is no benefit from casting
to the full struct watchdog_info __user * pointer type other than maybe
clarity to the human reader.



WBR, Sergei

<Prev in Thread] Current Thread [Next in Thread>