linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] virtio-mmio: Cocci spatch "ptr_ret.spatch"
@ 2013-06-01  9:56 Thomas Meyer
  2013-06-03  2:29 ` [RFC] PTR_ERR: return 0 if ptr isn't an error value Rusty Russell
  0 siblings, 1 reply; 27+ messages in thread
From: Thomas Meyer @ 2013-06-01  9:56 UTC (permalink / raw)
  To: rusty, mst, grant.likely, rob.herring, virtualization, linux-kernel


Signed-off-by: Thomas Meyer <thomas@m3y3r.de>
---

diff -u -p a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
--- a/drivers/virtio/virtio_mmio.c
+++ b/drivers/virtio/virtio_mmio.c
@@ -567,10 +567,7 @@ static int vm_cmdline_set(const char *de
 	pdev = platform_device_register_resndata(&vm_cmdline_parent,
 			"virtio-mmio", vm_cmdline_id++,
 			resources, ARRAY_SIZE(resources), NULL, 0);
-	if (IS_ERR(pdev))
-		return PTR_ERR(pdev);
-
-	return 0;
+	return PTR_RET(pdev);
 }
 
 static int vm_cmdline_get_device(struct device *dev, void *data)



^ permalink raw reply	[flat|nested] 27+ messages in thread

* [RFC] PTR_ERR: return 0 if ptr isn't an error value.
  2013-06-01  9:56 [PATCH] virtio-mmio: Cocci spatch "ptr_ret.spatch" Thomas Meyer
@ 2013-06-03  2:29 ` Rusty Russell
  2013-06-03  7:15   ` Uwe Kleine-König
  0 siblings, 1 reply; 27+ messages in thread
From: Rusty Russell @ 2013-06-03  2:29 UTC (permalink / raw)
  To: Thomas Meyer, mst, grant.likely, rob.herring, linux-kernel
  Cc: Uwe Kleine-König


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.

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
 #endif
 
 #endif /* _LINUX_ERR_H */

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [RFC] PTR_ERR: return 0 if ptr isn't an error value.
  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
  2013-06-09  5:55     ` [RFC] PTR_ERR: return 0 if ptr isn't an error value Rusty Russell
  0 siblings, 2 replies; 27+ messages in thread
From: Uwe Kleine-König @ 2013-06-03  7:15 UTC (permalink / raw)
  To: Rusty Russell
  Cc: Thomas Meyer, mst, grant.likely, rob.herring, linux-kernel,
	Andrew Morton, Julia Lawall

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.

Best regards
Uwe


-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [RFC] PTR_ERR: return 0 if ptr isn't an error value.
  2013-06-03  7:15   ` Uwe Kleine-König
@ 2013-06-08 21:07     ` Julia Lawall
  2013-06-13  4:37       ` Rusty Russell
  2013-06-09  5:55     ` [RFC] PTR_ERR: return 0 if ptr isn't an error value Rusty Russell
  1 sibling, 1 reply; 27+ messages in thread
From: Julia Lawall @ 2013-06-08 21:07 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Rusty Russell, Thomas Meyer, mst, grant.likely, rob.herring,
	linux-kernel, Andrew Morton, Julia Lawall

[-- 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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [RFC] PTR_ERR: return 0 if ptr isn't an error value.
  2013-06-03  7:15   ` Uwe Kleine-König
  2013-06-08 21:07     ` Julia Lawall
@ 2013-06-09  5:55     ` Rusty Russell
  1 sibling, 0 replies; 27+ messages in thread
From: Rusty Russell @ 2013-06-09  5:55 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Thomas Meyer, mst, grant.likely, rob.herring, linux-kernel,
	Andrew Morton, Julia Lawall

Uwe Kleine-König <u.kleine-koenig@pengutronix.de> writes:
> 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?

Good q.  I just wrote a simple test to confirm that GCC usually did,
then compared the text sizes.  Since it was bigger, I assume GCC isn't
doing it all the time.

Hmm, first change is in do_debug.  Ah, no surprise here:

	if (notify_die(DIE_DEBUG, "debug", regs, PTR_ERR(&dr6), error_code,
							SIGTRAP) == NOTIFY_STOP)
		goto exit;

Huh?  dr6 is on the stack?  Ancient, fixed.

I'll wade through the other differences after the weekend...

Cheers,
Rusty.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [RFC] PTR_ERR: return 0 if ptr isn't an error value.
  2013-06-08 21:07     ` Julia Lawall
@ 2013-06-13  4:37       ` Rusty Russell
  2013-06-13  7:30         ` Michael S. Tsirkin
  0 siblings, 1 reply; 27+ messages in thread
From: Rusty Russell @ 2013-06-13  4:37 UTC (permalink / raw)
  To: Julia Lawall, Uwe Kleine-König
  Cc: Thomas Meyer, mst, grant.likely, rob.herring, linux-kernel,
	Andrew Morton, Julia Lawall

Julia Lawall <julia.lawall@lip6.fr> writes:
> On Mon, 3 Jun 2013, Uwe Kleine-König wrote:
> For a random example, here is a function that currently uses PTR_RET:

Heheh, nice choice: I think I wrote that code originally :)

> 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?

That is a valid point, though in this case the reader will know that
can't be the case.

On the other hand, there's an incremental learning curve cost to every
convenience function we add.  There are only 50 places where we use
PTR_RET(), so it's not saving us very much typing over the clearest
solution: open-coding the test.

I think using PTR_ERR() is a less bad solution than promoting PTR_RET,
which has a non-obvious name.

Cheers,
Rusty.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [RFC] PTR_ERR: return 0 if ptr isn't an error value.
  2013-06-13  4:37       ` Rusty Russell
@ 2013-06-13  7:30         ` Michael S. Tsirkin
  2013-06-13  7:56           ` Julia Lawall
  0 siblings, 1 reply; 27+ messages in thread
From: Michael S. Tsirkin @ 2013-06-13  7:30 UTC (permalink / raw)
  To: Rusty Russell
  Cc: Julia Lawall, Uwe Kleine-König, Thomas Meyer, grant.likely,
	rob.herring, linux-kernel, Andrew Morton

On Thu, Jun 13, 2013 at 02:07:40PM +0930, Rusty Russell wrote:
> Julia Lawall <julia.lawall@lip6.fr> writes:
> > On Mon, 3 Jun 2013, Uwe Kleine-König wrote:
> > For a random example, here is a function that currently uses PTR_RET:
> 
> Heheh, nice choice: I think I wrote that code originally :)
> 
> > 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?
> 
> That is a valid point, though in this case the reader will know that
> can't be the case.
> 
> On the other hand, there's an incremental learning curve cost to every
> convenience function we add.  There are only 50 places where we use
> PTR_RET(), so it's not saving us very much typing over the clearest
> solution: open-coding the test.
> 
> I think using PTR_ERR() is a less bad solution than promoting PTR_RET,
> which has a non-obvious name.
> 
> Cheers,
> Rusty.

Will a longer name make the function more obvious?
	PTR_ERR_OR_ZERO() ?
	PTR_ERR0() ?
PTR_ERR() can then stay simple for cases where we know we
are on the error path.

-- 
MST

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [RFC] PTR_ERR: return 0 if ptr isn't an error value.
  2013-06-13  7:30         ` Michael S. Tsirkin
@ 2013-06-13  7:56           ` Julia Lawall
  2013-06-16  2:44             ` Rusty Russell
  0 siblings, 1 reply; 27+ messages in thread
From: Julia Lawall @ 2013-06-13  7:56 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Rusty Russell, Julia Lawall, Uwe Kleine-König, Thomas Meyer,
	grant.likely, rob.herring, linux-kernel, Andrew Morton

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

On Thu, 13 Jun 2013, Michael S. Tsirkin wrote:

> On Thu, Jun 13, 2013 at 02:07:40PM +0930, Rusty Russell wrote:
> > Julia Lawall <julia.lawall@lip6.fr> writes:
> > > On Mon, 3 Jun 2013, Uwe Kleine-König wrote:
> > > For a random example, here is a function that currently uses PTR_RET:
> >
> > Heheh, nice choice: I think I wrote that code originally :)
> >
> > > 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?
> >
> > That is a valid point, though in this case the reader will know that
> > can't be the case.
> >
> > On the other hand, there's an incremental learning curve cost to every
> > convenience function we add.  There are only 50 places where we use
> > PTR_RET(), so it's not saving us very much typing over the clearest
> > solution: open-coding the test.
> >
> > I think using PTR_ERR() is a less bad solution than promoting PTR_RET,
> > which has a non-obvious name.
> >
> > Cheers,
> > Rusty.
>
> Will a longer name make the function more obvious?
> 	PTR_ERR_OR_ZERO() ?
> 	PTR_ERR0() ?
> PTR_ERR() can then stay simple for cases where we know we
> are on the error path.

I was thinking of something along those lines.  And in that case, PTR_ERR
could stay without the additional test.

julia

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [RFC] PTR_ERR: return 0 if ptr isn't an error value.
  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
  0 siblings, 1 reply; 27+ messages in thread
From: Rusty Russell @ 2013-06-16  2:44 UTC (permalink / raw)
  To: Julia Lawall, Michael S. Tsirkin
  Cc: Julia Lawall, Uwe Kleine-König, Thomas Meyer, grant.likely,
	rob.herring, linux-kernel, Andrew Morton

Julia Lawall <julia.lawall@lip6.fr> writes:
> On Thu, 13 Jun 2013, Michael S. Tsirkin wrote:
>
>> On Thu, Jun 13, 2013 at 02:07:40PM +0930, Rusty Russell wrote:
>> > I think using PTR_ERR() is a less bad solution than promoting PTR_RET,
>> > which has a non-obvious name.
>>
>> Will a longer name make the function more obvious?
>> 	PTR_ERR_OR_ZERO() ?
>> 	PTR_ERR0() ?
>> PTR_ERR() can then stay simple for cases where we know we
>> are on the error path.
>
> I was thinking of something along those lines.  And in that case, PTR_ERR
> could stay without the additional test.
> julia

OK, sold :)

Will send out a series now with PTR_ERR_OR_ZERO.

Thanks,
Rusty.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 1/9] PTR_RET is now PTR_ERR_OR_ZERO
  2013-06-16  2:44             ` Rusty Russell
@ 2013-06-16  4:42               ` Rusty Russell
  2013-06-16  4:42                 ` [PATCH 2/9] PTR_RET is now PTR_ERR_OR_ZERO(): Replace most Rusty Russell
                                   ` (7 more replies)
  0 siblings, 8 replies; 27+ messages in thread
From: Rusty Russell @ 2013-06-16  4:42 UTC (permalink / raw)
  To: linux-kernel; +Cc: Rusty Russell, Julia Lawall, Michael S. Tsirkin

True, it's often used in return statements, but after much bikeshedding
it's probably better to have an explicit name.

(I tried just putting the IS_ERR check inside PTR_ERR itself and gcc
usually generated no more code.  But that clashes current expectations
of how PTR_ERR behaves, so having a separate function is better).

Suggested-by: Julia Lawall <julia.lawall@lip6.fr>
Suggested-by: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Julia Lawall <julia.lawall@lip6.fr>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
 include/linux/err.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/include/linux/err.h b/include/linux/err.h
index f2edce2..ee365c4 100644
--- a/include/linux/err.h
+++ b/include/linux/err.h
@@ -52,7 +52,7 @@ static inline void * __must_check ERR_CAST(const void *ptr)
 	return (void *) ptr;
 }
 
-static inline int __must_check PTR_RET(const void *ptr)
+static inline int __must_check PTR_ERR_OR_ZERO(const void *ptr)
 {
 	if (IS_ERR(ptr))
 		return PTR_ERR(ptr);
@@ -60,6 +60,9 @@ static inline int __must_check PTR_RET(const void *ptr)
 		return 0;
 }
 
+/* Deprecated */
+#define PTR_RET(p) PTR_ERR_OR_ZERO(p)
+
 #endif
 
 #endif /* _LINUX_ERR_H */
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 2/9] PTR_RET is now PTR_ERR_OR_ZERO(): Replace most.
  2013-06-16  4:42               ` [PATCH 1/9] PTR_RET is now PTR_ERR_OR_ZERO Rusty Russell
@ 2013-06-16  4:42                 ` 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
                                   ` (6 subsequent siblings)
  7 siblings, 2 replies; 27+ messages in thread
From: Rusty Russell @ 2013-06-16  4:42 UTC (permalink / raw)
  To: linux-kernel
  Cc: Rusty Russell, netdev, linuxppc-dev, linux-arm-kernel, Julia Lawall

Sweep of the simple cases.

Cc: netdev@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
 arch/arm/mach-omap2/i2c.c                         |  2 +-
 arch/m68k/amiga/platform.c                        |  2 +-
 arch/m68k/kernel/time.c                           |  2 +-
 arch/m68k/q40/config.c                            |  2 +-
 arch/powerpc/kernel/iommu.c                       |  2 +-
 arch/powerpc/kernel/time.c                        |  2 +-
 arch/powerpc/platforms/ps3/time.c                 |  2 +-
 arch/powerpc/sysdev/rtc_cmos_setup.c              |  2 +-
 arch/s390/hypfs/hypfs_dbfs.c                      |  2 +-
 drivers/char/tile-srom.c                          |  2 +-
 drivers/infiniband/core/cma.c                     |  2 +-
 drivers/net/appletalk/cops.c                      |  2 +-
 drivers/net/appletalk/ltpc.c                      |  2 +-
 drivers/net/ethernet/amd/atarilance.c             |  2 +-
 drivers/net/ethernet/amd/mvme147.c                |  2 +-
 drivers/net/ethernet/amd/ni65.c                   |  2 +-
 drivers/net/ethernet/amd/sun3lance.c              |  2 +-
 drivers/net/wireless/brcm80211/brcmfmac/dhd_dbg.c |  2 +-
 drivers/net/wireless/brcm80211/brcmsmac/debug.c   |  2 +-
 drivers/platform/x86/samsung-q10.c                |  2 +-
 drivers/regulator/fan53555.c                      |  2 +-
 drivers/spi/spi-fsl-spi.c                         |  2 +-
 drivers/spi/spidev.c                              |  2 +-
 drivers/video/omap2/dss/core.c                    |  2 +-
 fs/btrfs/dev-replace.c                            |  2 +-
 fs/btrfs/inode.c                                  |  2 +-
 net/bluetooth/hci_sysfs.c                         |  2 +-
 net/bridge/netfilter/ebtable_broute.c             |  2 +-
 net/bridge/netfilter/ebtable_filter.c             |  2 +-
 net/bridge/netfilter/ebtable_nat.c                |  2 +-
 net/ipv4/netfilter/arptable_filter.c              |  2 +-
 net/ipv4/netfilter/iptable_filter.c               |  2 +-
 net/ipv4/netfilter/iptable_mangle.c               |  2 +-
 net/ipv4/netfilter/iptable_nat.c                  |  2 +-
 net/ipv4/netfilter/iptable_raw.c                  |  2 +-
 net/ipv4/netfilter/iptable_security.c             |  2 +-
 net/ipv6/netfilter/ip6table_filter.c              |  2 +-
 net/ipv6/netfilter/ip6table_mangle.c              |  2 +-
 net/ipv6/netfilter/ip6table_nat.c                 |  2 +-
 net/ipv6/netfilter/ip6table_raw.c                 |  2 +-
 net/ipv6/netfilter/ip6table_security.c            |  2 +-
 scripts/coccinelle/api/ptr_ret.cocci              | 10 +++++-----
 sound/soc/soc-io.c                                |  2 +-
 43 files changed, 47 insertions(+), 47 deletions(-)

diff --git a/arch/arm/mach-omap2/i2c.c b/arch/arm/mach-omap2/i2c.c
index d940e53..b456b44 100644
--- a/arch/arm/mach-omap2/i2c.c
+++ b/arch/arm/mach-omap2/i2c.c
@@ -181,7 +181,7 @@ int __init omap_i2c_add_bus(struct omap_i2c_bus_platform_data *i2c_pdata,
 				 sizeof(struct omap_i2c_bus_platform_data));
 	WARN(IS_ERR(pdev), "Could not build omap_device for %s\n", name);
 
-	return PTR_RET(pdev);
+	return PTR_ERR_OR_ZERO(pdev);
 }
 
 static  int __init omap_i2c_cmdline(void)
diff --git a/arch/m68k/amiga/platform.c b/arch/m68k/amiga/platform.c
index 6083088..dacd9f9 100644
--- a/arch/m68k/amiga/platform.c
+++ b/arch/m68k/amiga/platform.c
@@ -56,7 +56,7 @@ static int __init amiga_init_bus(void)
 	n = AMIGAHW_PRESENT(ZORRO3) ? 4 : 2;
 	pdev = platform_device_register_simple("amiga-zorro", -1,
 					       zorro_resources, n);
-	return PTR_RET(pdev);
+	return PTR_ERR_OR_ZERO(pdev);
 }
 
 subsys_initcall(amiga_init_bus);
diff --git a/arch/m68k/kernel/time.c b/arch/m68k/kernel/time.c
index bea6bcf..7eb9792 100644
--- a/arch/m68k/kernel/time.c
+++ b/arch/m68k/kernel/time.c
@@ -90,7 +90,7 @@ static int __init rtc_init(void)
 		return -ENODEV;
 
 	pdev = platform_device_register_simple("rtc-generic", -1, NULL, 0);
-	return PTR_RET(pdev);
+	return PTR_ERR_OR_ZERO(pdev);
 }
 
 module_init(rtc_init);
diff --git a/arch/m68k/q40/config.c b/arch/m68k/q40/config.c
index 658542b..078bb74 100644
--- a/arch/m68k/q40/config.c
+++ b/arch/m68k/q40/config.c
@@ -338,6 +338,6 @@ static __init int q40_add_kbd_device(void)
 		return -ENODEV;
 
 	pdev = platform_device_register_simple("q40kbd", -1, NULL, 0);
-	return PTR_RET(pdev);
+	return PTR_ERR_OR_ZERO(pdev);
 }
 arch_initcall(q40_add_kbd_device);
diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c
index c0d0dbd..3a149eb 100644
--- a/arch/powerpc/kernel/iommu.c
+++ b/arch/powerpc/kernel/iommu.c
@@ -102,7 +102,7 @@ static int __init fail_iommu_debugfs(void)
 	struct dentry *dir = fault_create_debugfs_attr("fail_iommu",
 						       NULL, &fail_iommu);
 
-	return PTR_RET(dir);
+	return PTR_ERR_OR_ZERO(dir);
 }
 late_initcall(fail_iommu_debugfs);
 
diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index 5fc29ad..77e78ef 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -1050,7 +1050,7 @@ static int __init rtc_init(void)
 
 	pdev = platform_device_register_simple("rtc-generic", -1, NULL, 0);
 
-	return PTR_RET(pdev);
+	return PTR_ERR_OR_ZERO(pdev);
 }
 
 module_init(rtc_init);
diff --git a/arch/powerpc/platforms/ps3/time.c b/arch/powerpc/platforms/ps3/time.c
index cba1e6b..ce73ce8 100644
--- a/arch/powerpc/platforms/ps3/time.c
+++ b/arch/powerpc/platforms/ps3/time.c
@@ -90,7 +90,7 @@ static int __init ps3_rtc_init(void)
 
 	pdev = platform_device_register_simple("rtc-ps3", -1, NULL, 0);
 
-	return PTR_RET(pdev);
+	return PTR_ERR_OR_ZERO(pdev);
 }
 
 module_init(ps3_rtc_init);
diff --git a/arch/powerpc/sysdev/rtc_cmos_setup.c b/arch/powerpc/sysdev/rtc_cmos_setup.c
index af79e1e..af0f9be 100644
--- a/arch/powerpc/sysdev/rtc_cmos_setup.c
+++ b/arch/powerpc/sysdev/rtc_cmos_setup.c
@@ -62,7 +62,7 @@ static int  __init add_rtc(void)
 	pd = platform_device_register_simple("rtc_cmos", -1,
 					     &res[0], num_res);
 
-	return PTR_RET(pd);
+	return PTR_ERR_OR_ZERO(pd);
 }
 fs_initcall(add_rtc);
 
diff --git a/arch/s390/hypfs/hypfs_dbfs.c b/arch/s390/hypfs/hypfs_dbfs.c
index bb5dd49..17ab8b7 100644
--- a/arch/s390/hypfs/hypfs_dbfs.c
+++ b/arch/s390/hypfs/hypfs_dbfs.c
@@ -105,7 +105,7 @@ void hypfs_dbfs_remove_file(struct hypfs_dbfs_file *df)
 int hypfs_dbfs_init(void)
 {
 	dbfs_dir = debugfs_create_dir("s390_hypfs", NULL);
-	return PTR_RET(dbfs_dir);
+	return PTR_ERR_OR_ZERO(dbfs_dir);
 }
 
 void hypfs_dbfs_exit(void)
diff --git a/drivers/char/tile-srom.c b/drivers/char/tile-srom.c
index 2e2036e..a3a792f 100644
--- a/drivers/char/tile-srom.c
+++ b/drivers/char/tile-srom.c
@@ -371,7 +371,7 @@ static int srom_setup_minor(struct srom_dev *srom, int index)
 
 	dev = device_create(srom_class, &platform_bus,
 			    MKDEV(srom_major, index), srom, "%d", index);
-	return PTR_RET(dev);
+	return PTR_ERR_OR_ZERO(dev);
 }
 
 /** srom_init() - Initialize the driver's module. */
diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index 71c2c71..17a6ec5 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -3055,7 +3055,7 @@ static int cma_join_ib_multicast(struct rdma_id_private *id_priv,
 						id_priv->id.port_num, &rec,
 						comp_mask, GFP_KERNEL,
 						cma_ib_mc_handler, mc);
-	return PTR_RET(mc->multicast.ib);
+	return PTR_ERR_OR_ZERO(mc->multicast.ib);
 }
 
 static void iboe_mcast_work_handler(struct work_struct *work)
diff --git a/drivers/net/appletalk/cops.c b/drivers/net/appletalk/cops.c
index cff6f02..7f2a032 100644
--- a/drivers/net/appletalk/cops.c
+++ b/drivers/net/appletalk/cops.c
@@ -996,7 +996,7 @@ static int __init cops_module_init(void)
 		printk(KERN_WARNING "%s: You shouldn't autoprobe with insmod\n",
 			cardname);
 	cops_dev = cops_probe(-1);
-	return PTR_RET(cops_dev);
+	return PTR_ERR_OR_ZERO(cops_dev);
 }
 
 static void __exit cops_module_exit(void)
diff --git a/drivers/net/appletalk/ltpc.c b/drivers/net/appletalk/ltpc.c
index b5782cd..01e2ac5 100644
--- a/drivers/net/appletalk/ltpc.c
+++ b/drivers/net/appletalk/ltpc.c
@@ -1243,7 +1243,7 @@ static int __init ltpc_module_init(void)
 		       "ltpc: Autoprobing is not recommended for modules\n");
 
 	dev_ltpc = ltpc_probe();
-	return PTR_RET(dev_ltpc);
+	return PTR_ERR_OR_ZERO(dev_ltpc);
 }
 module_init(ltpc_module_init);
 #endif
diff --git a/drivers/net/ethernet/amd/atarilance.c b/drivers/net/ethernet/amd/atarilance.c
index e8d0ef5..10ceca5 100644
--- a/drivers/net/ethernet/amd/atarilance.c
+++ b/drivers/net/ethernet/amd/atarilance.c
@@ -1147,7 +1147,7 @@ static struct net_device *atarilance_dev;
 static int __init atarilance_module_init(void)
 {
 	atarilance_dev = atarilance_probe(-1);
-	return PTR_RET(atarilance_dev);
+	return PTR_ERR_OR_ZERO(atarilance_dev);
 }
 
 static void __exit atarilance_module_exit(void)
diff --git a/drivers/net/ethernet/amd/mvme147.c b/drivers/net/ethernet/amd/mvme147.c
index a51497c..e108e91 100644
--- a/drivers/net/ethernet/amd/mvme147.c
+++ b/drivers/net/ethernet/amd/mvme147.c
@@ -188,7 +188,7 @@ static struct net_device *dev_mvme147_lance;
 int __init init_module(void)
 {
 	dev_mvme147_lance = mvme147lance_probe(-1);
-	return PTR_RET(dev_mvme147_lance);
+	return PTR_ERR_OR_ZERO(dev_mvme147_lance);
 }
 
 void __exit cleanup_module(void)
diff --git a/drivers/net/ethernet/amd/ni65.c b/drivers/net/ethernet/amd/ni65.c
index 26fc0ce..1cf33ad 100644
--- a/drivers/net/ethernet/amd/ni65.c
+++ b/drivers/net/ethernet/amd/ni65.c
@@ -1238,7 +1238,7 @@ MODULE_PARM_DESC(dma, "ni6510 ISA DMA channel (ignored for some cards)");
 int __init init_module(void)
 {
  	dev_ni65 = ni65_probe(-1);
-	return PTR_RET(dev_ni65);
+	return PTR_ERR_OR_ZERO(dev_ni65);
 }
 
 void __exit cleanup_module(void)
diff --git a/drivers/net/ethernet/amd/sun3lance.c b/drivers/net/ethernet/amd/sun3lance.c
index 4375abe..d6b2029 100644
--- a/drivers/net/ethernet/amd/sun3lance.c
+++ b/drivers/net/ethernet/amd/sun3lance.c
@@ -940,7 +940,7 @@ static struct net_device *sun3lance_dev;
 int __init init_module(void)
 {
 	sun3lance_dev = sun3lance_probe(-1);
-	return PTR_RET(sun3lance_dev);
+	return PTR_ERR_OR_ZERO(sun3lance_dev);
 }
 
 void __exit cleanup_module(void)
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd_dbg.c b/drivers/net/wireless/brcm80211/brcmfmac/dhd_dbg.c
index 202869c..3962a7a 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/dhd_dbg.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/dhd_dbg.c
@@ -50,7 +50,7 @@ int brcmf_debugfs_attach(struct brcmf_pub *drvr)
 		return -ENODEV;
 
 	drvr->dbgfs_dir = debugfs_create_dir(dev_name(dev), root_folder);
-	return PTR_RET(drvr->dbgfs_dir);
+	return PTR_ERR_OR_ZERO(drvr->dbgfs_dir);
 }
 
 void brcmf_debugfs_detach(struct brcmf_pub *drvr)
diff --git a/drivers/net/wireless/brcm80211/brcmsmac/debug.c b/drivers/net/wireless/brcm80211/brcmsmac/debug.c
index 9761deb..a5d4add 100644
--- a/drivers/net/wireless/brcm80211/brcmsmac/debug.c
+++ b/drivers/net/wireless/brcm80211/brcmsmac/debug.c
@@ -56,7 +56,7 @@ int brcms_debugfs_attach(struct brcms_pub *drvr)
 
 	drvr->dbgfs_dir = debugfs_create_dir(
 		 dev_name(&drvr->wlc->hw->d11core->dev), root_folder);
-	return PTR_RET(drvr->dbgfs_dir);
+	return PTR_ERR_OR_ZERO(drvr->dbgfs_dir);
 }
 
 void brcms_debugfs_detach(struct brcms_pub *drvr)
diff --git a/drivers/platform/x86/samsung-q10.c b/drivers/platform/x86/samsung-q10.c
index 1a90b62..4430b8c 100644
--- a/drivers/platform/x86/samsung-q10.c
+++ b/drivers/platform/x86/samsung-q10.c
@@ -176,7 +176,7 @@ static int __init samsungq10_init(void)
 						   samsungq10_probe,
 						   NULL, 0, NULL, 0);
 
-	return PTR_RET(samsungq10_device);
+	return PTR_ERR_OR_ZERO(samsungq10_device);
 }
 
 static void __exit samsungq10_exit(void)
diff --git a/drivers/regulator/fan53555.c b/drivers/regulator/fan53555.c
index f0e1ae5..192444a 100644
--- a/drivers/regulator/fan53555.c
+++ b/drivers/regulator/fan53555.c
@@ -219,7 +219,7 @@ static int fan53555_regulator_register(struct fan53555_device_info *di,
 	rdesc->owner = THIS_MODULE;
 
 	di->rdev = regulator_register(&di->desc, config);
-	return PTR_RET(di->rdev);
+	return PTR_ERR_OR_ZERO(di->rdev);
 
 }
 
diff --git a/drivers/spi/spi-fsl-spi.c b/drivers/spi/spi-fsl-spi.c
index 14e202e..6e80639 100644
--- a/drivers/spi/spi-fsl-spi.c
+++ b/drivers/spi/spi-fsl-spi.c
@@ -901,7 +901,7 @@ static int plat_mpc8xxx_spi_probe(struct platform_device *pdev)
 		return -EINVAL;
 
 	master = fsl_spi_probe(&pdev->dev, mem, irq);
-	return PTR_RET(master);
+	return PTR_ERR_OR_ZERO(master);
 }
 
 static int plat_mpc8xxx_spi_remove(struct platform_device *pdev)
diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index 911e9e0..ca5bcfe 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -603,7 +603,7 @@ static int spidev_probe(struct spi_device *spi)
 		dev = device_create(spidev_class, &spi->dev, spidev->devt,
 				    spidev, "spidev%d.%d",
 				    spi->master->bus_num, spi->chip_select);
-		status = PTR_RET(dev);
+		status = PTR_ERR_OR_ZERO(dev);
 	} else {
 		dev_dbg(&spi->dev, "no minor number available!\n");
 		status = -ENODEV;
diff --git a/drivers/video/omap2/dss/core.c b/drivers/video/omap2/dss/core.c
index c9c2252..a65f1ac 100644
--- a/drivers/video/omap2/dss/core.c
+++ b/drivers/video/omap2/dss/core.c
@@ -189,7 +189,7 @@ int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
 	d = debugfs_create_file(name, S_IRUGO, dss_debugfs_dir,
 			write, &dss_debug_fops);
 
-	return PTR_RET(d);
+	return PTR_ERR_OR_ZERO(d);
 }
 #else /* CONFIG_OMAP2_DSS_DEBUGFS */
 static inline int dss_initialize_debugfs(void)
diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index 65241f3..b63903f 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -747,7 +747,7 @@ int btrfs_resume_dev_replace_async(struct btrfs_fs_info *fs_info)
 	WARN_ON(atomic_xchg(
 		&fs_info->mutually_exclusive_operation_running, 1));
 	task = kthread_run(btrfs_dev_replace_kthread, fs_info, "btrfs-devrepl");
-	return PTR_RET(task);
+	return PTR_ERR_OR_ZERO(task);
 }
 
 static int btrfs_dev_replace_kthread(void *data)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index af978f7..1850a96 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3140,7 +3140,7 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
 		found_key.type = BTRFS_INODE_ITEM_KEY;
 		found_key.offset = 0;
 		inode = btrfs_iget(root->fs_info->sb, &found_key, root, NULL);
-		ret = PTR_RET(inode);
+		ret = PTR_ERR_OR_ZERO(inode);
 		if (ret && ret != -ESTALE)
 			goto out;
 
diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c
index 7ad6ecf..edf623a 100644
--- a/net/bluetooth/hci_sysfs.c
+++ b/net/bluetooth/hci_sysfs.c
@@ -590,7 +590,7 @@ int __init bt_sysfs_init(void)
 
 	bt_class = class_create(THIS_MODULE, "bluetooth");
 
-	return PTR_RET(bt_class);
+	return PTR_ERR_OR_ZERO(bt_class);
 }
 
 void bt_sysfs_cleanup(void)
diff --git a/net/bridge/netfilter/ebtable_broute.c b/net/bridge/netfilter/ebtable_broute.c
index 70f656c..dbd1c78 100644
--- a/net/bridge/netfilter/ebtable_broute.c
+++ b/net/bridge/netfilter/ebtable_broute.c
@@ -64,7 +64,7 @@ static int ebt_broute(struct sk_buff *skb)
 static int __net_init broute_net_init(struct net *net)
 {
 	net->xt.broute_table = ebt_register_table(net, &broute_table);
-	return PTR_RET(net->xt.broute_table);
+	return PTR_ERR_OR_ZERO(net->xt.broute_table);
 }
 
 static void __net_exit broute_net_exit(struct net *net)
diff --git a/net/bridge/netfilter/ebtable_filter.c b/net/bridge/netfilter/ebtable_filter.c
index 3c2e9dc..94b2b70 100644
--- a/net/bridge/netfilter/ebtable_filter.c
+++ b/net/bridge/netfilter/ebtable_filter.c
@@ -100,7 +100,7 @@ static struct nf_hook_ops ebt_ops_filter[] __read_mostly = {
 static int __net_init frame_filter_net_init(struct net *net)
 {
 	net->xt.frame_filter = ebt_register_table(net, &frame_filter);
-	return PTR_RET(net->xt.frame_filter);
+	return PTR_ERR_OR_ZERO(net->xt.frame_filter);
 }
 
 static void __net_exit frame_filter_net_exit(struct net *net)
diff --git a/net/bridge/netfilter/ebtable_nat.c b/net/bridge/netfilter/ebtable_nat.c
index 10871bc..322555a 100644
--- a/net/bridge/netfilter/ebtable_nat.c
+++ b/net/bridge/netfilter/ebtable_nat.c
@@ -100,7 +100,7 @@ static struct nf_hook_ops ebt_ops_nat[] __read_mostly = {
 static int __net_init frame_nat_net_init(struct net *net)
 {
 	net->xt.frame_nat = ebt_register_table(net, &frame_nat);
-	return PTR_RET(net->xt.frame_nat);
+	return PTR_ERR_OR_ZERO(net->xt.frame_nat);
 }
 
 static void __net_exit frame_nat_net_exit(struct net *net)
diff --git a/net/ipv4/netfilter/arptable_filter.c b/net/ipv4/netfilter/arptable_filter.c
index eadab1e..a865f6f 100644
--- a/net/ipv4/netfilter/arptable_filter.c
+++ b/net/ipv4/netfilter/arptable_filter.c
@@ -48,7 +48,7 @@ static int __net_init arptable_filter_net_init(struct net *net)
 	net->ipv4.arptable_filter =
 		arpt_register_table(net, &packet_filter, repl);
 	kfree(repl);
-	return PTR_RET(net->ipv4.arptable_filter);
+	return PTR_ERR_OR_ZERO(net->ipv4.arptable_filter);
 }
 
 static void __net_exit arptable_filter_net_exit(struct net *net)
diff --git a/net/ipv4/netfilter/iptable_filter.c b/net/ipv4/netfilter/iptable_filter.c
index 6b3da5c..50af5b4 100644
--- a/net/ipv4/netfilter/iptable_filter.c
+++ b/net/ipv4/netfilter/iptable_filter.c
@@ -69,7 +69,7 @@ static int __net_init iptable_filter_net_init(struct net *net)
 	net->ipv4.iptable_filter =
 		ipt_register_table(net, &packet_filter, repl);
 	kfree(repl);
-	return PTR_RET(net->ipv4.iptable_filter);
+	return PTR_ERR_OR_ZERO(net->ipv4.iptable_filter);
 }
 
 static void __net_exit iptable_filter_net_exit(struct net *net)
diff --git a/net/ipv4/netfilter/iptable_mangle.c b/net/ipv4/netfilter/iptable_mangle.c
index cba5658..0d8cd82 100644
--- a/net/ipv4/netfilter/iptable_mangle.c
+++ b/net/ipv4/netfilter/iptable_mangle.c
@@ -107,7 +107,7 @@ static int __net_init iptable_mangle_net_init(struct net *net)
 	net->ipv4.iptable_mangle =
 		ipt_register_table(net, &packet_mangler, repl);
 	kfree(repl);
-	return PTR_RET(net->ipv4.iptable_mangle);
+	return PTR_ERR_OR_ZERO(net->ipv4.iptable_mangle);
 }
 
 static void __net_exit iptable_mangle_net_exit(struct net *net)
diff --git a/net/ipv4/netfilter/iptable_nat.c b/net/ipv4/netfilter/iptable_nat.c
index 6383273..683bfaf 100644
--- a/net/ipv4/netfilter/iptable_nat.c
+++ b/net/ipv4/netfilter/iptable_nat.c
@@ -292,7 +292,7 @@ static int __net_init iptable_nat_net_init(struct net *net)
 		return -ENOMEM;
 	net->ipv4.nat_table = ipt_register_table(net, &nf_nat_ipv4_table, repl);
 	kfree(repl);
-	return PTR_RET(net->ipv4.nat_table);
+	return PTR_ERR_OR_ZERO(net->ipv4.nat_table);
 }
 
 static void __net_exit iptable_nat_net_exit(struct net *net)
diff --git a/net/ipv4/netfilter/iptable_raw.c b/net/ipv4/netfilter/iptable_raw.c
index 03d9696..1f82aea 100644
--- a/net/ipv4/netfilter/iptable_raw.c
+++ b/net/ipv4/netfilter/iptable_raw.c
@@ -48,7 +48,7 @@ static int __net_init iptable_raw_net_init(struct net *net)
 	net->ipv4.iptable_raw =
 		ipt_register_table(net, &packet_raw, repl);
 	kfree(repl);
-	return PTR_RET(net->ipv4.iptable_raw);
+	return PTR_ERR_OR_ZERO(net->ipv4.iptable_raw);
 }
 
 static void __net_exit iptable_raw_net_exit(struct net *net)
diff --git a/net/ipv4/netfilter/iptable_security.c b/net/ipv4/netfilter/iptable_security.c
index b283d8e..f867a8d 100644
--- a/net/ipv4/netfilter/iptable_security.c
+++ b/net/ipv4/netfilter/iptable_security.c
@@ -66,7 +66,7 @@ static int __net_init iptable_security_net_init(struct net *net)
 	net->ipv4.iptable_security =
 		ipt_register_table(net, &security_table, repl);
 	kfree(repl);
-	return PTR_RET(net->ipv4.iptable_security);
+	return PTR_ERR_OR_ZERO(net->ipv4.iptable_security);
 }
 
 static void __net_exit iptable_security_net_exit(struct net *net)
diff --git a/net/ipv6/netfilter/ip6table_filter.c b/net/ipv6/netfilter/ip6table_filter.c
index beb5777..29b44b1 100644
--- a/net/ipv6/netfilter/ip6table_filter.c
+++ b/net/ipv6/netfilter/ip6table_filter.c
@@ -61,7 +61,7 @@ static int __net_init ip6table_filter_net_init(struct net *net)
 	net->ipv6.ip6table_filter =
 		ip6t_register_table(net, &packet_filter, repl);
 	kfree(repl);
-	return PTR_RET(net->ipv6.ip6table_filter);
+	return PTR_ERR_OR_ZERO(net->ipv6.ip6table_filter);
 }
 
 static void __net_exit ip6table_filter_net_exit(struct net *net)
diff --git a/net/ipv6/netfilter/ip6table_mangle.c b/net/ipv6/netfilter/ip6table_mangle.c
index e075399..c705907 100644
--- a/net/ipv6/netfilter/ip6table_mangle.c
+++ b/net/ipv6/netfilter/ip6table_mangle.c
@@ -101,7 +101,7 @@ static int __net_init ip6table_mangle_net_init(struct net *net)
 	net->ipv6.ip6table_mangle =
 		ip6t_register_table(net, &packet_mangler, repl);
 	kfree(repl);
-	return PTR_RET(net->ipv6.ip6table_mangle);
+	return PTR_ERR_OR_ZERO(net->ipv6.ip6table_mangle);
 }
 
 static void __net_exit ip6table_mangle_net_exit(struct net *net)
diff --git a/net/ipv6/netfilter/ip6table_nat.c b/net/ipv6/netfilter/ip6table_nat.c
index 6383f90..9b076d2 100644
--- a/net/ipv6/netfilter/ip6table_nat.c
+++ b/net/ipv6/netfilter/ip6table_nat.c
@@ -293,7 +293,7 @@ static int __net_init ip6table_nat_net_init(struct net *net)
 		return -ENOMEM;
 	net->ipv6.ip6table_nat = ip6t_register_table(net, &nf_nat_ipv6_table, repl);
 	kfree(repl);
-	return PTR_RET(net->ipv6.ip6table_nat);
+	return PTR_ERR_OR_ZERO(net->ipv6.ip6table_nat);
 }
 
 static void __net_exit ip6table_nat_net_exit(struct net *net)
diff --git a/net/ipv6/netfilter/ip6table_raw.c b/net/ipv6/netfilter/ip6table_raw.c
index 60d1bdd..9a626d8 100644
--- a/net/ipv6/netfilter/ip6table_raw.c
+++ b/net/ipv6/netfilter/ip6table_raw.c
@@ -40,7 +40,7 @@ static int __net_init ip6table_raw_net_init(struct net *net)
 	net->ipv6.ip6table_raw =
 		ip6t_register_table(net, &packet_raw, repl);
 	kfree(repl);
-	return PTR_RET(net->ipv6.ip6table_raw);
+	return PTR_ERR_OR_ZERO(net->ipv6.ip6table_raw);
 }
 
 static void __net_exit ip6table_raw_net_exit(struct net *net)
diff --git a/net/ipv6/netfilter/ip6table_security.c b/net/ipv6/netfilter/ip6table_security.c
index db15535..ce88d1d 100644
--- a/net/ipv6/netfilter/ip6table_security.c
+++ b/net/ipv6/netfilter/ip6table_security.c
@@ -58,7 +58,7 @@ static int __net_init ip6table_security_net_init(struct net *net)
 	net->ipv6.ip6table_security =
 		ip6t_register_table(net, &security_table, repl);
 	kfree(repl);
-	return PTR_RET(net->ipv6.ip6table_security);
+	return PTR_ERR_OR_ZERO(net->ipv6.ip6table_security);
 }
 
 static void __net_exit ip6table_security_net_exit(struct net *net)
diff --git a/scripts/coccinelle/api/ptr_ret.cocci b/scripts/coccinelle/api/ptr_ret.cocci
index 15f076f..e0981bb 100644
--- a/scripts/coccinelle/api/ptr_ret.cocci
+++ b/scripts/coccinelle/api/ptr_ret.cocci
@@ -1,5 +1,5 @@
 ///
-/// Use PTR_RET rather than if(IS_ERR(...)) + PTR_ERR
+/// Use PTR_ERR_OR_ZERO rather than if(IS_ERR(...)) + PTR_ERR
 ///
 // Confidence: High
 // Copyright: (C) 2012 Julia Lawall, INRIA/LIP6.  GPLv2.
@@ -7,7 +7,7 @@
 // URL: http://coccinelle.lip6.fr/
 // Options: -no_includes -include_headers
 //
-// Keywords: ERR_PTR, PTR_ERR, PTR_RET
+// Keywords: ERR_PTR, PTR_ERR, PTR_RET, PTR_ERR_OR_ZERO
 // Version min: 2.6.39
 //
 
@@ -21,21 +21,21 @@ expression ptr;
 @@
 
 - if (IS_ERR(ptr)) return PTR_ERR(ptr); else return 0;
-+ return PTR_RET(ptr);
++ return PTR_ERR_OR_ZERO(ptr);
 
 @depends on patch@
 expression ptr;
 @@
 
 - if (IS_ERR(ptr)) return PTR_ERR(ptr); return 0;
-+ return PTR_RET(ptr);
++ return PTR_ERR_OR_ZERO(ptr);
 
 @depends on patch@
 expression ptr;
 @@
 
 - (IS_ERR(ptr) ? PTR_ERR(ptr) : 0)
-+ PTR_RET(ptr)
++ PTR_ERR_OR_ZERO(ptr)
 
 @r1 depends on !patch@
 expression ptr;
diff --git a/sound/soc/soc-io.c b/sound/soc/soc-io.c
index 8ca9ecc..122c0c1 100644
--- a/sound/soc/soc-io.c
+++ b/sound/soc/soc-io.c
@@ -158,7 +158,7 @@ int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,
 		return -EINVAL;
 	}
 
-	return PTR_RET(codec->control_data);
+	return PTR_ERR_OR_ZERO(codec->control_data);
 }
 EXPORT_SYMBOL_GPL(snd_soc_codec_set_cache_io);
 #else
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 3/9] s390: Replace weird use of PTR_RET.
  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-16  4:42                 ` Rusty Russell
  2013-06-17  5:03                   ` Heiko Carstens
  2013-06-16  4:42                 ` [PATCH 4/9] acpi: " Rusty Russell
                                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 27+ messages in thread
