mfd: viperboard: fix cache line sharing and cleanups
v4 cover mfd: viperboard: fix cache line sharing and cleanups
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(-)
Signature · 1 line
1.9.1
PATCH v4 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
@@ -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
@@ -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
Re: [PATCH v4 1/3] mfd: viperboard: allocate I/O buffer separately
Quoted 10 lines · 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 <[email protected]>
Quoted 50 lines
--- drivers/mfd/viperboard.c | 8 ++++++++ include/linux/mfd/viperboard.h | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-)drivers/mfd/viperboard.c +8
-0@@ -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@@ -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; };
PATCH v4 2/3 mfd: viperboard: switch to devm_ allocation
In reply to Octavian PurdilaSwitch to using devm_ allocation to simplify the error path. Also remove a redundant OOM error message.
--- drivers/mfd/viperboard.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-)
drivers/mfd/viperboard.c +7 -16
@@ -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" ); }
Signature · 1 line
1.9.1
Re: [PATCH v4 2/3] mfd: viperboard: switch to devm_ allocation
Quoted 4 lines · Octavian Purdila
Switch to using
devm_allocation to simplify the error path. Also remove a redundant OOM error message.Signed-off-by Octavian Purdila <[email protected]>
Quoted 54 lines
--- drivers/mfd/viperboard.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-)drivers/mfd/viperboard.c +7
-16@@ -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" ); }
PATCH v4 3/3 mfd: viperboard: remove unused platform_device
In reply to Octavian PurdilaRemove pdev field from struct vpbrd as it is not used in the MFD driver or in any of the sub-drivers.
--- drivers/mfd/viperboard.c | 1 - include/linux/mfd/viperboard.h | 1 - 2 files changed, 2 deletions(-)
drivers/mfd/viperboard.c +0 -1
@@ -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 );
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__ */
Signature · 1 line
1.9.1
Re: [PATCH v4 3/3] mfd: viperboard: remove unused platform_device
Quoted 4 lines · 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 <[email protected]>
Quoted 29 lines
--- drivers/mfd/viperboard.c | 1 - include/linux/mfd/viperboard.h | 1 - 2 files changed, 2 deletions(-)drivers/mfd/viperboard.c +0
-1@@ -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 );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__ */
Quoted 19 lines · 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_deviceChanges since v1:
* split cache sharing fix and cleanups into separate patches
Quoted 9 lines
Octavian Purdila (3):
mfd: viperboard: allocate I/O buffer separately
mfd: viperboard: switch todevm_allocation
mfd: viperboard: remove unusedplatform_devicedrivers/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