* [PATCH v3 1/3] mfd: viperboard: allocate I/O buffer separately
2014-09-25 14:43 [PATCH v3 0/3] mfd: viperboard: fix cache line sharing and cleanups Octavian Purdila
@ 2014-09-25 14:43 ` Octavian Purdila
2014-09-25 14:43 ` [PATCH v3 2/3] mfd: viperboard: switch to devm_ allocation Octavian Purdila
2014-09-25 14:43 ` [PATCH v3 3/3] mfd: viperboard: remove unused platform_device Octavian Purdila
2 siblings, 0 replies; 8+ messages in thread
From: Octavian Purdila @ 2014-09-25 14:43 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 v3 2/3] mfd: viperboard: switch to devm_ allocation
2014-09-25 14:43 [PATCH v3 0/3] mfd: viperboard: fix cache line sharing and cleanups Octavian Purdila
2014-09-25 14:43 ` [PATCH v3 1/3] mfd: viperboard: allocate I/O buffer separately Octavian Purdila
@ 2014-09-25 14:43 ` Octavian Purdila
2014-09-25 14:58 ` Johan Hovold
2014-09-25 14:43 ` [PATCH v3 3/3] mfd: viperboard: remove unused platform_device Octavian Purdila
2 siblings, 1 reply; 8+ messages in thread
From: Octavian Purdila @ 2014-09-25 14:43 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 | 18 +++++-------------
1 file changed, 5 insertions(+), 13 deletions(-)
diff --git a/drivers/mfd/viperboard.c b/drivers/mfd/viperboard.c
index 5f62f4e..57fac1d 100644
--- a/drivers/mfd/viperboard.c
+++ b/drivers/mfd/viperboard.c
@@ -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");
}
--
1.9.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH v3 2/3] mfd: viperboard: switch to devm_ allocation
2014-09-25 14:43 ` [PATCH v3 2/3] mfd: viperboard: switch to devm_ allocation Octavian Purdila
@ 2014-09-25 14:58 ` Johan Hovold
0 siblings, 0 replies; 8+ messages in thread
From: Johan Hovold @ 2014-09-25 14:58 UTC (permalink / raw)
To: Octavian Purdila; +Cc: sameo, lee.jones, linux-kernel, linux-usb, johan
On Thu, Sep 25, 2014 at 05:43:16PM +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>
> ---
> drivers/mfd/viperboard.c | 18 +++++-------------
> 1 file changed, 5 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/mfd/viperboard.c b/drivers/mfd/viperboard.c
> index 5f62f4e..57fac1d 100644
> --- a/drivers/mfd/viperboard.c
> +++ b/drivers/mfd/viperboard.c
> @@ -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.
> 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;
You should just return -ENOMEM here.
> @@ -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");
> }
Johan
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v3 3/3] mfd: viperboard: remove unused platform_device
2014-09-25 14:43 [PATCH v3 0/3] mfd: viperboard: fix cache line sharing and cleanups Octavian Purdila
2014-09-25 14:43 ` [PATCH v3 1/3] mfd: viperboard: allocate I/O buffer separately Octavian Purdila
2014-09-25 14:43 ` [PATCH v3 2/3] mfd: viperboard: switch to devm_ allocation Octavian Purdila
@ 2014-09-25 14:43 ` Octavian Purdila
2014-09-25 15:07 ` Johan Hovold
2 siblings, 1 reply; 8+ messages in thread
From: Octavian Purdila @ 2014-09-25 14:43 UTC (permalink / raw)
To: sameo, lee.jones; +Cc: linux-kernel, linux-usb, johan, Octavian Purdila
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 57fac1d..1e7c316 100644
--- a/drivers/mfd/viperboard.c
+++ b/drivers/mfd/viperboard.c
@@ -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);
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 v3 3/3] mfd: viperboard: remove unused platform_device
2014-09-25 14:43 ` [PATCH v3 3/3] mfd: viperboard: remove unused platform_device Octavian Purdila
@ 2014-09-25 15:07 ` Johan Hovold
2014-09-25 15:29 ` Octavian Purdila
0 siblings, 1 reply; 8+ messages in thread
From: Johan Hovold @ 2014-09-25 15:07 UTC (permalink / raw)
To: Octavian Purdila; +Cc: sameo, lee.jones, linux-kernel, linux-usb, johan
On Thu, Sep 25, 2014 at 05:43:17PM +0300, Octavian Purdila wrote:
Where's the commit message body?
> 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 57fac1d..1e7c316 100644
> --- a/drivers/mfd/viperboard.c
> +++ b/drivers/mfd/viperboard.c
> @@ -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?
>
> /* 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__ */
Still feels like the kind of clean up that should have a Tested-by.
Johan
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH v3 3/3] mfd: viperboard: remove unused platform_device
2014-09-25 15:07 ` Johan Hovold
@ 2014-09-25 15:29 ` Octavian Purdila
2014-09-25 15:36 ` Johan Hovold
0 siblings, 1 reply; 8+ messages in thread
From: Octavian Purdila @ 2014-09-25 15:29 UTC (permalink / raw)
To: Johan Hovold; +Cc: Samuel Ortiz, Lee Jones, lkml, linux-usb
On Thu, Sep 25, 2014 at 6:07 PM, Johan Hovold <johan@kernel.org> wrote:
> On Thu, Sep 25, 2014 at 05:43:17PM +0300, Octavian Purdila wrote:
>
> Where's the commit message body?
>
>> 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 57fac1d..1e7c316 100644
>> --- a/drivers/mfd/viperboard.c
>> +++ b/drivers/mfd/viperboard.c
>> @@ -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?
Yes, I checked that the pdev field of struct vpbrd is not used in the
rest of the drivers.
>
>>
>> /* 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__ */
>
> Still feels like the kind of clean up that should have a Tested-by.
>
Unfortunately I do not have access to hardware to test.
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH v3 3/3] mfd: viperboard: remove unused platform_device
2014-09-25 15:29 ` Octavian Purdila
@ 2014-09-25 15:36 ` Johan Hovold
0 siblings, 0 replies; 8+ messages in thread
From: Johan Hovold @ 2014-09-25 15:36 UTC (permalink / raw)
To: Octavian Purdila; +Cc: Johan Hovold, Samuel Ortiz, Lee Jones, lkml, linux-usb
On Thu, Sep 25, 2014 at 06:29:48PM +0300, Octavian Purdila wrote:
> On Thu, Sep 25, 2014 at 6:07 PM, Johan Hovold <johan@kernel.org> wrote:
> > 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
^ permalink raw reply [flat|nested] 8+ messages in thread