Re: [PATCH] sound_core.c: Remove BKL from soundcore_open

From: John Kacur
Date: Mon Oct 12 2009 - 06:45:21 EST




On Mon, 12 Oct 2009, Takashi Iwai wrote:

> At Mon, 12 Oct 2009 10:37:05 +0200 (CEST),
> John Kacur wrote:
> >
> > On Mon, 12 Oct 2009, Takashi Iwai wrote:
> >
> > > At Sun, 11 Oct 2009 14:41:15 +0200 (CEST),
> > > John Kacur wrote:
> > > >
> > > > @@ -631,17 +629,17 @@ static int soundcore_open(struct inode *inode, struct file *file)
> > > > file->f_op = new_fops;
> > > > spin_unlock(&sound_loader_lock);
> > > > if(file->f_op->open)
> > > > + lock_kernel();
> > > > err = file->f_op->open(inode,file);
> > > > + unlock_kernel();
> > >
> > > You certainly want braces around here, no?
> > >
> >
> > Oh, I don't know, I was kinda hoping that the spaces would magically
> > impart bracketnishish to the whole thing. My God yes we want the brackets -
> > Thank you Takashi!
> >
> > What follows is version four.
> >
> > >From 90f527d2ae660a3a0e712075479a4cc24504ad45 Mon Sep 17 00:00:00 2001
> > From: John Kacur <jkacur@xxxxxxxxxx>
> > Date: Sun, 11 Oct 2009 14:25:46 +0200
> > Subject: [PATCH] soundcore_open: Reduce the area BKL coverage in this function.
> >
> > Most of this function is protected by the sound_loader_lock.
> > We can push down the BKL to this call out err = file->f_op->open(inode,file);
> >
> > Signed-off-by: John Kacur <jkacur@xxxxxxxxxx>
> > Acked-by: Alan Cox <alan@xxxxxxxxxxxxxxx>
> > ---
> > sound/sound_core.c | 10 ++++------
> > 1 files changed, 4 insertions(+), 6 deletions(-)
> >
> > diff --git a/sound/sound_core.c b/sound/sound_core.c
> > index 49c9981..643a61f 100644
> > --- a/sound/sound_core.c
> > +++ b/sound/sound_core.c
> > @@ -576,8 +576,6 @@ static int soundcore_open(struct inode *inode, struct file *file)
> > struct sound_unit *s;
> > const struct file_operations *new_fops = NULL;
> >
> > - lock_kernel ();
> > -
> > chain=unit&0x0F;
> > if(chain==4 || chain==5) /* dsp/audio/dsp16 */
> > {
> > @@ -630,18 +628,18 @@ static int soundcore_open(struct inode *inode, struct file *file)
> > const struct file_operations *old_fops = file->f_op;
> > file->f_op = new_fops;
> > spin_unlock(&sound_loader_lock);
> > - if(file->f_op->open)
> > + if(file->f_op->open) {
> > + lock_kernel();
> > err = file->f_op->open(inode,file);
> > - if (err) {
> > + unlock_kernel();
> > + } if (err) {
>
> It's better to break the line after the closing brace here.
>

Thank you for your review Takashi.

I corrected the style problems, and added a bit of spacing to make the
code more readable.

Version 5 follows