lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 5 Feb 2020 10:48:21 +0800
From:   Jerry Lin <wahahab11@...il.com>
To:     gregkh@...uxfoundation.org, linux-kernel@...r.kernel.org
Subject: [PATCH] staging: kpc2000: rename some variables and clean up code

Rename some variables to be more understandable and module-related
and remove some redundant code to make it more easy-to-read.

Signed-off-by: Jerry Lin <wahahab11@...il.com>
---
 drivers/staging/kpc2000/kpc2000_i2c.c | 118 +++++++++++++---------------------
 1 file changed, 44 insertions(+), 74 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000_i2c.c b/drivers/staging/kpc2000/kpc2000_i2c.c
index 4b8ab4b..ed2f823 100644
--- a/drivers/staging/kpc2000/kpc2000_i2c.c
+++ b/drivers/staging/kpc2000/kpc2000_i2c.c
@@ -16,6 +16,7 @@
  *	Matt Sickler <matt.sickler@...tronics.com>,
  *	Jordon Hofer <jordon.hofer@...tronics.com>
  */
+
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/types.h>
@@ -27,13 +28,14 @@
 #include <linux/fs.h>
 #include <linux/delay.h>
 #include <linux/i2c.h>
+
 #include "kpc.h"
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Matt.Sickler@...tronics.com");
 
 struct kpc_i2c {
-	unsigned long           smba;
+	unsigned long           io_base;
 	struct i2c_adapter      adapter;
 	unsigned int            features;
 };
@@ -45,16 +47,16 @@ struct kpc_i2c {
 #define REG_SIZE 8
 
 /* I801 SMBus address offsets */
-#define SMBHSTSTS(p)    ((0  * REG_SIZE) + (p)->smba)
-#define SMBHSTCNT(p)    ((2  * REG_SIZE) + (p)->smba)
-#define SMBHSTCMD(p)    ((3  * REG_SIZE) + (p)->smba)
-#define SMBHSTADD(p)    ((4  * REG_SIZE) + (p)->smba)
-#define SMBHSTDAT0(p)   ((5  * REG_SIZE) + (p)->smba)
-#define SMBHSTDAT1(p)   ((6  * REG_SIZE) + (p)->smba)
-#define SMBBLKDAT(p)    ((7  * REG_SIZE) + (p)->smba)
-#define SMBPEC(p)       ((8  * REG_SIZE) + (p)->smba)   /* ICH3 and later */
-#define SMBAUXSTS(p)    ((12 * REG_SIZE) + (p)->smba)   /* ICH4 and later */
-#define SMBAUXCTL(p)    ((13 * REG_SIZE) + (p)->smba)   /* ICH4 and later */
+#define SMBHSTSTS(p)    ((0  * REG_SIZE) + (p)->io_base)
+#define SMBHSTCNT(p)    ((2  * REG_SIZE) + (p)->io_base)
+#define SMBHSTCMD(p)    ((3  * REG_SIZE) + (p)->io_base)
+#define SMBHSTADD(p)    ((4  * REG_SIZE) + (p)->io_base)
+#define SMBHSTDAT0(p)   ((5  * REG_SIZE) + (p)->io_base)
+#define SMBHSTDAT1(p)   ((6  * REG_SIZE) + (p)->io_base)
+#define SMBBLKDAT(p)    ((7  * REG_SIZE) + (p)->io_base)
+#define SMBPEC(p)       ((8  * REG_SIZE) + (p)->io_base)   /* ICH3 and later */
+#define SMBAUXSTS(p)    ((12 * REG_SIZE) + (p)->io_base)   /* ICH4 and later */
+#define SMBAUXCTL(p)    ((13 * REG_SIZE) + (p)->io_base)   /* ICH4 and later */
 
 /* PCI Address Constants */
 #define SMBBAR      4
@@ -433,9 +435,9 @@ static int i801_block_transaction(struct kpc_i2c *priv,
 }
 
 /* Return negative errno on error. */
-static s32 i801_access(struct i2c_adapter *adap, u16 addr,
-		       unsigned short flags, char read_write, u8 command,
-		       int size, union i2c_smbus_data *data)
+static s32 kpc_smbus_xfer(struct i2c_adapter *adap, u16 addr,
+			  unsigned short flags, char read_write, u8 command,
+			  int size, union i2c_smbus_data *data)
 {
 	int hwpec;
 	int block = 0;
@@ -444,19 +446,18 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr,
 
 	hwpec = (priv->features & FEATURE_SMBUS_PEC) &&
 		(flags & I2C_CLIENT_PEC) &&
-		size != I2C_SMBUS_QUICK && size != I2C_SMBUS_I2C_BLOCK_DATA;
+		(size != I2C_SMBUS_QUICK) &&
+		(size != I2C_SMBUS_I2C_BLOCK_DATA);
 
 	switch (size) {
 	case I2C_SMBUS_QUICK:
 		dev_dbg(&priv->adapter.dev, "  [acc] SMBUS_QUICK\n");
 		outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
 		       SMBHSTADD(priv));
-
 		xact = I801_QUICK;
 		break;
 	case I2C_SMBUS_BYTE:
 		dev_dbg(&priv->adapter.dev, "  [acc] SMBUS_BYTE\n");
-
 		outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
 		       SMBHSTADD(priv));
 		if (read_write == I2C_SMBUS_WRITE)
@@ -467,7 +468,6 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr,
 		dev_dbg(&priv->adapter.dev, "  [acc] SMBUS_BYTE_DATA\n");
 		outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
 		       SMBHSTADD(priv));
