Skip to contentSkip to conversation

mfd: viperboard: fix cache line sharing and cleanups

PATCH Superseded Octavian Purdila 2 participants 8 messages Sep 25, 2014 Multifunction devices (MFD)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover mfd: viperboard: fix cache line sharing and cleanups

Changes since v2:

* switch to using devm_ allocation

* remove unused platform_device

Changes since v1:

* split cache sharing fix and cleanups into separate patches

Octavian Purdila (3):
mfd: viperboard: allocate I/O buffer separately
mfd: viperboard: switch to devm_ allocation
mfd: viperboard: remove unused platform_device

 drivers/mfd/viperboard.c       | 19 +++++++++----------
 include/linux/mfd/viperboard.h |  3 +--
 2 files changed, 10 insertions(+), 12 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH v3 1/3 mfd: viperboard: allocate I/O buffer separately

Currently the I/O buffer is allocated part of the device status structure, potentially sharing the same cache line with other members in this structure.

Allocate the buffer separately, to avoid the I/O operations corrupting the device status structure due to cache line sharing.

Compiled tested only as I don't have access to hardware.

---
 drivers/mfd/viperboard.c       | 8 ++++++++
 include/linux/mfd/viperboard.h | 2 +-
 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/mfd/viperboard.c +8 -0
index e00f534..5f62f4e 100644
@@ -64,6 +64,12 @@ static int vprbrd_probe(struct usb_interface *interface,
 		return -ENOMEM;
 	}
 
+	vb->buf = kzalloc(sizeof(struct vprbrd_i2c_write_msg), GFP_KERNEL);
+	if (vb->buf == NULL) {
+		ret = -ENOMEM;
+		goto error;
+	}
+
 	mutex_init(&vb->lock);
 
 	vb->usb_dev = usb_get_dev(interface_to_usbdev(interface));
