From patchwork Mon Nov 12 14:12:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 10678713 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0816D14BA for ; Mon, 12 Nov 2018 14:12:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB33E29D6F for ; Mon, 12 Nov 2018 14:12:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DEC9B29D83; Mon, 12 Nov 2018 14:12:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 114C129D7D for ; Mon, 12 Nov 2018 14:12:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728505AbeKMAGR (ORCPT ); Mon, 12 Nov 2018 19:06:17 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:41927 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727103AbeKMAGR (ORCPT ); Mon, 12 Nov 2018 19:06:17 -0500 Received: by mail-lj1-f194.google.com with SMTP id z80-v6so7731281ljb.8 for ; Mon, 12 Nov 2018 06:12:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=j82EKe+wRAgT6Athn6eo09la18zaAjt/fVKoE3mDKu4=; b=iG4r+mLK5eTJhEUIkhoxf8pviJcETEBujKpfk0OBjA7q/2KEpCKFis2V2aaF7KDwYm b4fBAofgUsLVhnv1ezOvIXhZr4WZ/yLLdlfByJq+p1QS/bTHkDtTIbnRyS1tnmXVq4tI G3OsyRlEicbE5+bWwwld3NcZTQi2OCkoBl6G8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=j82EKe+wRAgT6Athn6eo09la18zaAjt/fVKoE3mDKu4=; b=DFkaKOyDS2VBfCJRRQQkB8muVY114rkHaHgiI0PvYAvg3bJG5XLq6to7CFiBoJOLUL aHCvvl2Ot1N3FhkxGu3ubSasnBr7mf0RJ2rX4EkdND08gVS1RHYq1KCxv2jctgBhuOz7 JziT3b1pew2cNRXpd9l5u1tT6vM5mJH/lKgqh4RqUPJvvBR4YfcVB75e4esw7Xt9F+3B qZypuDNiF/H/mjwJ3nOCcShIlGB9LxX3tlvsag/ZNtW1MgPuL5YQZDxlMRV/xI0B/xPz jrJ/Ekn3xN7PEHGITR0BuOYjIFj5Cm8XEcPQW/48/Vqn/OhuN/rKW6V5Ub8264nLdZfi Iedw== X-Gm-Message-State: AGRZ1gKjIuR/o6I7EsxasnP8gYKAT9b01/NRcNtxSqaFfq3r2rX9O0vi SqPm4EJHeMWO9fIRXK2CVGk7UfGKx4JiLw== X-Google-Smtp-Source: AJdET5dMS15w3N7D0EX/U+yFCZArc38nKkhpTQ6kiUnfyRkqYhHwXqDRUob0AHKD3u0Qt81Lan+tzA== X-Received: by 2002:a2e:5246:: with SMTP id g67-v6mr777260ljb.73.1542031968565; Mon, 12 Nov 2018 06:12:48 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id m14-v6sm3056889lji.29.2018.11.12.06.12.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Nov 2018 06:12:47 -0800 (PST) From: Linus Walleij To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Linus Walleij Subject: [PATCH 01/10] mmc: slot-gpio: Allocate GPIO labels dynamically Date: Mon, 12 Nov 2018 15:12:30 +0100 Message-Id: <20181112141239.19646-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181112141239.19646-1-linus.walleij@linaro.org> References: <20181112141239.19646-1-linus.walleij@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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; }