public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] i2c : algos : i2c-algo-pcf.c : fixed errors shown by checkpatch
@ 2025-09-07 11:45 Cezar Chiru
  2025-09-07 12:07 ` [PATCH v2] " Cezar Chiru
  2025-09-17 13:35 ` [PATCH v4 0/3] i2c: pcf8584: Fix errors reported by checkpatch.pl Cezar Chiru
  0 siblings, 2 replies; 49+ messages in thread
From: Cezar Chiru @ 2025-09-07 11:45 UTC (permalink / raw)
  To: andi.shyti; +Cc: linux-i2c, linux-kernel, Cezar Chiru

Fixed all 18 errors revealed using checkpatch.pl on i2c-algo-pcf.c
file. Errors fixed were: macros starting with 'if' should be
enclosed by do - while loop to avoid possible if/else logic defects,
do not use assignment in if condition, spaces required around '=' ,
';', '<' and ','.
Motivation is to fix all errors and warnings i2c-algo-pcf kerenel
module.

Testing:
    * built kernel with my changes and I2C_ALGOPCF=m enabled
    and it built successfully.
    * installed kernel and external modules generated by build
    * rebooted and loaded using modprobe i2c-algo-pcf kernel module
    with param i2c_debug=3 and no message was found related to
    module in dmesg. But also no error was generated.

Errors on patch: on running checkpatch.pl on this patch 4 warnings
were raised. Will be fixed on following warnings fixes patch.

Signed-off-by: Cezar Chiru <chiru.cezar.89@gmail.com>
---
 drivers/i2c/algos/i2c-algo-pcf.c | 50 +++++++++++++++++++++-----------
 1 file changed, 33 insertions(+), 17 deletions(-)

diff --git a/drivers/i2c/algos/i2c-algo-pcf.c b/drivers/i2c/algos/i2c-algo-pcf.c
index fd563e845d4b..18ba21ff8992 100644
--- a/drivers/i2c/algos/i2c-algo-pcf.c
+++ b/drivers/i2c/algos/i2c-algo-pcf.c
@@ -23,9 +23,18 @@
 #include "i2c-algo-pcf.h"
 
 
-#define DEB2(x) if (i2c_debug >= 2) x
-#define DEB3(x) if (i2c_debug >= 3) x /* print several statistical values */
-#define DEBPROTO(x) if (i2c_debug >= 9) x;
+#define DEB2(x) do { \
+			if (i2c_debug >= 2)	\
+				x;	\
+		} while (0)
+#define DEB3(x) do { \
+			if (i2c_debug >= 3)	\
+				x;	\ /* print several statistical values */
+		} while (0)
+#define DEBPROTO(x) do { \
+			if (i2c_debug >= 9)	\
+				x;	\
+		} while (0)
 	/* debug the protocol by showing transferred bits */
 #define DEF_TIMEOUT 16
 
@@ -160,7 +169,8 @@ static int pcf_init_8584 (struct i2c_algo_pcf_data *adap)
 	 * check to see S1 now used as R/W ctrl -
 	 * PCF8584 does that when ESO is zero
 	 */
