<div dir="ltr">Pavel,<div><br></div><div>Feel free to commit the patch. </div><div><br></div><div>Why do you think the warning is a false positive?</div><div><br></div><div>--joel</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 25, 2017 at 4:53 AM, Pavel Pisa <span dir="ltr"><<a href="mailto:ppisa4lists@pikron.com" target="_blank">ppisa4lists@pikron.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From 3a2957faeb744af08196f1fd3baac7<wbr>1f15d76c85 Mon Sep 17 00:00:00 2001<br>
Message-Id: <<a href="mailto:3a2957faeb744af08196f1fd3baac71f15d76c85.1493113587.git.ppisa@pikron.com">3a2957faeb744af08196f1fd3baac<wbr>71f15d76c85.1493113587.git.<wbr>ppisa@pikron.com</a>><br>
From: Pavel Pisa <<a href="mailto:ppisa@pikron.com">ppisa@pikron.com</a>><br>
Date: Tue, 25 Apr 2017 11:45:57 +0200<br>
Subject: [PATCH] bsp/raspberrypi: GPIO silence warning and ensure that lock is<br>
always released.<br>
To: <a href="mailto:rtems-devel@rtems.org">rtems-devel@rtems.org</a><br>
<br>
Signed-off-by: Pavel Pisa <<a href="mailto:ppisa@pikron.com">ppisa@pikron.com</a>><br>
---<br>
c/src/lib/libbsp/shared/gpio.c | 18 ++++++++++++------<br>
1 file changed, 12 insertions(+), 6 deletions(-)<br>
<br>
Not tested or even compiled quick fix of warning and more serious real problem.<br>
The waning seems to be GCC false positive. The first iteration<br>
(i == 0) sets *bank_number for sure. But return with RTEMS_INVALID_ID can<br>
happen without lock release.<br>
<br>
diff --git a/c/src/lib/libbsp/shared/<wbr>gpio.c b/c/src/lib/libbsp/shared/<wbr>gpio.c<br>
index 9ceeb407..bf0e415 100644<br>
--- a/c/src/lib/libbsp/shared/<wbr>gpio.c<br>
+++ b/c/src/lib/libbsp/shared/<wbr>gpio.c<br>
@@ -303,6 +303,7 @@ static rtems_status_code get_pin_bitmask(<br>
uint32_t pin_number;<br>
uint32_t bank;<br>
uint8_t i;<br>
+ int locked_bank = -1;<br>
<br>
if ( pin_count < 1 ) {<br>
return RTEMS_UNSATISFIED;<br>
@@ -314,18 +315,23 @@ static rtems_status_code get_pin_bitmask(<br>
pin_number = pins[i];<br>
<br>
if ( pin_number < 0 || pin_number >= BSP_GPIO_PIN_COUNT ) {<br>
+ if (locked_bank >= 0)<br>
+ RELEASE_LOCK(gpio_bank_state[<wbr>locked_bank].lock);<br>
+<br>
return RTEMS_INVALID_ID;<br>
}<br>
<br>
bank = BANK_NUMBER(pin_number);<br>
<br>
- if ( i == 0 ) {<br>
+ if ( locked_bank < 0 ) {<br>
*bank_number = bank;<br>
+ locked_bank = bank;<br>
<br>
- ACQUIRE_LOCK(gpio_bank_state[<wbr>bank].lock);<br>
+ ACQUIRE_LOCK(gpio_bank_state[<wbr>locked_bank].lock);<br>
}<br>
- else if ( bank != *bank_number ) {<br>
- RELEASE_LOCK(gpio_bank_state[*<wbr>bank_number].lock);<br>
+ else if ( bank != locked_bank ) {<br>
+ if (locked_bank >= 0)<br>
+ RELEASE_LOCK(gpio_bank_state[<wbr>locked_bank].lock);<br>
<br>
return RTEMS_UNSATISFIED;<br>
}<br>
@@ -334,7 +340,7 @@ static rtems_status_code get_pin_bitmask(<br>
gpio_pin_state[pin_number].<wbr>pin_function != function ||<br>
gpio_pin_state[pin_number].on_<wbr>group<br>
) {<br>
- RELEASE_LOCK(gpio_bank_state[<wbr>bank].lock);<br>
+ RELEASE_LOCK(gpio_bank_state[<wbr>locked_bank].lock);<br>
<br>
return RTEMS_NOT_CONFIGURED;<br>
}<br>
@@ -342,7 +348,7 @@ static rtems_status_code get_pin_bitmask(<br>
*bitmask |= (1 << PIN_NUMBER(pin_number));<br>
}<br>
<br>
- RELEASE_LOCK(gpio_bank_state[<wbr>bank].lock);<br>
+ RELEASE_LOCK(gpio_bank_state[<wbr>locked_bank].lock);<br>
<br>
return RTEMS_SUCCESSFUL;<br>
}<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.9.1<br>
<br>
</font></span></blockquote></div><br></div>