* [PATCH v8 1/2] i2c: pcf8584: Move 'ret' variable inside for loop, break if ret < 0.
2025-10-20 3:06 [PATCH v8 0/2] Improve usage of 'ret' variable and make pcf_doAdress() void Cezar Chiru
@ 2025-10-20 3:06 ` Cezar Chiru
2025-10-20 3:06 ` [PATCH v8 2/2] i2c: pcf8584: Make pcf_doAddress() function void Cezar Chiru
1 sibling, 0 replies; 3+ messages in thread
From: Cezar Chiru @ 2025-10-20 3:06 UTC (permalink / raw)
To: andi.shyti, wsa+renesas; +Cc: linux-i2c, linux-kernel, Cezar Chiru
Require spaces around '=' and '<'. Add spaces around binary operators.
Enforce error fixing based on checkpatch.pl output on file.
Move 'ret' variable inside for loop. Then check if (ret < 0) break. This
improves usage of ret variable.
Signed-off-by: Cezar Chiru <chiru.cezar.89@gmail.com>
---
drivers/i2c/algos/i2c-algo-pcf.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/i2c/algos/i2c-algo-pcf.c b/drivers/i2c/algos/i2c-algo-pcf.c
index 41a81d37e880..d1b0e55fd871 100644
--- a/drivers/i2c/algos/i2c-algo-pcf.c
+++ b/drivers/i2c/algos/i2c-algo-pcf.c
@@ -183,7 +183,7 @@ static int pcf_sendbytes(struct i2c_adapter *i2c_adap, const char *buf,
struct i2c_algo_pcf_data *adap = i2c_adap->algo_data;
int wrcount, status, timeout;
- for (wrcount=0; wrcount<count; ++wrcount) {
+ for (wrcount = 0; wrcount < count; ++wrcount) {
i2c_outb(adap, buf[wrcount]);
timeout = wait_for_pin(adap, &status);
if (timeout) {
@@ -272,7 +272,7 @@ static int pcf_xfer(struct i2c_adapter *i2c_adap,
struct i2c_algo_pcf_data *adap = i2c_adap->algo_data;
struct i2c_msg *pmsg;
int i;
- int ret=0, timeout, status;
+ int timeout, status;
if (adap->xfer_begin)
adap->xfer_begin(adap->data);
@@ -284,9 +284,10 @@ static int pcf_xfer(struct i2c_adapter *i2c_adap,
goto out;
}
- for (i = 0;ret >= 0 && i < num; i++) {
- pmsg = &msgs[i];
+ for (i = 0; i < num; i++) {
+ int ret;
+ pmsg = &msgs[i];
ret = pcf_doAddress(adap, pmsg);
/* Send START */
@@ -321,6 +322,9 @@ static int pcf_xfer(struct i2c_adapter *i2c_adap,
ret = pcf_sendbytes(i2c_adap, pmsg->buf, pmsg->len,
(i + 1 == num));
}
+
+ if (ret < 0)
+ break;
}
out:
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH v8 2/2] i2c: pcf8584: Make pcf_doAddress() function void
2025-10-20 3:06 [PATCH v8 0/2] Improve usage of 'ret' variable and make pcf_doAdress() void Cezar Chiru
2025-10-20 3:06 ` [PATCH v8 1/2] i2c: pcf8584: Move 'ret' variable inside for loop, break if ret < 0 Cezar Chiru
@ 2025-10-20 3:06 ` Cezar Chiru
1 sibling, 0 replies; 3+ messages in thread
From: Cezar Chiru @ 2025-10-20 3:06 UTC (permalink / raw)
To: andi.shyti, wsa+renesas; +Cc: linux-i2c, linux-kernel, Cezar Chiru
Change pcf_doAddress() function's type from int to void as it is always
returns 0. This way there is no need for extra assignment and extra checks
when the function is called.
Remove assignment of pcf_doAddress() and replace it with a simple function
call.
Signed-off-by: Cezar Chiru <chiru.cezar.89@gmail.com>
---
drivers/i2c/algos/i2c-algo-pcf.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/i2c/algos/i2c-algo-pcf.c b/drivers/i2c/algos/i2c-algo-pcf.c
index d1b0e55fd871..7e4a6d19494b 100644
--- a/drivers/i2c/algos/i2c-algo-pcf.c
+++ b/drivers/i2c/algos/i2c-algo-pcf.c
@@ -253,7 +253,7 @@ static int pcf_readbytes(struct i2c_adapter *i2c_adap, char *buf,
}
-static int pcf_doAddress(struct i2c_algo_pcf_data *adap,
+static void pcf_doAddress(struct i2c_algo_pcf_data *adap,
struct i2c_msg *msg)
{
unsigned char addr = i2c_8bit_addr_from_msg(msg);
@@ -261,8 +261,6 @@ static int pcf_doAddress(struct i2c_algo_pcf_data *adap,
if (msg->flags & I2C_M_REV_DIR_ADDR)
addr ^= 1;
i2c_outb(adap, addr);
-
- return 0;
}
static int pcf_xfer(struct i2c_adapter *i2c_adap,
@@ -288,7 +286,7 @@ static int pcf_xfer(struct i2c_adapter *i2c_adap,
int ret;
pmsg = &msgs[i];
- ret = pcf_doAddress(adap, pmsg);
+ pcf_doAddress(adap, pmsg);
/* Send START */
if (i == 0)
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread