Skip to contentSkip to conversation

Staging: android: timed_gpio.c: remove else statement after return

PATCH In review Murilo Opsfelder Araujo 3 participants 5 messages Jul 28, 2014 – Jul 31, 2014 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Staging: android: timed_gpio.c: remove else statement after return

This patch makes checkpatch.pl script happy by fixing the following warning:

WARNING: else is not generally useful after a break or return

---
 drivers/staging/android/timed_gpio.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/staging/android/timed_gpio.c +3 -2
index 180c209..05cb578 100644
@@ -53,8 +53,9 @@ static int gpio_get_time(struct timed_output_dev *dev)
 		struct timeval t = ktime_to_timeval(r);
 
 		return t.tv_sec * 1000 + t.tv_usec / 1000;
-	} else
-		return 0;
+	}
+
+	return 0;
 }
 
 static void gpio_enable(struct timed_output_dev *dev, int value)
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 15 lines · Murilo Opsfelder Araujo

This patch makes checkpatch.pl script happy by fixing the following warning:

WARNING: else is not generally useful after a break or return

---
 drivers/staging/android/timed_gpio.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/staging/android/timed_gpio.c +0 -0
index 180c209..05cb578 100644

drivers/staging/android/timed_gpio.c static int gpio_get_time(struct timed_output_dev *dev) · line 59

Quoted 9 lines
drivers/staging/android/timed_gpio.c +3 -2
@@ -53,8 +53,9 @@ static int gpio_get_time(struct timed_output_dev *dev)
 		struct timeval t = ktime_to_timeval(r);
 
 		return t.tv_sec * 1000 + t.tv_usec / 1000;
-	} else
-		return 0;
+	}
+
+	return 0;
 }

It may be better to reverse the logic here.
Something like:

 drivers/staging/android/timed_gpio.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/staging/android/timed_gpio.c +8 -7
index 180c209..8fa4758 100644
@@ -45,16 +45,17 @@ static enum hrtimer_restart gpio_timer_func(struct hrtimer *timer)
 
 static int gpio_get_time(struct timed_output_dev *dev)
 {
-	struct timed_gpio_data	*data =
-		container_of(dev, struct timed_gpio_data, dev);
+	struct timed_gpio_data *data;
+	struct timeval t;
 
-	if (hrtimer_active(&data->timer)) {
-		ktime_t r = hrtimer_get_remaining(&data->timer);
-		struct timeval t = ktime_to_timeval(r);
+	data = container_of(dev, struct timed_gpio_data, dev);
 
-		return t.tv_sec * 1000 + t.tv_usec / 1000;
-	} else
+	if (!hrtimer_active(&data->timer))
 		return 0;
+
+	t = ktime_to_timeval(hrtimer_get_remaining(&data->timer));
+
+	return t.tv_sec * 1000 + t.tv_usec / 1000;
 }
 
 static void gpio_enable(struct timed_output_dev *dev, int value)
#2 lore raw

PATCH 1/1 Staging: android: timed_gpio.c: improved logic of gpio_get_time()

Thanks for reviewing my first patch, Joe. How about this new one, guys?

-- >8 --
Consequently, made checkpatch.pl happy.

---
 drivers/staging/android/timed_gpio.c |   15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/staging/android/timed_gpio.c +8 -7
index 180c209..8fa4758 100644
@@ -45,16 +45,17 @@ static enum hrtimer_restart gpio_timer_func(struct hrtimer *timer)
 
 static int gpio_get_time(struct timed_output_dev *dev)
 {
-	struct timed_gpio_data	*data =
-		container_of(dev, struct timed_gpio_data, dev);
+	struct timed_gpio_data *data;
+	struct timeval t;
 
-	if (hrtimer_active(&data->timer)) {
-		ktime_t r = hrtimer_get_remaining(&data->timer);
-		struct timeval t = ktime_to_timeval(r);
+	data = container_of(dev, struct timed_gpio_data, dev);
 
-		return t.tv_sec * 1000 + t.tv_usec / 1000;
-	} else
+	if (!hrtimer_active(&data->timer))
 		return 0;
+
+	t = ktime_to_timeval(hrtimer_get_remaining(&data->timer));
+
+	return t.tv_sec * 1000 + t.tv_usec / 1000;
 }
 
 static void gpio_enable(struct timed_output_dev *dev, int value)

--
1.7.10.4

#3 lore raw

Re: [PATCH] Staging: android: timed_gpio.c: improved logic of gpio_get_time()

Quoted 7 lines · Murilo Opsfelder Araujo

Thanks for reviewing my first patch, Joe. How about this new one, guys?

-- >8 --
Consequently, made checkpatch.pl happy.

This changelog is all mangled. Try applying it with git am. It doesn't make sense to begin with. What consequently?

regards,
dan carpenter

#4 lore raw

PATCH v2 1/1 Staging: android: timed_gpio.c: improved logic of gpio_get_time()

This patch improves the logic of gpio_get_time() and, thereafter, makes checkpatch.pl happy.

---

Thanks for reviweing my patch, Dan. I think I got the proper way without using option --scissors in git-am.

What about this new commit message?

 drivers/staging/android/timed_gpio.c |   15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/staging/android/timed_gpio.c +8 -7
index 180c209..8fa4758 100644
@@ -45,16 +45,17 @@ static enum hrtimer_restart gpio_timer_func(struct hrtimer *timer)
 
 static int gpio_get_time(struct timed_output_dev *dev)
 {
-	struct timed_gpio_data	*data =
-		container_of(dev, struct timed_gpio_data, dev);
+	struct timed_gpio_data *data;
+	struct timeval t;
 
-	if (hrtimer_active(&data->timer)) {
-		ktime_t r = hrtimer_get_remaining(&data->timer);
-		struct timeval t = ktime_to_timeval(r);
+	data = container_of(dev, struct timed_gpio_data, dev);
 
-		return t.tv_sec * 1000 + t.tv_usec / 1000;
-	} else
+	if (!hrtimer_active(&data->timer))
 		return 0;
+
+	t = ktime_to_timeval(hrtimer_get_remaining(&data->timer));
+
+	return t.tv_sec * 1000 + t.tv_usec / 1000;
 }
 
 static void gpio_enable(struct timed_output_dev *dev, int value)

--
1.7.10.4