From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932965AbbIURHX (ORCPT ); Mon, 21 Sep 2015 13:07:23 -0400 Received: from mx2.spb.prosoft.ru ([195.218.156.34]:64734 "EHLO mx2.spb.prosoft.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932542AbbIURHW (ORCPT ); Mon, 21 Sep 2015 13:07:22 -0400 From: Grigoryev Denis To: Lee Jones CC: "linux-kernel@vger.kernel.org" , "Samuel Ortiz" Subject: Re: [PATCH v2] mfd: tps6105x: Fix NULL pointer access. Thread-Topic: [PATCH v2] mfd: tps6105x: Fix NULL pointer access. Thread-Index: AQHQ9I/3H1k1xR+M00661J+TtfNbyw== Date: Mon, 21 Sep 2015 17:07:16 +0000 Message-ID: <1E0B3F54A97F2C4591427D8CCF3028AD691D8AE0@SPB-PRIMARY-1.spb.prosoft.ru> References: <1E0B3F54A97F2C4591427D8CCF3028AD691D8879@SPB-PRIMARY-1.spb.prosoft.ru> <20150920042003.GW3039@x1> <1E0B3F54A97F2C4591427D8CCF3028AD691D8ACE@SPB-PRIMARY-1.spb.prosoft.ru> In-Reply-To: <1E0B3F54A97F2C4591427D8CCF3028AD691D8ACE@SPB-PRIMARY-1.spb.prosoft.ru> Accept-Language: ru-RU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [192.168.16.170] Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id t8LH7T2x032569 Oh, sorry. With further testing I realized that I made a mistake and typos. I will send the patch v3. My apologies for the flood. I'm new in LKML. On Mon., 21/09/2015 at 13:41 +0000, 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 adds an mfd_cell for each possible mode thereby excluding runtime > .name assignment. > > Signed-off-by: Denis Grigoryev > --- > drivers/mfd/tps6105x.c | 62 ++++++++++++++++++++++++++++-------------------- > 1 file changed, 36 insertions(+), 26 deletions(-) > > diff --git a/drivers/mfd/tps6105x.c b/drivers/mfd/tps6105x.c > index 5de95c2..4dbfb45 100644 > --- a/drivers/mfd/tps6105x.c > +++ b/drivers/mfd/tps6105x.c > @@ -119,17 +119,25 @@ static int tps6105x_startup(struct tps6105x *tps6105x) > } > > /* > - * MFD cells - we have one cell which is selected operation > - * mode, and we always have a GPIO cell. > - */ > + * * MFD cells - we always have a GPIO cell and we have one cell > + * * which is selected operation mode. > + * */ > static struct mfd_cell tps6105x_cells[] = { > - { > - /* name will be runtime assigned */ > - .id = -1, > + [TPS6105X_REG0_MODE_SHUTDOWN] = { > + .name = "tps6105x-gpio", > + .id = -1, > + }, > + [TPS6105X_REG0_MODE_TORCH] = { > + .name = "tps6105x-leds", > + .id = -1, > + }, > + [TPS6105X_REG0_MODE_TORCH_FLASH] = { > + .name = "tps6105x-flash", > + .id = -1, > }, > - { > - .name = "tps6105x-gpio", > - .id = -1, > + [TPS6105X_REG0_MODE_VOLTAGE] = { > + .name = "tps6105x-regulator", > + .id = -1, > }, > }; > > @@ -157,6 +165,18 @@ static int tps6105x_probe(struct i2c_client *client, > return ret; > } > > + /* Set up and register the platform devices. */ > + for (i = 0; i < ARRAY_SIZE(tps6105x_cells); i++) { > + /* One state holder for all drivers, this is simple */ > + tps6105x_cells[i].platform_data = tps6105x; > + tps6105x_cells[i].pdata_size = sizeof(*tps6105x); > + } > + > + ret = mfd_add_devices(&client->dev, -1, tps6105x_cells, > + 1, NULL, 0, NULL); > + if (ret) > + return ret; > + > /* Remove warning texts when you implement new cell drivers */ > switch (pdata->mode) { > case TPS6105X_MODE_SHUTDOWN: > @@ -164,31 +184,21 @@ static int tps6105x_probe(struct i2c_client *client, > "present, not used for anything, only GPIO\n"); > break; > case TPS6105X_MODE_TORCH: > - tps6105x_cells[0].name = "tps6105x-leds"; > - dev_warn(&client->dev, > - "torch mode is unsupported\n"); > - break; > case TPS6105X_MODE_TORCH_FLASH: > - tps6105x_cells[0].name = "tps6105x-flash"; > - dev_warn(&client->dev, > - "flash mode is unsupported\n"); > - break; > case TPS6105X_MODE_VOLTAGE: > - tps6105x_cells[0].name ="tps6105x-regulator"; > + ret = mfd_add_devices(&client->dev, -1, > + &tps6105x_cells[pdata->mode], > + 1, NULL, 0, NULL); > break; > default: > + dev_warn(&client->dev, "invalid mode: %d\n", pdata->mode); > break; > } > > - /* Set up and register the platform devices. */ > - for (i = 0; i < ARRAY_SIZE(tps6105x_cells); i++) { > - /* One state holder for all drivers, this is simple */ > - tps6105x_cells[i].platform_data = tps6105x; > - tps6105x_cells[i].pdata_size = sizeof(*tps6105x); > - } > + if (ret) > + mfd_remove_devices(&client->dev); > > - return mfd_add_devices(&client->dev, 0, tps6105x_cells, > - ARRAY_SIZE(tps6105x_cells), NULL, 0, NULL); > + return ret; > } > > static int tps6105x_remove(struct i2c_client *client) {.n++%ݶw{.n+{G{ayʇڙ,jfhz_(階ݢj"mG?&~iOzv^m ?I