linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/8] staging: kpc2000: kpc_i2c: assorted driver cleanup
@ 2019-05-26  1:18 Geordan Neukum
  2019-05-26  1:18 ` [PATCH 1/8] staging: kpc2000: kpc_i2c: Remove unused rw_sem Geordan Neukum
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Geordan Neukum @ 2019-05-26  1:18 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: devel, linux-kernel, Geordan Neukum

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


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

* [PATCH 1/8] staging: kpc2000: kpc_i2c: Remove unused rw_sem
  2019-05-26  1:18 [PATCH 0/8] staging: kpc2000: kpc_i2c: assorted driver cleanup Geordan Neukum
@ 2019-05-26  1:18 ` Geordan Neukum
  2019-05-26  1:18 ` [PATCH 2/8] staging: kpc2000: kpc_i2c: Remove pldev from i2c_device structure Geordan Neukum
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Geordan Neukum @ 2019-05-26  1:18 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: devel, linux-kernel, Geordan Neukum

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.

Signed-off-by: Geordan Neukum <gneukum1@gmail.com>
---
 drivers/staging/kpc2000/kpc2000_i2c.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000_i2c.c b/drivers/staging/kpc2000/kpc2000_i2c.c
index fb9a8386bcce..2c272ad8eca6 100644
--- a/drivers/staging/kpc2000/kpc2000_i2c.c
+++ b/drivers/staging/kpc2000/kpc2000_i2c.c
@@ -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;
-- 
2.21.0


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

* [PATCH 2/8] staging: kpc2000: kpc_i2c: Remove pldev from i2c_device structure
  2019-05-26  1:18 [PATCH 0/8] staging: kpc2000: kpc_i2c: assorted driver cleanup Geordan Neukum
  2019-05-26  1:18 ` [PATCH 1/8] staging: kpc2000: kpc_i2c: Remove unused rw_sem Geordan Neukum
@ 2019-05-26  1:18 ` Geordan Neukum
  2019-05-26  1:18 ` [PATCH 3/8] staging: kpc2000: kpc_i2c: Use BIT macro rather than manual bit shifting Geordan Neukum
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Geordan Neukum @ 2019-05-26  1:18 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: devel, linux-kernel, Geordan Neukum

The 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.

Signed-off-by: Geordan Neukum <gneukum1@gmail.com>
---
 drivers/staging/kpc2000/kpc2000_i2c.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000_i2c.c b/drivers/staging/kpc2000/kpc2000_i2c.c
index 2c272ad8eca6..b2a9cda05f1b 100644
--- a/drivers/staging/kpc2000/kpc2000_i2c.c
+++ b/drivers/staging/kpc2000/kpc2000_i2c.c
@@ -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;
-- 
2.21.0


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

* [PATCH 3/8] staging: kpc2000: kpc_i2c: Use BIT macro rather than manual bit shifting
  2019-05-26  1:18 [PATCH 0/8] staging: kpc2000: kpc_i2c: assorted driver cleanup Geordan Neukum
  2019-05-26  1:18 ` [PATCH 1/8] staging: kpc2000: kpc_i2c: Remove unused rw_sem Geordan Neukum
  2019-05-26  1:18 ` [PATCH 2/8] staging: kpc2000: kpc_i2c: Remove pldev from i2c_device structure Geordan Neukum
@ 2019-05-26  1:18 ` Geordan Neukum
  2019-05-26  1:18 ` [PATCH 4/8] staging: kpc2000: kpc_i2c: Remove unnecessary consecutive newlines Geordan Neukum
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Geordan Neukum @ 2019-05-26  1:18 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: devel, linux-kernel, Geordan Neukum

The 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.

Signed-off-by: Geordan Neukum <gneukum1@gmail.com>
---
 drivers/staging/kpc2000/kpc2000_i2c.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000_i2c.c b/drivers/staging/kpc2000/kpc2000_i2c.c
index b2a9cda05f1b..1d100bb7c548 100644
--- a/drivers/staging/kpc2000/kpc2000_i2c.c
+++ b/drivers/staging/kpc2000/kpc2000_i2c.c
@@ -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
-- 
2.21.0


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

* [PATCH 4/8] staging: kpc2000: kpc_i2c: Remove unnecessary consecutive newlines
  2019-05-26  1:18 [PATCH 0/8] staging: kpc2000: kpc_i2c: assorted driver cleanup Geordan Neukum
                   ` (2 preceding siblings ...)
  2019-05-26  1:18 ` [PATCH 3/8] staging: kpc2000: kpc_i2c: Use BIT macro rather than manual bit shifting Geordan Neukum
@ 2019-05-26  1:18 ` Geordan Neukum
  2019-05-26  1:18 ` [PATCH 5/8] staging: kpc2000: kpc_i2c: Use drvdata instead of platform_data Geordan Neukum
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Geordan Neukum @ 2019-05-26  1:18 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: devel, linux-kernel, Geordan Neukum

The kpc2000_i2c.c file contains instances of unnecessary consecutive
newlines which impact the readability of the file. Remove these
unnecessary newlines.

Signed-off-by: Geordan Neukum <gneukum1@gmail.com>
---
 drivers/staging/kpc2000/kpc2000_i2c.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000_i2c.c b/drivers/staging/kpc2000/kpc2000_i2c.c
index 1d100bb7c548..1767f351a116 100644
--- a/drivers/staging/kpc2000/kpc2000_i2c.c
+++ b/drivers/staging/kpc2000/kpc2000_i2c.c
@@ -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 ***
  ********************************/
-- 
2.21.0


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

* [PATCH 5/8] staging: kpc2000: kpc_i2c: Use drvdata instead of platform_data
  2019-05-26  1:18 [PATCH 0/8] staging: kpc2000: kpc_i2c: assorted driver cleanup Geordan Neukum
                   ` (3 preceding siblings ...)
  2019-05-26  1:18 ` [PATCH 4/8] staging: kpc2000: kpc_i2c: Remove unnecessary consecutive newlines Geordan Neukum
@ 2019-05-26  1:18 ` Geordan Neukum
  2019-05-26  1:18 ` [PATCH 6/8] staging: kpc2000: kpc_i2c: fail probe if unable to get I/O resource Geordan Neukum
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Geordan Neukum @ 2019-05-26  1:18 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: devel, linux-kernel, Geordan Neukum

The 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.

Signed-off-by: Geordan Neukum <gneukum1@gmail.com>
---
 drivers/staging/kpc2000/kpc2000_i2c.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000_i2c.c b/drivers/staging/kpc2000/kpc2000_i2c.c
index 1767f351a116..e4bbb91af972 100644
--- a/drivers/staging/kpc2000/kpc2000_i2c.c
+++ b/drivers/staging/kpc2000/kpc2000_i2c.c
@@ -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);
 
-- 
2.21.0


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

* [PATCH 6/8] staging: kpc2000: kpc_i2c: fail probe if unable to get I/O resource
  2019-05-26  1:18 [PATCH 0/8] staging: kpc2000: kpc_i2c: assorted driver cleanup Geordan Neukum
                   ` (4 preceding siblings ...)
  2019-05-26  1:18 ` [PATCH 5/8] staging: kpc2000: kpc_i2c: Use drvdata instead of platform_data Geordan Neukum