-	if (((temp = get_pcf(adap, 1)) & 0x7f) != (0)) {
+	temp = get_pcf(adap, 1);
+	if ((temp & 0x7f) != (0)) {
 		DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S0 (0x%02x).\n", temp));
 		return -ENXIO; /* definitely not PCF8584 */
 	}
@@ -168,7 +178,8 @@ static int pcf_init_8584 (struct i2c_algo_pcf_data *adap)
 	/* load own address in S0, effective address is (own << 1) */
 	i2c_outb(adap, get_own(adap));
 	/* check it's really written */
-	if ((temp = i2c_inb(adap)) != get_own(adap)) {
+	temp = i2c_inb(adap);
+	if (temp  != get_own(adap)) {
 		DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't set S0 (0x%02x).\n", temp));
 		return -ENXIO;
 	}
@@ -176,7 +187,8 @@ static int pcf_init_8584 (struct i2c_algo_pcf_data *adap)
 	/* S1=0xA0, next byte in S2 */
 	set_pcf(adap, 1, I2C_PCF_PIN | I2C_PCF_ES1);
 	/* check to see S2 now selected */
-	if (((temp = get_pcf(adap, 1)) & 0x7f) != I2C_PCF_ES1) {
+	temp = get_pcf(adap, 1);
+	if ((temp & 0x7f) != I2C_PCF_ES1) {
 		DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S2 (0x%02x).\n", temp));
 		return -ENXIO;
 	}
@@ -184,7 +196,8 @@ static int pcf_init_8584 (struct i2c_algo_pcf_data *adap)
 	/* load clock register S2 */
 	i2c_outb(adap, get_clock(adap));
 	/* check it's really written, the only 5 lowest bits does matter */
-	if (((temp = i2c_inb(adap)) & 0x1f) != get_clock(adap)) {
+	temp = i2c_inb(adap);
+	if ((temp & 0x1f) != get_clock(adap)) {
 		DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't set S2 (0x%02x).\n", temp));
 		return -ENXIO;
 	}
@@ -193,7 +206,8 @@ static int pcf_init_8584 (struct i2c_algo_pcf_data *adap)
 	set_pcf(adap, 1, I2C_PCF_IDLE);
 
 	/* check to see PCF is really idled and we can access status register */
-	if ((temp = get_pcf(adap, 1)) != (I2C_PCF_PIN | I2C_PCF_BB)) {
+	temp = get_pcf(adap, 1);
+	if (temp != (I2C_PCF_PIN | I2C_PCF_BB)) {
 		DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S1` (0x%02x).\n", temp));
 		return -ENXIO;
 	}
@@ -209,7 +223,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) {
 		DEB2(dev_dbg(&i2c_adap->dev, "i2c_write: writing %2.2X\n",
 				buf[wrcount] & 0xff));
 		i2c_outb(adap, buf[wrcount]);
@@ -246,7 +260,8 @@ static int pcf_readbytes(struct i2c_adapter *i2c_adap, char *buf,
 	/* increment number of bytes to read by one -- read dummy byte */
 	for (i = 0; i <= count; i++) {
 
-		if ((wfp = wait_for_pin(adap, &status))) {
+		wfp = wait_for_pin(adap, &status);
+		if (wfp) {
 			if (wfp == -EINTR)
 				return -EINTR; /* arbitration lost */
 
@@ -299,7 +314,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 ret = 0, timeout, status;
 
 	if (adap->xfer_begin)
 		adap->xfer_begin(adap->data);
@@ -313,7 +328,7 @@ static int pcf_xfer(struct i2c_adapter *i2c_adap,
 		goto out;
 	}
 
-	for (i = 0;ret >= 0 && i < num; i++) {
+	for (i = 0; ret >= 0 && i < num; i++) {
 		pmsg = &msgs[i];
 
 		DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: Doing %s %d bytes to 0x%02x - %d of %d messages\n",
@@ -358,9 +373,9 @@ static int pcf_xfer(struct i2c_adapter *i2c_adap,
 
 			if (ret != pmsg->len) {
 				DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: fail: "
-					    "only read %d bytes.\n",ret));
+					    "only read %d bytes.\n", ret));
 			} else {
-				DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: read %d bytes.\n",ret));
+				DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: read %d bytes.\n", ret));
 			}
 		} else {
 			ret = pcf_sendbytes(i2c_adap, pmsg->buf, pmsg->len,
@@ -368,9 +383,9 @@ static int pcf_xfer(struct i2c_adapter *i2c_adap,
 
 			if (ret != pmsg->len) {
 				DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: fail: "
-					    "only wrote %d bytes.\n",ret));
+					    "only wrote %d bytes.\n", ret));
 			} else {
-				DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: wrote %d bytes.\n",ret));
+				DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: wrote %d bytes.\n", ret));
 			}
 		}
 	}
@@ -406,7 +421,8 @@ int i2c_pcf_add_bus(struct i2c_adapter *adap)
 	/* register new adapter to i2c module... */
 	adap->algo = &pcf_algo;
 
-	if ((rval = pcf_init_8584(pcf_adap)))
+	rval = pcf_init_8584(pcf_adap);
+	if (rval)
 		return rval;
 
 	rval = i2c_add_adapter(adap);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 49+ messages in thread

end of thread, other threads:[~2025-10-17 20:58 UTC | newest]

Thread overview: 49+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-07 11:45 [PATCH] i2c : algos : i2c-algo-pcf.c : fixed errors shown by checkpatch Cezar Chiru
2025-09-07 12:07 ` [PATCH v2] " Cezar Chiru
2025-09-07 13:19   ` Markus Elfring
2025-09-07 15:38     ` Cezar Chiru
2025-09-07 17:45       ` [PATCH v3] " Markus Elfring
2025-09-08 11:13         ` [PATCH 0/3] i2c : PCF8584 : Cover Letter Cezar Chiru
2025-09-08 11:13           ` [PATCH 1/3] i2c : pcf8584 : Fix debug macros defines of if statements Cezar Chiru
2025-09-08 12:44             ` Markus Elfring
2025-09-08 13:36               ` [PATCH v2 0/3] i2c: PCF8584: Cover letter Cezar Chiru
2025-09-08 13:36                 ` [PATCH v2 1/3] i2c: PCF8584: Fix debug macros defines of if statements Cezar Chiru
2025-09-08 14:46                   ` Markus Elfring
2025-09-08 15:42                     ` Cezar Chiru
2025-09-08 17:08                       ` [v2 " Markus Elfring
2025-09-08 17:58                         ` [PATCH v3 0/3] i2c: PCF8584: Fix errors reported by checkpatch.pl Cezar Chiru
2025-09-08 17:59                           ` [PATCH v3 1/3] i2c: PCF8584: Fix debug macros defines of if statements Cezar Chiru
2025-09-08 19:18                             ` Markus Elfring
2025-09-08 17:59                           ` [PATCH v3 2/3] i2c: PCF8584: Fix do not use assignment in if conditional Cezar Chiru
2025-09-08 17:59                           ` [PATCH v3 3/3] i2c: PCF8584: Fix space(s) required before or after different operators Cezar Chiru
2025-09-09  7:30                             ` Markus Elfring
2025-09-09  8:18                               ` Cezar Chiru
2025-09-08 13:36                 ` [PATCH v2 2/3] i2c: PCF8584: Fix do not use assignment in 'if' conditional Cezar Chiru
2025-09-08 13:36                 ` [PATCH v2 3/3] i2c: PCF8584: Fixed space(s) required after different operators Cezar Chiru
2025-09-08 11:13           ` [PATCH 2/3] i2c : PCF8584 : Fix do not use assignment in 'if' conditional Cezar Chiru
2025-09-08 11:13           ` [PATCH 3/3] i2c : PCF8584 : Fixed space required after different operators Cezar Chiru
2025-09-17 13:35 ` [PATCH v4 0/3] i2c: pcf8584: Fix errors reported by checkpatch.pl Cezar Chiru
2025-09-17 13:35   ` [PATCH v4 1/3] i2c: pcf8584: Fix debug macros defines of if statements Cezar Chiru
2025-09-25 10:35     ` Wolfram Sang
2025-09-25 11:56       ` Cezar Chiru
2025-09-26 15:45       ` [PATCH v5 0/3] i2c: pcf8584: Fix errors reported by checkpatch Cezar Chiru
2025-09-26 15:45         ` [PATCH v5 1/3] i2c: pcf8584: Remove debug macros from i2c-algo-pcf.c Cezar Chiru
2025-09-26 18:07           ` Wolfram Sang
2025-09-26 19:05             ` Cezar Chiru
2025-09-27  4:13             ` [PATCH v6 0/3] i2c: pcf8584: Fix errors and warnings reported by checkpatch Cezar Chiru
2025-09-27  4:13               ` [PATCH v6 1/3] i2c: pcf8584: Remove debug macros from i2c-algo-pcf.c Cezar Chiru
2025-10-17 20:47                 ` Andi Shyti
2025-09-27  4:13               ` [PATCH v6 2/3] i2c: pcf8584: Fix do not use assignment inside if conditional Cezar Chiru
2025-09-27  4:14               ` [PATCH v6 3/3] i2c: pcf8584: Fix space(s) required before or after different operators Cezar Chiru
2025-10-17 20:58                 ` Andi Shyti
2025-10-17 20:39               ` [PATCH v6 0/3] i2c: pcf8584: Fix errors and warnings reported by checkpatch Andi Shyti
2025-09-26 15:45         ` [PATCH v5 2/3] i2c: pcf8584: Fix do not use assignment inside if conditional Cezar Chiru
2025-09-26 15:45         ` [PATCH v5 3/3] i2c: pcf8584: Fix space(s) required before or after different operators Cezar Chiru
2025-10-16 16:14         ` [PATCH v6 0/3] i2c: pcf8584: Fix errors and warnings reported by checkpatch Cezar Chiru
2025-10-16 16:14           ` [PATCH v6 1/3] i2c: pcf8584: Remove debug macros from i2c-algo-pcf.c Cezar Chiru
2025-10-16 16:14           ` [PATCH v6 2/3] i2c: pcf8584: Fix do not use assignment inside if conditional Cezar Chiru
2025-10-16 16:14           ` [PATCH v6 3/3] i2c: pcf8584: Fix space(s) required before or after different operators Cezar Chiru
2025-09-17 13:35   ` [PATCH v4 2/3] i2c: pcf8584: Fix do not use assignment inside if conditional Cezar Chiru
2025-09-25 10:35     ` Wolfram Sang
2025-09-17 13:35   ` [PATCH v4 3/3] i2c: pcf8584: Fix space(s) required before or after different operators Cezar Chiru
2025-09-25 10:35     ` Wolfram Sang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox