diff mbox series

[01/10] mmc: slot-gpio: Allocate GPIO labels dynamically

Message ID 20181112141239.19646-2-linus.walleij@linaro.org (mailing list archive)
State New, archived
Headers show
Series Convert MMC slot GPIO to descriptors | expand

Commit Message

Linus Walleij Nov. 12, 2018, 2:12 p.m. UTC
The use of string pointers in the MMC slot GPIO context is
pretty dubious, allocating some 2*len extra bytes for each
label of the ro and wp pins.

Tidy this up using kasprintf() with dynamic allocation of
labels for these strings.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/mmc/core/slot-gpio.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

Comments

Ulf Hansson Nov. 20, 2018, 9:29 a.m. UTC | #1
On 12 November 2018 at 15:12, Linus Walleij <linus.walleij@linaro.org> wrote:
> The use of string pointers in the MMC slot GPIO context is
> pretty dubious, allocating some 2*len extra bytes for each
> label of the ro and wp pins.
>
> Tidy this up using kasprintf() with dynamic allocation of
> labels for these strings.
>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

Applied for next, thanks!

Kind regards
Uffe

> ---
>  drivers/mmc/core/slot-gpio.c | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/mmc/core/slot-gpio.c b/drivers/mmc/core/slot-gpio.c
> index 86803a3a04dc..e5bb86b02373 100644
> --- a/drivers/mmc/core/slot-gpio.c
> +++ b/drivers/mmc/core/slot-gpio.c
> @@ -27,8 +27,8 @@ struct mmc_gpio {
>         bool override_cd_active_level;
>         irqreturn_t (*cd_gpio_isr)(int irq, void *dev_id);
>         char *ro_label;
> +       char *cd_label;
>         u32 cd_debounce_delay_ms;
> -       char cd_label[];
>  };
>
>  static irqreturn_t mmc_gpio_cd_irqt(int irq, void *dev_id)
> @@ -45,15 +45,19 @@ static irqreturn_t mmc_gpio_cd_irqt(int irq, void *dev_id)
>
>  int mmc_gpio_alloc(struct mmc_host *host)
>  {
> -       size_t len = strlen(dev_name(host->parent)) + 4;
>         struct mmc_gpio *ctx = devm_kzalloc(host->parent,
> -                               sizeof(*ctx) + 2 * len, GFP_KERNEL);
> +                                           sizeof(*ctx), GFP_KERNEL);
>
>         if (ctx) {
> -               ctx->ro_label = ctx->cd_label + len;
>                 ctx->cd_debounce_delay_ms = 200;
> -               snprintf(ctx->cd_label, len, "%s cd", dev_name(host->parent));
> -               snprintf(ctx->ro_label, len, "%s ro", dev_name(host->parent));
> +               ctx->cd_label = devm_kasprintf(host->parent, GFP_KERNEL,
> +                               "%s cd", dev_name(host->parent));
> +               if (!ctx->cd_label)
> +                       return -ENOMEM;
> +               ctx->ro_label = devm_kasprintf(host->parent, GFP_KERNEL,
> +                               "%s ro", dev_name(host->parent));
> +               if (!ctx->ro_label)
> +                       return -ENOMEM;
>                 host->slot.handler_priv = ctx;
>                 host->slot.cd_irq = -EINVAL;
>         }
> --
> 2.17.2
>
diff mbox series

Patch

diff --git a/drivers/mmc/core/slot-gpio.c b/drivers/mmc/core/slot-gpio.c
index 86803a3a04dc..e5bb86b02373 100644
--- a/drivers/mmc/core/slot-gpio.c
+++ b/drivers/mmc/core/slot-gpio.c
@@ -27,8 +27,8 @@  struct mmc_gpio {
 	bool override_cd_active_level;
 	irqreturn_t (*cd_gpio_isr)(int irq, void *dev_id);
 	char *ro_label;
+	char *cd_label;
 	u32 cd_debounce_delay_ms;
-	char cd_label[];
 };
 
 static irqreturn_t mmc_gpio_cd_irqt(int irq, void *dev_id)
@@ -45,15 +45,19 @@  static irqreturn_t mmc_gpio_cd_irqt(int irq, void *dev_id)
 
 int mmc_gpio_alloc(struct mmc_host *host)
 {
-	size_t len = strlen(dev_name(host->parent)) + 4;
 	struct mmc_gpio *ctx = devm_kzalloc(host->parent,
-				sizeof(*ctx) + 2 * len,	GFP_KERNEL);
+					    sizeof(*ctx), GFP_KERNEL);
 
 	if (ctx) {
-		ctx->ro_label = ctx->cd_label + len;
 		ctx->cd_debounce_delay_ms = 200;
-		snprintf(ctx->cd_label, len, "%s cd", dev_name(host->parent));
-		snprintf(ctx->ro_label, len, "%s ro", dev_name(host->parent));
+		ctx->cd_label = devm_kasprintf(host->parent, GFP_KERNEL,
+				"%s cd", dev_name(host->parent));
+		if (!ctx->cd_label)
+			return -ENOMEM;
+		ctx->ro_label = devm_kasprintf(host->parent, GFP_KERNEL,
+				"%s ro", dev_name(host->parent));
+		if (!ctx->ro_label)
+			return -ENOMEM;
 		host->slot.handler_priv = ctx;
 		host->slot.cd_irq = -EINVAL;
 	}