diff mbox series

[v2,6/8] mtd: maps: gpio-addr-flash: Split allocation in two

Message ID 20180905143643.9871-7-ricardo.ribalda@gmail.com
State Superseded
Delegated to: Boris Brezillon
Headers show
Series gpio-addr-flash: Support for device-tree and cleanup | expand

Commit Message

Ricardo Ribalda Delgado Sept. 5, 2018, 2:36 p.m. UTC
Instead of making one allocation and then calculating the addresses of
those two pointers in that area make two allocations. This simplifies
the code.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
---
 drivers/mtd/maps/gpio-addr-flash.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Comments

Ricardo Ribalda Delgado Oct. 1, 2018, 9:58 a.m. UTC | #1
Hi Boris

PLEASE do not apply this one!

There is a bug, value from gpio->addr is lost.
On Wed, Sep 5, 2018 at 4:37 PM Ricardo Ribalda Delgado
<ricardo.ribalda@gmail.com> wrote:
>
> Instead of making one allocation and then calculating the addresses of
> those two pointers in that area make two allocations. This simplifies
> the code.
>
> Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
> ---
>  drivers/mtd/maps/gpio-addr-flash.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/mtd/maps/gpio-addr-flash.c b/drivers/mtd/maps/gpio-addr-flash.c
> index 8f5e3dce9be3..9455a8448064 100644
> --- a/drivers/mtd/maps/gpio-addr-flash.c
> +++ b/drivers/mtd/maps/gpio-addr-flash.c
> @@ -205,7 +205,7 @@ static const char * const part_probe_types[] = {
>   */
>  static int gpio_flash_probe(struct platform_device *pdev)
>  {
> -       size_t i, arr_size;
> +       size_t i;
>         struct physmap_flash_data *pdata;
>         struct resource *memory;
>         struct resource *gpios;
> @@ -218,8 +218,7 @@ static int gpio_flash_probe(struct platform_device *pdev)
>         if (!memory || !gpios || !gpios->end)
>                 return -EINVAL;
>
> -       arr_size = sizeof(state->gpio_addrs[0]) * gpios->end;
> -       state = devm_kzalloc(&pdev->dev, sizeof(*state) + arr_size, GFP_KERNEL);
> +       state = devm_kzalloc(&pdev->dev, sizeof(*state), GFP_KERNEL);
>         if (!state)
>                 return -ENOMEM;
>
> @@ -228,7 +227,12 @@ static int gpio_flash_probe(struct platform_device *pdev)
>          * away their pointer types here to the known types (gpios->xxx).
>          */
>         state->gpio_count     = gpios->end;
> -       state->gpio_addrs     = (void *)(unsigned long)gpios->start;
> +       state->gpio_addrs     = devm_kzalloc(&pdev->dev,
> +                                            sizeof(state->gpio_addrs[0]) *
> +                                                               gpios->end,
> +                                            GFP_KERNEL);
> +       if (!state->gpio_addrs)
> +               return -ENOMEM;
>         state->win_order      = get_bitmask_order(resource_size(memory)) - 1;
>
>         state->map.name       = DRIVER_NAME;
> --
> 2.18.0
>
Boris Brezillon Oct. 1, 2018, 11:38 a.m. UTC | #2
On Mon, 1 Oct 2018 11:58:49 +0200
Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com> wrote:

> Hi Boris
> 
> PLEASE do not apply this one!

Okay, should I wait for a v6 of the whole series, or do you still want
me to apply patches 1 to 5?
Ricardo Ribalda Delgado Oct. 1, 2018, 11:40 a.m. UTC | #3
Hi
On Mon, Oct 1, 2018 at 1:39 PM Boris Brezillon
<boris.brezillon@bootlin.com> wrote:
>
> On Mon, 1 Oct 2018 11:58:49 +0200
> Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com> wrote:
>
> > Hi Boris
> >
> > PLEASE do not apply this one!
>
> Okay, should I wait for a v6 of the whole series, or do you still want
> me to apply patches 1 to 5?

I think is better to send v6 of the whole series. Thanks!
diff mbox series

Patch

diff --git a/drivers/mtd/maps/gpio-addr-flash.c b/drivers/mtd/maps/gpio-addr-flash.c
index 8f5e3dce9be3..9455a8448064 100644
--- a/drivers/mtd/maps/gpio-addr-flash.c
+++ b/drivers/mtd/maps/gpio-addr-flash.c
@@ -205,7 +205,7 @@  static const char * const part_probe_types[] = {
  */
 static int gpio_flash_probe(struct platform_device *pdev)
 {
-	size_t i, arr_size;
+	size_t i;
 	struct physmap_flash_data *pdata;
 	struct resource *memory;
 	struct resource *gpios;
@@ -218,8 +218,7 @@  static int gpio_flash_probe(struct platform_device *pdev)
 	if (!memory || !gpios || !gpios->end)
 		return -EINVAL;
 
-	arr_size = sizeof(state->gpio_addrs[0]) * gpios->end;
-	state = devm_kzalloc(&pdev->dev, sizeof(*state) + arr_size, GFP_KERNEL);
+	state = devm_kzalloc(&pdev->dev, sizeof(*state), GFP_KERNEL);
 	if (!state)
 		return -ENOMEM;
 
@@ -228,7 +227,12 @@  static int gpio_flash_probe(struct platform_device *pdev)
 	 * away their pointer types here to the known types (gpios->xxx).
 	 */
 	state->gpio_count     = gpios->end;
-	state->gpio_addrs     = (void *)(unsigned long)gpios->start;
+	state->gpio_addrs     = devm_kzalloc(&pdev->dev,
+					     sizeof(state->gpio_addrs[0]) *
+								gpios->end,
+					     GFP_KERNEL);
+	if (!state->gpio_addrs)
+		return -ENOMEM;
 	state->win_order      = get_bitmask_order(resource_size(memory)) - 1;
 
 	state->map.name       = DRIVER_NAME;