From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753816AbdLMTop (ORCPT ); Wed, 13 Dec 2017 14:44:45 -0500 Received: from smtprelay0248.hostedemail.com ([216.40.44.248]:56578 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753144AbdLMTom (ORCPT ); Wed, 13 Dec 2017 14:44:42 -0500 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::,RULES_HIT:41:355:379:541:599:966:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1540:1593:1594:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:2828:3138:3139:3140:3141:3142:3352:3622:3865:3866:3867:3868:4321:4385:5007:10004:10400:10848:11026:11232:11658:11914:12043:12296:12438:12740:12760:12895:13069:13311:13357:13439:14659:14721:21080:21451:21627:30012:30036:30046:30054:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: cave85_28d0cead35c1f X-Filterd-Recvd-Size: 1713 Message-ID: <1513194279.27409.37.camel@perches.com> Subject: Re: [PATCH 2/2] gpiolib: use kstrdup_const() for gpio_device label From: Joe Perches To: Bartosz Golaszewski , Linus Walleij Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Date: Wed, 13 Dec 2017 11:44:39 -0800 In-Reply-To: <20171213112520.7479-2-brgl@bgdev.pl> References: <20171213112520.7479-1-brgl@bgdev.pl> <20171213112520.7479-2-brgl@bgdev.pl> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.26.1-1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2017-12-13 at 12:25 +0100, Bartosz Golaszewski wrote: > 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. [] > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c [] > @@ -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); A plain ?: would be more intelligible and a bit smaller object code too. ie: gdev->label = kstrdup_const(chip->label ?: "unknown", GFP_KERNEL); > if (!gdev->label) { > status = -ENOMEM; > goto err_free_descs;