lkml.org 
[lkml]   [2008]   [May]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Date
    From
    SubjectRe: [PATCH 1/6] ERR_PTR: if errno value is known at compile time, make sure it's valid
    On Sun, May 18, 2008 at 11:56:53PM +0200, Marcin Slusarz wrote:
    > ERR_PTR is easy to call with wrong argument (positive errno),
    > and this error lead to catastrophic event - oops or kernel panic
    > (dereference of invalid pointer).
    >
    > As most of error handling code paths are rarely tested, this kind of
    > bug can be hidden for years.
    >
    > (Currently there are > 1400 calls of ERR_PTR with constant argument.)

    > --- a/include/linux/err.h
    > +++ b/include/linux/err.h
    > @@ -19,11 +19,13 @@
    >
    > #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
    >
    > -static inline void *ERR_PTR(long error)
    > +static inline void *__ERR_PTR(long error)
    > {
    > return (void *) error;
    > }
    >
    > +#define ERR_PTR(error) (BUILD_BUG_ON(__builtin_constant_p(error) && !IS_ERR_VALUE(error)), __ERR_PTR(error))

    This needs comment that this construct must be a macro, otherwise gcc
    does something stupid and doesn't break the build (at least in the case
    below). BTW, I used grep(1) to find it.


    [PATCH] xprtrdma: fix ERR_PTR(E typo

    Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
    ---

    net/sunrpc/xprtrdma/svc_rdma_transport.c | 2 +-
    1 file changed, 1 insertion(+), 1 deletion(-)

    --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
    +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
    @@ -661,7 +661,7 @@ static struct svc_xprt *svc_rdma_create(struct svc_serv *serv,

    cma_xprt = rdma_create_xprt(serv, 1);
    if (!cma_xprt)
    - return ERR_PTR(ENOMEM);
    + return ERR_PTR(-ENOMEM);
    xprt = &cma_xprt->sc_xprt;

    listen_id = rdma_create_id(rdma_listen_handler, cma_xprt, RDMA_PS_TCP);


    \
     
     \ /
      Last update: 2008-05-19 07:45    [W:0.024 / U:0.960 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site