From patchwork Tue Dec 20 11:28:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 88585 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp1668435qgi; Tue, 20 Dec 2016 03:29:29 -0800 (PST) X-Received: by 10.98.41.3 with SMTP id p3mr18788256pfp.22.1482233369636; Tue, 20 Dec 2016 03:29:29 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 191si21767638pgb.332.2016.12.20.03.29.29; Tue, 20 Dec 2016 03:29:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@baylibre-com.20150623.gappssmtp.com; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1763303AbcLTL3T (ORCPT + 4 others); Tue, 20 Dec 2016 06:29:19 -0500 Received: from mail-wj0-f173.google.com ([209.85.210.173]:35308 "EHLO mail-wj0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1762227AbcLTL2g (ORCPT ); Tue, 20 Dec 2016 06:28:36 -0500 Received: by mail-wj0-f173.google.com with SMTP id v7so173983028wjy.2 for ; Tue, 20 Dec 2016 03:28:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CdNdVkRdsirKVo4/DaLLveULsteg8GOYLz636DEToOQ=; b=SVhfJvxmhmrlDwH0azKMfUxGtNf8eI6dgmbI9IcASOapMntmqAzgARi8pmdSNbFRyJ fS5KCsh87PZqNX8I6YxoVJwG7D0puiJ/9HfPD4KYU2ybynheqc3r3vTQeSTeW2ZcYWg5 SEZUPil1ExGBcIZwmORTQVQ2e2fzHrJZWYMiRiL4rWsFHgsV/aXOyTTdV4DdI/tjocs4 6mhfX6c3nHUc/bEmduzLNSXMXUA8N1TM6iuA/hLlYQDF+Itn/J4NvnYlIAg7/XlPQwmD csDyHm1TsuJepvvuIwP74oPKRObTp0q2p1ZTyDuF2pF/Q8b8uDj0j7dH9bIqf0fLdFUS 8b5A== 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=CdNdVkRdsirKVo4/DaLLveULsteg8GOYLz636DEToOQ=; b=qqrPP6TPSZgWVrY42VpebiVNqt1J1eUgZ79GOhXp2GIDDvDw3KZJWibkKC5FpO6cDO alGQ5Jh3/x33i5F/3TDpTpTDR79Ovr546x0sFxLm/EWgRSy1+udrxzOjvrSyZ13lHqSs m4erB2TaQIdRII0S6xSaSvFV4kifAhOMx1Ljr9R+UTMk/M3dDZNQNX3m4oW/Yib1ydS4 E6YFQa2A67m0t5S2oGLsvZKoGlTd8Co/keIKBcG6LMr+wZLy2CTfbZA1SJLJeIOHxxUF 2tPmxsAv7rE7V/Ve0AYQlGp+pBYCh7Vsy/bYBKMc5tbil7942KaYzbrBLiJ6cD2MJxBM 6f0Q== X-Gm-Message-State: AIkVDXJcusYSiMKjBAvITCIEgz5mRSJzDJJr+5dgTThsUt/dUmLxpKTCHLtE75lbqWVYs2rA X-Received: by 10.194.3.47 with SMTP id 15mr17070611wjz.17.1482233314904; Tue, 20 Dec 2016 03:28:34 -0800 (PST) Received: from localhost.localdomain ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id x5sm25070467wje.36.2016.12.20.03.28.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 20 Dec 2016 03:28:34 -0800 (PST) From: Bartosz Golaszewski To: Bamvor Jian Zhang , Linus Walleij , Alexandre Courbot Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 2/3] gpio: mockup: dynamically allocate memory for chip name Date: Tue, 20 Dec 2016 12:28:19 +0100 Message-Id: <1482233300-20078-3-git-send-email-bgolaszewski@baylibre.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1482233300-20078-1-git-send-email-bgolaszewski@baylibre.com> References: <1482233300-20078-1-git-send-email-bgolaszewski@baylibre.com> Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Currently the chip name buffer is allocated on the stack and the address of the buffer is passed to the gpio framework. It's invalid after probe() returns, so the sysfs label attribute displays garbage. Use devm_kasprintf() for each string instead. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) -- 2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index af0c1e8..10f6bf6 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -126,7 +126,7 @@ static int mockup_gpio_probe(struct platform_device *pdev) int i; int base; int ngpio; - char chip_name[sizeof(GPIO_NAME) + 3]; + char *chip_name; if (gpio_mockup_params_nr < 2) return -EINVAL; @@ -146,8 +146,12 @@ static int mockup_gpio_probe(struct platform_device *pdev) ngpio = gpio_mockup_ranges[i * 2 + 1] - base; if (ngpio >= 0) { - sprintf(chip_name, "%s-%c", GPIO_NAME, - pins_name_start + i); + chip_name = devm_kasprintf(dev, GFP_KERNEL, + "%s-%c", GPIO_NAME, + pins_name_start + i); + if (!chip_name) + return -ENOMEM; + ret = mockup_gpio_add(dev, &cntr[i], chip_name, base, ngpio); } else {