public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/3] mfd: viperboard: fix cache line sharing and cleanups
@ 2014-09-25 15:41 Octavian Purdila
  2014-09-25 15:41 ` [PATCH v4 1/3] mfd: viperboard: allocate I/O buffer separately Octavian Purdila
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Octavian Purdila @ 2014-09-25 15:41 UTC (permalink / raw)
  To: sameo, lee.jones; +Cc: linux-kernel, linux-usb, johan, Octavian Purdila

Changes since v3:

 * undo a whitespace change

 * one more error path cleanup

 * add commit body to the last patch

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       | 18 ++++++++----------
 include/linux/mfd/viperboard.h |  3 +--
 2 files changed, 9 insertions(+), 12 deletions(-)

-- 
1.9.1


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

* [PATCH v4 1/3] mfd: viperboard: allocate I/O buffer separately
  2014-09-25 15:41 [PATCH v4 0/3] mfd: viperboard: fix cache line sharing and cleanups Octavian Purdila
@ 2014-09-25 15:41 ` Octavian Purdila
  2014-09-25 15:52   ` Johan Hovold
  2014-09-25 15:41 ` [PATCH v4 2/3] mfd: viperboard: switch to devm_ allocation Octavian Purdila
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Octavian Purdila @ 2014-09-25 15:41 UTC (permalink / raw)
  To: sameo, lee.jones; +Cc: linux-kernel, linux-usb, johan, Octavian Purdila

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.

Signed-off-by: Octavian Purdila <octavian.purdila@intel.com>
---
 drivers/mfd/viperboard.c       | 8 ++++++++
 include/linux/mfd/viperboard.h | 2 +-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/viperboard.c b/drivers/mfd/viperboard.c
index e00f534..5f62f4e 100644
--- a/drivers/mfd/viperboard.c
+++ b/drivers/mfd/viperboard.c
@@ -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");
diff --git a/include/linux/mfd/viperboard.h b/include/linux/mfd/viperboard.h
index 1934528..af928d0 100644
--- a/include/linux/mfd/viperboard.h
+++ b/include/linux/mfd/viperboard.h
@@ -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;
 };
 
-- 
1.9.1


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

* [PATCH v4 2/3] mfd: viperboard: switch to devm_ allocation
  2014-09-25 15:41 [PATCH v4 0/3] mfd: viperboard: fix cache line sharing and cleanups Octavian Purdila
  2014-09-25 15:41 ` [PATCH v4 1/3] mfd: viperboard: allocate I/O buffer separately Octavian Purdila
@ 2014-09-25 15:41 ` Octavian Purdila
  2014-09-25 15:53   ` Johan Hovold
  2014-09-25 15:41 ` [PATCH v4 3/3] mfd: viperboard: remove unused platform_device Octavian Purdila
  2014-10-09 20:39 ` [PATCH v4 0/3] mfd: viperboard: fix cache line sharing and cleanups Octavian Purdila
  3 siblings, 1 reply; 8+ messages in thread
From: Octavian Purdila @ 2014-09-25 15:41 UTC (permalink / raw)
  To: sameo, lee.jones; +Cc: linux-kernel, linux-usb, johan, Octavian Purdila

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

Signed-off-by: Octavian Purdila <octavian.purdila@intel.com>
---
 drivers/mfd/viperboard.c | 23 +++++++----------------
 1 file changed, 7 insertions(+), 16 deletions(-)

diff --git a/drivers/mfd/viperboard.c b/drivers/mfd/viperboard.c
index 5f62f4e..0d46d05 100644
--- a/drivers/mfd/viperboard.c
+++ b/drivers/mfd/viperboard.c
@@ -58,17 +58,14 @@ static int vprbrd_probe(struct usb_interface *interface,
 	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);
-	if (vb->buf == NULL) {
-		ret = -ENOMEM;
-		goto error;
-	}
+	vb->buf = devm_kzalloc(&interface->dev,
+			       sizeof(struct vprbrd_i2c_write_msg), GFP_KERNEL);
+	if (vb->buf == NULL)
+		return -ENOMEM;
 
 	mutex_init(&vb->lock);
 
@@ -109,11 +106,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 +118,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");
 }
-- 
1.9.1


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

* [PATCH v4 3/3] mfd: viperboard: remove unused platform_device
  2014-09-25 15:41 [PATCH v4 0/3] mfd: viperboard: fix cache line sharing and cleanups Octavian Purdila
  2014-09-25 15:41 ` [PATCH v4 1/3] mfd: viperboard: allocate I/O buffer separately Octavian Purdila
  2014-09-25 15:41 ` [PATCH v4 2/3] mfd: viperboard: switch to devm_ allocation Octavian Purdila
@ 2014-09-25 15:41 ` Octavian Purdila
  2014-09-25 15:54   ` Johan Hovold
  2014-10-09 20:39 ` [PATCH v4 0/3] mfd: viperboard: fix cache line sharing and cleanups Octavian Purdila
  3 siblings, 1 reply; 8+ messages in thread
