All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drivers: virtio: Use PTR_RET function
@ 2013-03-25 13:25 Alexandru Gheorghiu
  0 siblings, 0 replies; 9+ messages in thread
From: Alexandru Gheorghiu @ 2013-03-25 13:25 UTC (permalink / raw)
  To: Rusty Russell
  Cc: Alexandru Gheorghiu, virtualization, linux-kernel, Michael S. Tsirkin

Used PTR_RET function instead of IS_ERR and PTR_ERR.
Patch found using coccinelle.

Signed-off-by: Alexandru Gheorghiu <gheorghiuandru@gmail.com>
---
 drivers/virtio/virtio_mmio.c |    5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
index 1ba0d68..d1e664f 100644
--- a/drivers/virtio/virtio_mmio.c
+++ b/drivers/virtio/virtio_mmio.c
@@ -567,10 +567,7 @@ static int vm_cmdline_set(const char *device,
 	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)
-- 
1.7.9.5

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

* Re: [PATCH] drivers: virtio: Use PTR_RET function
  2013-03-26  7:41     ` Andru Gheorghiu
@ 2013-03-26 10:23         ` Rusty Russell
  0 siblings, 0 replies; 9+ messages in thread
From: Rusty Russell @ 2013-03-26 10:23 UTC (permalink / raw)
  To: Andru Gheorghiu, Andrew Morton
  Cc: Michael S. Tsirkin, virtualization, linux-kernel, Uwe Kleine-König

Andru Gheorghiu <gheorghiuandru@gmail.com> writes:
> PTR_RET does return. It's perfectly equivalent to using IS_ERR and the
> returning PTR_ERR. The implementation is here [1].

Um, I read the implementation, thanks.

> The reason for using it is this: if you have a function that does
> something why not call it instead of reproducing it's behavior by
> explicitly writing what it does.

Because clarity matters, and this function makes callers less clear.
It's the most breathtakingly bad name since BUILD_BUG_ON_ZERO().

Why not change PTR_ERR to return 0 if !IS_ERR()?  Noone breaks, gcc
probably produces the same code, and noone needs to learn your weird
new kernel meme.

In fact, as gcc will produce the same code for "if (PTR_ERR(p))" as it
does for "if (IS_ERR(p))", you get to be one of the very, very few
people who have ever *reduced* the complexity of a kernel interface.

Cheers,
Rusty.

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

* Re: [PATCH] drivers: virtio: Use PTR_RET function
@ 2013-03-26 10:23         ` Rusty Russell
  0 siblings, 0 replies; 9+ messages in thread
From: Rusty Russell @ 2013-03-26 10:23 UTC (permalink / raw)
  To: Andru Gheorghiu, Andrew Morton
  Cc: Uwe Kleine-König, virtualization, linux-kernel, Michael S. Tsirkin

Andru Gheorghiu <gheorghiuandru@gmail.com> writes:
> PTR_RET does return. It's perfectly equivalent to using IS_ERR and the
> returning PTR_ERR. The implementation is here [1].

Um, I read the implementation, thanks.

> The reason for using it is this: if you have a function that does
> something why not call it instead of reproducing it's behavior by
> explicitly writing what it does.

Because clarity matters, and this function makes callers less clear.
It's the most breathtakingly bad name since BUILD_BUG_ON_ZERO().

Why not change PTR_ERR to return 0 if !IS_ERR()?  Noone breaks, gcc
probably produces the same code, and noone needs to learn your weird
new kernel meme.

In fact, as gcc will produce the same code for "if (PTR_ERR(p))" as it
does for "if (IS_ERR(p))", you get to be one of the very, very few
people who have ever *reduced* the complexity of a kernel interface.

Cheers,
Rusty.

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

* Re: [PATCH] drivers: virtio: Use PTR_RET function
  2013-03-26  5:01     ` Andrew Morton
  (?)
@ 2013-03-26  7:41     ` Andru Gheorghiu
  2013-03-26 10:23         ` Rusty Russell
  -1 siblings, 1 reply; 9+ messages in thread
From: Andru Gheorghiu @ 2013-03-26  7:41 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Uwe Kleine-König, virtualization, linux-kernel, Michael S. Tsirkin