-
 		outb_p(command, SMBHSTCMD(priv));
 		if (read_write == I2C_SMBUS_WRITE)
 			outb_p(data->byte, SMBHSTDAT0(priv));
@@ -477,7 +477,6 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr,
 		dev_dbg(&priv->adapter.dev, "  [acc] SMBUS_WORD_DATA\n");
 		outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
 		       SMBHSTADD(priv));
-
 		outb_p(command, SMBHSTCMD(priv));
 		if (read_write == I2C_SMBUS_WRITE) {
 			outb_p(data->word & 0xff, SMBHSTDAT0(priv));
@@ -489,7 +488,6 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr,
 		dev_dbg(&priv->adapter.dev, "  [acc] SMBUS_BLOCK_DATA\n");
 		outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
 		       SMBHSTADD(priv));
-
 		outb_p(command, SMBHSTCMD(priv));
 		block = 1;
 		break;
@@ -517,11 +515,12 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr,
 
 	if (hwpec) { /* enable/disable hardware PEC */
 		dev_dbg(&priv->adapter.dev, "  [acc] hwpec: yes\n");
-		outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_CRC, SMBAUXCTL(priv));
+		outb_p(inb_p(SMBAUXCTL(priv)) | SMBAUXCTL_CRC,
+		       SMBAUXCTL(priv));
 	} else {
 		dev_dbg(&priv->adapter.dev, "  [acc] hwpec: no\n");
-		outb_p(inb_p(SMBAUXCTL(priv)) &
-				(~SMBAUXCTL_CRC), SMBAUXCTL(priv));
+		outb_p(inb_p(SMBAUXCTL(priv)) & (~SMBAUXCTL_CRC),
+		       SMBAUXCTL(priv));
 	}
 
 	if (block) {
@@ -572,7 +571,7 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr,
 	return 0;
 }
 
