Skip to contentSkip to conversation

Fix checkpatch.pl warnings and errors in i2c driver directory and subdirectories

PATCH In review Cezar Chiru 3 participants 3 messages Aug 29, 2025 – Sep 3, 2025

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

PATCH 1/1 Fix checkpatch.pl warnings and errors in i2c driver directory and subdirectories

Fix warnings and errors that were generated by checkpatch.pl script on several files of the i2c driver. Some false positives were left into place. Also /i2c/busses/ and /i2c/muxes/ folders have not been checked. The patch would have been too long.

---
 drivers/i2c/Kconfig              |  2 +-
 drivers/i2c/algos/i2c-algo-bit.c | 29 +++++++++------
 drivers/i2c/algos/i2c-algo-pca.c | 25 +++++++++----
 drivers/i2c/algos/i2c-algo-pcf.c | 61 +++++++++++++++++++++----------
 drivers/i2c/algos/i2c-algo-pcf.h | 10 ++---
 drivers/i2c/i2c-boardinfo.c      |  2 +-
 drivers/i2c/i2c-core-base.c      | 63 ++++++++++++++++++++------------
 drivers/i2c/i2c-dev.c            | 47 +++++++++++++++---------
 drivers/i2c/i2c-mux.c            |  1 +
 drivers/i2c/i2c-slave-eeprom.c   |  4 +-
 drivers/i2c/i2c-smbus.c          |  2 +-
 drivers/i2c/i2c-stub.c           | 29 ++++++++-------
 12 files changed, 173 insertions(+), 102 deletions(-)
drivers/i2c/Kconfig +1 -1
index c232054fddd6..6a3aa09d316a 100644
@@ -48,7 +48,7 @@ config I2C_CHARDEV
 	  programs use the I2C bus.  Information on how to do this is
 	  contained in the file <file:Documentation/i2c/dev-interface.rst>.
 
-	  This support is also available as a module.  If so, the module 
+	  This support is also available as a module. If so, the module
 	  will be called i2c-dev.
 
 config I2C_MUX
drivers/i2c/algos/i2c-algo-bit.c +18 -11
index 6544d27e4419..475f33a8b37a 100644
@@ -33,12 +33,12 @@
 /* ----- global variables ---------------------------------------------	*/
 
 static int bit_test;	/* see if the line-setting functions work	*/
-module_param(bit_test, int, S_IRUGO);
+module_param(bit_test, int, 0444);
 MODULE_PARM_DESC(bit_test, "lines testing - 0 off; 1 report; 2 fail if stuck");
 
 #ifdef DEBUG
 static int i2c_debug = 1;
-module_param(i2c_debug, int, S_IRUGO | S_IWUSR);
+module_param(i2c_debug, int, 0644);
 MODULE_PARM_DESC(i2c_debug,
 		 "debug level - 0 off; 1 normal; 2 verbose; 3 very verbose");
 #endif
@@ -142,9 +142,12 @@ static void i2c_stop(struct i2c_algo_bit_data *adap)
 
 
 
-/* send a byte without start cond., look for arbitration,
-   check ackn. from slave */
-/* returns:
+/*
+ * send a byte without start cond., look for arbitration,
+ * check ackn. from slave
+ */
+/*
+ * returns:
  * 1 if the device acknowledged
  * 0 if the device did not ack
  * -ETIMEDOUT if an error occurred (while raising the scl line)
@@ -404,7 +407,7 @@ static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
 	int rdcount = 0;	/* counts bytes read */
 	unsigned char *temp = msg->buf;
 	int count = msg->len;
-	const unsigned flags = msg->flags;
+	const unsigned int flags = msg->flags;
 	struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
 
 	if (!adap->getsda)
@@ -422,8 +425,10 @@ static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
 		temp++;
 		count--;
 
-		/* Some SMBus transactions require that we receive the
-		   transaction length as the first read byte. */
+		/*
+		 * Some SMBus transactions require that we receive the
+		 * transaction length as the first read byte.
+		 */
 		if (rdcount == 1 && (flags & I2C_M_RECV_LEN)) {
 			if (inval <= 0 || inval > I2C_SMBUS_BLOCK_MAX) {
 				if (!(flags & I2C_M_NO_RD_ACK))
@@ -433,9 +438,11 @@ static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
 					inval);
 				return -EPROTO;
 			}
