From patchwork Wed Dec 13 11:25:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 847949 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="WkOfKhGy"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yxZBP02Shz9t2M for ; Wed, 13 Dec 2017 22:25:49 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752523AbdLMLZr (ORCPT ); Wed, 13 Dec 2017 06:25:47 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:33093 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752676AbdLMLZ0 (ORCPT ); Wed, 13 Dec 2017 06:25:26 -0500 Received: by mail-wm0-f67.google.com with SMTP id g130so21407210wme.0 for ; Wed, 13 Dec 2017 03:25:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ytHg5OZpk+LGLChC69Z1C/7WFDwTbU6ypwmUi8vhWKs=; b=WkOfKhGyFCalSCGyTpe6cm83G2tReegA+wJZNT4CQ24wwdkfXEC+mMvy6DPh2f3zHO mtNuIsmKk130qoAjkxYD+tps2Dq1D/kiQ/O0K8ODMYOS7Eyzc7OMFMg2KUFAw+FKaZEu zJ34CYFFRHrWCgOb7N8njqKTNb9YXJj+uCgoPaawR1gdNVsu7TeX7195sqnItIKG7ry7 lM9v7/freNNnu34q1LrtfMabdo4niohcYOmcawbc2MuNtCbMss+jpDOBPNKdgRKIsiI4 thfMOZ2xdhCZSle5mIyvKoPoHTqKilRQXqkRZlyClAwRx6exs6voTmoizm4YiH5tXuC1 mj4A== 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=ytHg5OZpk+LGLChC69Z1C/7WFDwTbU6ypwmUi8vhWKs=; b=XPhBLE76Nc7K/FO84lATJXL1BkI5f9BQSfS+Ju8E4EYF2PDwJQ9uKGExOYyLHoA+ty PRxM7ir/YhSCC7+S5MO4SSy4z5dmgZnzliSu/ej1s6/IfayMFNrclr4dIBKN22F7w1S8 Ie/3rozRsYV8cCtKMLo4ktSt0cmeAFIBDCtpIq15NBk0ic8n+NsLmxIXVpx6UH8XQRaK JW8zJVLwRtDGctQQ9HDDK8nwUIsxYxaXrU3tc0zhYMoVmR35YL1BSIgP8a8xX7Qt59LL +GP6G5QHnEuTtQBhNY/kK5WdAfRzBCbmgCFURGuA+DNafteGdTsNFmMxOaqrWxdLTfJ4 fkHw== X-Gm-Message-State: AKGB3mLOn+mWoLDg6DxDOkoMRsfaeIW0c7sbY9hovDzWq2OKWadbprQ0 ri5kmSgQsyi1HSrwLWcxIhohvQ== X-Google-Smtp-Source: ACJfBotEwFhkm7sjNvBexrFDA3nmzauKpJVTlXh/OXzUCFYj+RdAgz1Nkljvq5fa36laemlz+J7w2A== X-Received: by 10.28.221.138 with SMTP id u132mr1625343wmg.113.1513164324852; Wed, 13 Dec 2017 03:25:24 -0800 (PST) Received: from bgdev-debian.baylibre.local ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id o22sm3484126wrb.40.2017.12.13.03.25.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Dec 2017 03:25:24 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 2/2] gpiolib: use kstrdup_const() for gpio_device label Date: Wed, 13 Dec 2017 12:25:20 +0100 Message-Id: <20171213112520.7479-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171213112520.7479-1-brgl@bgdev.pl> References: <20171213112520.7479-1-brgl@bgdev.pl> Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Users often pass a pointer to a static string to gpiochip_add_data() family of functions. Avoid unnecessary memory allocations with the provided helper routine. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 56eec094184c..c078f7f35100 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1062,7 +1062,7 @@ static void gpiodevice_release(struct device *dev) list_del(&gdev->list); ida_simple_remove(&gpio_ida, gdev->id); - kfree(gdev->label); + kfree_const(gdev->label); kfree(gdev->descs); kfree(gdev); } @@ -1171,9 +1171,9 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data, } if (chip->label) - gdev->label = kstrdup(chip->label, GFP_KERNEL); + gdev->label = kstrdup_const(chip->label, GFP_KERNEL); else - gdev->label = kstrdup("unknown", GFP_KERNEL); + gdev->label = kstrdup_const("unknown", GFP_KERNEL); if (!gdev->label) { status = -ENOMEM; goto err_free_descs; @@ -1294,7 +1294,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data, list_del(&gdev->list); spin_unlock_irqrestore(&gpio_lock, flags); err_free_label: - kfree(gdev->label); + kfree_const(gdev->label); err_free_descs: kfree(gdev->descs); err_free_gdev: