All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] RTC: JZ4740: Fix IRQ error check
@ 2012-08-21 13:32 Lars-Peter Clausen
  2012-08-21 13:32 ` [PATCH 2/2] RTC: spear: Fix several error checks Lars-Peter Clausen
  0 siblings, 1 reply; 2+ messages in thread
From: Lars-Peter Clausen @ 2012-08-21 13:32 UTC (permalink / raw)
  To: Alessandro Zummo, Andrew Morton
  Cc: rtc-linux, linux-kernel, Lars-Peter Clausen

The irq field of the jz4740_irc struct is unsigned. Yet we assign the result of
platform_get_irq() to it. platform_get_irq() may return a negative error code
and the code checks for this condition by checking if 'irq' is less than zero.
But since 'irq' is unsigned this test will always be false. Fix it by making
'irq' signed.

The issue was found using the following coccinelle semantic patch:

//<smpl>
@@
type T;
unsigned T i;
@@
(
*i < 0
|
*i >= 0
)
//</smpl>

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/rtc/rtc-jz4740.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c
index 05ab227..1224182 100644
--- a/drivers/rtc/rtc-jz4740.c
+++ b/drivers/rtc/rtc-jz4740.c
@@ -42,7 +42,7 @@ struct jz4740_rtc {
 
 	struct rtc_device *rtc;
 
-	unsigned int irq;
+	int irq;
 
 	spinlock_t lock;
 };
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 2/2] RTC: spear: Fix several error checks
  2012-08-21 13:32 [PATCH 1/2] RTC: JZ4740: Fix IRQ error check Lars-Peter Clausen
@ 2012-08-21 13:32 ` Lars-Peter Clausen
  0 siblings, 0 replies; 2+ messages in thread
From: Lars-Peter Clausen @ 2012-08-21 13:32 UTC (permalink / raw)
  To: Alessandro Zummo, Andrew Morton
  Cc: rtc-linux, linux-kernel, Lars-Peter Clausen, Viresh Kumar

There are several comparisons of a unsigned int to less than zero int spear RTC
driver. Such a check will always be true. In all these cases a signed int is
assigned to the unsigned variable, which is checked, before. So the right fix is
to make the checked variable signed as well. In one case the check can be
dropped completely, because all it does it returns 'err' if 'err' is less than
zero, otherwise it returns 0. Since in this particular case 'err' is always
either 0 or less this is the same as just returning 'err'.

The issue has been found using the following coccinelle semantic patch:

//<smpl>
@@
type T;
unsigned T i;
@@
(
*i < 0
|
*i >= 0
)
//</smpl>

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Cc: Viresh Kumar <viresh.kumar@st.com>
---
 drivers/rtc/rtc-spear.c |   12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/rtc/rtc-spear.c b/drivers/rtc/rtc-spear.c
index e278547..bb507d2 100644
--- a/drivers/rtc/rtc-spear.c
+++ b/drivers/rtc/rtc-spear.c
@@ -235,7 +235,7 @@ static int spear_rtc_read_time(struct device *dev, struct rtc_time *tm)
 static int spear_rtc_set_time(struct device *dev, struct rtc_time *tm)
 {
 	struct spear_rtc_config *config = dev_get_drvdata(dev);
-	unsigned int time, date, err = 0;
+	unsigned int time, date;
 
 	if (tm2bcd(tm) < 0)
 		return -EINVAL;
@@ -247,11 +247,8 @@ static int spear_rtc_set_time(struct device *dev, struct rtc_time *tm)
 		(tm->tm_year << YEAR_SHIFT);
 	writel(time, config->ioaddr + TIME_REG);
 	writel(date, config->ioaddr + DATE_REG);
-	err = is_write_complete(config);
-	if (err < 0)
-		return err;
 
-	return 0;
+	return is_write_complete(config);
 }
 
 /*
@@ -295,7 +292,8 @@ static int spear_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
 static int spear_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
 {
 	struct spear_rtc_config *config = dev_get_drvdata(dev);
-	unsigned int time, date, err = 0;
+	unsigned int time, date;
+	int err;
 
 	if (tm2bcd(&alm->time) < 0)
 		return -EINVAL;
@@ -357,7 +355,7 @@ static int __devinit spear_rtc_probe(struct platform_device *pdev)
 {
 	struct resource *res;
 	struct spear_rtc_config *config;
-	unsigned int status = 0;
+	int status = 0;
 	int irq;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-08-21 13:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-21 13:32 [PATCH 1/2] RTC: JZ4740: Fix IRQ error check Lars-Peter Clausen
2012-08-21 13:32 ` [PATCH 2/2] RTC: spear: Fix several error checks Lars-Peter Clausen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.