public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Lee Jones <lee.jones@linaro.org>
To: Grigoryev Denis <grigoryev@fastwel.ru>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Samuel Ortiz <sameo@linux.intel.com>
Subject: Re: [PATCH] mfd: tps6105x: Fix NULL pointer access.
Date: Sun, 20 Sep 2015 05:20:03 +0100	[thread overview]
Message-ID: <20150920042003.GW3039@x1> (raw)
In-Reply-To: <1E0B3F54A97F2C4591427D8CCF3028AD691D8879@SPB-PRIMARY-1.spb.prosoft.ru>

On Fri, 04 Sep 2015, Grigoryev Denis wrote:

> When tps6105x used in TPS6105X_MODE_SHUTDOWN mode the driver calls
> mfd_add_devices() with mfd_cell->name == NULL, that causes an ooops in
> platform_device_register() later.
> 
> This patch reorders mfd_cell structures and makes code to call
> mfd_add_devices() with proper number of cells.
> 
> Signed-off-by: Denis Grigoryev <grigoryev@spb.prosoft.ru>
> ---
>  drivers/mfd/tps6105x.c |   16 +++++++++-------
>  1 file changed, 9 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/mfd/tps6105x.c b/drivers/mfd/tps6105x.c
> index 5de95c2..be2c286 100644
> --- a/drivers/mfd/tps6105x.c
> +++ b/drivers/mfd/tps6105x.c
> @@ -124,11 +124,11 @@ static int tps6105x_startup(struct tps6105x *tps6105x)
>   */
>  static struct mfd_cell tps6105x_cells[] = {
>  	{
> -		/* name will be runtime assigned */
> +		.name = "tps6105x-gpio",
>  		.id = -1,
>  	},
>  	{
> -		.name = "tps6105x-gpio",
> +		/* name will be runtime assigned */
>  		.id = -1,
>  	},
>  };

So you have 2 cells with identical .name's and identical .id's.

How does that work?

> @@ -138,6 +138,7 @@ static int tps6105x_probe(struct i2c_client *client,
>  {
>  	struct tps6105x			*tps6105x;
>  	struct tps6105x_platform_data	*pdata;
> +	int n_cells = ARRAY_SIZE(tps6105x_cells);
>  	int ret;
>  	int i;
>  
> @@ -162,33 +163,34 @@ static int tps6105x_probe(struct i2c_client *client,
>  	case TPS6105X_MODE_SHUTDOWN:
>  		dev_info(&client->dev,
>  			 "present, not used for anything, only GPIO\n");
> +		n_cells = 1;
>  		break;
>  	case TPS6105X_MODE_TORCH:
> -		tps6105x_cells[0].name = "tps6105x-leds";
> +		tps6105x_cells[1].name = "tps6105x-leds";

Now you're over-writing cell names!  I'd say this was a hack.

Please just create an entry for each device, like usual.

>  		dev_warn(&client->dev,
>  			 "torch mode is unsupported\n");
>  		break;
>  	case TPS6105X_MODE_TORCH_FLASH:
> -		tps6105x_cells[0].name = "tps6105x-flash";
> +		tps6105x_cells[1].name = "tps6105x-flash";
>  		dev_warn(&client->dev,
>  			 "flash mode is unsupported\n");
>  		break;
>  	case TPS6105X_MODE_VOLTAGE:
> -		tps6105x_cells[0].name ="tps6105x-regulator";
> +		tps6105x_cells[1].name = "tps6105x-regulator";
>  		break;
>  	default:
>  		break;
>  	}
>  
>  	/* Set up and register the platform devices. */
> -	for (i = 0; i < ARRAY_SIZE(tps6105x_cells); i++) {
> +	for (i = 0; i < n_cells; i++) {
>  		/* One state holder for all drivers, this is simple */
>  		tps6105x_cells[i].platform_data = tps6105x;
>  		tps6105x_cells[i].pdata_size = sizeof(*tps6105x);
>  	}
>  
>  	return mfd_add_devices(&client->dev, 0, tps6105x_cells,
> -			       ARRAY_SIZE(tps6105x_cells), NULL, 0, NULL);
> +			       n_cells, NULL, 0, NULL);
>  }
>  
>  static int tps6105x_remove(struct i2c_client *client)

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

  reply	other threads:[~2015-09-20  4:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-04 15:14 [PATCH] mfd: tps6105x: Fix NULL pointer access Grigoryev Denis
2015-09-20  4:20 ` Lee Jones [this message]
2015-09-21 11:22   ` Grigoryev Denis
2015-09-21 13:41   ` [PATCH v2] " Grigoryev Denis
2015-09-21 17:07     ` Grigoryev Denis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150920042003.GW3039@x1 \
    --to=lee.jones@linaro.org \
    --cc=grigoryev@fastwel.ru \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sameo@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox