From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <linux-kernel-owner@vger.kernel.org>
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
	id S1754656AbaIVTjb (ORCPT <rfc822;w@1wt.eu>);
	Mon, 22 Sep 2014 15:39:31 -0400
Received: from mga09.intel.com ([134.134.136.24]:47090 "EHLO mga09.intel.com"
	rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP
	id S1752856AbaIVTj3 (ORCPT <rfc822;linux-kernel@vger.kernel.org>);
	Mon, 22 Sep 2014 15:39:29 -0400
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.04,573,1406617200"; 
   d="scan'208";a="577112516"
From: Octavian Purdila <octavian.purdila@intel.com>
To: sameo@linux.intel.com, lee.jones@linaro.org
Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, johan@kernel.org,
        Octavian Purdila <octavian.purdila@intel.com>
Subject: [PATCH v2 0/2] mfd: viperboard: cleanups and fix for cache line sharing
Date: Mon, 22 Sep 2014 22:39:17 +0300
Message-Id: <1411414759-7056-1-git-send-email-octavian.purdila@intel.com>
X-Mailer: git-send-email 1.9.1
Sender: linux-kernel-owner@vger.kernel.org
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

Changes since v1:

 * split cache sharing fix and cleanups into separate patches

Octavian Purdila (2):
  mfd: viperboard: allocate I/O buffer separately
  mfd: viperboard: remove redundant OOM message and NULL pointer check

 drivers/mfd/viperboard.c       | 16 ++++++++++------
 include/linux/mfd/viperboard.h |  2 +-
 2 files changed, 11 insertions(+), 7 deletions(-)

-- 
1.9.1


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <linux-kernel-owner@vger.kernel.org>
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
	id S1754712AbaIVTjf (ORCPT <rfc822;w@1wt.eu>);
	Mon, 22 Sep 2014 15:39:35 -0400
Received: from mga09.intel.com ([134.134.136.24]:47090 "EHLO mga09.intel.com"
	rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP
	id S1752856AbaIVTjd (ORCPT <rfc822;linux-kernel@vger.kernel.org>);
	Mon, 22 Sep 2014 15:39:33 -0400
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.04,573,1406617200"; 
   d="scan'208";a="577112530"
From: Octavian Purdila <octavian.purdila@intel.com>
To: sameo@linux.intel.com, lee.jones@linaro.org
Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, johan@kernel.org,
        Octavian Purdila <octavian.purdila@intel.com>
Subject: [PATCH v2 1/2] mfd: viperboard: allocate I/O buffer separately
Date: Mon, 22 Sep 2014 22:39:18 +0300
Message-Id: <1411414759-7056-2-git-send-email-octavian.purdila@intel.com>
X-Mailer: git-send-email 1.9.1
In-Reply-To: <1411414759-7056-1-git-send-email-octavian.purdila@intel.com>
References: <1411414759-7056-1-git-send-email-octavian.purdila@intel.com>
Sender: linux-kernel-owner@vger.kernel.org
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

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


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <linux-kernel-owner@vger.kernel.org>
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
	id S1754744AbaIVTjj (ORCPT <rfc822;w@1wt.eu>);
	Mon, 22 Sep 2014 15:39:39 -0400
Received: from mga09.intel.com ([134.134.136.24]:47090 "EHLO mga09.intel.com"
	rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP
	id S1752856AbaIVTjg (ORCPT <rfc822;linux-kernel@vger.kernel.org>);
	Mon, 22 Sep 2014 15:39:36 -0400
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.04,573,1406617200"; 
   d="scan'208";a="577112548"
From: Octavian Purdila <octavian.purdila@intel.com>
To: sameo@linux.intel.com, lee.jones@linaro.org
Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, johan@kernel.org,
        Octavian Purdila <octavian.purdila@intel.com>
Subject: [PATCH v2 2/2] mfd: viperboard: remove redundant OOM message and NULL pointer check
Date: Mon, 22 Sep 2014 22:39:19 +0300
Message-Id: <1411414759-7056-3-git-send-email-octavian.purdila@intel.com>
X-Mailer: git-send-email 1.9.1
In-Reply-To: <1411414759-7056-1-git-send-email-octavian.purdila@intel.com>
References: <1411414759-7056-1-git-send-email-octavian.purdila@intel.com>
Sender: linux-kernel-owner@vger.kernel.org
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

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

diff --git a/drivers/mfd/viperboard.c b/drivers/mfd/viperboard.c
index 5f62f4e..d27c131 100644
--- a/drivers/mfd/viperboard.c
+++ b/drivers/mfd/viperboard.c
@@ -59,10 +59,8 @@ static int vprbrd_probe(struct usb_interface *interface,
 
 	/* 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");
+	if (vb == NULL)
 		return -ENOMEM;
-	}
 
 	vb->buf = kzalloc(sizeof(struct vprbrd_i2c_write_msg), GFP_KERNEL);
 	if (vb->buf == NULL) {
@@ -109,11 +107,9 @@ 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);
+	kfree(vb->buf);
+	kfree(vb);
 
 	return ret;
 }
-- 
1.9.1


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <linux-kernel-owner@vger.kernel.org>
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
	id S1753909AbaIWHiR (ORCPT <rfc822;w@1wt.eu>);
	Tue, 23 Sep 2014 03:38:17 -0400
Received: from mail-lb0-f177.google.com ([209.85.217.177]:58835 "EHLO
	mail-lb0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
	with ESMTP id S1753620AbaIWHiP (ORCPT
	<rfc822;linux-kernel@vger.kernel.org>);
	Tue, 23 Sep 2014 03:38:15 -0400
X-Google-Original-Sender: <johan@hovold.com>
Date: Tue, 23 Sep 2014 09:35:41 +0200
From: Johan Hovold <johan@kernel.org>
To: Octavian Purdila <octavian.purdila@intel.com>
Cc: sameo@linux.intel.com, lee.jones@linaro.org, linux-kernel@vger.kernel.org,
        linux-usb@vger.kernel.org, johan@kernel.org
Subject: Re: [PATCH v2 1/2] mfd: viperboard: allocate I/O buffer separately
Message-ID: <20140923073541.GM5237@localhost>
References: <1411414759-7056-1-git-send-email-octavian.purdila@intel.com>
 <1411414759-7056-2-git-send-email-octavian.purdila@intel.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <1411414759-7056-2-git-send-email-octavian.purdila@intel.com>
User-Agent: Mutt/1.5.22 (2013-10-16)
Sender: linux-kernel-owner@vger.kernel.org
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

On Mon, Sep 22, 2014 at 10:39:18PM +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>
> ---
>  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;

This will cause a kref imbalance as you have a usb_put_dev in error,
but haven't done the get yet.

> +	}
> +
>  	mutex_init(&vb->lock);
>  
>  	vb->usb_dev = usb_get_dev(interface_to_usbdev(interface));

Here's the get.

Johan

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <linux-kernel-owner@vger.kernel.org>
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
	id S1754124AbaIWHlP (ORCPT <rfc822;w@1wt.eu>);
	Tue, 23 Sep 2014 03:41:15 -0400
Received: from mail-lb0-f169.google.com ([209.85.217.169]:48258 "EHLO
	mail-lb0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
	with ESMTP id S1751559AbaIWHlO (ORCPT
	<rfc822;linux-kernel@vger.kernel.org>);
	Tue, 23 Sep 2014 03:41:14 -0400
X-Google-Original-Sender: <johan@hovold.com>
Date: Tue, 23 Sep 2014 09:38:40 +0200
From: Johan Hovold <johan@kernel.org>
To: Octavian Purdila <octavian.purdila@intel.com>
Cc: sameo@linux.intel.com, lee.jones@linaro.org, linux-kernel@vger.kernel.org,
        linux-usb@vger.kernel.org, johan@kernel.org
Subject: Re: [PATCH v2 1/2] mfd: viperboard: allocate I/O buffer separately
Message-ID: <20140923073840.GN5237@localhost>
References: <1411414759-7056-1-git-send-email-octavian.purdila@intel.com>
 <1411414759-7056-2-git-send-email-octavian.purdila@intel.com>
 <20140923073541.GM5237@localhost>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20140923073541.GM5237@localhost>
User-Agent: Mutt/1.5.22 (2013-10-16)
Sender: linux-kernel-owner@vger.kernel.org
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

On Tue, Sep 23, 2014 at 09:35:41AM +0200, Johan Hovold wrote:
> On Mon, Sep 22, 2014 at 10:39:18PM +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>
> > ---
> >  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;
> 
> This will cause a kref imbalance as you have a usb_put_dev in error,
> but haven't done the get yet.

Nevermind. This isn't problem as the usb device is null.

Haven't had my morning coffee yet. ;)

Johan

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <linux-kernel-owner@vger.kernel.org>
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
	id S1754536AbaIWHuZ (ORCPT <rfc822;w@1wt.eu>);
	Tue, 23 Sep 2014 03:50:25 -0400
Received: from mail-lb0-f174.google.com ([209.85.217.174]:37961 "EHLO
	mail-lb0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
	with ESMTP id S1753705AbaIWHuX (ORCPT
	<rfc822;linux-kernel@vger.kernel.org>);
	Tue, 23 Sep 2014 03:50:23 -0400
X-Google-Original-Sender: <johan@hovold.com>
Date: Tue, 23 Sep 2014 09:47:49 +0200
From: Johan Hovold <johan@kernel.org>
To: Octavian Purdila <octavian.purdila@intel.com>
Cc: sameo@linux.intel.com, lee.jones@linaro.org, linux-kernel@vger.kernel.org,
        linux-usb@vger.kernel.org, johan@kernel.org
Subject: Re: [PATCH v2 1/2] mfd: viperboard: allocate I/O buffer separately
Message-ID: <20140923074749.GO5237@localhost>
References: <1411414759-7056-1-git-send-email-octavian.purdila@intel.com>
 <1411414759-7056-2-git-send-email-octavian.purdila@intel.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <1411414759-7056-2-git-send-email-octavian.purdila@intel.com>
User-Agent: Mutt/1.5.22 (2013-10-16)
Sender: linux-kernel-owner@vger.kernel.org
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

On Mon, Sep 22, 2014 at 10:39:18PM +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;
>  };

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <linux-kernel-owner@vger.kernel.org>
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
	id S1752979AbaIXKMP (ORCPT <rfc822;w@1wt.eu>);
	Wed, 24 Sep 2014 06:12:15 -0400
Received: from mail-ig0-f177.google.com ([209.85.213.177]:42440 "EHLO
	mail-ig0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
	with ESMTP id S1750940AbaIXKMN (ORCPT
	<rfc822;linux-kernel@vger.kernel.org>);
	Wed, 24 Sep 2014 06:12:13 -0400
Date: Wed, 24 Sep 2014 11:12:06 +0100
From: Lee Jones <lee.jones@linaro.org>
To: Octavian Purdila <octavian.purdila@intel.com>
Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, johan@kernel.org,
        Octavian Purdila <octavian.purdila@intel.com>
Subject: Re: [PATCH v2 1/2] mfd: viperboard: allocate I/O buffer separately
Message-ID: <20140924101206.GD19999@lee--X1>
References: <1411414759-7056-1-git-send-email-octavian.purdila@intel.com>
 <1411414759-7056-2-git-send-email-octavian.purdila@intel.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
In-Reply-To: <1411414759-7056-2-git-send-email-octavian.purdila@intel.com>
User-Agent: Mutt/1.5.21 (2010-09-15)
Sender: linux-kernel-owner@vger.kernel.org
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

On Mon, 22 Sep 2014, 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>
> ---
>  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);

Can you obtain the 'struct device' first then use managed resources
(devm_*)?

> +	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);

Then you don't need this.

>  		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);

Or this.

>  	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;
>  };
>  

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <linux-kernel-owner@vger.kernel.org>
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
	id S1753735AbaIXKOA (ORCPT <rfc822;w@1wt.eu>);
	Wed, 24 Sep 2014 06:14:00 -0400
Received: from mail-ie0-f179.google.com ([209.85.223.179]:35004 "EHLO
	mail-ie0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
	with ESMTP id S1752749AbaIXKN6 (ORCPT
	<rfc822;linux-kernel@vger.kernel.org>);
	Wed, 24 Sep 2014 06:13:58 -0400
Date: Wed, 24 Sep 2014 11:13:52 +0100
From: Lee Jones <lee.jones@linaro.org>
To: Octavian Purdila <octavian.purdila@intel.com>
Cc: sameo@linux.intel.com, linux-kernel@vger.kernel.org,
        linux-usb@vger.kernel.org, johan@kernel.org
Subject: Re: [PATCH v2 2/2] mfd: viperboard: remove redundant OOM message and
 NULL pointer check
Message-ID: <20140924101352.GE19999@lee--X1>
References: <1411414759-7056-1-git-send-email-octavian.purdila@intel.com>
 <1411414759-7056-3-git-send-email-octavian.purdila@intel.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
In-Reply-To: <1411414759-7056-3-git-send-email-octavian.purdila@intel.com>
User-Agent: Mutt/1.5.21 (2010-09-15)
Sender: linux-kernel-owner@vger.kernel.org
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

On Mon, 22 Sep 2014, Octavian Purdila wrote:

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

Looks fine, but won't apply without patch 1.

> diff --git a/drivers/mfd/viperboard.c b/drivers/mfd/viperboard.c
> index 5f62f4e..d27c131 100644
> --- a/drivers/mfd/viperboard.c
> +++ b/drivers/mfd/viperboard.c
> @@ -59,10 +59,8 @@ static int vprbrd_probe(struct usb_interface *interface,
>  
>  	/* 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");
> +	if (vb == NULL)
>  		return -ENOMEM;
> -	}
>  
>  	vb->buf = kzalloc(sizeof(struct vprbrd_i2c_write_msg), GFP_KERNEL);
>  	if (vb->buf == NULL) {
> @@ -109,11 +107,9 @@ 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);
> +	kfree(vb->buf);
> +	kfree(vb);
>  
>  	return ret;
>  }

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <linux-kernel-owner@vger.kernel.org>
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
	id S1753880AbaIXKbc (ORCPT <rfc822;w@1wt.eu>);
	Wed, 24 Sep 2014 06:31:32 -0400
Received: from mail-lb0-f182.google.com ([209.85.217.182]:38087 "EHLO
	mail-lb0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
	with ESMTP id S1751184AbaIXKb1 (ORCPT
	<rfc822;linux-kernel@vger.kernel.org>);
	Wed, 24 Sep 2014 06:31:27 -0400
X-Google-Original-Sender: <johan@hovold.com>
Date: Wed, 24 Sep 2014 12:28:53 +0200
From: Johan Hovold <johan@kernel.org>
To: Lee Jones <lee.jones@linaro.org>
Cc: Octavian Purdila <octavian.purdila@intel.com>,
        linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
        johan@kernel.org
Subject: Re: [PATCH v2 1/2] mfd: viperboard: allocate I/O buffer separately
Message-ID: <20140924102853.GA17019@localhost>
References: <1411414759-7056-1-git-send-email-octavian.purdila@intel.com>
 <1411414759-7056-2-git-send-email-octavian.purdila@intel.com>
 <20140924101206.GD19999@lee--X1>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20140924101206.GD19999@lee--X1>
User-Agent: Mutt/1.5.22 (2013-10-16)
Sender: linux-kernel-owner@vger.kernel.org
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

On Wed, Sep 24, 2014 at 11:12:06AM +0100, Lee Jones wrote:
> On Mon, 22 Sep 2014, 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>
> > ---
> >  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);
> 
> Can you obtain the 'struct device' first then use managed resources
> (devm_*)?

I think any devres conversion should be done in a follow-up patch and
not be included in the fix (e.g. in order to facilitate backporting). We
also don't want to mix allocation schemes.

Johan

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <linux-kernel-owner@vger.kernel.org>
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
	id S1752737AbaIXMAK (ORCPT <rfc822;w@1wt.eu>);
	Wed, 24 Sep 2014 08:00:10 -0400
Received: from mail-ig0-f182.google.com ([209.85.213.182]:37755 "EHLO
	mail-ig0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
	with ESMTP id S1750767AbaIXMAI (ORCPT
	<rfc822;linux-kernel@vger.kernel.org>);
	Wed, 24 Sep 2014 08:00:08 -0400
Date: Wed, 24 Sep 2014 13:00:02 +0100
From: Lee Jones <lee.jones@linaro.org>
To: Johan Hovold <johan@kernel.org>
Cc: Octavian Purdila <octavian.purdila@intel.com>,
        linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org
Subject: Re: [PATCH v2 1/2] mfd: viperboard: allocate I/O buffer separately
Message-ID: <20140924120002.GA32069@lee--X1>
References: <1411414759-7056-1-git-send-email-octavian.purdila@intel.com>
 <1411414759-7056-2-git-send-email-octavian.purdila@intel.com>
 <20140924101206.GD19999@lee--X1>
 <20140924102853.GA17019@localhost>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
In-Reply-To: <20140924102853.GA17019@localhost>
User-Agent: Mutt/1.5.21 (2010-09-15)
Sender: linux-kernel-owner@vger.kernel.org
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

On Wed, 24 Sep 2014, Johan Hovold wrote:

> On Wed, Sep 24, 2014 at 11:12:06AM +0100, Lee Jones wrote:
> > On Mon, 22 Sep 2014, 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>
> > > ---
> > >  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);
> > 
> > Can you obtain the 'struct device' first then use managed resources
> > (devm_*)?
> 
> I think any devres conversion should be done in a follow-up patch and
> not be included in the fix (e.g. in order to facilitate backporting). We
> also don't want to mix allocation schemes.

I agree, but equally I'm not keen on accepting this patch as I believe
it could be done better.

Please submit two patches, one converting to shared resources and this
being the subsequent one, fixed up to do the right thing.

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <linux-kernel-owner@vger.kernel.org>
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
	id S1754012AbaIXM3f (ORCPT <rfc822;w@1wt.eu>);
	Wed, 24 Sep 2014 08:29:35 -0400
Received: from mail-la0-f41.google.com ([209.85.215.41]:64599 "EHLO
	mail-la0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
	with ESMTP id S1751201AbaIXM3c (ORCPT
	<rfc822;linux-kernel@vger.kernel.org>);
	Wed, 24 Sep 2014 08:29:32 -0400
X-Google-Original-Sender: <johan@hovold.com>
Date: Wed, 24 Sep 2014 14:26:58 +0200
From: Johan Hovold <johan@kernel.org>
To: Lee Jones <lee.jones@linaro.org>
Cc: Johan Hovold <johan@kernel.org>,
        Octavian Purdila <octavian.purdila@intel.com>,
        linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org
Subject: Re: [PATCH v2 1/2] mfd: viperboard: allocate I/O buffer separately
Message-ID: <20140924122658.GD17019@localhost>
References: <1411414759-7056-1-git-send-email-octavian.purdila@intel.com>
 <1411414759-7056-2-git-send-email-octavian.purdila@intel.com>
 <20140924101206.GD19999@lee--X1>
 <20140924102853.GA17019@localhost>
 <20140924120002.GA32069@lee--X1>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20140924120002.GA32069@lee--X1>
User-Agent: Mutt/1.5.22 (2013-10-16)
Sender: linux-kernel-owner@vger.kernel.org
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

On Wed, Sep 24, 2014 at 01:00:02PM +0100, Lee Jones wrote:
> On Wed, 24 Sep 2014, Johan Hovold wrote:
> 
> > On Wed, Sep 24, 2014 at 11:12:06AM +0100, Lee Jones wrote:
> > > On Mon, 22 Sep 2014, 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>
> > > > ---
> > > >  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);
> > > 
> > > Can you obtain the 'struct device' first then use managed resources
> > > (devm_*)?
> > 
> > I think any devres conversion should be done in a follow-up patch and
> > not be included in the fix (e.g. in order to facilitate backporting). We
> > also don't want to mix allocation schemes.
> 
> I agree, but equally I'm not keen on accepting this patch as I believe
> it could be done better.
>
> Please submit two patches, one converting to shared resources and this
> being the subsequent one, fixed up to do the right thing.

A buffer-corruption fix is a candidate for stable, whereas a devres
conversion (clean up) is not. Hence the former should not depend on the
latter.

Johan

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <linux-kernel-owner@vger.kernel.org>
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
	id S1751595AbaIXMem (ORCPT <rfc822;w@1wt.eu>);
	Wed, 24 Sep 2014 08:34:42 -0400
Received: from mail-wi0-f176.google.com ([209.85.212.176]:65086 "EHLO
	mail-wi0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
	with ESMTP id S1751184AbaIXMeK (ORCPT
	<rfc822;linux-kernel@vger.kernel.org>);
	Wed, 24 Sep 2014 08:34:10 -0400
MIME-Version: 1.0
In-Reply-To: <20140924122658.GD17019@localhost>
References: <1411414759-7056-1-git-send-email-octavian.purdila@intel.com>
	<1411414759-7056-2-git-send-email-octavian.purdila@intel.com>
	<20140924101206.GD19999@lee--X1>
	<20140924102853.GA17019@localhost>
	<20140924120002.GA32069@lee--X1>
	<20140924122658.GD17019@localhost>
Date: Wed, 24 Sep 2014 15:34:08 +0300
Message-ID: <CAE1zotLx-mB=rejxA9JwtWRwdYWinC82AXwtsczgQXFOSLMdrA@mail.gmail.com>
Subject: Re: [PATCH v2 1/2] mfd: viperboard: allocate I/O buffer separately
From: Octavian Purdila <octavian.purdila@intel.com>
To: Johan Hovold <johan@kernel.org>
Cc: Lee Jones <lee.jones@linaro.org>, lkml <linux-kernel@vger.kernel.org>,
        linux-usb@vger.kernel.org
Content-Type: text/plain; charset=UTF-8
Sender: linux-kernel-owner@vger.kernel.org
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

On Wed, Sep 24, 2014 at 3:26 PM, Johan Hovold <johan@kernel.org> wrote:
> On Wed, Sep 24, 2014 at 01:00:02PM +0100, Lee Jones wrote:
>> On Wed, 24 Sep 2014, Johan Hovold wrote:
>>
>> > On Wed, Sep 24, 2014 at 11:12:06AM +0100, Lee Jones wrote:
>> > > On Mon, 22 Sep 2014, 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>
>> > > > ---
>> > > >  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);
>> > >
>> > > Can you obtain the 'struct device' first then use managed resources
>> > > (devm_*)?
>> >
>> > I think any devres conversion should be done in a follow-up patch and
>> > not be included in the fix (e.g. in order to facilitate backporting). We
>> > also don't want to mix allocation schemes.
>>
>> I agree, but equally I'm not keen on accepting this patch as I believe
>> it could be done better.
>>
>> Please submit two patches, one converting to shared resources and this
>> being the subsequent one, fixed up to do the right thing.
>
> A buffer-corruption fix is a candidate for stable, whereas a devres
> conversion (clean up) is not. Hence the former should not depend on the
> latter.
>

I can follow-up with a v3 3 patch series: first for the fix, second
for the OOM & error path cleanup, third for devm conversion.

I think this will address both issues (backport and better final result).

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <linux-kernel-owner@vger.kernel.org>
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
	id S1753419AbaIXMh0 (ORCPT <rfc822;w@1wt.eu>);
	Wed, 24 Sep 2014 08:37:26 -0400
Received: from mail-lb0-f176.google.com ([209.85.217.176]:38794 "EHLO
	mail-lb0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
	with ESMTP id S1750936AbaIXMhY (ORCPT
	<rfc822;linux-kernel@vger.kernel.org>);
	Wed, 24 Sep 2014 08:37:24 -0400
X-Google-Original-Sender: <johan@hovold.com>
Date: Wed, 24 Sep 2014 14:34:51 +0200
From: Johan Hovold <johan@kernel.org>
To: Octavian Purdila <octavian.purdila@intel.com>
Cc: Johan Hovold <johan@kernel.org>, Lee Jones <lee.jones@linaro.org>,
        lkml <linux-kernel@vger.kernel.org>, linux-usb@vger.kernel.org
Subject: Re: [PATCH v2 1/2] mfd: viperboard: allocate I/O buffer separately
Message-ID: <20140924123451.GA18804@localhost>
References: <1411414759-7056-1-git-send-email-octavian.purdila@intel.com>
 <1411414759-7056-2-git-send-email-octavian.purdila@intel.com>
 <20140924101206.GD19999@lee--X1>
 <20140924102853.GA17019@localhost>
 <20140924120002.GA32069@lee--X1>
 <20140924122658.GD17019@localhost>
 <CAE1zotLx-mB=rejxA9JwtWRwdYWinC82AXwtsczgQXFOSLMdrA@mail.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <CAE1zotLx-mB=rejxA9JwtWRwdYWinC82AXwtsczgQXFOSLMdrA@mail.gmail.com>
User-Agent: Mutt/1.5.22 (2013-10-16)
Sender: linux-kernel-owner@vger.kernel.org
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

On Wed, Sep 24, 2014 at 03:34:08PM +0300, Octavian Purdila wrote:

> I can follow-up with a v3 3 patch series: first for the fix, second
> for the OOM & error path cleanup, third for devm conversion.

I'd include the error-path clean up bit in the devres conversion as that
is what it's really all about.

Johan

