lkml.org 
[lkml]   [2015]   [Nov]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Anonymous inode cleanup?
On Thu, Nov 12, 2015 at 09:43:00PM -0800, Rajat Jain wrote:
> Hello,
>
> I'm writing a module that wants to get anonymous fd [using
> anon_inode_getfd()] and my code looks like this:
>
> fd = anon_inode_getfd(...)
> if (fd < 0)
> return -EINVAL;
>
> if (foobar_fail()) {
> /* undo everything */
> return -EINVAL;
> }
>
> My question is that in case of a failure after the anon_inode_getfd(),
> I want to cleanup and undo whatever needs to be done w.r.t. anodnymous
> fd I just allocated. (May be put a reference, or return the fd to the
> free pool or whatever). Can some one please let me know what cleanup
> needs to be done?
>
> However neither I see a cleanup function, nor I see any of the drivers
> attempting
> to free the fd in case of failure.
>

It is impossible to properly clean up in this case without serious
tinkering. In fact this code cannot realiably work without weird
locking. By the time anon_inode_getfd returns, the file could have been
closed by a different thread.

What you want instead is anon_inode_getfile. See perf_event_open for an
example how to use it.

--
Mateusz Guzik


\
 
 \ /
  Last update: 2015-11-13 07:21    [W:0.044 / U:0.936 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site