-static u32 i801_func(struct i2c_adapter *adapter)
+static u32 kpc_func(struct i2c_adapter *adapter)
 {
 	struct kpc_i2c *priv = i2c_get_adapdata(adapter);
 
@@ -587,54 +586,25 @@ static u32 i801_func(struct i2c_adapter *adapter)
 
 	// http://lxr.free-electrons.com/source/include/uapi/linux/i2c.h#L85
 
-	u32 f =
-		I2C_FUNC_I2C                     | /* 0x00000001(I enabled this
-						    * one)
-						    */
-		!I2C_FUNC_10BIT_ADDR             |		/* 0x00000002 */
-		!I2C_FUNC_PROTOCOL_MANGLING      |		/* 0x00000004 */
-		((priv->features & FEATURE_SMBUS_PEC) ?
-			I2C_FUNC_SMBUS_PEC : 0)  |		/* 0x00000008 */
-		!I2C_FUNC_SMBUS_BLOCK_PROC_CALL  |		/* 0x00008000 */
-		I2C_FUNC_SMBUS_QUICK             |		/* 0x00010000 */
-		!I2C_FUNC_SMBUS_READ_BYTE	 |		/* 0x00020000 */
-		!I2C_FUNC_SMBUS_WRITE_BYTE       |		/* 0x00040000 */
-		!I2C_FUNC_SMBUS_READ_BYTE_DATA   |		/* 0x00080000 */
-		!I2C_FUNC_SMBUS_WRITE_BYTE_DATA  |		/* 0x00100000 */
-		!I2C_FUNC_SMBUS_READ_WORD_DATA   |		/* 0x00200000 */
-		!I2C_FUNC_SMBUS_WRITE_WORD_DATA  |		/* 0x00400000 */
-		!I2C_FUNC_SMBUS_PROC_CALL        |		/* 0x00800000 */
-		!I2C_FUNC_SMBUS_READ_BLOCK_DATA  |		/* 0x01000000 */
-		!I2C_FUNC_SMBUS_WRITE_BLOCK_DATA |		/* 0x02000000 */
-		((priv->features & FEATURE_I2C_BLOCK_READ) ?
-			I2C_FUNC_SMBUS_READ_I2C_BLOCK : 0) |	/* 0x04000000 */
-		I2C_FUNC_SMBUS_WRITE_I2C_BLOCK   |		/* 0x08000000 */
-
-		I2C_FUNC_SMBUS_BYTE              | /* _READ_BYTE  _WRITE_BYTE */
-		I2C_FUNC_SMBUS_BYTE_DATA         | /* _READ_BYTE_DATA
-						    * _WRITE_BYTE_DATA
-						    */
-		I2C_FUNC_SMBUS_WORD_DATA         | /* _READ_WORD_DATA
-						    * _WRITE_WORD_DATA
-						    */
-		I2C_FUNC_SMBUS_BLOCK_DATA        | /* _READ_BLOCK_DATA
-						    * _WRITE_BLOCK_DATA
-						    */
-		!I2C_FUNC_SMBUS_I2C_BLOCK        | /* _READ_I2C_BLOCK
-						    * _WRITE_I2C_BLOCK
-						    */
-		!I2C_FUNC_SMBUS_EMUL;              /* _QUICK  _BYTE
-						    * _BYTE_DATA  _WORD_DATA
-						    * _PROC_CALL
-						    * _WRITE_BLOCK_DATA
-						    * _I2C_BLOCK _PEC
-						    */
+	u32 f = I2C_FUNC_I2C |
+		I2C_FUNC_SMBUS_QUICK |
+		I2C_FUNC_SMBUS_WRITE_I2C_BLOCK |
+		I2C_FUNC_SMBUS_BYTE |
+		I2C_FUNC_SMBUS_BYTE_DATA |
+		I2C_FUNC_SMBUS_WORD_DATA |
+		I2C_FUNC_SMBUS_BLOCK_DATA;
+
+	if (priv->features & FEATURE_SMBUS_PEC)
+		f |= I2C_FUNC_SMBUS_PEC;
+	if (priv->features & FEATURE_I2C_BLOCK_READ)
+		f |= I2C_FUNC_SMBUS_READ_I2C_BLOCK;
+
 	return f;
 }
 
-static const struct i2c_algorithm smbus_algorithm = {
-	.smbus_xfer     = i801_access,
-	.functionality  = i801_func,
+static const struct i2c_algorithm kpc_algorithm = {
+	.smbus_xfer     = kpc_smbus_xfer,
+	.functionality  = kpc_func,
 };
 
 /********************************
@@ -653,16 +623,16 @@ static int kpc_i2c_probe(struct platform_device *pldev)
 	i2c_set_adapdata(&priv->adapter, priv);
 	priv->adapter.owner = THIS_MODULE;
 	priv->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
-	priv->adapter.algo = &smbus_algorithm;
+	priv->adapter.algo = &kpc_algorithm;
 
 	res = platform_get_resource(pldev, IORESOURCE_MEM, 0);
 	if (!res)
 		return -ENXIO;
 
-	priv->smba = (unsigned long)devm_ioremap_nocache(&pldev->dev,
-							 res->start,
-							 resource_size(res));
-	if (!priv->smba)
+	priv->io_base = (unsigned long)devm_ioremap_nocache(&pldev->dev,
+							    res->start,
+							    resource_size(res));
+	if (!priv->io_base)
 		return -ENOMEM;
 
 	platform_set_drvdata(pldev, priv);
-- 
2.7.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