Re: [PATCH v2] perf: Synchronously cleanup child events

From: Peter Zijlstra
Date: Tue Jan 26 2016 - 12:24:35 EST


On Tue, Jan 26, 2016 at 05:16:37PM +0100, Peter Zijlstra wrote:
> > +struct file *perf_event_get(unsigned int fd)
> > {
> > + struct file *file;
> >
> > + file = fget_raw(fd);
>
> fget_raw() to guarantee the return value isn't NULL? afaict the O_PATH
> stuff does not apply to perf events, so you'd put any fd for which the
> distinction matters anyway.
>
> > + if (file->f_op != &perf_fops) {
> > + fput(file);
> > + return ERR_PTR(-EBADF);
> > + }
> >
> > + return file;
> > }

It is not possible for one thread to concurrently call close() while
this thread tries to fget() ? In which case, we must check the return
value anyway?