@@ -105,6 +111,7 @@ static int vprbrd_probe(struct usb_interface *interface,
 error:
 	if (vb) {
 		usb_put_dev(vb->usb_dev);
+		kfree(vb->buf);
 		kfree(vb);
 	}
 
@@ -118,6 +125,7 @@ static void vprbrd_disconnect(struct usb_interface *interface)
 	mfd_remove_devices(&interface->dev);
 	usb_set_intfdata(interface, NULL);
 	usb_put_dev(vb->usb_dev);
+	kfree(vb->buf);
 	kfree(vb);
 
 	dev_dbg(&interface->dev, "disconnected\n");
include/linux/mfd/viperboard.h +1 -1
index 1934528..af928d0 100644
@@ -103,7 +103,7 @@ struct vprbrd_i2c_addr_msg {
 struct vprbrd {
 	struct usb_device *usb_dev; /* the usb device for this device */
 	struct mutex lock;
-	u8 buf[sizeof(struct vprbrd_i2c_write_msg)];
+	u8 *buf;
 	struct platform_device pdev;
 };
 
Signature · 1 line
1.9.1
#2 lore raw

PATCH v3 2/3 mfd: viperboard: switch to devm_ allocation

In reply to Octavian Purdila

Switch to using devm_ allocation to simplify the error path. Also remove a redundant OOM error message.

---
 drivers/mfd/viperboard.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)
drivers/mfd/viperboard.c +5 -13
index 5f62f4e..57fac1d 100644
@@ -53,18 +53,16 @@ static int vprbrd_probe(struct usb_interface *interface,
 			      const struct usb_device_id *id)
 {
 	struct vprbrd *vb;
-
 	u16 version = 0;
 	int pipe, ret;
 
 	/* allocate memory for our device state and initialize it */
-	vb = kzalloc(sizeof(*vb), GFP_KERNEL);
-	if (vb == NULL) {
-		dev_err(&interface->dev, "Out of memory\n");
+	vb = devm_kzalloc(&interface->dev, sizeof(*vb), GFP_KERNEL);
+	if (vb == NULL)
 		return -ENOMEM;
-	}
 
-	vb->buf = kzalloc(sizeof(struct vprbrd_i2c_write_msg), GFP_KERNEL);
+	vb->buf = devm_kzalloc(&interface->dev,
+			       sizeof(struct vprbrd_i2c_write_msg), GFP_KERNEL);
 	if (vb->buf == NULL) {
 		ret = -ENOMEM;
 		goto error;
@@ -109,11 +107,7 @@ static int vprbrd_probe(struct usb_interface *interface,
 	return 0;
 
 error:
-	if (vb) {
-		usb_put_dev(vb->usb_dev);
-		kfree(vb->buf);
-		kfree(vb);
-	}
+	usb_put_dev(vb->usb_dev);
 
 	return ret;
 }
@@ -125,8 +119,6 @@ static void vprbrd_disconnect(struct usb_interface *interface)
 	mfd_remove_devices(&interface->dev);
 	usb_set_intfdata(interface, NULL);
 	usb_put_dev(vb->usb_dev);
-	kfree(vb->buf);
-	kfree(vb);
 
 	dev_dbg(&interface->dev, "disconnected\n");
 }
Signature · 1 line
1.9.1
#3 lore raw

Re: [PATCH v3 2/3] mfd: viperboard: switch to devm_ allocation

Quoted 13 lines · Octavian Purdila

Switch to using devm_ allocation to simplify the error path. Also remove a redundant OOM error message.

---
 drivers/mfd/viperboard.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)
drivers/mfd/viperboard.c +0 -0
index 5f62f4e..57fac1d 100644

drivers/mfd/viperboard.c static int vprbrd_probe(struct usb_interface *interface, · line 56

Quoted 4 lines
drivers/mfd/viperboard.c +0 -1
@@ -53,18 +53,16 @@ static int vprbrd_probe(struct usb_interface *interface,
 			      const struct usb_device_id *id)
 {
 	struct vprbrd *vb;
-

Don't include random whitespace changes in your patches.

Quoted 8 lines
drivers/mfd/viperboard.c +1 -3
 	u16 version = 0;
 	int pipe, ret;
 
 	/* allocate memory for our device state and initialize it */
-	vb = kzalloc(sizeof(*vb), GFP_KERNEL);
-	if (vb == NULL) {
-		dev_err(&interface->dev, "Out of memory\n");
+	vb = devm_kzalloc(&interface->dev, sizeof(*vb), GFP_KERNEL);

drivers/mfd/viperboard.c static int vprbrd_probe(struct usb_interface *interface, · line 68

Quoted 10 lines
drivers/mfd/viperboard.c +3 -2
+	if (vb == NULL)
 		return -ENOMEM;
-	}
 
-	vb->buf = kzalloc(sizeof(struct vprbrd_i2c_write_msg), GFP_KERNEL);
+	vb->buf = devm_kzalloc(&interface->dev,
+			       sizeof(struct vprbrd_i2c_write_msg), GFP_KERNEL);
 	if (vb->buf == NULL) {
 		ret = -ENOMEM;
 		goto error;

You should just return -ENOMEM here.

Quoted 14 lines
drivers/mfd/viperboard.c +1 -5
@@ -109,11 +107,7 @@ static int vprbrd_probe(struct usb_interface *interface,
 	return 0;
 
 error:
-	if (vb) {
-		usb_put_dev(vb->usb_dev);
-		kfree(vb->buf);
-		kfree(vb);
-	}
+	usb_put_dev(vb->usb_dev);
 
 	return ret;
 }

drivers/mfd/viperboard.c static void vprbrd_disconnect(struct usb_interface *interface) · line 124

Quoted 8 lines
drivers/mfd/viperboard.c +0 -2
@@ -125,8 +119,6 @@ static void vprbrd_disconnect(struct usb_interface *interface)
 	mfd_remove_devices(&interface->dev);
 	usb_set_intfdata(interface, NULL);
 	usb_put_dev(vb->usb_dev);
-	kfree(vb->buf);
-	kfree(vb);
 
 	dev_dbg(&interface->dev, "disconnected\n");
 }

Johan

#4 lore raw

PATCH v3 3/3 mfd: viperboard: remove unused platform_device

In reply to Octavian Purdila
---
 drivers/mfd/viperboard.c       | 1 -
 include/linux/mfd/viperboard.h | 1 -
 2 files changed, 2 deletions(-)
drivers/mfd/viperboard.c +0 -1
index 57fac1d..1e7c316 100644
@@ -74,7 +74,6 @@ static int vprbrd_probe(struct usb_interface *interface,
 
 	/* save our data pointer in this interface device */
 	usb_set_intfdata(interface, vb);
-	dev_set_drvdata(&vb->pdev.dev, vb);
 
 	/* get version information, major first, minor then */
 	pipe = usb_rcvctrlpipe(vb->usb_dev, 0);
include/linux/mfd/viperboard.h +0 -1
index af928d0..afc14ed 100644
@@ -104,7 +104,6 @@ struct vprbrd {
 	struct usb_device *usb_dev; /* the usb device for this device */
 	struct mutex lock;
 	u8 *buf;
-	struct platform_device pdev;
 };
 
 #endif /* __MFD_VIPERBOARD_H__ */
Signature · 1 line
1.9.1
#5 lore raw

Re: [PATCH v3 3/3] mfd: viperboard: remove unused platform_device

On Thu, Sep 25, 2014 at 05:43:17PM +0300, Octavian Purdila wrote:

Where's the commit message body?

Quoted 11 lines
---
 drivers/mfd/viperboard.c       | 1 -
 include/linux/mfd/viperboard.h | 1 -
 2 files changed, 2 deletions(-)
drivers/mfd/viperboard.c +0 -0
index 57fac1d..1e7c316 100644

drivers/mfd/viperboard.c static int vprbrd_probe(struct usb_interface *interface, · line 77

Quoted 4 lines
drivers/mfd/viperboard.c +0 -1
@@ -74,7 +74,6 @@ static int vprbrd_probe(struct usb_interface *interface,
 
 	/* save our data pointer in this interface device */
 	usb_set_intfdata(interface, vb);
-	dev_set_drvdata(&vb->pdev.dev, vb);

This looks ok, as the subdrivers are accessing the driver data via the usb-interface (their parent) device.

You verified that too, right?

Quoted 8 lines
drivers/mfd/viperboard.c +0 -0
 	/* get version information, major first, minor then */
 	pipe = usb_rcvctrlpipe(vb->usb_dev, 0);
include/linux/mfd/viperboard.h +0 -0
index af928d0..afc14ed 100644

include/linux/mfd/viperboard.h struct vprbrd { · line 109

Quoted 7 lines
include/linux/mfd/viperboard.h +0 -1
@@ -104,7 +104,6 @@ struct vprbrd {
 	struct usb_device *usb_dev; /* the usb device for this device */
 	struct mutex lock;
 	u8 *buf;
-	struct platform_device pdev;
 };
 
 #endif /* __MFD_VIPERBOARD_H__ */

Still feels like the kind of clean up that should have a Tested-by.

Johan

#6 lore raw

Re: [PATCH v3 3/3] mfd: viperboard: remove unused platform_device

Quoted 16 lines · Johan Hovold

On Thu, Sep 25, 2014 at 05:43:17PM +0300, Octavian Purdila wrote:

Where's the commit message body?

Quoted 12 lines
---
 drivers/mfd/viperboard.c       | 1 -
 include/linux/mfd/viperboard.h | 1 -
 2 files changed, 2 deletions(-)
drivers/mfd/viperboard.c +0 -0
index 57fac1d..1e7c316 100644
@@ -74,7 +74,6 @@ static int vprbrd_probe(struct usb_interface *interface,
 
Quoted 8 lines

drivers/mfd/viperboard.c static int vprbrd_probe(struct usb_interface *interface, · line 77

Quoted 3 lines
drivers/mfd/viperboard.c +0 -1
      /* save our data pointer in this interface device */
      usb_set_intfdata(interface, vb);
-     dev_set_drvdata(&vb->pdev.dev, vb);

This looks ok, as the subdrivers are accessing the driver data via the usb-interface (their parent) device.

You verified that too, right?

Yes, I checked that the pdev field of struct vpbrd is not used in the rest of the drivers.

Quoted 15 lines
Quoted 15 lines
drivers/mfd/viperboard.c +0 -0
      /* get version information, major first, minor then */
      pipe = usb_rcvctrlpipe(vb->usb_dev, 0);
include/linux/mfd/viperboard.h +0 -1
index af928d0..afc14ed 100644
@@ -104,7 +104,6 @@ struct vprbrd {
      struct usb_device *usb_dev; /* the usb device for this device */
      struct mutex lock;
      u8 *buf;
-     struct platform_device pdev;
 };
 
Quoted 4 lines

include/linux/mfd/viperboard.h struct vprbrd { · line 109

Quoted 1 line
include/linux/mfd/viperboard.h +0 -0
 #endif /* __MFD_VIPERBOARD_H__ */

Still feels like the kind of clean up that should have a Tested-by.

Unfortunately I do not have access to hardware to test.

#7 lore raw

Re: [PATCH v3 3/3] mfd: viperboard: remove unused platform_device

Quoted 5 lines · Octavian Purdila
Quoted 1 line · Johan Hovold

Still feels like the kind of clean up that should have a Tested-by.

Unfortunately I do not have access to hardware to test.

On second thought, compile-testing should be enough. But please add a proper commit message.

Johan