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: