Patchwork ioctl(RTC_IRQP_SET) returns -EACCES, not -EBUSY

login
register
mail settings
Submitter Chris Brand
Date April 4, 2013, 11:42 p.m.
Message ID <20130404234259.6AC95C410D9@lbrmn-lnxub61.ric.broadcom.com>
Download mbox | patch
Permalink /patch/234006/
State New
Headers show

Comments

Chris Brand - April 4, 2013, 11:42 p.m.
Hi,

I'm new here, so please be gentle...

Playing with ioctl(RTC_IRQP_SET), I found that I was getting
"Permission denied" unexpectedly. It turned out that the RTC
was actually busy, and I was hitting some strange behaviour
in the driver. I'd suggest something like the following
patch to fix it.

Chris
(Not subscribed to the list)

From: Chris Brand <chris.brand@broadcom.com>
Date: Thu, 4 Apr 2013 16:19:16 -0700
Subject: [PATCH] RTC: Return -EBUSY, not -EACCES when device is busy

If rtc->irq_task is non-NULL and task is NULL, they always
differ, which means that in rtc_irq_set_state() and
rtc_irq_set_freq(), whenever err is set to -EBUSY it will
then immediately be set to -EACCES, misleading the caller
as to the underlying problem.

Signed-off-by: Chris Brand <chris.brand@broadcom.com>
---
 drivers/rtc/interface.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

Patch

diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 42bd57d..40d4032 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -698,9 +698,9 @@  retry:
 	spin_lock_irqsave(&rtc->irq_task_lock, flags);
 	if (rtc->irq_task != NULL && task == NULL)
 		err = -EBUSY;
-	if (rtc->irq_task != task)
+	else if (rtc->irq_task != task)
 		err = -EACCES;
-	if (!err) {
+	else {
 		if (rtc_update_hrtimer(rtc, enabled) < 0) {
 			spin_unlock_irqrestore(&rtc->irq_task_lock, flags);
 			cpu_relax();
@@ -734,9 +734,9 @@  retry:
 	spin_lock_irqsave(&rtc->irq_task_lock, flags);
 	if (rtc->irq_task != NULL && task == NULL)
 		err = -EBUSY;
-	if (rtc->irq_task != task)
+	else if (rtc->irq_task != task)
 		err = -EACCES;
-	if (!err) {
+	else {
 		rtc->irq_freq = freq;
 		if (rtc->pie_enabled && rtc_update_hrtimer(rtc, 1) < 0) {
 			spin_unlock_irqrestore(&rtc->irq_task_lock, flags);