-			/* The original count value accounts for the extra
-			   bytes, that is, either 1 for a regular transaction,
-			   or 2 for a PEC transaction. */
+			/*
+			 * The original count value accounts for the extra
+			 * bytes, that is, either 1 for a regular transaction,
+			 * or 2 for a PEC transaction.
+			 */
 			count += inval;
 			msg->len += inval;
 		}
drivers/i2c/algos/i2c-algo-pca.c +18 -7
index 74b66aec33d4..9be4901337d4 100644
@@ -14,12 +14,18 @@
 #include <linux/i2c.h>
 #include <linux/i2c-algo-pca.h>
 
-#define DEB1(fmt, args...) do { if (i2c_debug >= 1)			\
-				 printk(KERN_DEBUG fmt, ## args); } while (0)
-#define DEB2(fmt, args...) do { if (i2c_debug >= 2)			\
-				 printk(KERN_DEBUG fmt, ## args); } while (0)
-#define DEB3(fmt, args...) do { if (i2c_debug >= 3)			\
-				 printk(KERN_DEBUG fmt, ## args); } while (0)
+#define DEB1(fmt, args...)	do {	\
+					if (i2c_debug >= 1)	\
+						printk(KERN_DEBUG fmt, ## args);	\
+				} while (0)
+#define DEB2(fmt, args...)	do {	\
+					if (i2c_debug >= 2)	\
+						printk(KERN_DEBUG fmt, ## args);	\
+				} while (0)
+#define DEB3(fmt, args...)	do {	\
+					if (i2c_debug >= 3)	\
+						printk(KERN_DEBUG fmt, ## args);	\
+				} while (0)
 
 static int i2c_debug;
 
@@ -68,6 +74,7 @@ static void pca_reset(struct i2c_algo_pca_data *adap)
 static int pca_start(struct i2c_algo_pca_data *adap)
 {
 	int sta = pca_get_con(adap);
+
 	DEB2("=== START\n");
 	sta |= I2C_PCA_CON_STA;
 	sta &= ~(I2C_PCA_CON_STO|I2C_PCA_CON_SI);
@@ -83,6 +90,7 @@ static int pca_start(struct i2c_algo_pca_data *adap)
 static int pca_repeated_start(struct i2c_algo_pca_data *adap)
 {
 	int sta = pca_get_con(adap);
+
 	DEB2("=== REPEATED START\n");
 	sta |= I2C_PCA_CON_STA;
 	sta &= ~(I2C_PCA_CON_STO|I2C_PCA_CON_SI);
@@ -102,6 +110,7 @@ static int pca_repeated_start(struct i2c_algo_pca_data *adap)
 static void pca_stop(struct i2c_algo_pca_data *adap)
 {
 	int sta = pca_get_con(adap);
+
 	DEB2("=== STOP\n");
 	sta |= I2C_PCA_CON_STO;
 	sta &= ~(I2C_PCA_CON_STA|I2C_PCA_CON_SI);
@@ -139,6 +148,7 @@ static int pca_tx_byte(struct i2c_algo_pca_data *adap,
 		       __u8 b)
 {
 	int sta = pca_get_con(adap);
+
 	DEB2("=== WRITE %#04x\n", b);
 	pca_outw(adap, I2C_PCA_DAT, b);
 
@@ -207,9 +217,10 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
 	if (i2c_debug >= 2) {
 		for (curmsg = 0; curmsg < num; curmsg++) {
 			int addr, i;
+
 			msg = &msgs[curmsg];
 
-			addr = (0x7f & msg->addr) ;
+			addr = (0x7f & msg->addr);
 
 			if (msg->flags & I2C_M_RD)
 				printk(KERN_INFO "    [%02d] RD %d bytes from %#02x [%#02x, ...]\n",
drivers/i2c/algos/i2c-algo-pcf.c +42 -19

153 lines not on this page · raw message

drivers/i2c/algos/i2c-algo-pcf.h +5 -5
index 2448ab192ce5..c593593c2446 100644
@@ -2,9 +2,9 @@
 /* -------------------------------------------------------------------- */
 /* i2c-pcf8584.h: PCF 8584 global defines				*/
 /* -------------------------------------------------------------------- */
-/*   Copyright (C) 1996 Simon G. Vogl
-                   1999 Hans Berglund
-
+/*  Copyright (C)	1996 Simon G. Vogl
+ *			1999 Hans Berglund
+ *
  */
 /* --------------------------------------------------------------------	*/
 
@@ -25,7 +25,7 @@
 
 #define I2C_PCF_START    (I2C_PCF_PIN | I2C_PCF_ESO | I2C_PCF_STA | I2C_PCF_ACK)
 #define I2C_PCF_STOP     (I2C_PCF_PIN | I2C_PCF_ESO | I2C_PCF_STO | I2C_PCF_ACK)
-#define I2C_PCF_REPSTART (              I2C_PCF_ESO | I2C_PCF_STA | I2C_PCF_ACK)
+#define I2C_PCF_REPSTART	       (I2C_PCF_ESO | I2C_PCF_STA | I2C_PCF_ACK)
 #define I2C_PCF_IDLE     (I2C_PCF_PIN | I2C_PCF_ESO               | I2C_PCF_ACK)
 
 /* ----- Status register bits -----------------------------------------	*/
@@ -55,7 +55,7 @@
 
 
 /* ----- Access to internal registers according to ES1,ES2 ------------	*/
-/* they are mapped to the data port ( a0 = 0 ) 				*/
+/* they are mapped to the data port ( a0 = 0 )				*/
 /* available when ESO == 0 :						*/
 
 #define I2C_PCF_OWNADR	0
drivers/i2c/i2c-boardinfo.c +1 -1
index 4df8ad092df3..89fc7c39efca 100644
@@ -48,7 +48,7 @@ EXPORT_SYMBOL_GPL(__i2c_first_dynamic_bus_num);
  * The board info passed can safely be __initdata, but be careful of embedded
  * pointers (for platform_data, functions, etc) since that won't be copied.
  */
-int i2c_register_board_info(int busnum, struct i2c_board_info const *info, unsigned len)
+int i2c_register_board_info(int busnum, struct i2c_board_info const *info, unsigned int len)
 {
 	int status;
 
drivers/i2c/i2c-core-base.c +40 -23

182 lines not on this page · raw message

drivers/i2c/i2c-dev.c +29 -18

114 lines not on this page · raw message

drivers/i2c/i2c-mux.c +1 -0
index 4d8690981a55..bb692e5bd5f8 100644
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Multiplexed I2C bus driver.
  *
drivers/i2c/i2c-slave-eeprom.c +2 -2
index 6bc2ef650a74..3e0ae12b29ab 100644
@@ -27,7 +27,7 @@
 #include <linux/sysfs.h>
 
 struct eeprom_data {
-	struct bin_attribute bin;
+	const struct bin_attribute bin;
 	spinlock_t buffer_lock;
 	u16 buffer_idx;
 	u16 address_mask;
@@ -164,7 +164,7 @@ static int i2c_slave_eeprom_probe(struct i2c_client *client)
 
 	sysfs_bin_attr_init(&eeprom->bin);
 	eeprom->bin.attr.name = "slave-eeprom";
-	eeprom->bin.attr.mode = S_IRUSR | S_IWUSR;
+	eeprom->bin.attr.mode = 0600;
 	eeprom->bin.read = i2c_slave_eeprom_bin_read;
 	eeprom->bin.write = i2c_slave_eeprom_bin_write;
 	eeprom->bin.size = size;
drivers/i2c/i2c-smbus.c +1 -1
index 0316b347f9e7..473bd6d681bc 100644
@@ -468,7 +468,7 @@ static void i2c_register_spd(struct i2c_adapter *adap, bool write_disabled)
 
 		if (!IS_ERR(i2c_new_scanned_device(adap, &info, addr_list, NULL))) {
 			dev_info(&adap->dev,
-				 "Successfully instantiated SPD at 0x%hx\n",
+				 "Successfully instantiated SPD at 0x%x\n",
 				 addr_list[0]);
 			dimm_count--;
 		}
drivers/i2c/i2c-stub.c +15 -14
index 09e7b7bf4c5f..4c3dd2f2aaf9 100644
@@ -1,11 +1,10 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
-    i2c-stub.c - I2C/SMBus chip emulator
-
-    Copyright (c) 2004 Mark M. Hoffman <[email protected]>
-    Copyright (C) 2007-2014 Jean Delvare <[email protected]>
-
-*/
+ * i2c-stub.c - I2C/SMBus chip emulator
+ *
+ * Copyright (c) 2004 Mark M. Hoffman <[email protected]>
+ * Copyright (C) 2007-2014 Jean Delvare <[email protected]>
+ */
 
 #define pr_fmt(fmt) "i2c-stub: " fmt
 
@@ -33,30 +32,30 @@
 		(STUB_FUNC_DEFAULT | I2C_FUNC_SMBUS_BLOCK_DATA)
 
 static unsigned short chip_addr[MAX_CHIPS];
-module_param_array(chip_addr, ushort, NULL, S_IRUGO);
+module_param_array(chip_addr, ushort, NULL, 0444);
 MODULE_PARM_DESC(chip_addr,
 		 "Chip addresses (up to 10, between 0x03 and 0x77)");
 
 static unsigned long functionality = STUB_FUNC_DEFAULT;
-module_param(functionality, ulong, S_IRUGO | S_IWUSR);
+module_param(functionality, ulong, 0644);
 MODULE_PARM_DESC(functionality, "Override functionality bitfield");
 
 /* Some chips have banked register ranges */
 
 static u8 bank_reg[MAX_CHIPS];
-module_param_array(bank_reg, byte, NULL, S_IRUGO);
+module_param_array(bank_reg, byte, NULL, 0444);
 MODULE_PARM_DESC(bank_reg, "Bank register");
 
 static u8 bank_mask[MAX_CHIPS];
-module_param_array(bank_mask, byte, NULL, S_IRUGO);
+module_param_array(bank_mask, byte, NULL, 0444);
 MODULE_PARM_DESC(bank_mask, "Bank value mask");
 
 static u8 bank_start[MAX_CHIPS];
-module_param_array(bank_start, byte, NULL, S_IRUGO);
+module_param_array(bank_start, byte, NULL, 0444);
 MODULE_PARM_DESC(bank_start, "First banked register");
 
 static u8 bank_end[MAX_CHIPS];
-module_param_array(bank_end, byte, NULL, S_IRUGO);
+module_param_array(bank_end, byte, NULL, 0444);
 MODULE_PARM_DESC(bank_end, "Last banked register");
 
 struct smbus_block_data {
@@ -68,8 +67,10 @@ struct smbus_block_data {
 
 struct stub_chip {
 	u8 pointer;
-	u16 words[256];		/* Byte operations use the LSB as per SMBus
-				   specification */
+	u16 words[256];		/*
+				 * Byte operations use the LSB as per SMBus
+				 * specification
+				 */
 	struct list_head smbus_blocks;
 
 	/* For chips with banks, extra registers are allocated dynamically */
Signature · 1 line
2.43.0
maintainer
#1 lore raw

Hi Cezar,

Quoted 4 lines · Cezar Chiru

Fix warnings and errors that were generated by checkpatch.pl script on several files of the i2c driver. Some false positives were left into place. Also /i2c/busses/ and /i2c/muxes/ folders have not been checked. The patch would have been too long.

please, make sure to run checkpatch before sending checkpatch fixes.

Thanks,
Andi

Quoted 14 lines
---
 drivers/i2c/Kconfig              |  2 +-
 drivers/i2c/algos/i2c-algo-bit.c | 29 +++++++++------
 drivers/i2c/algos/i2c-algo-pca.c | 25 +++++++++----
 drivers/i2c/algos/i2c-algo-pcf.c | 61 +++++++++++++++++++++----------
 drivers/i2c/algos/i2c-algo-pcf.h | 10 ++---
 drivers/i2c/i2c-boardinfo.c      |  2 +-
 drivers/i2c/i2c-core-base.c      | 63 ++++++++++++++++++++------------
 drivers/i2c/i2c-dev.c            | 47 +++++++++++++++---------
 drivers/i2c/i2c-mux.c            |  1 +
 drivers/i2c/i2c-slave-eeprom.c   |  4 +-
 drivers/i2c/i2c-smbus.c          |  2 +-
 drivers/i2c/i2c-stub.c           | 29 ++++++++-------
 12 files changed, 173 insertions(+), 102 deletions(-)
#2 lore raw
Quoted 10 lines · Andi Shyti

Hi Cezar,

Quoted 4 lines · Cezar Chiru

Fix warnings and errors that were generated by checkpatch.pl script on several files of the i2c driver. Some false positives were left into place. Also /i2c/busses/ and /i2c/muxes/ folders have not been checked. The patch would have been too long.

please, make sure to run checkpatch before sending checkpatch fixes.

Even more, please describe how you tested the patches or otherwise verified correctness.