Re: [PATCH] rtc.c fix

From: Cesar Eduardo Barros (cesarb@web4u.com.br)
Date: Fri Apr 28 2000 - 15:30:46 EST


On Fri, Apr 28, 2000 at 08:56:52PM +0100, Tigran Aivazian wrote:
> On Fri, 28 Apr 2000, Cesar Eduardo Barros wrote:
> > static int rtc_open(struct inode *inode, struct file *file)
> > {
> > - unsigned long flags;
> > -
> > - if(atomic_read(&rtc_status) & RTC_IS_OPEN)
> > + /* If someday somebody decides to remove the kernel_lock on open and
> > + * close and ioctl this is gonna get open to races */
> > + if(rtc_status & RTC_IS_OPEN)
> > return -EBUSY;
> >
> > MOD_INC_USE_COUNT;
> >
> > - atomic_set(&rtc_status, atomic_read(&rtc_status) | RTC_IS_OPEN);
> > + rtc_status |= RTC_IS_OPEN;
> >
>
> why not use:
>
> if (test_and_set_bit(RTC_IS_OPEN, &rtc_status))
> return -EBUSY;
>
> (and also get rid of the comment claiming that it has a problem because
> then it won't).

There is no need, we will never have two threads of control trying to change
rtc_status at the same time, because of the kernel lock. The comment is a
reminder for the future (I believe someday the kernel lock will be removed from
open, close or ioctl).

-- 
Cesar Eduardo Barros
cesarb@web4u.com.br
cesarb@dcc.ufrj.br

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sun Apr 30 2000 - 21:00:15 EST