Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3037670pxk; Mon, 28 Sep 2020 06:58:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzshgxpQfD/Q/VDv3qSSFeBBU11AVJDkMEFpGcMIb2B57N01djZwTvzULjszXMnTxTmOou8 X-Received: by 2002:a17:906:2712:: with SMTP id z18mr1842292ejc.380.1601301507948; Mon, 28 Sep 2020 06:58:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601301507; cv=none; d=google.com; s=arc-20160816; b=P2ax1sBDr3/hsOYn0frJEA8NfU2IENMoMTLqQs8qj6ArPjkPZ962iSpg6YX5mdXJ7S k+K+FkAkEpMV8RU6T3JO74zgq4UOkJYbS2oC8FON49qZFKF5LuKzB9CQwN7/QOP0K8FM 5cvuT4IYHHRmf1dgXNsl8DuBFmPrQlJsvd4MULYD8he3IYrPjezHev23020zmQiP6/Pg VCTpi5cXTKm3zOy1GJfUgrNNX+PUueDjSI3EhlgjWx6rh5rZarxsB5c3JCAH0PJlU+eS UT1VnkGjo4NI4PQKiZiClvvP6NQy0pzwOiu/FZ5nqevYfJKVhCbISgyDkYyYnYq74x/s BGZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :ironport-sdr:ironport-sdr; bh=XrMUSP/NakQ+/ueJD1pjHcKbgLAZBtJLmdqbElUX074=; b=e8/l37QiSKax6h4+04AiqHqtnJ1sjdVNiBnrOrxnFsIUG3yHYOpkbdxa8wpPhCaLbR 1rlv18Eu1WW9kQF18TG1VQNGisjw0FIZpQFpJvrW0kR1x0Ynq1GsBKaneIY/qps+aCjL uOy9i/jVppucWPi4/9oTbsMNhWrDChWax6rUhsF3KwznwkZPjhfUlvWegJ0o3JzJMxgk XM2rDpIqPCNTcmnhldYDPPQ1N1e2vMrErEHeqp5OFXDyKpU1MFv+rBWhTWApqKPueQvB m+qvvtBQQVJsjFzCnYYqrCZ9mqTZknI2OUaaeRxVgy8lJ2b2DqxXLtaI5W7P3FsdLaNP RGvg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id df4si647910edb.378.2020.09.28.06.58.04; Mon, 28 Sep 2020 06:58:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726485AbgI1N4v (ORCPT + 99 others); Mon, 28 Sep 2020 09:56:51 -0400 Received: from mga06.intel.com ([134.134.136.31]:24535 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726310AbgI1N4v (ORCPT ); Mon, 28 Sep 2020 09:56:51 -0400 IronPort-SDR: XKp1XTLvDmswJ909bckJVvzFZUdol4q4kSH2USS+vDbNDuJpgaXST6E4gejCKYNL9rQKmxpcla ekZI+vBJ+eQw== X-IronPort-AV: E=McAfee;i="6000,8403,9757"; a="223590127" X-IronPort-AV: E=Sophos;i="5.77,313,1596524400"; d="scan'208";a="223590127" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2020 06:56:50 -0700 IronPort-SDR: OwHsEXA7Z+isGbAHhn3T7zOOgXqwBd6JBx6joDeq/7ffw8gRbF/ivmsnckYJgkGsZm0k5moa4U JoIIUV2Odm4w== X-IronPort-AV: E=Sophos;i="5.77,313,1596524400"; d="scan'208";a="514265573" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2020 06:56:48 -0700 Received: from andy by smile with local (Exim 4.94) (envelope-from ) id 1kMtdz-002Zcy-BC; Mon, 28 Sep 2020 16:56:43 +0300 Date: Mon, 28 Sep 2020 16:56:43 +0300 From: Andy Shevchenko To: Bartosz Golaszewski Cc: Bartosz Golaszewski , Linus Walleij , Jonathan Corbet , Kent Gibson , linux-gpio , linux-doc , LKML Subject: Re: [PATCH v2 1/9] lib: string_helpers: provide kfree_strarray() Message-ID: <20200928135643.GN3956970@smile.fi.intel.com> References: <20200928104155.7385-1-brgl@bgdev.pl> <20200928104155.7385-2-brgl@bgdev.pl> <20200928125539.GI3956970@smile.fi.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 28, 2020 at 03:04:05PM +0200, Bartosz Golaszewski wrote: > On Mon, Sep 28, 2020 at 2:55 PM Andy Shevchenko > wrote: > > > > On Mon, Sep 28, 2020 at 12:41:47PM +0200, Bartosz Golaszewski wrote: > > > From: Bartosz Golaszewski > > > > > > There's a common pattern of dynamically allocating an array of char > > > pointers and then also dynamically allocating each string in this > > > array. Provide a helper for freeing such a string array with one call. > > > > Reviewed-by: Andy Shevchenko > > But see below. > > > > > Signed-off-by: Bartosz Golaszewski > > > --- > > > include/linux/string_helpers.h | 2 ++ > > > lib/string_helpers.c | 25 +++++++++++++++++++++++++ > > > 2 files changed, 27 insertions(+) > > > > > > diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h > > > index 86f150c2a6b6..55b25120a1c6 100644 > > > --- a/include/linux/string_helpers.h > > > +++ b/include/linux/string_helpers.h > > > @@ -94,4 +94,6 @@ char *kstrdup_quotable(const char *src, gfp_t gfp); > > > char *kstrdup_quotable_cmdline(struct task_struct *task, gfp_t gfp); > > > char *kstrdup_quotable_file(struct file *file, gfp_t gfp); > > > > > > +void kfree_strarray(char **str_array, size_t num_str); > > > + > > > #endif > > > diff --git a/lib/string_helpers.c b/lib/string_helpers.c > > > index 963050c0283e..bfa4c9f3ca0a 100644 > > > --- a/lib/string_helpers.c > > > +++ b/lib/string_helpers.c > > > @@ -649,3 +649,28 @@ char *kstrdup_quotable_file(struct file *file, gfp_t gfp) > > > return pathname; > > > } > > > EXPORT_SYMBOL_GPL(kstrdup_quotable_file); > > > + > > > +/** > > > + * kfree_strarray - free a number of dynamically allocated strings contained > > > + * in an array and the array itself > > > + * > > > + * @str_array: Dynamically allocated array of strings to free. If NULL - the > > > + * function does nothing. > > > + * @num_str: Number of strings (starting from the beginning of the array) to > > > + * free. > > > + * > > > + * Passing a non-null str_array and num_str == 0 as well as NULL str_array > > > + * are valid use-cases. > > > + */ > > > +void kfree_strarray(char **str_array, size_t num_str) > > > > Hmm... I have missed your answer to > > str_array -> array > > num_str -> n > > > > The rationale behind dropping str is to avoid duplicates in the name of the > > function and its parameters. 'array' is harder to avoid, but also possible, > > though I leave it to you. > > > > Are you fine with me fixing this when applying the patches? Sure! -- With Best Regards, Andy Shevchenko