linux-mips
[Top] [All Lists]

Re: [PATCH] use rtc_lock to protect RTC operations

To: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Subject: Re: [PATCH] use rtc_lock to protect RTC operations
From: Ralf Baechle <ralf@linux-mips.org>
Date: Thu, 3 Nov 2005 12:59:26 +0000
Cc: linux-mips@linux-mips.org, "Maciej W. Rozycki" <macro@linux-mips.org>
In-reply-to: <20051103.010115.07642880.anemo@mba.ocn.ne.jp>
Original-recipient: rfc822;linux-mips@linux-mips.org
References: <20051103.010115.07642880.anemo@mba.ocn.ne.jp>
Sender: linux-mips-bounce@linux-mips.org
User-agent: Mutt/1.4.2.1i
On Thu, Nov 03, 2005 at 01:01:15AM +0900, Atsushi Nemoto wrote:

> Many RTC routines are not protected each other.  There are potential
> race, for example, ntp-update and /dev/rtc.  This patch fixes them
> using rtc_lock.
> 
> Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>

> --- a/arch/mips/dec/time.c
> +++ b/arch/mips/dec/time.c
> @@ -37,10 +37,25 @@
>  #include <asm/dec/machtype.h>
>  
>  
> +/*
> + * Returns true if a clock update is in progress
> + */
> +static inline unsigned char dec_rtc_is_updating(void)
> +{
> +     unsigned char uip;
> +     unsigned long flags;
> +
> +     spin_lock_irqsave(&rtc_lock, flags);
> +     uip = (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP);
> +     spin_unlock_irqrestore(&rtc_lock, flags);

Unlike on PC CMOS_READ on a DEC is a single read operation, so atomic
and so doesn't need to be protected.  I'd have to check the datasheet
for any other reason why it might need locking though, so I apply your
patch for now and leave this to Maciej for later optimization.

  Ralf

<Prev in Thread] Current Thread [Next in Thread>