mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Julia Lawall <julia.lawall@lip6.fr>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: Rusty Russell <rusty@rustcorp.com.au>,
	Thomas Meyer <thomas@m3y3r.de>,
	mst@redhat.com, grant.likely@linaro.org, rob.herring@calxeda.com,
	linux-kernel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Julia Lawall <Julia.Lawall@lip6.fr>
Subject: Re: [RFC] PTR_ERR: return 0 if ptr isn't an error value.
Date: Sat, 8 Jun 2013 23:07:59 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.02.1306082305220.1968@localhost6.localdomain6> (raw)
In-Reply-To: <20130603071526.GA5483@pengutronix.de>

[-- Attachment #1: Type: TEXT/PLAIN, Size: 3142 bytes --]

On Mon, 3 Jun 2013, Uwe Kleine-König wrote:

> Hello Rusty,
> 
> [added akpm to Cc: who took the patch back then and Julia for the
> coccinelle part below]
> 
> On Mon, Jun 03, 2013 at 11:59:15AM +0930, Rusty Russell wrote:
> > 
> > Back in 2011, Uwe Kleine-König added the nonsensically-named
> > PTR_RET(), providing a means to avoid if() statements in code (commit 
> > fa9ee9c4b9).
> > 
> > Instead, just make PTR_ERR() return 0 if the pointer isn't an error
> > value.  This is harmless, since PTR_ERR() should have never been
> > passed a non-error value.  And GCC is usually smart enough to remove
> > the extra test if IS_ERR() has already been called.
> I wonder in which situations gcc fails to be smart enough. Did you check
> this?
> 
> > My vmlinux text increased by 300 bytes:
> > 
> > 	   text	   data	    bss	    dec	    hex	filename
> > 	6029452	 491628	2576384	9097464	 8ad0f8	vmlinux
> > 	6029721	 491628	2576384	9097733	 8ad205	vmlinux.PTR_ERR
> > 
> > Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > Cc: Thomas Meyer <thomas@m3y3r.de>
> > Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
> > 
> > diff --git a/include/linux/err.h b/include/linux/err.h
> > index f2edce2..621d859 100644
> > --- a/include/linux/err.h
> > +++ b/include/linux/err.h
> > @@ -24,14 +24,16 @@ static inline void * __must_check ERR_PTR(long error)
> >  	return (void *) error;
> >  }
> >  
> > -static inline long __must_check PTR_ERR(const void *ptr)
> > +static inline long __must_check IS_ERR(const void *ptr)
> >  {
> > -	return (long) ptr;
> > +	return IS_ERR_VALUE((unsigned long)ptr);
> >  }
> >  
> > -static inline long __must_check IS_ERR(const void *ptr)
> > +static inline long __must_check PTR_ERR(const void *ptr)
> >  {
> > -	return IS_ERR_VALUE((unsigned long)ptr);
> > +	if (IS_ERR(ptr))
> > +		return (long) ptr;
> > +	return 0;
> >  }
> >  
> >  static inline long __must_check IS_ERR_OR_NULL(const void *ptr)
> > @@ -52,14 +54,7 @@ static inline void * __must_check ERR_CAST(const void *ptr)
> >  	return (void *) ptr;
> >  }
> >  
> > -static inline int __must_check PTR_RET(const void *ptr)
> > -{
> > -	if (IS_ERR(ptr))
> > -		return PTR_ERR(ptr);
> > -	else
> > -		return 0;
> > -}
> > -
> > +#define PTR_RET	PTR_ERR
> I'd add a comment here that PTR_RET shouldn't be used anymore.
> 
> >  #endif
> >  
> >  #endif /* _LINUX_ERR_H */
> > 
> 
> Is it worth to apply the same change to tools/virtio/linux/err.h to
> minimize the chance for later surprises?
> Also scripts/coccinelle/api/ptr_ret.cocci starts giving false warnings.
> 
> Other than that I think the change is fine.

For a random example, here is a function that currently uses PTR_RET:

static int __net_init iptable_raw_net_init(struct net *net)
{
        struct ipt_replace *repl;

        repl = ipt_alloc_initial_table(&packet_raw);
	if (repl == NULL)
                return -ENOMEM;
        net->ipv4.iptable_raw =
                ipt_register_table(net, &packet_raw, repl);
	kfree(repl);
        return PTR_RET(net->ipv4.iptable_raw);
}

If it becomes return PTR_ERR(...); at the end, won't it look like the 
function always fails?

julia

  reply	other threads:[~2013-06-08 21:08 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-01  9:56 [PATCH] virtio-mmio: Cocci spatch "ptr_ret.spatch" Thomas Meyer
2013-06-03  2:29 ` [RFC] PTR_ERR: return 0 if ptr isn't an error value Rusty Russell
2013-06-03  7:15   ` Uwe Kleine-König
2013-06-08 21:07     ` Julia Lawall [this message]
2013-06-13  4:37       ` Rusty Russell
2013-06-13  7:30         ` Michael S. Tsirkin
2013-06-13  7:56           ` Julia Lawall
2013-06-16  2:44             ` Rusty Russell
2013-06-16  4:42               ` [PATCH 1/9] PTR_RET is now PTR_ERR_OR_ZERO Rusty Russell
2013-06-16  4:42                 ` [PATCH 2/9] PTR_RET is now PTR_ERR_OR_ZERO(): Replace most Rusty Russell
2013-06-20  6:05                   ` David Miller
2013-06-25  7:47                   ` Benjamin Herrenschmidt
2013-06-16  4:42                 ` [PATCH 3/9] s390: Replace weird use of PTR_RET Rusty Russell
2013-06-17  5:03                   ` Heiko Carstens
2013-06-16  4:42                 ` [PATCH 4/9] acpi: " Rusty Russell
2013-06-16 11:55                   ` Rafael J. Wysocki
2013-06-16  4:42                 ` [PATCH 5/9] pinctrl: don't use PTR_RET() Rusty Russell
2013-06-16  4:42                 ` [PATCH 6/9] remoteproc: " Rusty Russell
2013-06-17  3:15                   ` Ohad Ben-Cohen
2013-06-17  3:49                     ` Rusty Russell
2013-06-16  4:42                 ` [PATCH 7/9] staging/zcache: " Rusty Russell
2013-06-16  4:42                 ` [PATCH 8/9] x86: remove weird PTR_ERR() in do_debug Rusty Russell
2013-06-19 18:43                   ` [tip:x86/debug] x86: Remove " tip-bot for Rusty Russell
2013-06-16  4:42                 ` [PATCH 9/9] mm/oom_kill: remove weird use of ERR_PTR()/PTR_ERR() Rusty Russell
2013-06-16 18:11                   ` David Rientjes
2013-06-17  3:50                     ` Rusty Russell
2013-06-09  5:55     ` [RFC] PTR_ERR: return 0 if ptr isn't an error value Rusty Russell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.02.1306082305220.1968@localhost6.localdomain6 \
    --to=julia.lawall@lip6.fr \
    --cc=akpm@linux-foundation.org \
    --cc=grant.likely@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=rob.herring@calxeda.com \
    --cc=rusty@rustcorp.com.au \
    --cc=thomas@m3y3r.de \
    --cc=u.kleine-koenig@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®