@ 2019-05-26  1:18 ` Geordan Neukum
  2019-05-26  1:18 ` [PATCH 7/8] staging: kpc2000: kpc_i2c: fail probe if unable to map I/O space Geordan Neukum
  2019-05-26  1:18 ` [PATCH 8/8] staging: kpc2000: kpc_i2c: Use devm_* API to manage mapped " Geordan Neukum
  7 siblings, 0 replies; 9+ messages in thread
From: Geordan Neukum @ 2019-05-26  1:18 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: devel, linux-kernel, Geordan Neukum

The 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.

Signed-off-by: Geordan Neukum <gneukum1@gmail.com>
---
 drivers/staging/kpc2000/kpc2000_i2c.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/staging/kpc2000/kpc2000_i2c.c b/drivers/staging/kpc2000/kpc2000_i2c.c
index e4bbb91af972..452052bf9476 100644
--- a/drivers/staging/kpc2000/kpc2000_i2c.c
+++ b/drivers/staging/kpc2000/kpc2000_i2c.c
@@ -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);
-- 
2.21.0


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

* [PATCH 7/8] staging: kpc2000: kpc_i2c: fail probe if unable to map I/O space
  2019-05-26  1:18 [PATCH 0/8] staging: kpc2000: kpc_i2c: assorted driver cleanup Geordan Neukum
                   ` (5 preceding siblings ...)
  2019-05-26  1:18 ` [PATCH 6/8] staging: kpc2000: kpc_i2c: fail probe if unable to get I/O resource Geordan Neukum
@ 2019-05-26  1:18 ` Geordan Neukum
  2019-05-26  1:18 ` [PATCH 8/8] staging: kpc2000: kpc_i2c: Use devm_* API to manage mapped " Geordan Neukum
  7 siblings, 0 replies; 9+ messages in thread
From: Geordan Neukum @ 2019-05-26  1:18 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: devel, linux-kernel, Geordan Neukum

The 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.

Signed-off-by: Geordan Neukum <gneukum1@gmail.com>
---
 drivers/staging/kpc2000/kpc2000_i2c.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/staging/kpc2000/kpc2000_i2c.c b/drivers/staging/kpc2000/kpc2000_i2c.c
index 452052bf9476..51e91653e183 100644
--- a/drivers/staging/kpc2000/kpc2000_i2c.c
+++ b/drivers/staging/kpc2000/kpc2000_i2c.c
@@ -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);
 
-- 
2.21.0


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

* [PATCH 8/8] staging: kpc2000: kpc_i2c: Use devm_* API to manage mapped I/O space
  2019-05-26  1:18 [PATCH 0/8] staging: kpc2000: kpc_i2c: assorted driver cleanup Geordan Neukum
                   ` (6 preceding siblings ...)
  2019-05-26  1:18 ` [PATCH 7/8] staging: kpc2000: kpc_i2c: fail probe if unable to map I/O space Geordan Neukum
@ 2019-05-26  1:18 ` Geordan Neukum
  7 siblings, 0 replies; 9+ messages in thread
From: Geordan Neukum @ 2019-05-26  1:18 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: devel, linux-kernel, Geordan Neukum

The 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.

Signed-off-by: Geordan Neukum <gneukum1@gmail.com>
---
 drivers/staging/kpc2000/kpc2000_i2c.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/kpc2000/kpc2000_i2c.c b/drivers/staging/kpc2000/kpc2000_i2c.c
index 51e91653e183..a434dd0b78c4 100644
--- a/drivers/staging/kpc2000/kpc2000_i2c.c
+++ b/drivers/staging/kpc2000/kpc2000_i2c.c
@@ -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;
 
-- 
2.21.0


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

end of thread, other threads:[~2019-05-26  1:19 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-26  1:18 [PATCH 0/8] staging: kpc2000: kpc_i2c: assorted driver cleanup Geordan Neukum
2019-05-26  1:18 ` [PATCH 1/8] staging: kpc2000: kpc_i2c: Remove unused rw_sem Geordan Neukum
2019-05-26  1:18 ` [PATCH 2/8] staging: kpc2000: kpc_i2c: Remove pldev from i2c_device structure Geordan Neukum
2019-05-26  1:18 ` [PATCH 3/8] staging: kpc2000: kpc_i2c: Use BIT macro rather than manual bit shifting Geordan Neukum
2019-05-26  1:18 ` [PATCH 4/8] staging: kpc2000: kpc_i2c: Remove unnecessary consecutive newlines Geordan Neukum
2019-05-26  1:18 ` [PATCH 5/8] staging: kpc2000: kpc_i2c: Use drvdata instead of platform_data Geordan Neukum
2019-05-26  1:18 ` [PATCH 6/8] staging: kpc2000: kpc_i2c: fail probe if unable to get I/O resource Geordan Neukum
2019-05-26  1:18 ` [PATCH 7/8] staging: kpc2000: kpc_i2c: fail probe if unable to map I/O space Geordan Neukum
2019-05-26  1:18 ` [PATCH 8/8] staging: kpc2000: kpc_i2c: Use devm_* API to manage mapped " Geordan Neukum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).