From: Octavian Purdila @ 2014-09-25 15:41 UTC (permalink / raw)
  To: sameo, lee.jones; +Cc: linux-kernel, linux-usb, johan, Octavian Purdila

Remove pdev field from struct vpbrd as it is not used in the MFD
driver or in any of the sub-drivers.

Signed-off-by: Octavian Purdila <octavian.purdila@intel.com>
---
 drivers/mfd/viperboard.c       | 1 -
 include/linux/mfd/viperboard.h | 1 -
 2 files changed, 2 deletions(-)

diff --git a/drivers/mfd/viperboard.c b/drivers/mfd/viperboard.c
index 0d46d05..f4dcba6 100644
--- a/drivers/mfd/viperboard.c
+++ b/drivers/mfd/viperboard.c
@@ -73,7 +73,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);
diff --git a/include/linux/mfd/viperboard.h b/include/linux/mfd/viperboard.h
index af928d0..afc14ed 100644
--- a/include/linux/mfd/viperboard.h
+++ b/include/linux/mfd/viperboard.h
@@ -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__ */
-- 
1.9.1


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

* Re: [PATCH v4 1/3] mfd: viperboard: allocate I/O buffer separately
  2014-09-25 15:41 ` [PATCH v4 1/3] mfd: viperboard: allocate I/O buffer separately Octavian Purdila
@ 2014-09-25 15:52   ` Johan Hovold
  0 siblings, 0 replies; 8+ messages in thread
From: Johan Hovold @ 2014-09-25 15:52 UTC (permalink / raw)
  To: Octavian Purdila; +Cc: sameo, lee.jones, linux-kernel, linux-usb, johan

On Thu, Sep 25, 2014 at 06:41:35PM +0300, Octavian Purdila wrote:
> 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.
> 
> Signed-off-by: Octavian Purdila <octavian.purdila@intel.com>

Reviewed-by: Johan Hovold <johan@kernel.org>

> ---
>  drivers/mfd/viperboard.c       | 8 ++++++++
>  include/linux/mfd/viperboard.h | 2 +-
>  2 files changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mfd/viperboard.c b/drivers/mfd/viperboard.c
> index e00f534..5f62f4e 100644
> --- a/drivers/mfd/viperboard.c
> +++ b/drivers/mfd/viperboard.c
> @@ -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");
> diff --git a/include/linux/mfd/viperboard.h b/include/linux/mfd/viperboard.h
> index 1934528..af928d0 100644
> --- a/include/linux/mfd/viperboard.h
> +++ b/include/linux/mfd/viperboard.h
> @@ -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;
>  };

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

* Re: [PATCH v4 2/3] mfd: viperboard: switch to devm_ allocation
  2014-09-25 15:41 ` [PATCH v4 2/3] mfd: viperboard: switch to devm_ allocation Octavian Purdila
@ 2014-09-25 15:53   ` Johan Hovold
  0 siblings, 0 replies; 8+ messages in thread
From: Johan Hovold @ 2014-09-25 15:53 UTC (permalink / raw)
  To: Octavian Purdila; +Cc: sameo, lee.jones, linux-kernel, linux-usb, johan

On Thu, Sep 25, 2014 at 06:41:36PM +0300, Octavian Purdila wrote:
> Switch to using devm_ allocation to simplify the error path. Also
> remove a redundant OOM error message.
> 
> Signed-off-by: Octavian Purdila <octavian.purdila@intel.com>

Reviewed-by: Johan Hovold <johan@kernel.org>

> ---
>  drivers/mfd/viperboard.c | 23 +++++++----------------
>  1 file changed, 7 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/mfd/viperboard.c b/drivers/mfd/viperboard.c
> index 5f62f4e..0d46d05 100644
> --- a/drivers/mfd/viperboard.c
> +++ b/drivers/mfd/viperboard.c
> @@ -58,17 +58,14 @@ static int vprbrd_probe(struct usb_interface *interface,
>  	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);
> -	if (vb->buf == NULL) {
> -		ret = -ENOMEM;
> -		goto error;
> -	}
> +	vb->buf = devm_kzalloc(&interface->dev,
> +			       sizeof(struct vprbrd_i2c_write_msg), GFP_KERNEL);
> +	if (vb->buf == NULL)
> +		return -ENOMEM;
>  
>  	mutex_init(&vb->lock);
>  
> @@ -109,11 +106,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 +118,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");
>  }

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

* Re: [PATCH v4 3/3] mfd: viperboard: remove unused platform_device
  2014-09-25 15:41 ` [PATCH v4 3/3] mfd: viperboard: remove unused platform_device Octavian Purdila
@ 2014-09-25 15:54   ` Johan Hovold
  0 siblings, 0 replies; 8+ messages in thread
From: Johan Hovold @ 2014-09-25 15:54 UTC (permalink / raw)
  To: Octavian Purdila; +Cc: sameo, lee.jones, linux-kernel, linux-usb, johan

On Thu, Sep 25, 2014 at 06:41:37PM +0300, Octavian Purdila wrote:
> Remove pdev field from struct vpbrd as it is not used in the MFD
> driver or in any of the sub-drivers.
> 
> Signed-off-by: Octavian Purdila <octavian.purdila@intel.com>

Reviewed-by: Johan Hovold <johan@kernel.org>

> ---
>  drivers/mfd/viperboard.c       | 1 -
>  include/linux/mfd/viperboard.h | 1 -
>  2 files changed, 2 deletions(-)
> 
> diff --git a/drivers/mfd/viperboard.c b/drivers/mfd/viperboard.c
> index 0d46d05..f4dcba6 100644
> --- a/drivers/mfd/viperboard.c
> +++ b/drivers/mfd/viperboard.c
> @@ -73,7 +73,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);
> diff --git a/include/linux/mfd/viperboard.h b/include/linux/mfd/viperboard.h
> index af928d0..afc14ed 100644
> --- a/include/linux/mfd/viperboard.h
> +++ b/include/linux/mfd/viperboard.h
> @@ -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__ */

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

* Re: [PATCH v4 0/3] mfd: viperboard: fix cache line sharing and cleanups
  2014-09-25 15:41 [PATCH v4 0/3] mfd: viperboard: fix cache line sharing and cleanups Octavian Purdila
                   ` (2 preceding siblings ...)
  2014-09-25 15:41 ` [PATCH v4 3/3] mfd: viperboard: remove unused platform_device Octavian Purdila
@ 2014-10-09 20:39 ` Octavian Purdila
  3 siblings, 0 replies; 8+ messages in thread
From: Octavian Purdila @ 2014-10-09 20:39 UTC (permalink / raw)
  To: Lee Jones; +Cc: lkml, Samuel Ortiz, linux-usb, Johan Hovold, Octavian Purdila

On Thu, Sep 25, 2014 at 6:41 PM, Octavian Purdila
<octavian.purdila@intel.com> wrote:
> Changes since v3:
>
>  * undo a whitespace change
>
>  * one more error path cleanup
>
>  * add commit body to the last patch
>
> 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       | 18 ++++++++----------
>  include/linux/mfd/viperboard.h |  3 +--
>  2 files changed, 9 insertions(+), 12 deletions(-)
>

Hi Lee,

Does these look ok now?

Thanks,
Tavi

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

end of thread, other threads:[~2014-10-09 20:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-25 15:41 [PATCH v4 0/3] mfd: viperboard: fix cache line sharing and cleanups Octavian Purdila
2014-09-25 15:41 ` [PATCH v4 1/3] mfd: viperboard: allocate I/O buffer separately Octavian Purdila
2014-09-25 15:52   ` Johan Hovold
2014-09-25 15:41 ` [PATCH v4 2/3] mfd: viperboard: switch to devm_ allocation Octavian Purdila
2014-09-25 15:53   ` Johan Hovold
2014-09-25 15:41 ` [PATCH v4 3/3] mfd: viperboard: remove unused platform_device Octavian Purdila
2014-09-25 15:54   ` Johan Hovold
2014-10-09 20:39 ` [PATCH v4 0/3] mfd: viperboard: fix cache line sharing and cleanups Octavian Purdila

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox