diff mbox series

[3/5] i2c: cadence: Remove redundant expression in if clause

Message ID 20230107211814.1179438-4-lars@metafoo.de
State New
Headers show
Series i2c: cadence: Small cleanups | expand

Commit Message

Lars-Peter Clausen Jan. 7, 2023, 9:18 p.m. UTC
In the mrecv() function the Cadence I2C driver has the following expression
in an if clause.

	((id->p_msg->flags & I2C_M_RECV_LEN) != I2C_M_RECV_LEN) &&
	 (id->recv_count <= CDNS_I2C_FIFO_DEPTH))

Earlier in the same function when I2C_M_RECV_LEN is set the recv_count is
initialized to a value that is larger than CDNS_I2C_FIFO_DEPTH. This means
if the first expression is false the second expression is also false.
Checking the first expression is thus redundant and can be removed.

This slightly simplifies the logic.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/i2c/busses/i2c-cadence.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Comments

Michal Simek Jan. 16, 2023, 2:44 p.m. UTC | #1
On 1/7/23 22:18, Lars-Peter Clausen wrote:
> 
> 
> In the mrecv() function the Cadence I2C driver has the following expression
> in an if clause.
> 
>          ((id->p_msg->flags & I2C_M_RECV_LEN) != I2C_M_RECV_LEN) &&
>           (id->recv_count <= CDNS_I2C_FIFO_DEPTH))
> 
> Earlier in the same function when I2C_M_RECV_LEN is set the recv_count is
> initialized to a value that is larger than CDNS_I2C_FIFO_DEPTH. This means
> if the first expression is false the second expression is also false.
> Checking the first expression is thus redundant and can be removed.
> 
> This slightly simplifies the logic.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> ---
>   drivers/i2c/busses/i2c-cadence.c | 4 +---
>   1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
> index e2a4cb694cfb..b5d22e7282c2 100644
> --- a/drivers/i2c/busses/i2c-cadence.c
> +++ b/drivers/i2c/busses/i2c-cadence.c
> @@ -612,9 +612,7 @@ static void cdns_i2c_mrecv(struct cdns_i2c *id)
>          }
> 
>          /* Determine hold_clear based on number of bytes to receive and hold flag */
> -       if (!id->bus_hold_flag &&
> -           ((id->p_msg->flags & I2C_M_RECV_LEN) != I2C_M_RECV_LEN) &&
> -           (id->recv_count <= CDNS_I2C_FIFO_DEPTH)) {
> +       if (!id->bus_hold_flag && id->recv_count <= CDNS_I2C_FIFO_DEPTH) {
>                  if (cdns_i2c_readreg(CDNS_I2C_CR_OFFSET) & CDNS_I2C_CR_HOLD) {
>                          hold_clear = true;
>                          if (id->quirks & CDNS_I2C_BROKEN_HOLD_BIT)
> --
> 2.30.2
> 

Reviewed-by: Michal Simek <michal.simek@amd.com>

Thanks,
Michal
Wolfram Sang Jan. 20, 2023, 8:56 a.m. UTC | #2
On Sat, Jan 07, 2023 at 01:18:12PM -0800, Lars-Peter Clausen wrote:
> In the mrecv() function the Cadence I2C driver has the following expression
> in an if clause.
> 
> 	((id->p_msg->flags & I2C_M_RECV_LEN) != I2C_M_RECV_LEN) &&
> 	 (id->recv_count <= CDNS_I2C_FIFO_DEPTH))
> 
> Earlier in the same function when I2C_M_RECV_LEN is set the recv_count is
> initialized to a value that is larger than CDNS_I2C_FIFO_DEPTH. This means
> if the first expression is false the second expression is also false.
> Checking the first expression is thus redundant and can be removed.
> 
> This slightly simplifies the logic.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>

Applied to for-next, thanks!
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
index e2a4cb694cfb..b5d22e7282c2 100644
--- a/drivers/i2c/busses/i2c-cadence.c
+++ b/drivers/i2c/busses/i2c-cadence.c
@@ -612,9 +612,7 @@  static void cdns_i2c_mrecv(struct cdns_i2c *id)
 	}
 
 	/* Determine hold_clear based on number of bytes to receive and hold flag */
-	if (!id->bus_hold_flag &&
-	    ((id->p_msg->flags & I2C_M_RECV_LEN) != I2C_M_RECV_LEN) &&
-	    (id->recv_count <= CDNS_I2C_FIFO_DEPTH)) {
+	if (!id->bus_hold_flag && id->recv_count <= CDNS_I2C_FIFO_DEPTH) {
 		if (cdns_i2c_readreg(CDNS_I2C_CR_OFFSET) & CDNS_I2C_CR_HOLD) {
 			hold_clear = true;
 			if (id->quirks & CDNS_I2C_BROKEN_HOLD_BIT)