Re: Add function attribute to copy_from_user to warn for unchecked results

From: Jakub Jelinek
Date: Tue Sep 16 2003 - 04:08:03 EST


On Tue, Sep 16, 2003 at 01:26:32AM -0700, Andrew Morton wrote:
> Arjan van de Ven <arjanv@xxxxxxxxxx> wrote:
> >
> > Hi,
> >
> > gcc 3.4 (CVS) has a new function attribute (warn_unused_result) that
> > will make gcc spit out a warning in the event that a "marked" function's
> > result is ignored by the caller.
>
> Nice.

Note that for macros like get_user something like this should be used
(as the attribute is only for functions):

extern inline __must_check int check_int_result (int arg) { return arg; }

#define get_user(x,ptr) \
check_int_result ( ({ \
int __ret_gu,__val_gu; \
switch(sizeof (*(ptr))) { \
case 1: __get_user_x(1,__ret_gu,__val_gu,ptr); break; \
case 2: __get_user_x(2,__ret_gu,__val_gu,ptr); break; \
case 4: __get_user_x(4,__ret_gu,__val_gu,ptr); break; \
default: __get_user_x(X,__ret_gu,__val_gu,ptr); break; \
} \
(x) = (__typeof__(*(ptr)))__val_gu; \
__ret_gu; \
}) )

Jakub
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/