Nathan Lynch wrote: > > One could argue that the real problem is using the proc_dir_entry's > reference count to enforce exclusive open.
I think this is better... the way these files are used is lame, but this should preserve the existing behavior. I haven't yet tested this, can you? diff --git a/arch/powerpc/kernel/rtas_flash.c b/arch/powerpc/kernel/rtas_flash.c index f227659..00bc308 100644 --- a/arch/powerpc/kernel/rtas_flash.c +++ b/arch/powerpc/kernel/rtas_flash.c @@ -139,7 +139,7 @@ struct rtas_validate_flash_t unsigned int update_results; /* Update results token */ }; -static DEFINE_SPINLOCK(flash_file_open_lock); +static atomic_t open_count = ATOMIC_INIT(0); static struct proc_dir_entry *firmware_flash_pde; static struct proc_dir_entry *firmware_update_pde; static struct proc_dir_entry *validate_pde; @@ -216,7 +216,7 @@ static int rtas_flash_release(struct inode *inode, struct file *file) uf->flist = NULL; } - atomic_dec(&dp->count); + atomic_dec(&open_count); return 0; } @@ -352,26 +352,17 @@ static ssize_t rtas_flash_write(struct file *file, const char __user *buffer, static int rtas_excl_open(struct inode *inode, struct file *file) { - struct proc_dir_entry *dp = PDE(inode); - - /* Enforce exclusive open with use count of PDE */ - spin_lock(&flash_file_open_lock); - if (atomic_read(&dp->count) > 1) { - spin_unlock(&flash_file_open_lock); + if (atomic_inc_return(&open_count) > 1) { + atomic_dec(&open_count); return -EBUSY; } - atomic_inc(&dp->count); - spin_unlock(&flash_file_open_lock); - return 0; } static int rtas_excl_release(struct inode *inode, struct file *file) { - struct proc_dir_entry *dp = PDE(inode); - - atomic_dec(&dp->count); + atomic_dec(&open_count); return 0; } @@ -580,7 +571,7 @@ static int validate_flash_release(struct inode *inode, struct file *file) } /* The matching atomic_inc was in rtas_excl_open() */ - atomic_dec(&dp->count); + atomic_dec(&open_count); return 0; } _______________________________________________ Linuxppc-dev mailing list Linuxppc-dev@ozlabs.org https://ozlabs.org/mailman/listinfo/linuxppc-dev