From patchwork Thu Dec 14 14:29:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 848582 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="Nfb1BSpf"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yyGDK2hjXz9sCZ for ; Fri, 15 Dec 2017 01:29:53 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752640AbdLNO3w (ORCPT ); Thu, 14 Dec 2017 09:29:52 -0500 Received: from mail-wr0-f195.google.com ([209.85.128.195]:42598 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752355AbdLNO32 (ORCPT ); Thu, 14 Dec 2017 09:29:28 -0500 Received: by mail-wr0-f195.google.com with SMTP id s66so5303407wrc.9 for ; Thu, 14 Dec 2017 06:29:27 -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=UD2gqKsYoYi5LSM6a7B5inHWnp+AlbvC7FsVXZ8ztws=; b=Nfb1BSpf7HtRjdExWT+RteAaG4kpvmMvktz9GHcaySq8Wz0cSz5wV3Jbf9RjLOpC6o t7XsM612e5nWsdqjtwevDge2fzwHn+JxqVzOSsDJ40OyJf+f5k6ooTcxfGAgflksZeti Rfhy03tWSfitU9pyhNxQzRmvnsUFFdeK2136SDV3RmqASZVw6Imyc0Ww5snxwFs7eS4U Navv23x9H/msSGQns7e9vtGKHTJq1M2EOaUJOWYZIbN5UaphAiZqLgThZXCeV+ZQ2NX3 g+c1m7fFHlfpdn66tK5PjgsmYG3nuPmpktqc41RG5VPMZQOxsAtqG/2PYmNY+dJrXzZd Fhkg== 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=UD2gqKsYoYi5LSM6a7B5inHWnp+AlbvC7FsVXZ8ztws=; b=SipHS7N8Hj4CTKol+4m0GYtVuImSLOhAc5bkF3I6IA7HCztyKTiZ8Y3x4TV/7czOYA 6qMwJJpqb3DMVVr6HDJ06dL79ZqjZUptpjt8dAZr7IHUgoPPySo9VhZWf3kUTxWAZiba iMj3c0rLgxU8r02ucBTm/wH0x2fI3FZgn7ErBZp9lgF/6d27KkWUQhqa9i+CUHgUorPY elPSWpgyf+ukpGaypIjGQIxTpk5JTa9h4NDzMQ57l76RIp/mY/Qpm+otB4B++Lea+csn X13aXsKYyKEHiz65gPqia/KaHYVMfbVocDF9NM+xwcK57YwVaKHLW5Qpqd4IUk5jRlAq 0y8w== X-Gm-Message-State: AKGB3mKZv3QSrPkV8lbBjsDhFxSoZy9VBuurA9fHLDAI2B5mLiNC6fvm KrYVFN780y0NGsfext1H6vdhk99+uIQMxg== X-Google-Smtp-Source: ACJfBos8bvlIbbFMyiFbS1Uj7zB2aNC5fTSnX5rl8eUzViFzePl7zgJFsc64aQ8b5TsGxp3P/JatCQ== X-Received: by 10.223.152.1 with SMTP id v1mr6803224wrb.234.1513261767218; Thu, 14 Dec 2017 06:29:27 -0800 (PST) Received: from localhost.localdomain (smb-orycl-01.wifihubtelecom.net. [213.174.123.193]) by smtp.gmail.com with ESMTPSA id 88sm1485109wrf.20.2017.12.14.06.29.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Dec 2017 06:29:26 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Joe Perches Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 1/2] gpiolib: constify label in gpio_device Date: Thu, 14 Dec 2017 15:29:19 +0100 Message-Id: <20171214142920.32683-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171214142920.32683-1-brgl@bgdev.pl> References: <20171214142920.32683-1-brgl@bgdev.pl> Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org This string is never modified. Make it const. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 5e1f7cc6eeb6..6e9228b94437 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -58,7 +58,7 @@ struct gpio_device { struct gpio_desc *descs; int base; u16 ngpio; - char *label; + const char *label; void *data; struct list_head list; From patchwork Thu Dec 14 14:29: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: 848581 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="sBSpKaJi"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yyGDD6hbwz9sCZ for ; Fri, 15 Dec 2017 01:29:48 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752955AbdLNO3d (ORCPT ); Thu, 14 Dec 2017 09:29:33 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:46791 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752910AbdLNO33 (ORCPT ); Thu, 14 Dec 2017 09:29:29 -0500 Received: by mail-wr0-f193.google.com with SMTP id x49so5293754wrb.13 for ; Thu, 14 Dec 2017 06:29:29 -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=5i0amokMFsSygD7qFDguoG4szCSFuXp29aRHNTCDX/g=; b=sBSpKaJigapu0uR4zkQ9iok0XeBUuMPINgmTpPQ3dsfFU2MZ/BhGxkEapaLA8bhzXk zA9d2UyKdXFSfKSDO6zZyIXJSv7rk793dFLEtVy+I2X1iJcmCOTbxpj5fCRs1hLz29ad Na3Kn2O/D3k0iGjj17DBIiei2unxSgT+/URJixM8H3IyKSvnvrkzRusWrTmVUpKP40Yn OeLuuUr/CKZ6Kb5VeUNvM/8x4dfBOavHJJ0KGsS9GCnT66T1QamuERY+NsMfNm1JpnHY BUlJDD0jmMj8BR6bTPt+1cXaqsub08ORKbA0XppAUR2D3dN06uMSXrSx+/R6e09qOFaD Gutw== 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=5i0amokMFsSygD7qFDguoG4szCSFuXp29aRHNTCDX/g=; b=VgYODPIMYXExQn14RGaOfghKKIZjdVi5wHpdb2lHEuDWV+4NNF80G8MbS6E/sFc3BD 0ODgdpv58JS5vkfJpeOQQtfONQqz8n4FOlsKcu854dIh5WFknT9rKsVAd/Ebsysfn+h+ 8DVoBgpovN4axLrda5vK+FPouTWO+coxzQN05AQ9dE/1cP0eyL4+84EOX9Xz/iXxG2WQ /Wl/vBavdD4C8sG+chrg+86nl4nYaVGW9+rkMA3NlItJ8puSFUQNQf1qRcaAg0RW5mbM dzasEOCZWUjlRevmILYxk1OvaGFwgPKyg3hIMz2oGxkl5yAkIHZa+dbn6gCOVWW99pio BcqA== X-Gm-Message-State: AKGB3mLG3MoG0KYLKbaKa6vtuaUJS6GziKWzDrop7xEuu+hzVaRTBw5A VPi/LVxa6aNYZmfUBAgHb/VKwA== X-Google-Smtp-Source: ACJfBouCv8T1+Ihy/L7mkwdj40XVnxcP3+3by0wTVk0UG16x+IIRcglfcuwqkLzRwCKrkX4ORFfC9g== X-Received: by 10.223.201.139 with SMTP id f11mr4036273wrh.283.1513261768615; Thu, 14 Dec 2017 06:29:28 -0800 (PST) Received: from localhost.localdomain (smb-orycl-01.wifihubtelecom.net. [213.174.123.193]) by smtp.gmail.com with ESMTPSA id 88sm1485109wrf.20.2017.12.14.06.29.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Dec 2017 06:29:27 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Joe Perches Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 2/2] gpiolib: use kstrdup_const() for gpio_device label Date: Thu, 14 Dec 2017 15:29:20 +0100 Message-Id: <20171214142920.32683-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171214142920.32683-1-brgl@bgdev.pl> References: <20171214142920.32683-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. While at it: use a ternary operator instead of an if else for brevity. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 56eec094184c..e9ec44ffaaaf 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); } @@ -1170,10 +1170,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data, goto err_free_descs; } - if (chip->label) - gdev->label = kstrdup(chip->label, GFP_KERNEL); - else - gdev->label = kstrdup("unknown", GFP_KERNEL); + gdev->label = kstrdup_const(chip->label ?: "unknown", GFP_KERNEL); if (!gdev->label) { status = -ENOMEM; goto err_free_descs; @@ -1294,7 +1291,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: