Re: [PATCH] irda: remove BKL from irnet open function

From: Thadeu Lima de Souza Cascardo
Date: Mon Feb 01 2010 - 15:40:34 EST


On Mon, Feb 01, 2010 at 09:32:30PM +0100, John Kacur wrote:
> On Mon, Feb 1, 2010 at 7:18 PM, Thadeu Lima de Souza Cascardo
> <cascardo@xxxxxxxxxxxxxx> wrote:
> > Commit cddf63d99d0d145f18b293c3d0de4af7dab2a922 has push down the BKL
> > into irnet open function. However, there's nothing that needs locking in
> > there.
> >
> > Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@xxxxxxxxxxxxxx>
> > ---
> > Ânet/irda/irnet/irnet_ppp.c | Â Â3 ---
> > Â1 files changed, 0 insertions(+), 3 deletions(-)
> >
> > diff --git a/net/irda/irnet/irnet_ppp.c b/net/irda/irnet/irnet_ppp.c
> > index 156020d..d6b502c 100644
> > --- a/net/irda/irnet/irnet_ppp.c
> > +++ b/net/irda/irnet/irnet_ppp.c
> > @@ -479,7 +479,6 @@ dev_irnet_open(struct inode * Â Â Â inode,
> > Â ap = kzalloc(sizeof(*ap), GFP_KERNEL);
> > Â DABORT(ap == NULL, -ENOMEM, FS_ERROR, "Can't allocate struct irnet...\n");
> >
> > - Âlock_kernel();
> > Â /* initialize the irnet structure */
> > Â ap->file = file;
> >
> > @@ -501,7 +500,6 @@ dev_irnet_open(struct inode * Â Â Â inode,
> > Â Â {
> > Â Â Â DERROR(FS_ERROR, "Can't setup IrDA link...\n");
> > Â Â Â kfree(ap);
> > - Â Â Âunlock_kernel();
> > Â Â Â return err;
> > Â Â }
> >
> > @@ -512,7 +510,6 @@ dev_irnet_open(struct inode * Â Â Â inode,
> > Â file->private_data = ap;
> >
> > Â DEXIT(FS_TRACE, " - ap=0x%p\n", ap);
> > - Âunlock_kernel();
> > Â return 0;
> > Â}
> >
> > --
> > 1.6.6.1
>
> This is probably NOT safe to do, because the BKL is synchronizing the
> ioctl code.
>
> Thanks

And is it possible that ioctl will be called before open returns? If it
is, then, yes, this is not safe. But I don't really believe the case. Or
is it?

Or is it only possible to happen with different struct file*? In that
case, open is only allocating and initializing the irnet_socket *ap.
Then, ioctl uses it. There is some race between the different ioctls,
but no race between open/ioctl for different opened devices. That is, a
process may open /dev/irnet while another process is issuing ioctls to
its own opened /dev/irnet.

Besides, dev_irnet_ioctl uses the file private_data to get to the
irnet_socket, which is the last thing the open call does. I assume doing
an attribution to a pointer is atomic in all architectures supported by
Linux currently, isn't it?

Regards,
Cascardo.

Attachment: signature.asc
Description: Digital signature