Skip to contentSkip to conversation

iio: adc: stmpe-adc: Shuffle an if statement around in stmpe_adc_isr

PATCH In review Nathan Chancellor 3 participants 3 messages Mar 7, 2019 – Mar 10, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: adc: stmpe-adc: Shuffle an if statement around in stmpe_adc_isr

When building with -Wsometimes-uninitialized, Clang warns:

drivers/iio/adc/stmpe-adc.c:204:13: warning: variable 'data' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]

Clang can't tell that data will never be used uninitialized because the two if statements take care of all cases. Remove the first if statement and make it the else branch of the second one so that it is apparent to Clang that all cases are covered.

---
 drivers/iio/adc/stmpe-adc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/iio/adc/stmpe-adc.c +2 -3
index 37f4b74a5d32..7921f827c6ec 100644
@@ -184,9 +184,6 @@ static irqreturn_t stmpe_adc_isr(int irq, void *dev_id)
 	struct stmpe_adc *info = (struct stmpe_adc *)dev_id;
 	u16 data;
 
-	if (info->channel > STMPE_TEMP_CHANNEL)
-		return IRQ_NONE;
-
 	if (info->channel <= STMPE_ADC_LAST_NR) {
 		int int_sta;
 
@@ -205,6 +202,8 @@ static irqreturn_t stmpe_adc_isr(int irq, void *dev_id)
 		/* Read value */
 		stmpe_block_read(info->stmpe, STMPE_REG_TEMP_DATA, 2,
 				(u8 *) &data);
+	} else {
+		return IRQ_NONE;
 	}
 
 	info->value = (u32) be16_to_cpu(data);
Signature · 1 line
2.21.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Nathan Chancellor

When building with -Wsometimes-uninitialized, Clang warns:

drivers/iio/adc/stmpe-adc.c:204:13: warning: variable 'data' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]

Quoted 8 lines

Clang can't tell that data will never be used uninitialized because the two if statements take care of all cases. Remove the first if statement and make it the else branch of the second one so that it is apparent to Clang that all cases are covered.

LGTM, thanks Nathan.

Quoted 30 lines
---
 drivers/iio/adc/stmpe-adc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/iio/adc/stmpe-adc.c +2 -4
index 37f4b74a5d32..7921f827c6ec 100644
@@ -184,9 +184,6 @@ static irqreturn_t stmpe_adc_isr(int irq, void *dev_id)
        struct stmpe_adc *info = (struct stmpe_adc *)dev_id;
        u16 data;
 
-       if (info->channel > STMPE_TEMP_CHANNEL)
-               return IRQ_NONE;
-
        if (info->channel <= STMPE_ADC_LAST_NR) {
                int int_sta;
 
@@ -205,6 +202,8 @@ static irqreturn_t stmpe_adc_isr(int irq, void *dev_id)
                /* Read value */
                stmpe_block_read(info->stmpe, STMPE_REG_TEMP_DATA, 2,
                                (u8 *) &data);
+       } else {
+               return IRQ_NONE;
        }
 
        info->value = (u32) be16_to_cpu(data);
--

2.21.0

Signature · 2 lines
Thanks,
~Nick Desaulniers
maintainer
#2 lore raw
Quoted 12 lines · On Thu, 7 Mar 2019 10:31:55 -0800 Nick Desaulniers <[email protected]>…
Quoted 10 lines · Nathan Chancellor

When building with -Wsometimes-uninitialized, Clang warns:

drivers/iio/adc/stmpe-adc.c:204:13: warning: variable 'data' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]

Clang can't tell that data will never be used uninitialized because the two if statements take care of all cases. Remove the first if statement and make it the else branch of the second one so that it is apparent to Clang that all cases are covered.

Quoted 6 lines
Quoted 3 lines

LGTM, thanks Nathan.

Agreed. Seems obviously correct. Stefan, I'm only pushing this out as testing for now so happy to rebase if you have comments.

Thanks,

Jonathan

Quoted 33 lines
Quoted 31 lines
---
 drivers/iio/adc/stmpe-adc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/iio/adc/stmpe-adc.c +2 -4
index 37f4b74a5d32..7921f827c6ec 100644
@@ -184,9 +184,6 @@ static irqreturn_t stmpe_adc_isr(int irq, void *dev_id)
        struct stmpe_adc *info = (struct stmpe_adc *)dev_id;
        u16 data;
 
-       if (info->channel > STMPE_TEMP_CHANNEL)
-               return IRQ_NONE;
-
        if (info->channel <= STMPE_ADC_LAST_NR) {
                int int_sta;
 
@@ -205,6 +202,8 @@ static irqreturn_t stmpe_adc_isr(int irq, void *dev_id)
                /* Read value */
                stmpe_block_read(info->stmpe, STMPE_REG_TEMP_DATA, 2,
                                (u8 *) &data);
+       } else {
+               return IRQ_NONE;
        }
 
        info->value = (u32) be16_to_cpu(data);
--

2.21.0