lkml.org 
[lkml]   [2013]   [Jun]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [RFC] PTR_ERR: return 0 if ptr isn't an error value.
Date
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.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2013-06-13 09:01    [W:0.134 / U:0.096 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site