[lkml]   [2019]   [Nov]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [PATCH v16 02/12] namei: allow nd_jump_link() to produce errors
On Sat, Nov 16, 2019 at 11:27:52AM +1100, Aleksa Sarai wrote:
> + error = nd_jump_link(&path);
> + if (error)
> + path_put(&path);

> + error = nd_jump_link(&ns_path);
> + if (error)
> + path_put(&ns_path);

> + error = nd_jump_link(&path);
> + if (error)
> + path_put(&path);

3 calls. Exact same boilerplate in each to handle a failure case.
Which spells "wrong calling conventions"; it's absolutely clear
that we want that path_put() inside nd_jump_link().

The rule should be this: reference that used to be held in
*path is consumed in any case. On success it goes into
nd->path, on error it's just dropped, but in any case, the
caller has the same refcounting environment to deal with.

If you need the same boilerplate cleanup on failure again and again,
the calling conventions are wrong and need to be fixed.

And I'm not sure that int is the right return type here, to be honest.
void * might be better - return ERR_PTR() or NULL, so that the value
could be used as return value of ->get_link() that calls that thing.

 \ /
  Last update: 2019-11-16 01:39    [W:0.082 / U:1.104 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site