Skip to contentSkip to conversation

serial: imx: remove a redundant check

PATCH In review Tom Rix 3 participants 3 messages Feb 11, 2023 – Feb 13, 2023

Subsystems (2)
lore
Share & tools
lore

Tom Rix

author
#0 lore raw

PATCH 1/1 serial: imx: remove a redundant check

cpp_check reports
drivers/tty/serial/imx.c:1207:15: style: Condition 'r_bytes>0' is always true [knownConditionTrueFalse]
if (r_bytes > 0) {

r_byte is set to
r_bytes = rx_ring->head - rx_ring->tail;

The head - tail calculation is also done by the earlier check
if (rx_ring->head <= sg_dma_len(sgl) &&

      rx_ring->head > rx_ring->tail) {

so r_bytes will always be > 0, so the second check is not needed.

---
 drivers/tty/serial/imx.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/tty/serial/imx.c +3 -5
index 363c77a140f0..523f296d5747 100644
@@ -1204,11 +1204,9 @@ static void imx_uart_dma_rx_callback(void *data)
 		r_bytes = rx_ring->head - rx_ring->tail;
 
 		/* If we received something, check for 0xff flood */
-		if (r_bytes > 0) {
-			spin_lock(&sport->port.lock);
-			imx_uart_check_flood(sport, imx_uart_readl(sport, USR2));
-			spin_unlock(&sport->port.lock);
-		}
+		spin_lock(&sport->port.lock);
+		imx_uart_check_flood(sport, imx_uart_readl(sport, USR2));
+		spin_unlock(&sport->port.lock);
 
 		if (!(sport->port.ignore_status_mask & URXD_DUMMY_READ)) {
 
Signature · 1 line
2.26.3
#1 lore raw
Quoted 27 lines · Tom Rix

cpp_check reports
drivers/tty/serial/imx.c:1207:15: style: Condition 'r_bytes>0' is always true [knownConditionTrueFalse]
if (r_bytes > 0) {

r_byte is set to
r_bytes = rx_ring->head - rx_ring->tail;

The head - tail calculation is also done by the earlier check
if (rx_ring->head <= sg_dma_len(sgl) &&

      rx_ring->head > rx_ring->tail) {

so r_bytes will always be > 0, so the second check is not needed.

---
 drivers/tty/serial/imx.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/tty/serial/imx.c +0 -1
index 363c77a140f0..523f296d5747 100644
@@ -1204,11 +1204,9 @@ static void imx_uart_dma_rx_callback(void *data)
 		r_bytes = rx_ring->head - rx_ring->tail;
 
 		/* If we received something, check for 0xff flood */
-		if (r_bytes > 0) {

drivers/tty/serial/imx.c static void imx_uart_dma_rx_callback(void *data) · line 1212

Quoted 10 lines
drivers/tty/serial/imx.c +3 -4
-			spin_lock(&sport->port.lock);
-			imx_uart_check_flood(sport, imx_uart_readl(sport, USR2));
-			spin_unlock(&sport->port.lock);
-		}
+		spin_lock(&sport->port.lock);
+		imx_uart_check_flood(sport, imx_uart_readl(sport, USR2));
+		spin_unlock(&sport->port.lock);
 
 		if (!(sport->port.ignore_status_mask & URXD_DUMMY_READ))
 		{

Nice catch. Didn't notice this when wrote the check-flood patch, sorry!

Thanks,
-- Sergey Organov

Reviewed-by on v1 1/1
#2 lore raw
In reply to Tom Rix
Quoted 7 lines · Tom Rix

cpp_check reports
drivers/tty/serial/imx.c:1207:15: style: Condition 'r_bytes>0' is always true [knownConditionTrueFalse]
if (r_bytes > 0) {

r_byte is set to
r_bytes = rx_ring->head - rx_ring->tail;

Quoted 7 lines

The head - tail calculation is also done by the earlier check
if (rx_ring->head <= sg_dma_len(sgl) &&

       rx_ring->head > rx_ring->tail) {

so r_bytes will always be > 0, so the second check is not needed.

Quoted 23 lines
---
  drivers/tty/serial/imx.c | 8 +++-----
  1 file changed, 3 insertions(+), 5 deletions(-)
drivers/tty/serial/imx.c +3 -5
index 363c77a140f0..523f296d5747 100644
@@ -1204,11 +1204,9 @@ static void imx_uart_dma_rx_callback(void *data)
  		r_bytes = rx_ring->head - rx_ring->tail;
 
  		/* If we received something, check for 0xff flood */
-		if (r_bytes > 0) {
-			spin_lock(&sport->port.lock);
-			imx_uart_check_flood(sport, imx_uart_readl(sport, USR2));
-			spin_unlock(&sport->port.lock);
-		}
+		spin_lock(&sport->port.lock);
+		imx_uart_check_flood(sport, imx_uart_readl(sport, USR2));
+		spin_unlock(&sport->port.lock);
 
  		if (!(sport->port.ignore_status_mask & URXD_DUMMY_READ)) {