From: Rusty Russell @ 2013-06-16  4:42 UTC (permalink / raw)
  To: linux-kernel
  Cc: Rusty Russell, Heiko Carstens, Christian Borntraeger, Martin Schwidefsky

Saves repeating "(void __force *)__uptr" but it's less clear.  Using
the output of PTR_RET() to determine the error rather than just
testing IS_ERR() is odd.

For example, I *assume* __gptr_to_uptr() never returns NULL?  Because
the __ret would be 0 for the old code.  The new version is clearer, IMHO:
it would try to get_user() on that address.

If you hate this variant, I can just s/PTR_RET/PTR_ERR_OR_ZERO/ instead.

Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
 arch/s390/kvm/gaccess.h | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/arch/s390/kvm/gaccess.h b/arch/s390/kvm/gaccess.h
index 302e0e5..99d789e 100644
--- a/arch/s390/kvm/gaccess.h
+++ b/arch/s390/kvm/gaccess.h
@@ -42,9 +42,11 @@ static inline void __user *__gptr_to_uptr(struct kvm_vcpu *vcpu,
 ({								\
 	__typeof__(gptr) __uptr = __gptr_to_uptr(vcpu, gptr, 1);\
 	int __mask = sizeof(__typeof__(*(gptr))) - 1;		\
-	int __ret = PTR_RET((void __force *)__uptr);		\
+	int __ret;						\
 								\
-	if (!__ret) {						\
+	if (IS_ERR((void __force *)__uptr)) {			\
+		__ret = PTR_ERR((void __force *)__uptr);	\
+	} else {						\
 		BUG_ON((unsigned long)__uptr & __mask);		\
 		__ret = get_user(x, __uptr);			\
 	}							\
@@ -55,9 +57,11 @@ static inline void __user *__gptr_to_uptr(struct kvm_vcpu *vcpu,
 ({								\
 	__typeof__(gptr) __uptr = __gptr_to_uptr(vcpu, gptr, 1);\
 	int __mask = sizeof(__typeof__(*(gptr))) - 1;		\
-	int __ret = PTR_RET((void __force *)__uptr);		\
+	int __ret;						\
 								\
-	if (!__ret) {						\
+	if (IS_ERR((void __force *)__uptr)) {			\
+		__ret = PTR_ERR((void __force *)__uptr);	\
+	} else {						\
 		BUG_ON((unsigned long)__uptr & __mask);		\
 		__ret = put_user(x, __uptr);			\
 	}							\
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 4/9] acpi: Replace weird use of PTR_RET.
  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-16  4:42                 ` [PATCH 3/9] s390: Replace weird use of PTR_RET Rusty Russell
@ 2013-06-16  4:42                 ` 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
                                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 27+ messages in thread
From: Rusty Russell @ 2013-06-16  4:42 UTC (permalink / raw)
  To: linux-kernel; +Cc: Rusty Russell, Rafael J. Wysocki, Alexandru Gheorghiu

This functions is really weird.  It sets rc to -ENOMEM, then overrides
it.  It was converted to PTR_RET in a1458187 when it should have
simply been rewritten.

This version makes it more explicit, with a single IS_ERR() test.

Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: Alexandru Gheorghiu <gheorghiuandru@gmail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
 drivers/acpi/acpi_pad.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/acpi/acpi_pad.c b/drivers/acpi/acpi_pad.c
index 27bb6a9..46e0b3c 100644
--- a/drivers/acpi/acpi_pad.c
+++ b/drivers/acpi/acpi_pad.c
@@ -231,16 +231,19 @@ static struct task_struct *ps_tsks[NR_CPUS];
 static unsigned int ps_tsk_num;
 static int create_power_saving_task(void)
 {
-	int rc = -ENOMEM;
+	int rc;
 
 	ps_tsks[ps_tsk_num] = kthread_run(power_saving_thread,
 		(void *)(unsigned long)ps_tsk_num,
 		"acpi_pad/%d", ps_tsk_num);
-	rc = PTR_RET(ps_tsks[ps_tsk_num]);
-	if (!rc)
-		ps_tsk_num++;
-	else
+
+	if (IS_ERR(ps_tsks[ps_tsk_num])) {
+		rc = PTR_ERR(ps_tsks[ps_tsk_num]);
 		ps_tsks[ps_tsk_num] = NULL;
+	} else {
+		rc = 0;
+		ps_tsk_num++;
+	}
 
 	return rc;
 }
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 5/9] pinctrl: don't use PTR_RET().
  2013-06-16  4:42               ` [PATCH 1/9] PTR_RET is now PTR_ERR_OR_ZERO Rusty Russell
                                   ` (2 preceding siblings ...)
  2013-06-16  4:42                 ` [PATCH 4/9] acpi: " Rusty Russell
@ 2013-06-16  4:42                 ` Rusty Russell
  2013-06-16  4:42                 ` [PATCH 6/9] remoteproc: " Rusty Russell
                                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 27+ messages in thread
From: Rusty Russell @ 2013-06-16  4:42 UTC (permalink / raw)
  To: linux-kernel; +Cc: Rusty Russell, Sebastian Hesselbarth

We've already tested that it's an error.

Cc: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
 drivers/pinctrl/mvebu/pinctrl-dove.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pinctrl/mvebu/pinctrl-dove.c b/drivers/pinctrl/mvebu/pinctrl-dove.c
index 428ea96..dd7e0a8 100644
--- a/drivers/pinctrl/mvebu/pinctrl-dove.c
+++ b/drivers/pinctrl/mvebu/pinctrl-dove.c
@@ -597,7 +597,7 @@ static int dove_pinctrl_probe(struct platform_device *pdev)
 	clk = devm_clk_get(&pdev->dev, NULL);
 	if (IS_ERR(clk)) {
 		dev_err(&pdev->dev, "Unable to get pdma clock");
-		return PTR_RET(clk);
+		return PTR_ERR(clk);
 	}
 	clk_prepare_enable(clk);
 
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 6/9] remoteproc: don't use PTR_RET().
  2013-06-16  4:42               ` [PATCH 1/9] PTR_RET is now PTR_ERR_OR_ZERO Rusty Russell
                                   ` (3 preceding siblings ...)
  2013-06-16  4:42                 ` [PATCH 5/9] pinctrl: don't use PTR_RET() Rusty Russell
@ 2013-06-16  4:42                 ` Rusty Russell
  2013-06-17  3:15                   ` Ohad Ben-Cohen
  2013-06-16  4:42                 ` [PATCH 7/9] staging/zcache: " Rusty Russell
                                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 27+ messages in thread
From: Rusty Russell @ 2013-06-16  4:42 UTC (permalink / raw)
  To: linux-kernel; +Cc: Rusty Russell, Ohad Ben-Cohen, Robert Tivy

We've already tested that it's an error.

Cc: Ohad Ben-Cohen <ohad@wizery.com>
Cc: Robert Tivy <rtivy@ti.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
 drivers/remoteproc/da8xx_remoteproc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/remoteproc/da8xx_remoteproc.c b/drivers/remoteproc/da8xx_remoteproc.c
index 9b2e60a..129f7b9 100644
--- a/drivers/remoteproc/da8xx_remoteproc.c
+++ b/drivers/remoteproc/da8xx_remoteproc.c
@@ -165,7 +165,7 @@ static int reset_assert(struct device *dev)
 	dsp_clk = clk_get(dev, NULL);
 	if (IS_ERR(dsp_clk)) {
 		dev_err(dev, "clk_get error: %ld\n", PTR_ERR(dsp_clk));
-		return PTR_RET(dsp_clk);
+		return PTR_ERR(dsp_clk);
 	}
 
 	davinci_clk_reset_assert(dsp_clk);
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 7/9] staging/zcache: don't use PTR_RET().
  2013-06-16  4:42               ` [PATCH 1/9] PTR_RET is now PTR_ERR_OR_ZERO Rusty Russell
                                   ` (4 preceding siblings ...)
  2013-06-16  4:42                 ` [PATCH 6/9] remoteproc: " Rusty Russell
@ 2013-06-16  4:42                 ` Rusty Russell
  2013-06-16  4:42                 ` [PATCH 8/9] x86: remove weird PTR_ERR() in do_debug Rusty Russell
  2013-06-16  4:42                 ` [PATCH 9/9] mm/oom_kill: remove weird use of ERR_PTR()/PTR_ERR() Rusty Russell
  7 siblings, 0 replies; 27+ messages in thread
From: Rusty Russell @ 2013-06-16  4:42 UTC (permalink / raw)
  To: linux-kernel; +Cc: Rusty Russell, Dan Magenheimer

We've already tested that it's an error.

Cc: Dan Magenheimer <dan.magenheimer@oracle.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
 drivers/staging/zcache/zcache-main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/zcache/zcache-main.c b/drivers/staging/zcache/zcache-main.c
index dcceed2..88e7fe7 100644
--- a/drivers/staging/zcache/zcache-main.c
+++ b/drivers/staging/zcache/zcache-main.c
@@ -1908,7 +1908,7 @@ static int zcache_init(void)
 #endif
 		if (IS_ERR(old_ops) || old_ops) {
 			if (IS_ERR(old_ops))
-				return PTR_RET(old_ops);
+				return PTR_ERR(old_ops);
 			pr_warn("%s: frontswap_ops overridden\n", namestr);
 		}
 	}
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 8/9] x86: remove weird PTR_ERR() in do_debug
  2013-06-16  4:42               ` [PATCH 1/9] PTR_RET is now PTR_ERR_OR_ZERO Rusty Russell
                                   ` (5 preceding siblings ...)
  2013-06-16  4:42                 ` [PATCH 7/9] staging/zcache: " Rusty Russell
@ 2013-06-16  4:42                 ` 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
  7 siblings, 1 reply; 27+ messages in thread
From: Rusty Russell @ 2013-06-16  4:42 UTC (permalink / raw)
  To: linux-kernel; +Cc: Rusty Russell, x86, K.Prasad

62edab905 changed the argument to notify_die() from dr6 to &dr6, but weirdly,
used PTR_ERR() to cast it to a long.  Since dr6 is on the stack, this is
an abuse of PTR_ERR().  Cast to long, as per kernel standard.

Cc: x86@kernel.org
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
 arch/x86/kernel/traps.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index 772e2a8..9340dfb 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -437,7 +437,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
 	/* Store the virtualized DR6 value */
 	tsk->thread.debugreg6 = dr6;
 
-	if (notify_die(DIE_DEBUG, "debug", regs, PTR_ERR(&dr6), error_code,
+	if (notify_die(DIE_DEBUG, "debug", regs, (long)&dr6, error_code,
 							SIGTRAP) == NOTIFY_STOP)
 		goto exit;
 
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 9/9] mm/oom_kill: remove weird use of ERR_PTR()/PTR_ERR().
  2013-06-16  4:42               ` [PATCH 1/9] PTR_RET is now PTR_ERR_OR_ZERO Rusty Russell
                                   ` (6 preceding siblings ...)
  2013-06-16  4:42                 ` [PATCH 8/9] x86: remove weird PTR_ERR() in do_debug Rusty Russell
@ 2013-06-16  4:42                 ` Rusty Russell
  2013-06-16 18:11                   ` David Rientjes
  7 siblings, 1 reply; 27+ messages in thread
From: Rusty Russell @ 2013-06-16  4:42 UTC (permalink / raw)
  To: linux-kernel; +Cc: Rusty Russell, Andrew Morton

The normal expectation for ERR_PTR() is to put a negative errno into a
pointer.  oom_kill puts the magic -1 in the result (and has since
pre-git), which is probably clearer with an explicit cast.

Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
 mm/oom_kill.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 79e451a..f9b9cd7 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -288,7 +288,7 @@ enum oom_scan_t oom_scan_process_thread(struct task_struct *task,
 
 /*
  * Simple selection loop. We chose the process with the highest
- * number of 'points'.
+ * number of 'points'.  Returns -1 on scan abort.
  *
  * (not docbooked, we don't want this one cluttering up the manual)
  */
@@ -314,7 +314,7 @@ static struct task_struct *select_bad_process(unsigned int *ppoints,
 			continue;
 		case OOM_SCAN_ABORT:
 			rcu_read_unlock();
-			return ERR_PTR(-1UL);
+			return (void *)(-1UL);
 		case OOM_SCAN_OK:
 			break;
 		};
@@ -657,7 +657,7 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
 		dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
 		panic("Out of memory and no killable processes...\n");
 	}
-	if (PTR_ERR(p) != -1UL) {
+	if (p != (void *)-1UL) {
 		oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
 				 nodemask, "Out of memory");
 		killed = 1;
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [PATCH 4/9] acpi: Replace weird use of PTR_RET.
  2013-06-16  4:42                 ` [PATCH 4/9] acpi: " Rusty Russell
@ 2013-06-16 11:55                   ` Rafael J. Wysocki
  0 siblings, 0 replies; 27+ messages in thread
From: Rafael J. Wysocki @ 2013-06-16 11:55 UTC (permalink / raw)
  To: Rusty Russell; +Cc: linux-kernel, Rafael J. Wysocki, Alexandru Gheorghiu

On Sunday, June 16, 2013 02:12:43 PM Rusty Russell wrote:
> This functions is really weird.  It sets rc to -ENOMEM, then overrides
> it.  It was converted to PTR_RET in a1458187 when it should have
> simply been rewritten.
> 
> This version makes it more explicit, with a single IS_ERR() test.
> 
> Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> Cc: Alexandru Gheorghiu <gheorghiuandru@gmail.com>
> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

> ---
>  drivers/acpi/acpi_pad.c | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/acpi/acpi_pad.c b/drivers/acpi/acpi_pad.c
> index 27bb6a9..46e0b3c 100644
> --- a/drivers/acpi/acpi_pad.c
> +++ b/drivers/acpi/acpi_pad.c
> @@ -231,16 +231,19 @@ static struct task_struct *ps_tsks[NR_CPUS];
>  static unsigned int ps_tsk_num;
>  static int create_power_saving_task(void)
>  {
> -	int rc = -ENOMEM;
> +	int rc;
>  
>  	ps_tsks[ps_tsk_num] = kthread_run(power_saving_thread,
>  		(void *)(unsigned long)ps_tsk_num,
>  		"acpi_pad/%d", ps_tsk_num);
> -	rc = PTR_RET(ps_tsks[ps_tsk_num]);
> -	if (!rc)
> -		ps_tsk_num++;
> -	else
> +
> +	if (IS_ERR(ps_tsks[ps_tsk_num])) {
> +		rc = PTR_ERR(ps_tsks[ps_tsk_num]);
>  		ps_tsks[ps_tsk_num] = NULL;
> +	} else {
> +		rc = 0;
> +		ps_tsk_num++;
> +	}
>  
>  	return rc;
>  }
> 
-- 
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 9/9] mm/oom_kill: remove weird use of ERR_PTR()/PTR_ERR().
  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
  0 siblings, 1 reply; 27+ messages in thread
From: David Rientjes @ 2013-06-16 18:11 UTC (permalink / raw)
  To: Rusty Russell; +Cc: linux-kernel, Andrew Morton

On Sun, 16 Jun 2013, Rusty Russell wrote:

> diff --git a/mm/oom_kill.c b/mm/oom_kill.c
> index 79e451a..f9b9cd7 100644
> --- a/mm/oom_kill.c
> +++ b/mm/oom_kill.c
> @@ -288,7 +288,7 @@ enum oom_scan_t oom_scan_process_thread(struct task_struct *task,
>  
>  /*
>   * Simple selection loop. We chose the process with the highest
> - * number of 'points'.
> + * number of 'points'.  Returns -1 on scan abort.
>   *
>   * (not docbooked, we don't want this one cluttering up the manual)
>   */
> @@ -314,7 +314,7 @@ static struct task_struct *select_bad_process(unsigned int *ppoints,
>  			continue;
>  		case OOM_SCAN_ABORT:
>  			rcu_read_unlock();
> -			return ERR_PTR(-1UL);
> +			return (void *)(-1UL);
>  		case OOM_SCAN_OK:
>  			break;
>  		};

Any reason it's not struct task_struct *?

> @@ -657,7 +657,7 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
>  		dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
>  		panic("Out of memory and no killable processes...\n");
>  	}
> -	if (PTR_ERR(p) != -1UL) {
> +	if (p != (void *)-1UL) {
>  		oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
>  				 nodemask, "Out of memory");
>  		killed = 1;

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 6/9] remoteproc: don't use PTR_RET().
  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
  0 siblings, 1 reply; 27+ messages in thread
From: Ohad Ben-Cohen @ 2013-06-17  3:15 UTC (permalink / raw)
  To: Rusty Russell; +Cc: linux-kernel, Robert Tivy

On Sun, Jun 16, 2013 at 7:42 AM, Rusty Russell <rusty@rustcorp.com.au> wrote:
>
> We've already tested that it's an error.
>
> Cc: Ohad Ben-Cohen <ohad@wizery.com>
> Cc: Robert Tivy <rtivy@ti.com>
> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

Acked-by: Ohad Ben-Cohen <ohad@wizery.com>

Thanks Rusty, feel free to take it via your tree together with the
rest of the PTR_RET patches.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 6/9] remoteproc: don't use PTR_RET().
  2013-06-17  3:15                   ` Ohad Ben-Cohen
@ 2013-06-17  3:49                     ` Rusty Russell
  0 siblings, 0 replies; 27+ messages in thread
From: Rusty Russell @ 2013-06-17  3:49 UTC (permalink / raw)
  To: Ohad Ben-Cohen; +Cc: linux-kernel, Robert Tivy

Ohad Ben-Cohen <ohad@wizery.com> writes:
> On Sun, Jun 16, 2013 at 7:42 AM, Rusty Russell <rusty@rustcorp.com.au> wrote:
>>
>> We've already tested that it's an error.
>>
>> Cc: Ohad Ben-Cohen <ohad@wizery.com>
>> Cc: Robert Tivy <rtivy@ti.com>
>> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
>
> Acked-by: Ohad Ben-Cohen <ohad@wizery.com>
>
> Thanks Rusty, feel free to take it via your tree together with the
> rest of the PTR_RET patches.

Thanks, done.

Cheers,
Rusty.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 9/9] mm/oom_kill: remove weird use of ERR_PTR()/PTR_ERR().
  2013-06-16 18:11                   ` David Rientjes
@ 2013-06-17  3:50                     ` Rusty Russell
  0 siblings, 0 replies; 27+ messages in thread
From: Rusty Russell @ 2013-06-17  3:50 UTC (permalink / raw)
  To: David Rientjes; +Cc: linux-kernel, Andrew Morton

David Rientjes <rientjes@google.com> writes:
> On Sun, 16 Jun 2013, Rusty Russell wrote:
>
>> diff --git a/mm/oom_kill.c b/mm/oom_kill.c
>> index 79e451a..f9b9cd7 100644
>> --- a/mm/oom_kill.c
>> +++ b/mm/oom_kill.c
>> @@ -288,7 +288,7 @@ enum oom_scan_t oom_scan_process_thread(struct task_struct *task,
>>  
>>  /*
>>   * Simple selection loop. We chose the process with the highest
>> - * number of 'points'.
>> + * number of 'points'.  Returns -1 on scan abort.
>>   *
>>   * (not docbooked, we don't want this one cluttering up the manual)
>>   */
>> @@ -314,7 +314,7 @@ static struct task_struct *select_bad_process(unsigned int *ppoints,
>>  			continue;
>>  		case OOM_SCAN_ABORT:
>>  			rcu_read_unlock();
>> -			return ERR_PTR(-1UL);
>> +			return (void *)(-1UL);
>>  		case OOM_SCAN_OK:
>>  			break;
>>  		};
>
> Any reason it's not struct task_struct *?

No good one.  Changed.

Cheers,
Rusty.

Subject: mm/oom_kill: remove weird use of ERR_PTR()/PTR_ERR().

The normal expectation for ERR_PTR() is to put a negative errno into a
pointer.  oom_kill puts the magic -1 in the result (and has since
pre-git), which is probably clearer with an explicit cast.

Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 79e451a..f9b9cd7 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -288,7 +288,7 @@ enum oom_scan_t oom_scan_process_thread(struct task_struct *task,
 
 /*
  * Simple selection loop. We chose the process with the highest
- * number of 'points'.
+ * number of 'points'.  Returns -1 on scan abort.
  *
  * (not docbooked, we don't want this one cluttering up the manual)
  */
@@ -314,7 +314,7 @@ static struct task_struct *select_bad_process(unsigned int *ppoints,
 			continue;
 		case OOM_SCAN_ABORT:
 			rcu_read_unlock();
-			return ERR_PTR(-1UL);
+			return (struct task_struct *)(-1UL);
 		case OOM_SCAN_OK:
 			break;
 		};
@@ -657,7 +657,7 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
 		dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
 		panic("Out of memory and no killable processes...\n");
 	}
-	if (PTR_ERR(p) != -1UL) {
+	if (p != (void *)-1UL) {
 		oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
 				 nodemask, "Out of memory");
 		killed = 1;

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [PATCH 3/9] s390: Replace weird use of PTR_RET.
  2013-06-16  4:42                 ` [PATCH 3/9] s390: Replace weird use of PTR_RET Rusty Russell
@ 2013-06-17  5:03                   ` Heiko Carstens
  0 siblings, 0 replies; 27+ messages in thread
From: Heiko Carstens @ 2013-06-17  5:03 UTC (permalink / raw)
  To: Rusty Russell; +Cc: linux-kernel, Christian Borntraeger, Martin Schwidefsky

On Sun, Jun 16, 2013 at 02:12:42PM +0930, Rusty Russell wrote:
> Saves repeating "(void __force *)__uptr" but it's less clear.  Using
> the output of PTR_RET() to determine the error rather than just
> testing IS_ERR() is odd.

Ok, if it's confusing I won't mind if it gets changed. I intended to
keep the code as short as possible, but.. ;)

> For example, I *assume* __gptr_to_uptr() never returns NULL?  Because
> the __ret would be 0 for the old code.  The new version is clearer, IMHO:
> it would try to get_user() on that address.

__gptr_to_uptr() could return 0 and it's not an error case. In that case
it should indeed try a to get_user() on that address.

> If you hate this variant, I can just s/PTR_RET/PTR_ERR_OR_ZERO/ instead.

Your patch is fine.

> Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
> Cc: Christian Borntraeger <borntraeger@de.ibm.com>
> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
> ---
>  arch/s390/kvm/gaccess.h | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)

Acked-by: Heiko Carstens <heiko.carstens@de.ibm.com>


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [tip:x86/debug] x86: Remove weird PTR_ERR() in do_debug
  2013-06-16  4:42                 ` [PATCH 8/9] x86: remove weird PTR_ERR() in do_debug Rusty Russell
@ 2013-06-19 18:43                   ` tip-bot for Rusty Russell
  0 siblings, 0 replies; 27+ messages in thread
From: tip-bot for Rusty Russell @ 2013-06-19 18:43 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, rusty, tglx, prasad

Commit-ID:  5a802e15308f152247433d87050d1bfbf9613483
Gitweb:     http://git.kernel.org/tip/5a802e15308f152247433d87050d1bfbf9613483
Author:     Rusty Russell <rusty@rustcorp.com.au>
AuthorDate: Sun, 16 Jun 2013 14:12:47 +0930
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 19 Jun 2013 15:01:36 +0200

x86: Remove weird PTR_ERR() in do_debug

62edab905 changed the argument to notify_die() from dr6 to &dr6,
but weirdly, used PTR_ERR() to cast it to a long.  Since dr6 is
on the stack, this is an abuse of PTR_ERR().  Cast to long, as
per kernel standard.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Link: http://lkml.kernel.org/r/1371357768-4968-8-git-send-email-rusty@rustcorp.com.au
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/kernel/traps.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index 772e2a8..9340dfb 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -437,7 +437,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
 	/* Store the virtualized DR6 value */
 	tsk->thread.debugreg6 = dr6;
 
-	if (notify_die(DIE_DEBUG, "debug", regs, PTR_ERR(&dr6), error_code,
+	if (notify_die(DIE_DEBUG, "debug", regs, (long)&dr6, error_code,
 							SIGTRAP) == NOTIFY_STOP)
 		goto exit;
 

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [PATCH 2/9] PTR_RET is now PTR_ERR_OR_ZERO(): Replace most.
  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
  1 sibling, 0 replies; 27+ messages in thread
From: David Miller @ 2013-06-20  6:05 UTC (permalink / raw)
  To: rusty; +Cc: linux-kernel, netdev, linuxppc-dev, linux-arm-kernel, julia.lawall

From: Rusty Russell <rusty@rustcorp.com.au>
Date: Sun, 16 Jun 2013 14:12:41 +0930

> Sweep of the simple cases.
> 
> Cc: netdev@vger.kernel.org
> Cc: linuxppc-dev@lists.ozlabs.org
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: Julia Lawall <julia.lawall@lip6.fr>
> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

Acked-by: David S. Miller <davem@davemloft.net>

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 2/9] PTR_RET is now PTR_ERR_OR_ZERO(): Replace most.
  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
  1 sibling, 0 replies; 27+ messages in thread
From: Benjamin Herrenschmidt @ 2013-06-25  7:47 UTC (permalink / raw)
  To: Rusty Russell
  Cc: linux-kernel, netdev, linuxppc-dev, linux-arm-kernel, Julia Lawall

On Sun, 2013-06-16 at 14:12 +0930, Rusty Russell wrote:
> Sweep of the simple cases.
> 
> Cc: netdev@vger.kernel.org
> Cc: linuxppc-dev@lists.ozlabs.org
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: Julia Lawall <julia.lawall@lip6.fr>
> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

> ---
>  arch/arm/mach-omap2/i2c.c                         |  2 +-
>  arch/m68k/amiga/platform.c                        |  2 +-
>  arch/m68k/kernel/time.c                           |  2 +-
>  arch/m68k/q40/config.c                            |  2 +-
>  arch/powerpc/kernel/iommu.c                       |  2 +-
>  arch/powerpc/kernel/time.c                        |  2 +-
>  arch/powerpc/platforms/ps3/time.c                 |  2 +-
>  arch/powerpc/sysdev/rtc_cmos_setup.c              |  2 +-
>  arch/s390/hypfs/hypfs_dbfs.c                      |  2 +-
>  drivers/char/tile-srom.c                          |  2 +-
>  drivers/infiniband/core/cma.c                     |  2 +-
>  drivers/net/appletalk/cops.c                      |  2 +-
>  drivers/net/appletalk/ltpc.c                      |  2 +-
>  drivers/net/ethernet/amd/atarilance.c             |  2 +-
>  drivers/net/ethernet/amd/mvme147.c                |  2 +-
>  drivers/net/ethernet/amd/ni65.c                   |  2 +-
>  drivers/net/ethernet/amd/sun3lance.c              |  2 +-
>  drivers/net/wireless/brcm80211/brcmfmac/dhd_dbg.c |  2 +-
>  drivers/net/wireless/brcm80211/brcmsmac/debug.c   |  2 +-
>  drivers/platform/x86/samsung-q10.c                |  2 +-
>  drivers/regulator/fan53555.c                      |  2 +-
>  drivers/spi/spi-fsl-spi.c                         |  2 +-
>  drivers/spi/spidev.c                              |  2 +-
>  drivers/video/omap2/dss/core.c                    |  2 +-
>  fs/btrfs/dev-replace.c                            |  2 +-
>  fs/btrfs/inode.c                                  |  2 +-
>  net/bluetooth/hci_sysfs.c                         |  2 +-
>  net/bridge/netfilter/ebtable_broute.c             |  2 +-
>  net/bridge/netfilter/ebtable_filter.c             |  2 +-
>  net/bridge/netfilter/ebtable_nat.c                |  2 +-
>  net/ipv4/netfilter/arptable_filter.c              |  2 +-
>  net/ipv4/netfilter/iptable_filter.c               |  2 +-
>  net/ipv4/netfilter/iptable_mangle.c               |  2 +-
>  net/ipv4/netfilter/iptable_nat.c                  |  2 +-
>  net/ipv4/netfilter/iptable_raw.c                  |  2 +-
>  net/ipv4/netfilter/iptable_security.c             |  2 +-
>  net/ipv6/netfilter/ip6table_filter.c              |  2 +-
>  net/ipv6/netfilter/ip6table_mangle.c              |  2 +-
>  net/ipv6/netfilter/ip6table_nat.c                 |  2 +-
>  net/ipv6/netfilter/ip6table_raw.c                 |  2 +-
>  net/ipv6/netfilter/ip6table_security.c            |  2 +-
>  scripts/coccinelle/api/ptr_ret.cocci              | 10 +++++-----
>  sound/soc/soc-io.c                                |  2 +-
>  43 files changed, 47 insertions(+), 47 deletions(-)
> 
> diff --git a/arch/arm/mach-omap2/i2c.c b/arch/arm/mach-omap2/i2c.c
> index d940e53..b456b44 100644
> --- a/arch/arm/mach-omap2/i2c.c
> +++ b/arch/arm/mach-omap2/i2c.c
> @@ -181,7 +181,7 @@ int __init omap_i2c_add_bus(struct omap_i2c_bus_platform_data *i2c_pdata,
>  				 sizeof(struct omap_i2c_bus_platform_data));
>  	WARN(IS_ERR(pdev), "Could not build omap_device for %s\n", name);
>  
> -	return PTR_RET(pdev);
> +	return PTR_ERR_OR_ZERO(pdev);
>  }
>  
>  static  int __init omap_i2c_cmdline(void)
> diff --git a/arch/m68k/amiga/platform.c b/arch/m68k/amiga/platform.c
> index 6083088..dacd9f9 100644
> --- a/arch/m68k/amiga/platform.c
> +++ b/arch/m68k/amiga/platform.c
> @@ -56,7 +56,7 @@ static int __init amiga_init_bus(void)
>  	n = AMIGAHW_PRESENT(ZORRO3) ? 4 : 2;
>  	pdev = platform_device_register_simple("amiga-zorro", -1,
>  					       zorro_resources, n);
> -	return PTR_RET(pdev);
> +	return PTR_ERR_OR_ZERO(pdev);
>  }
>  
>  subsys_initcall(amiga_init_bus);
> diff --git a/arch/m68k/kernel/time.c b/arch/m68k/kernel/time.c
> index bea6bcf..7eb9792 100644
> --- a/arch/m68k/kernel/time.c
> +++ b/arch/m68k/kernel/time.c
> @@ -90,7 +90,7 @@ static int __init rtc_init(void)
>  		return -ENODEV;
>  
>  	pdev = platform_device_register_simple("rtc-generic", -1, NULL, 0);
> -	return PTR_RET(pdev);
> +	return PTR_ERR_OR_ZERO(pdev);
>  }
>  
>  module_init(rtc_init);
> diff --git a/arch/m68k/q40/config.c b/arch/m68k/q40/config.c
> index 658542b..078bb74 100644
> --- a/arch/m68k/q40/config.c
> +++ b/arch/m68k/q40/config.c
> @@ -338,6 +338,6 @@ static __init int q40_add_kbd_device(void)
>  		return -ENODEV;
>  
>  	pdev = platform_device_register_simple("q40kbd", -1, NULL, 0);
> -	return PTR_RET(pdev);
> +	return PTR_ERR_OR_ZERO(pdev);
>  }
>  arch_initcall(q40_add_kbd_device);
> diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c
> index c0d0dbd..3a149eb 100644
> --- a/arch/powerpc/kernel/iommu.c
> +++ b/arch/powerpc/kernel/iommu.c
> @@ -102,7 +102,7 @@ static int __init fail_iommu_debugfs(void)
>  	struct dentry *dir = fault_create_debugfs_attr("fail_iommu",
>  						       NULL, &fail_iommu);
>  
> -	return PTR_RET(dir);
> +	return PTR_ERR_OR_ZERO(dir);
>  }
>  late_initcall(fail_iommu_debugfs);
>  
> diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
> index 5fc29ad..77e78ef 100644
> --- a/arch/powerpc/kernel/time.c
> +++ b/arch/powerpc/kernel/time.c
> @@ -1050,7 +1050,7 @@ static int __init rtc_init(void)
>  
>  	pdev = platform_device_register_simple("rtc-generic", -1, NULL, 0);
>  
> -	return PTR_RET(pdev);
> +	return PTR_ERR_OR_ZERO(pdev);
>  }
>  
>  module_init(rtc_init);
> diff --git a/arch/powerpc/platforms/ps3/time.c b/arch/powerpc/platforms/ps3/time.c
> index cba1e6b..ce73ce8 100644
> --- a/arch/powerpc/platforms/ps3/time.c
> +++ b/arch/powerpc/platforms/ps3/time.c
> @@ -90,7 +90,7 @@ static int __init ps3_rtc_init(void)
>  
>  	pdev = platform_device_register_simple("rtc-ps3", -1, NULL, 0);
>  
> -	return PTR_RET(pdev);
> +	return PTR_ERR_OR_ZERO(pdev);
>  }
>  
>  module_init(ps3_rtc_init);
> diff --git a/arch/powerpc/sysdev/rtc_cmos_setup.c b/arch/powerpc/sysdev/rtc_cmos_setup.c
> index af79e1e..af0f9be 100644
> --- a/arch/powerpc/sysdev/rtc_cmos_setup.c
> +++ b/arch/powerpc/sysdev/rtc_cmos_setup.c
> @@ -62,7 +62,7 @@ static int  __init add_rtc(void)
>  	pd = platform_device_register_simple("rtc_cmos", -1,
>  					     &res[0], num_res);
>  
> -	return PTR_RET(pd);
> +	return PTR_ERR_OR_ZERO(pd);
>  }
>  fs_initcall(add_rtc);
>  
> diff --git a/arch/s390/hypfs/hypfs_dbfs.c b/arch/s390/hypfs/hypfs_dbfs.c
> index bb5dd49..17ab8b7 100644
> --- a/arch/s390/hypfs/hypfs_dbfs.c
> +++ b/arch/s390/hypfs/hypfs_dbfs.c
> @@ -105,7 +105,7 @@ void hypfs_dbfs_remove_file(struct hypfs_dbfs_file *df)
>  int hypfs_dbfs_init(void)
>  {
>  	dbfs_dir = debugfs_create_dir("s390_hypfs", NULL);
> -	return PTR_RET(dbfs_dir);
> +	return PTR_ERR_OR_ZERO(dbfs_dir);
>  }
>  
>  void hypfs_dbfs_exit(void)
> diff --git a/drivers/char/tile-srom.c b/drivers/char/tile-srom.c
> index 2e2036e..a3a792f 100644
> --- a/drivers/char/tile-srom.c
> +++ b/drivers/char/tile-srom.c
> @@ -371,7 +371,7 @@ static int srom_setup_minor(struct srom_dev *srom, int index)
>  
>  	dev = device_create(srom_class, &platform_bus,
>  			    MKDEV(srom_major, index), srom, "%d", index);
> -	return PTR_RET(dev);
> +	return PTR_ERR_OR_ZERO(dev);
>  }
>  
>  /** srom_init() - Initialize the driver's module. */
> diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
> index 71c2c71..17a6ec5 100644
> --- a/drivers/infiniband/core/cma.c
> +++ b/drivers/infiniband/core/cma.c
> @@ -3055,7 +3055,7 @@ static int cma_join_ib_multicast(struct rdma_id_private *id_priv,
>  						id_priv->id.port_num, &rec,
>  						comp_mask, GFP_KERNEL,
>  						cma_ib_mc_handler, mc);
> -	return PTR_RET(mc->multicast.ib);
> +	return PTR_ERR_OR_ZERO(mc->multicast.ib);
>  }
>  
>  static void iboe_mcast_work_handler(struct work_struct *work)
> diff --git a/drivers/net/appletalk/cops.c b/drivers/net/appletalk/cops.c
> index cff6f02..7f2a032 100644
> --- a/drivers/net/appletalk/cops.c
> +++ b/drivers/net/appletalk/cops.c
> @@ -996,7 +996,7 @@ static int __init cops_module_init(void)
>  		printk(KERN_WARNING "%s: You shouldn't autoprobe with insmod\n",
>  			cardname);
>  	cops_dev = cops_probe(-1);
> -	return PTR_RET(cops_dev);
> +	return PTR_ERR_OR_ZERO(cops_dev);
>  }
>  
>  static void __exit cops_module_exit(void)
> diff --git a/drivers/net/appletalk/ltpc.c b/drivers/net/appletalk/ltpc.c
> index b5782cd..01e2ac5 100644
> --- a/drivers/net/appletalk/ltpc.c
> +++ b/drivers/net/appletalk/ltpc.c
> @@ -1243,7 +1243,7 @@ static int __init ltpc_module_init(void)
>  		       "ltpc: Autoprobing is not recommended for modules\n");
>  
>  	dev_ltpc = ltpc_probe();
> -	return PTR_RET(dev_ltpc);
> +	return PTR_ERR_OR_ZERO(dev_ltpc);
>  }
>  module_init(ltpc_module_init);
>  #endif
> diff --git a/drivers/net/ethernet/amd/atarilance.c b/drivers/net/ethernet/amd/atarilance.c
> index e8d0ef5..10ceca5 100644
> --- a/drivers/net/ethernet/amd/atarilance.c
> +++ b/drivers/net/ethernet/amd/atarilance.c
> @@ -1147,7 +1147,7 @@ static struct net_device *atarilance_dev;
>  static int __init atarilance_module_init(void)
>  {
>  	atarilance_dev = atarilance_probe(-1);
> -	return PTR_RET(atarilance_dev);
> +	return PTR_ERR_OR_ZERO(atarilance_dev);
>  }
>  
>  static void __exit atarilance_module_exit(void)
> diff --git a/drivers/net/ethernet/amd/mvme147.c b/drivers/net/ethernet/amd/mvme147.c
> index a51497c..e108e91 100644
> --- a/drivers/net/ethernet/amd/mvme147.c
> +++ b/drivers/net/ethernet/amd/mvme147.c
> @@ -188,7 +188,7 @@ static struct net_device *dev_mvme147_lance;
>  int __init init_module(void)
>  {
>  	dev_mvme147_lance = mvme147lance_probe(-1);
> -	return PTR_RET(dev_mvme147_lance);
> +	return PTR_ERR_OR_ZERO(dev_mvme147_lance);
>  }
>  
>  void __exit cleanup_module(void)
> diff --git a/drivers/net/ethernet/amd/ni65.c b/drivers/net/ethernet/amd/ni65.c
> index 26fc0ce..1cf33ad 100644
> --- a/drivers/net/ethernet/amd/ni65.c
> +++ b/drivers/net/ethernet/amd/ni65.c
> @@ -1238,7 +1238,7 @@ MODULE_PARM_DESC(dma, "ni6510 ISA DMA channel (ignored for some cards)");
>  int __init init_module(void)
>  {
>   	dev_ni65 = ni65_probe(-1);
> -	return PTR_RET(dev_ni65);
> +	return PTR_ERR_OR_ZERO(dev_ni65);
>  }
>  
>  void __exit cleanup_module(void)
> diff --git a/drivers/net/ethernet/amd/sun3lance.c b/drivers/net/ethernet/amd/sun3lance.c
> index 4375abe..d6b2029 100644
> --- a/drivers/net/ethernet/amd/sun3lance.c
> +++ b/drivers/net/ethernet/amd/sun3lance.c
> @@ -940,7 +940,7 @@ static struct net_device *sun3lance_dev;
>  int __init init_module(void)
>  {
>  	sun3lance_dev = sun3lance_probe(-1);
> -	return PTR_RET(sun3lance_dev);
> +	return PTR_ERR_OR_ZERO(sun3lance_dev);
>  }
>  
>  void __exit cleanup_module(void)
> diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd_dbg.c b/drivers/net/wireless/brcm80211/brcmfmac/dhd_dbg.c
> index 202869c..3962a7a 100644
> --- a/drivers/net/wireless/brcm80211/brcmfmac/dhd_dbg.c
> +++ b/drivers/net/wireless/brcm80211/brcmfmac/dhd_dbg.c
> @@ -50,7 +50,7 @@ int brcmf_debugfs_attach(struct brcmf_pub *drvr)
>  		return -ENODEV;
>  
>  	drvr->dbgfs_dir = debugfs_create_dir(dev_name(dev), root_folder);
> -	return PTR_RET(drvr->dbgfs_dir);
> +	return PTR_ERR_OR_ZERO(drvr->dbgfs_dir);
>  }
>  
>  void brcmf_debugfs_detach(struct brcmf_pub *drvr)
> diff --git a/drivers/net/wireless/brcm80211/brcmsmac/debug.c b/drivers/net/wireless/brcm80211/brcmsmac/debug.c
> index 9761deb..a5d4add 100644
> --- a/drivers/net/wireless/brcm80211/brcmsmac/debug.c
> +++ b/drivers/net/wireless/brcm80211/brcmsmac/debug.c
> @@ -56,7 +56,7 @@ int brcms_debugfs_attach(struct brcms_pub *drvr)
>  
>  	drvr->dbgfs_dir = debugfs_create_dir(
>  		 dev_name(&drvr->wlc->hw->d11core->dev), root_folder);
> -	return PTR_RET(drvr->dbgfs_dir);
> +	return PTR_ERR_OR_ZERO(drvr->dbgfs_dir);
>  }
>  
>  void brcms_debugfs_detach(struct brcms_pub *drvr)
> diff --git a/drivers/platform/x86/samsung-q10.c b/drivers/platform/x86/samsung-q10.c
> index 1a90b62..4430b8c 100644
> --- a/drivers/platform/x86/samsung-q10.c
> +++ b/drivers/platform/x86/samsung-q10.c
> @@ -176,7 +176,7 @@ static int __init samsungq10_init(void)
>  						   samsungq10_probe,
>  						   NULL, 0, NULL, 0);
>  
> -	return PTR_RET(samsungq10_device);
> +	return PTR_ERR_OR_ZERO(samsungq10_device);
>  }
>  
>  static void __exit samsungq10_exit(void)
> diff --git a/drivers/regulator/fan53555.c b/drivers/regulator/fan53555.c
> index f0e1ae5..192444a 100644
> --- a/drivers/regulator/fan53555.c
> +++ b/drivers/regulator/fan53555.c
> @@ -219,7 +219,7 @@ static int fan53555_regulator_register(struct fan53555_device_info *di,
>  	rdesc->owner = THIS_MODULE;
>  
>  	di->rdev = regulator_register(&di->desc, config);
> -	return PTR_RET(di->rdev);
> +	return PTR_ERR_OR_ZERO(di->rdev);
>  
>  }
>  
> diff --git a/drivers/spi/spi-fsl-spi.c b/drivers/spi/spi-fsl-spi.c
> index 14e202e..6e80639 100644
> --- a/drivers/spi/spi-fsl-spi.c
> +++ b/drivers/spi/spi-fsl-spi.c
> @@ -901,7 +901,7 @@ static int plat_mpc8xxx_spi_probe(struct platform_device *pdev)
>  		return -EINVAL;
>  
>  	master = fsl_spi_probe(&pdev->dev, mem, irq);
> -	return PTR_RET(master);
> +	return PTR_ERR_OR_ZERO(master);
>  }
>  
>  static int plat_mpc8xxx_spi_remove(struct platform_device *pdev)
> diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
> index 911e9e0..ca5bcfe 100644
> --- a/drivers/spi/spidev.c
> +++ b/drivers/spi/spidev.c
> @@ -603,7 +603,7 @@ static int spidev_probe(struct spi_device *spi)
>  		dev = device_create(spidev_class, &spi->dev, spidev->devt,
>  				    spidev, "spidev%d.%d",
>  				    spi->master->bus_num, spi->chip_select);
> -		status = PTR_RET(dev);
> +		status = PTR_ERR_OR_ZERO(dev);
>  	} else {
>  		dev_dbg(&spi->dev, "no minor number available!\n");
>  		status = -ENODEV;
> diff --git a/drivers/video/omap2/dss/core.c b/drivers/video/omap2/dss/core.c
> index c9c2252..a65f1ac 100644
> --- a/drivers/video/omap2/dss/core.c
> +++ b/drivers/video/omap2/dss/core.c
> @@ -189,7 +189,7 @@ int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *))
>  	d = debugfs_create_file(name, S_IRUGO, dss_debugfs_dir,
>  			write, &dss_debug_fops);
>  
> -	return PTR_RET(d);
> +	return PTR_ERR_OR_ZERO(d);
>  }
>  #else /* CONFIG_OMAP2_DSS_DEBUGFS */
>  static inline int dss_initialize_debugfs(void)
> diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
> index 65241f3..b63903f 100644
> --- a/fs/btrfs/dev-replace.c
> +++ b/fs/btrfs/dev-replace.c
> @@ -747,7 +747,7 @@ int btrfs_resume_dev_replace_async(struct btrfs_fs_info *fs_info)
>  	WARN_ON(atomic_xchg(
>  		&fs_info->mutually_exclusive_operation_running, 1));
>  	task = kthread_run(btrfs_dev_replace_kthread, fs_info, "btrfs-devrepl");
> -	return PTR_RET(task);
> +	return PTR_ERR_OR_ZERO(task);
>  }
>  
>  static int btrfs_dev_replace_kthread(void *data)
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index af978f7..1850a96 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -3140,7 +3140,7 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
>  		found_key.type = BTRFS_INODE_ITEM_KEY;
>  		found_key.offset = 0;
>  		inode = btrfs_iget(root->fs_info->sb, &found_key, root, NULL);
> -		ret = PTR_RET(inode);
> +		ret = PTR_ERR_OR_ZERO(inode);
>  		if (ret && ret != -ESTALE)
>  			goto out;
>  
> diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c
> index 7ad6ecf..edf623a 100644
> --- a/net/bluetooth/hci_sysfs.c
> +++ b/net/bluetooth/hci_sysfs.c
> @@ -590,7 +590,7 @@ int __init bt_sysfs_init(void)
>  
>  	bt_class = class_create(THIS_MODULE, "bluetooth");
>  
> -	return PTR_RET(bt_class);
> +	return PTR_ERR_OR_ZERO(bt_class);
>  }
>  
>  void bt_sysfs_cleanup(void)
> diff --git a/net/bridge/netfilter/ebtable_broute.c b/net/bridge/netfilter/ebtable_broute.c
> index 70f656c..dbd1c78 100644
> --- a/net/bridge/netfilter/ebtable_broute.c
> +++ b/net/bridge/netfilter/ebtable_broute.c
> @@ -64,7 +64,7 @@ static int ebt_broute(struct sk_buff *skb)
>  static int __net_init broute_net_init(struct net *net)
>  {
>  	net->xt.broute_table = ebt_register_table(net, &broute_table);
> -	return PTR_RET(net->xt.broute_table);
> +	return PTR_ERR_OR_ZERO(net->xt.broute_table);
>  }
>  
>  static void __net_exit broute_net_exit(struct net *net)
> diff --git a/net/bridge/netfilter/ebtable_filter.c b/net/bridge/netfilter/ebtable_filter.c
> index 3c2e9dc..94b2b70 100644
> --- a/net/bridge/netfilter/ebtable_filter.c
> +++ b/net/bridge/netfilter/ebtable_filter.c
> @@ -100,7 +100,7 @@ static struct nf_hook_ops ebt_ops_filter[] __read_mostly = {
>  static int __net_init frame_filter_net_init(struct net *net)
>  {
>  	net->xt.frame_filter = ebt_register_table(net, &frame_filter);
> -	return PTR_RET(net->xt.frame_filter);
> +	return PTR_ERR_OR_ZERO(net->xt.frame_filter);
>  }
>  
>  static void __net_exit frame_filter_net_exit(struct net *net)
> diff --git a/net/bridge/netfilter/ebtable_nat.c b/net/bridge/netfilter/ebtable_nat.c
> index 10871bc..322555a 100644
> --- a/net/bridge/netfilter/ebtable_nat.c
> +++ b/net/bridge/netfilter/ebtable_nat.c
> @@ -100,7 +100,7 @@ static struct nf_hook_ops ebt_ops_nat[] __read_mostly = {
>  static int __net_init frame_nat_net_init(struct net *net)
>  {
>  	net->xt.frame_nat = ebt_register_table(net, &frame_nat);
> -	return PTR_RET(net->xt.frame_nat);
> +	return PTR_ERR_OR_ZERO(net->xt.frame_nat);
>  }
>  
>  static void __net_exit frame_nat_net_exit(struct net *net)
> diff --git a/net/ipv4/netfilter/arptable_filter.c b/net/ipv4/netfilter/arptable_filter.c
> index eadab1e..a865f6f 100644
> --- a/net/ipv4/netfilter/arptable_filter.c
> +++ b/net/ipv4/netfilter/arptable_filter.c
> @@ -48,7 +48,7 @@ static int __net_init arptable_filter_net_init(struct net *net)
>  	net->ipv4.arptable_filter =
>  		arpt_register_table(net, &packet_filter, repl);
>  	kfree(repl);
> -	return PTR_RET(net->ipv4.arptable_filter);
> +	return PTR_ERR_OR_ZERO(net->ipv4.arptable_filter);
>  }
>  
>  static void __net_exit arptable_filter_net_exit(struct net *net)
> diff --git a/net/ipv4/netfilter/iptable_filter.c b/net/ipv4/netfilter/iptable_filter.c
> index 6b3da5c..50af5b4 100644
> --- a/net/ipv4/netfilter/iptable_filter.c
> +++ b/net/ipv4/netfilter/iptable_filter.c
> @@ -69,7 +69,7 @@ static int __net_init iptable_filter_net_init(struct net *net)
>  	net->ipv4.iptable_filter =
>  		ipt_register_table(net, &packet_filter, repl);
>  	kfree(repl);
> -	return PTR_RET(net->ipv4.iptable_filter);
> +	return PTR_ERR_OR_ZERO(net->ipv4.iptable_filter);
>  }
>  
>  static void __net_exit iptable_filter_net_exit(struct net *net)
> diff --git a/net/ipv4/netfilter/iptable_mangle.c b/net/ipv4/netfilter/iptable_mangle.c
> index cba5658..0d8cd82 100644
> --- a/net/ipv4/netfilter/iptable_mangle.c
> +++ b/net/ipv4/netfilter/iptable_mangle.c
> @@ -107,7 +107,7 @@ static int __net_init iptable_mangle_net_init(struct net *net)
>  	net->ipv4.iptable_mangle =
>  		ipt_register_table(net, &packet_mangler, repl);
>  	kfree(repl);
> -	return PTR_RET(net->ipv4.iptable_mangle);
> +	return PTR_ERR_OR_ZERO(net->ipv4.iptable_mangle);
>  }
>  
>  static void __net_exit iptable_mangle_net_exit(struct net *net)
> diff --git a/net/ipv4/netfilter/iptable_nat.c b/net/ipv4/netfilter/iptable_nat.c
> index 6383273..683bfaf 100644
> --- a/net/ipv4/netfilter/iptable_nat.c
> +++ b/net/ipv4/netfilter/iptable_nat.c
> @@ -292,7 +292,7 @@ static int __net_init iptable_nat_net_init(struct net *net)
>  		return -ENOMEM;
>  	net->ipv4.nat_table = ipt_register_table(net, &nf_nat_ipv4_table, repl);
>  	kfree(repl);
> -	return PTR_RET(net->ipv4.nat_table);
> +	return PTR_ERR_OR_ZERO(net->ipv4.nat_table);
>  }
>  
>  static void __net_exit iptable_nat_net_exit(struct net *net)
> diff --git a/net/ipv4/netfilter/iptable_raw.c b/net/ipv4/netfilter/iptable_raw.c
> index 03d9696..1f82aea 100644
> --- a/net/ipv4/netfilter/iptable_raw.c
> +++ b/net/ipv4/netfilter/iptable_raw.c
> @@ -48,7 +48,7 @@ static int __net_init iptable_raw_net_init(struct net *net)
>  	net->ipv4.iptable_raw =
>  		ipt_register_table(net, &packet_raw, repl);
>  	kfree(repl);
> -	return PTR_RET(net->ipv4.iptable_raw);
> +	return PTR_ERR_OR_ZERO(net->ipv4.iptable_raw);
>  }
>  
>  static void __net_exit iptable_raw_net_exit(struct net *net)
> diff --git a/net/ipv4/netfilter/iptable_security.c b/net/ipv4/netfilter/iptable_security.c
> index b283d8e..f867a8d 100644
> --- a/net/ipv4/netfilter/iptable_security.c
> +++ b/net/ipv4/netfilter/iptable_security.c
> @@ -66,7 +66,7 @@ static int __net_init iptable_security_net_init(struct net *net)
>  	net->ipv4.iptable_security =
>  		ipt_register_table(net, &security_table, repl);
>  	kfree(repl);
> -	return PTR_RET(net->ipv4.iptable_security);
> +	return PTR_ERR_OR_ZERO(net->ipv4.iptable_security);
>  }
>  
>  static void __net_exit iptable_security_net_exit(struct net *net)
> diff --git a/net/ipv6/netfilter/ip6table_filter.c b/net/ipv6/netfilter/ip6table_filter.c
> index beb5777..29b44b1 100644
> --- a/net/ipv6/netfilter/ip6table_filter.c
> +++ b/net/ipv6/netfilter/ip6table_filter.c
> @@ -61,7 +61,7 @@ static int __net_init ip6table_filter_net_init(struct net *net)
>  	net->ipv6.ip6table_filter =
>  		ip6t_register_table(net, &packet_filter, repl);
>  	kfree(repl);
> -	return PTR_RET(net->ipv6.ip6table_filter);
> +	return PTR_ERR_OR_ZERO(net->ipv6.ip6table_filter);
>  }
>  
>  static void __net_exit ip6table_filter_net_exit(struct net *net)
> diff --git a/net/ipv6/netfilter/ip6table_mangle.c b/net/ipv6/netfilter/ip6table_mangle.c
> index e075399..c705907 100644
> --- a/net/ipv6/netfilter/ip6table_mangle.c
> +++ b/net/ipv6/netfilter/ip6table_mangle.c
> @@ -101,7 +101,7 @@ static int __net_init ip6table_mangle_net_init(struct net *net)
>  	net->ipv6.ip6table_mangle =
>  		ip6t_register_table(net, &packet_mangler, repl);
>  	kfree(repl);
> -	return PTR_RET(net->ipv6.ip6table_mangle);
> +	return PTR_ERR_OR_ZERO(net->ipv6.ip6table_mangle);
>  }
>  
>  static void __net_exit ip6table_mangle_net_exit(struct net *net)
> diff --git a/net/ipv6/netfilter/ip6table_nat.c b/net/ipv6/netfilter/ip6table_nat.c
> index 6383f90..9b076d2 100644
> --- a/net/ipv6/netfilter/ip6table_nat.c
> +++ b/net/ipv6/netfilter/ip6table_nat.c
> @@ -293,7 +293,7 @@ static int __net_init ip6table_nat_net_init(struct net *net)
>  		return -ENOMEM;
>  	net->ipv6.ip6table_nat = ip6t_register_table(net, &nf_nat_ipv6_table, repl);
>  	kfree(repl);
> -	return PTR_RET(net->ipv6.ip6table_nat);
> +	return PTR_ERR_OR_ZERO(net->ipv6.ip6table_nat);
>  }
>  
>  static void __net_exit ip6table_nat_net_exit(struct net *net)
> diff --git a/net/ipv6/netfilter/ip6table_raw.c b/net/ipv6/netfilter/ip6table_raw.c
> index 60d1bdd..9a626d8 100644
> --- a/net/ipv6/netfilter/ip6table_raw.c
> +++ b/net/ipv6/netfilter/ip6table_raw.c
> @@ -40,7 +40,7 @@ static int __net_init ip6table_raw_net_init(struct net *net)
>  	net->ipv6.ip6table_raw =
>  		ip6t_register_table(net, &packet_raw, repl);
>  	kfree(repl);
> -	return PTR_RET(net->ipv6.ip6table_raw);
> +	return PTR_ERR_OR_ZERO(net->ipv6.ip6table_raw);
>  }
>  
>  static void __net_exit ip6table_raw_net_exit(struct net *net)
> diff --git a/net/ipv6/netfilter/ip6table_security.c b/net/ipv6/netfilter/ip6table_security.c
> index db15535..ce88d1d 100644
> --- a/net/ipv6/netfilter/ip6table_security.c
> +++ b/net/ipv6/netfilter/ip6table_security.c
> @@ -58,7 +58,7 @@ static int __net_init ip6table_security_net_init(struct net *net)
>  	net->ipv6.ip6table_security =
>  		ip6t_register_table(net, &security_table, repl);
>  	kfree(repl);
> -	return PTR_RET(net->ipv6.ip6table_security);
> +	return PTR_ERR_OR_ZERO(net->ipv6.ip6table_security);
>  }
>  
>  static void __net_exit ip6table_security_net_exit(struct net *net)
> diff --git a/scripts/coccinelle/api/ptr_ret.cocci b/scripts/coccinelle/api/ptr_ret.cocci
> index 15f076f..e0981bb 100644
> --- a/scripts/coccinelle/api/ptr_ret.cocci
> +++ b/scripts/coccinelle/api/ptr_ret.cocci
> @@ -1,5 +1,5 @@
>  ///
> -/// Use PTR_RET rather than if(IS_ERR(...)) + PTR_ERR
> +/// Use PTR_ERR_OR_ZERO rather than if(IS_ERR(...)) + PTR_ERR
>  ///
>  // Confidence: High
>  // Copyright: (C) 2012 Julia Lawall, INRIA/LIP6.  GPLv2.
> @@ -7,7 +7,7 @@
>  // URL: http://coccinelle.lip6.fr/
>  // Options: -no_includes -include_headers
>  //
> -// Keywords: ERR_PTR, PTR_ERR, PTR_RET
> +// Keywords: ERR_PTR, PTR_ERR, PTR_RET, PTR_ERR_OR_ZERO
>  // Version min: 2.6.39
>  //
>  
> @@ -21,21 +21,21 @@ expression ptr;
>  @@
>  
>  - if (IS_ERR(ptr)) return PTR_ERR(ptr); else return 0;
> -+ return PTR_RET(ptr);
> ++ return PTR_ERR_OR_ZERO(ptr);
>  
>  @depends on patch@
>  expression ptr;
>  @@
>  
>  - if (IS_ERR(ptr)) return PTR_ERR(ptr); return 0;
> -+ return PTR_RET(ptr);
> ++ return PTR_ERR_OR_ZERO(ptr);
>  
>  @depends on patch@
>  expression ptr;
>  @@
>  
>  - (IS_ERR(ptr) ? PTR_ERR(ptr) : 0)
> -+ PTR_RET(ptr)
> ++ PTR_ERR_OR_ZERO(ptr)
>  
>  @r1 depends on !patch@
>  expression ptr;
> diff --git a/sound/soc/soc-io.c b/sound/soc/soc-io.c
> index 8ca9ecc..122c0c1 100644
> --- a/sound/soc/soc-io.c
> +++ b/sound/soc/soc-io.c
> @@ -158,7 +158,7 @@ int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,
>  		return -EINVAL;
>  	}
>  
> -	return PTR_RET(codec->control_data);
> +	return PTR_ERR_OR_ZERO(codec->control_data);
>  }
>  EXPORT_SYMBOL_GPL(snd_soc_codec_set_cache_io);
>  #else



^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2013-06-25  7:49 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).