[-- Attachment #1.1: Type: text/plain, Size: 1319 bytes --]

PTR_RET does return. It's perfectly equivalent to using IS_ERR and the
returning PTR_ERR. The implementation is here [1]. The reason for using it
is this: if you have a function that does something why not call it instead
of reproducing it's behavior by explicitly writing what it does.

[1] http://lxr.free-electrons.com/source/include/linux/err.h#L55

Alexandru Gheorghiu


On Tue, Mar 26, 2013 at 7:01 AM, Andrew Morton <akpm@linux-foundation.org>wrote:

> On Tue, 26 Mar 2013 13:57:09 +1030 Rusty Russell <rusty@rustcorp.com.au>
> wrote:
>
> > Alexandru Gheorghiu <gheorghiuandru@gmail.com> writes:
> >
> > > Used PTR_RET function instead of IS_ERR and PTR_ERR.
> > > Patch found using coccinelle.
> >
> > WTF is PTR_RET?  PTR_RET doesn't return anything.  Why is it called
> > that?  It doesn't even make sense.
> >
> > ZERO_OR_PTR_ERR() maybe.
> >
> > But what problem are we solving?  Insufficient churn in the tree?  Code
> > being too readable?  This isn't some hard-to-get right corner case, or a
> > missed optimization.
> >
> > Andrew, what am I missing here?
>
> It seemed like a good idea at the time.  Merged it two years ago and
> have since been keenly awaiting an opportunity to use it.
>
> It seems that people _have_ been using it, but mainly netfilter people
> and we know they're all crazy ;)
>
>

[-- Attachment #1.2: Type: text/html, Size: 1981 bytes --]

[-- Attachment #2: Type: text/plain, Size: 183 bytes --]

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

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

* Re: [PATCH] drivers: virtio: Use PTR_RET function
  2013-03-26  3:27   ` Rusty Russell
@ 2013-03-26  5:01     ` Andrew Morton
  -1 siblings, 0 replies; 9+ messages in thread
From: Andrew Morton @ 2013-03-26  5:01 UTC (permalink / raw)
  To: Rusty Russell
  Cc: Alexandru Gheorghiu, Michael S. Tsirkin, virtualization,
	linux-kernel, Uwe Kleine-König

On Tue, 26 Mar 2013 13:57:09 +1030 Rusty Russell <rusty@rustcorp.com.au> wrote:

> Alexandru Gheorghiu <gheorghiuandru@gmail.com> writes:
> 
> > Used PTR_RET function instead of IS_ERR and PTR_ERR.
> > Patch found using coccinelle.
> 
> WTF is PTR_RET?  PTR_RET doesn't return anything.  Why is it called
> that?  It doesn't even make sense.
> 
> ZERO_OR_PTR_ERR() maybe.
> 
> But what problem are we solving?  Insufficient churn in the tree?  Code
> being too readable?  This isn't some hard-to-get right corner case, or a
> missed optimization.
> 
> Andrew, what am I missing here?

It seemed like a good idea at the time.  Merged it two years ago and
have since been keenly awaiting an opportunity to use it.

It seems that people _have_ been using it, but mainly netfilter people
and we know they're all crazy ;)


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

* Re: [PATCH] drivers: virtio: Use PTR_RET function
@ 2013-03-26  5:01     ` Andrew Morton
  0 siblings, 0 replies; 9+ messages in thread
From: Andrew Morton @ 2013-03-26  5:01 UTC (permalink / raw)
  To: Rusty Russell
  Cc: Alexandru Gheorghiu, virtualization, Uwe Kleine-König,
	linux-kernel, Michael S. Tsirkin

On Tue, 26 Mar 2013 13:57:09 +1030 Rusty Russell <rusty@rustcorp.com.au> wrote:

> Alexandru Gheorghiu <gheorghiuandru@gmail.com> writes:
> 
> > Used PTR_RET function instead of IS_ERR and PTR_ERR.
> > Patch found using coccinelle.
> 
> WTF is PTR_RET?  PTR_RET doesn't return anything.  Why is it called
> that?  It doesn't even make sense.
> 
> ZERO_OR_PTR_ERR() maybe.
> 
> But what problem are we solving?  Insufficient churn in the tree?  Code
> being too readable?  This isn't some hard-to-get right corner case, or a
> missed optimization.
> 
> Andrew, what am I missing here?

It seemed like a good idea at the time.  Merged it two years ago and
have since been keenly awaiting an opportunity to use it.

It seems that people _have_ been using it, but mainly netfilter people
and we know they're all crazy ;)

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

* Re: [PATCH] drivers: virtio: Use PTR_RET function
  2013-03-25 13:25 Alexandru Gheorghiu
@ 2013-03-26  3:27   ` Rusty Russell
  0 siblings, 0 replies; 9+ messages in thread
From: Rusty Russell @ 2013-03-26  3:27 UTC (permalink / raw)
  To: Alexandru Gheorghiu
  Cc: Michael S. Tsirkin, virtualization, linux-kernel,
	Alexandru Gheorghiu, Uwe Kleine-König, Andrew Morton

Alexandru Gheorghiu <gheorghiuandru@gmail.com> writes:

> Used PTR_RET function instead of IS_ERR and PTR_ERR.
> Patch found using coccinelle.

WTF is PTR_RET?  PTR_RET doesn't return anything.  Why is it called
that?  It doesn't even make sense.

ZERO_OR_PTR_ERR() maybe.

But what problem are we solving?  Insufficient churn in the tree?  Code
being too readable?  This isn't some hard-to-get right corner case, or a
missed optimization.

Andrew, what am I missing here?

Grumpy,
Rusty.

> Signed-off-by: Alexandru Gheorghiu <gheorghiuandru@gmail.com>
> ---
>  drivers/virtio/virtio_mmio.c |    5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
> index 1ba0d68..d1e664f 100644
> --- a/drivers/virtio/virtio_mmio.c
> +++ b/drivers/virtio/virtio_mmio.c
> @@ -567,10 +567,7 @@ static int vm_cmdline_set(const char *device,
>  	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)
> -- 
> 1.7.9.5

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

* Re: [PATCH] drivers: virtio: Use PTR_RET function
@ 2013-03-26  3:27   ` Rusty Russell
  0 siblings, 0 replies; 9+ messages in thread
From: Rusty Russell @ 2013-03-26  3:27 UTC (permalink / raw)
  Cc: Michael S. Tsirkin, linux-kernel, virtualization,
	Alexandru Gheorghiu, Uwe Kleine-König, Andrew Morton

Alexandru Gheorghiu <gheorghiuandru@gmail.com> writes:

> Used PTR_RET function instead of IS_ERR and PTR_ERR.
> Patch found using coccinelle.

WTF is PTR_RET?  PTR_RET doesn't return anything.  Why is it called
that?  It doesn't even make sense.

ZERO_OR_PTR_ERR() maybe.

But what problem are we solving?  Insufficient churn in the tree?  Code
being too readable?  This isn't some hard-to-get right corner case, or a
missed optimization.

Andrew, what am I missing here?

Grumpy,
Rusty.

> Signed-off-by: Alexandru Gheorghiu <gheorghiuandru@gmail.com>
> ---
>  drivers/virtio/virtio_mmio.c |    5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
> index 1ba0d68..d1e664f 100644
> --- a/drivers/virtio/virtio_mmio.c
> +++ b/drivers/virtio/virtio_mmio.c
> @@ -567,10 +567,7 @@ static int vm_cmdline_set(const char *device,
>  	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)
> -- 
> 1.7.9.5

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

* [PATCH] drivers: virtio: Use PTR_RET function
@ 2013-03-25 13:25 Alexandru Gheorghiu
  2013-03-26  3:27   ` Rusty Russell
  0 siblings, 1 reply; 9+ messages in thread
From: Alexandru Gheorghiu @ 2013-03-25 13:25 UTC (permalink / raw)
  To: Rusty Russell
  Cc: Michael S. Tsirkin, virtualization, linux-kernel, Alexandru Gheorghiu

Used PTR_RET function instead of IS_ERR and PTR_ERR.
Patch found using coccinelle.

Signed-off-by: Alexandru Gheorghiu <gheorghiuandru@gmail.com>
---
 drivers/virtio/virtio_mmio.c |    5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
index 1ba0d68..d1e664f 100644
--- a/drivers/virtio/virtio_mmio.c
+++ b/drivers/virtio/virtio_mmio.c
@@ -567,10 +567,7 @@ static int vm_cmdline_set(const char *device,
 	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)
-- 
1.7.9.5


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

end of thread, other threads:[~2013-03-26 22:51 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-25 13:25 [PATCH] drivers: virtio: Use PTR_RET function Alexandru Gheorghiu
2013-03-25 13:25 Alexandru Gheorghiu
2013-03-26  3:27 ` Rusty Russell
2013-03-26  3:27   ` Rusty Russell
2013-03-26  5:01   ` Andrew Morton
2013-03-26  5:01     ` Andrew Morton
2013-03-26  7:41     ` Andru Gheorghiu
2013-03-26 10:23       ` Rusty Russell
2013-03-26 10:23         ` Rusty Russell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.