staging: kpc2000: kpc_i2c: assorted driver cleanup
cover staging: kpc2000: kpc_i2c: assorted driver cleanup
This series contains some patches aimed toward:
- cleaning up unused/unneeded parts of driver state
- a couple of small style fixups
- a couple of API changes
- better error handling in probe()
in the kpc2000 i2c driver.
Geordan Neukum (8):
staging: kpc2000: kpc_i2c: Remove unused rw_sem
staging: kpc2000: kpc_i2c: Remove pldev from i2c_device structure
staging: kpc2000: kpc_i2c: Use BIT macro rather than manual bit
shifting
staging: kpc2000: kpc_i2c: Remove unnecessary consecutive newlines
staging: kpc2000: kpc_i2c: Use drvdata instead of platform_data
staging: kpc2000: kpc_i2c: fail probe if unable to get I/O resource
staging: kpc2000: kpc_i2c: fail probe if unable to map I/O space
staging: kpc2000: kpc_i2c: Use devm_* API to manage mapped I/O space
drivers/staging/kpc2000/kpc2000_i2c.c | 33 ++++++++++++--------------- 1 file changed, 15 insertions(+), 18 deletions(-)
--
2.21.0
PATCH 1/8 staging: kpc2000: kpc_i2c: Remove unused rw_sem
In pi2c_probe, a rw_sem is initialized and stashed off in the i2c_device private runtime state struct. This rw_sem is never used after initialization. Remove the rw_sem and cleanup unneeded header inclusion.
--- drivers/staging/kpc2000/kpc2000_i2c.c | 3 --- 1 file changed, 3 deletions(-)
drivers/staging/kpc2000/kpc2000_i2c.c +0 -3
@@ -25,7 +25,6 @@#include <linux/slab.h> #include <linux/platform_device.h> #include <linux/fs.h> -#include <linux/rwsem.h> #include <linux/delay.h> #include <linux/i2c.h> #include "kpc.h"
@@ -38,7 +37,6 @@ struct i2c_device {unsigned long smba;struct i2c_adapter adapter;struct platform_device *pldev; -struct rw_semaphore rw_sem;unsigned int features; };
@@ -606,7 +604,6 @@ static int pi2c_probe(struct platform_device *pldev) priv->features |=FEATURE_BLOCK_BUFFER ;//init_MUTEX(&lddata->sem); -init_rwsem (&priv->rw_sem);/* set up the sysfs linkage to our parent device */ priv->adapter.dev.parent = &pldev->dev;
Signature · 1 line
2.21.0
PATCH 2/8 staging: kpc2000: kpc_i2c: Remove pldev from i2c_device structure
In reply to Geordan NeukumThe i2c_device structure contains a member used to stash a pointer to a platform_device. The driver contains no cases of this member being used after initialization. Remove the unnecessary struct member and the initialization of this member in the sole instance where the driver creates a variable of type: struct i2c_device.
--- drivers/staging/kpc2000/kpc2000_i2c.c | 2 -- 1 file changed, 2 deletions(-)
drivers/staging/kpc2000/kpc2000_i2c.c +0 -2
@@ -36,7 +36,6 @@ MODULE_SOFTDEP("pre: i2c-dev");struct i2c_device {unsigned long smba;struct i2c_adapter adapter; -struct platform_device *pldev;unsigned int features; };
@@ -595,7 +594,6 @@ static int pi2c_probe(struct platform_device *pldev) res =platform_get_resource (pldev,IORESOURCE_MEM ,0 ); priv->smba = (unsigned long )ioremap_nocache (res->start,resource_size (res)); - priv->pldev = pldev; pldev->dev.platform_data = priv; priv->features |=FEATURE_IDF ;
Signature · 1 line
2.21.0
PATCH 3/8 staging: kpc2000: kpc_i2c: Use BIT macro rather than manual bit shifting
In reply to Geordan NeukumThe FEATURES_* symbols use bit shifting of the style (1 << k) in order to assign a certain meaning to the value of inividual bits being set in the value of a given variable. Instead, use the BIT() macro in order to improve readability and maintain consistency with the rest of the kernel.
--- drivers/staging/kpc2000/kpc2000_i2c.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/staging/kpc2000/kpc2000_i2c.c +5 -5
@@ -116,12 +116,12 @@ struct i2c_device {#define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS 0x9c22 -#define FEATURE_SMBUS_PEC (1 << 0) -#define FEATURE_BLOCK_BUFFER (1 << 1) -#define FEATURE_BLOCK_PROC (1 << 2) -#define FEATURE_I2C_BLOCK_READ (1 << 3) +#define FEATURE_SMBUS_PEC BIT(0) +#define FEATURE_BLOCK_BUFFER BIT(1) +#define FEATURE_BLOCK_PROC BIT(2) +#define FEATURE_I2C_BLOCK_READ BIT(3)/* Not really a feature, but it's convenient to handle it as such */ -#define FEATURE_IDF (1 << 15) +#define FEATURE_IDF BIT(15)// FIXME! #undef inb_p
Signature · 1 line
2.21.0
PATCH 4/8 staging: kpc2000: kpc_i2c: Remove unnecessary consecutive newlines
In reply to Geordan NeukumThe kpc2000_i2c.c file contains instances of unnecessary consecutive newlines which impact the readability of the file. Remove these unnecessary newlines.
--- drivers/staging/kpc2000/kpc2000_i2c.c | 5 ----- 1 file changed, 5 deletions(-)
drivers/staging/kpc2000/kpc2000_i2c.c +0 -5
@@ -115,7 +115,6 @@ struct i2c_device {#define PCI_DEVICE_ID_INTEL_LYNXPOINT_SMBUS 0x8c22#define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_SMBUS 0x9c22 -#define FEATURE_SMBUS_PEC BIT(0)#define FEATURE_BLOCK_BUFFER BIT(1)#define FEATURE_BLOCK_PROC BIT(2)
@@ -521,8 +520,6 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr, unsigned short flags,return 0 ; } - -static u32 i801_func (struct i2c_adapter *adapter) {struct i2c_device *priv =i2c_get_adapdata (adapter);
@@ -571,8 +568,6 @@ static const struct i2c_algorithm smbus_algorithm = { .functionality = i801_func, }; - -/******************************** *** Part 2 - Driver Handlers *** ********************************/
Signature · 1 line
2.21.0
PATCH 5/8 staging: kpc2000: kpc_i2c: Use drvdata instead of platform_data
In reply to Geordan NeukumThe kpc_i2c driver stashes private state data in the platform_data member of its device structure. In general, the platform_data structure is used for passing data to the driver during probe() rather than as a storage area for runtime state data. Instead, use the drvdata member for all state info meant to be accessible in driver callbacks.
--- drivers/staging/kpc2000/kpc2000_i2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/kpc2000/kpc2000_i2c.c +2 -2
@@ -589,7 +589,7 @@ static int pi2c_probe(struct platform_device *pldev) res =platform_get_resource (pldev,IORESOURCE_MEM ,0 ); priv->smba = (unsigned long )ioremap_nocache (res->start,resource_size (res)); - pldev->dev.platform_data = priv; +platform_set_drvdata (pldev, priv); priv->features |=FEATURE_IDF ; priv->features |=FEATURE_I2C_BLOCK_READ ;
@@ -620,7 +620,7 @@ static int pi2c_remove(struct platform_device *pldev) {struct i2c_device *lddev; - lddev = (struct i2c_device *)pldev->dev.platform_data; + lddev = (struct i2c_device *)platform_get_drvdata (pldev);i2c_del_adapter (&lddev->adapter);
Signature · 1 line
2.21.0
PATCH 6/8 staging: kpc2000: kpc_i2c: fail probe if unable to get I/O resource
In reply to Geordan NeukumThe kpc_i2c driver attempts to map its I/O space without verifying whether or not the result of platform_get_resource() is NULL. Make the driver check that platform_get_resource did not return NULL before attempting to use the value returned to map an I/O space.
--- drivers/staging/kpc2000/kpc2000_i2c.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/staging/kpc2000/kpc2000_i2c.c +3 -0
@@ -587,6 +587,9 @@ static int pi2c_probe(struct platform_device *pldev) priv->adapter.algo = &smbus_algorithm; res =platform_get_resource (pldev,IORESOURCE_MEM ,0 ); +if (!res) +return -ENXIO ; + priv->smba = (unsigned long )ioremap_nocache (res->start,resource_size (res));platform_set_drvdata (pldev, priv);
Signature · 1 line
2.21.0
PATCH 7/8 staging: kpc2000: kpc_i2c: fail probe if unable to map I/O space
In reply to Geordan NeukumThe kpc2000 driver does not verify whether or not mapping the I/O space succeeded during probe time. Make the driver verify that the mapping operation was successful before potentially using that area in the future.
--- drivers/staging/kpc2000/kpc2000_i2c.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/staging/kpc2000/kpc2000_i2c.c +2 -0
@@ -591,6 +591,8 @@ static int pi2c_probe(struct platform_device *pldev)return -ENXIO ; priv->smba = (unsigned long )ioremap_nocache (res->start,resource_size (res)); +if (!priv->smba) +return -ENOMEM ;platform_set_drvdata (pldev, priv);
Signature · 1 line
2.21.0
PATCH 8/8 staging: kpc2000: kpc_i2c: Use devm_* API to manage mapped I/O space
In reply to Geordan NeukumThe kpc_i2c driver does not unmap its I/O space upon error cases in the probe() function or upon remove(). Make the driver clean up after itself more maintainably by using the managed resource API.
--- drivers/staging/kpc2000/kpc2000_i2c.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/staging/kpc2000/kpc2000_i2c.c +3 -1
@@ -590,7 +590,9 @@ static int pi2c_probe(struct platform_device *pldev)if (!res)return -ENXIO ; - priv->smba = (unsigned long )ioremap_nocache (res->start,resource_size (res)); + priv->smba = (unsigned long )devm_ioremap_nocache (&pldev->dev, + res->start, +resource_size (res));if (!priv->smba)return -ENOMEM ;
Signature · 1 line
2.21.0