From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751179AbdBAXaL (ORCPT ); Wed, 1 Feb 2017 18:30:11 -0500 Received: from smtprelay0119.hostedemail.com ([216.40.44.119]:55085 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750890AbdBAXaJ (ORCPT ); Wed, 1 Feb 2017 18:30:09 -0500 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::,RULES_HIT:41:355:379:541:599:960:966:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:2693:2828:3138:3139:3140:3141:3142:3354:3622:3865:3871:3874:4321:4385:4605:5007:6119:10004:10400:10848:11026:11232:11473:11658:11914:12043:12296:12438:12740:12760:12895:13439:14181:14659:14721:21080:30029:30054:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:2,LUA_SUMMARY:none X-HE-Tag: birth65_752a106598c21 X-Filterd-Recvd-Size: 3181 Message-ID: <1485991803.22276.14.camel@perches.com> Subject: Re: [PATCH v3 3/4] driver property: constify property arrays values From: Joe Perches To: Dmitry Torokhov , "Rafael J. Wysocki" Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, Andy Shevchenko , Mika Westerberg , Hans de Goede , Wolfram Sang Date: Wed, 01 Feb 2017 15:30:03 -0800 In-Reply-To: <20170201173125.40354-4-dmitry.torokhov@gmail.com> References: <20170201173125.40354-1-dmitry.torokhov@gmail.com> <20170201173125.40354-4-dmitry.torokhov@gmail.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.22.3-0ubuntu0.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-02-01 at 09:31 -0800, Dmitry Torokhov wrote: > Data that is fed into property arrays should not be modified, so let's mark > relevant pointers as const. This will allow us making source arrays as > const/__initconst. trivia: > diff --git a/drivers/base/property.c b/drivers/base/property.c [] > @@ -682,44 +682,66 @@ int fwnode_property_match_string(struct fwnode_handle *fwnode, > } > EXPORT_SYMBOL_GPL(fwnode_property_match_string); > > +static int property_copy_string_array(struct property_entry *dst, > + const struct property_entry *src) > +{ > + char **d; > + size_t nval = src->length / sizeof(*d); > + size_t i; > + > + d = kcalloc(nval, sizeof(*d), GFP_KERNEL); > + if (!d) > + return -ENOMEM; > + > + for (i = 0; i < nval; i++) { > + d[i] = kstrdup(src->pointer.str[i], GFP_KERNEL); > + if (!d[i] && src->pointer.str[i]) { > + while (--i >= 0) > + kfree(d[i]); > + kfree(d); > + return -ENOMEM; > + } > + } > + > + dst->pointer.str = (void *)d; > + return 0; > +} > + > static int property_entry_copy(struct property_entry *dst, > const struct property_entry *src) > { > - const char **d, **s; > - size_t i, nval; > + int error; > > dst->name = kstrdup(src->name, GFP_KERNEL); > if (!dst->name) > return -ENOMEM; > > if (src->is_array) { > - if (!src->length) > - return -ENODATA; > + if (!src->length) { > + error = -ENODATA; > + goto out_free_name; > + } > > if (src->is_string) { > - nval = src->length / sizeof(const char *); > - dst->pointer.str = kcalloc(nval, sizeof(const char *), > - GFP_KERNEL); > - if (!dst->pointer.str) > - return -ENOMEM; > - > - d = dst->pointer.str; > - s = src->pointer.str; > - for (i = 0; i < nval; i++) { > - d[i] = kstrdup(s[i], GFP_KERNEL); > - if (!d[i] && s[i]) > - return -ENOMEM; > + error = property_copy_string_array(dst, src); > + if (error) { > + error = -ENOMEM; An unnecessary set as the return from the above property_copy_string_array is either 0 or -ENOMEM