From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DEA66C4332F for ; Sat, 6 Nov 2021 07:35:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B8C176120D for ; Sat, 6 Nov 2021 07:35:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233634AbhKFHhk (ORCPT ); Sat, 6 Nov 2021 03:37:40 -0400 Received: from smtprelay0121.hostedemail.com ([216.40.44.121]:33614 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232099AbhKFHhi (ORCPT ); Sat, 6 Nov 2021 03:37:38 -0400 Received: from omf20.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay07.hostedemail.com (Postfix) with ESMTP id CD4F7181D2090; Sat, 6 Nov 2021 07:34:56 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf20.hostedemail.com (Postfix) with ESMTPA id EE66118A5F8; Sat, 6 Nov 2021 07:34:52 +0000 (UTC) Message-ID: <6f27043dc7c50a7447b8fdcb6126f4c67a5936a5.camel@perches.com> Subject: Re: [PATCH v1 01/19] lib/string_helpers: Introduce kasprintf_strarray() From: Joe Perches To: Andy Shevchenko , Bartosz Golaszewski , Jianqun Xu , Linus Walleij , Sai Krishna Potthuri , Andrew Morton , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org Cc: Bamvor Jian Zhang , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Heiko Stuebner , Patrice Chotard , Michal Simek , Andy Shevchenko Date: Sat, 06 Nov 2021 00:34:51 -0700 In-Reply-To: <20211105124242.27288-1-andriy.shevchenko@linux.intel.com> References: <20211105124242.27288-1-andriy.shevchenko@linux.intel.com> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.40.4-1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Stat-Signature: 1ifh16fok5zodoyg17ub7y551gue9gq8 X-Rspamd-Server: rspamout03 X-Rspamd-Queue-Id: EE66118A5F8 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX1/zHRdlX+53TMDzXto5pNOnstJ0U8Gbcpk= X-HE-Tag: 1636184092-287531 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org On Fri, 2021-11-05 at 14:42 +0200, Andy Shevchenko wrote: > We have a few users already that basically want to have array of > sequential strings to be allocated and filled. > > Provide a helper for them (basically adjusted version from gpio-mockup.c). I think this is overkill and unnecessary bloat for the number of actual or possible in-tree uses. The devm_ variant too. And it'd be useful to have an 0/n patch cover letter describing why the patchset is useful so I could reply to that instead of the 1/n. > diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h [] > @@ -100,6 +100,7 @@ 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); > > +char **kasprintf_strarray(gfp_t gfp, const char *prefix, size_t n); > void kfree_strarray(char **array, size_t n); > > #endif > diff --git a/lib/string_helpers.c b/lib/string_helpers.c [] > @@ -674,6 +674,39 @@ char *kstrdup_quotable_file(struct file *file, gfp_t gfp) > } > EXPORT_SYMBOL_GPL(kstrdup_quotable_file); > > +/** > + * kasprintf_strarray - allocate and fill array of sequential strings > + * @gfp: flags for the slab allocator > + * @prefix: prefix to be used > + * @n: amount of lines to be allocated and filled > + * > + * Allocates and fills @n strings using pattern "%s-%zu", where prefix > + * is provided by caller. The caller is responsible to free them with > + * kfree_strarray() after use. > + * > + * Returns array of strings or NULL when memory can't be allocated. > + */ > +char **kasprintf_strarray(gfp_t gfp, const char *prefix, size_t n) > +{ > + char **names; > + size_t i; > + > + names = kcalloc(n + 1, sizeof(char *), gfp); > + if (!names) > + return NULL; > + > + for (i = 0; i < n; i++) { > + names[i] = kasprintf(gfp, "%s-%zu", prefix, i); > + if (!names[i]) { > + kfree_strarray(names, i); > + return NULL; > + } > + } > + > + return names; > +} > +EXPORT_SYMBOL_GPL(kasprintf_strarray); > + > /** > * kfree_strarray - free a number of dynamically allocated strings contained > * in an array and the array itself From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67D3EC433EF for ; Sat, 6 Nov 2021 07:35:17 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1F7A0611CE for ; Sat, 6 Nov 2021 07:35:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1F7A0611CE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=perches.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Date:Cc:To:From:Subject:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=fvmPRBk2VbGRV7WGMa3A8FXrxWajBn3mQCRfrDTwWQY=; b=gXiGkZE8klv2lL GznaUiCNRHRGhfUkgRv2+SR/r52tZKC9vCoph67pfROPSV5Tkxw761ModMqUZdZNfy4wUEFFkboEd T1JMEG2IzbgHOOKylRGoqtXY0pgpdz9YRd5xNz8N6STcMh0Hf5LQQAj15Biy5eteKfNDrZX0DWsln 1PZZFcYIYxOr9tQQXd00f3iW4JO/ZqV5L79cpwzBDq43bDLEz51B2HDFH/9JI7qvjfW17b8ZNOU8W 7tclsk46cg5lUKT2wI1AXH2Q7UfnpKIh5LPdeEGva3EPpARsPtREyVSnOPgUPzEC870ULnWtRyKAq dWTpK/o9YNnx+PVJ1GgQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mjGEL-00CkI0-6R; Sat, 06 Nov 2021 07:35:13 +0000 Received: from smtprelay0123.hostedemail.com ([216.40.44.123] helo=smtprelay.hostedemail.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mjGE9-00CkGg-6J; Sat, 06 Nov 2021 07:35:02 +0000 Received: from omf20.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay07.hostedemail.com (Postfix) with ESMTP id CD4F7181D2090; Sat, 6 Nov 2021 07:34:56 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf20.hostedemail.com (Postfix) with ESMTPA id EE66118A5F8; Sat, 6 Nov 2021 07:34:52 +0000 (UTC) Message-ID: <6f27043dc7c50a7447b8fdcb6126f4c67a5936a5.camel@perches.com> Subject: Re: [PATCH v1 01/19] lib/string_helpers: Introduce kasprintf_strarray() From: Joe Perches To: Andy Shevchenko , Bartosz Golaszewski , Jianqun Xu , Linus Walleij , Sai Krishna Potthuri , Andrew Morton , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org Cc: Bamvor Jian Zhang , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Heiko Stuebner , Patrice Chotard , Michal Simek , Andy Shevchenko Date: Sat, 06 Nov 2021 00:34:51 -0700 In-Reply-To: <20211105124242.27288-1-andriy.shevchenko@linux.intel.com> References: <20211105124242.27288-1-andriy.shevchenko@linux.intel.com> User-Agent: Evolution 3.40.4-1 MIME-Version: 1.0 X-Stat-Signature: 1ifh16fok5zodoyg17ub7y551gue9gq8 X-Rspamd-Server: rspamout03 X-Rspamd-Queue-Id: EE66118A5F8 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX1/zHRdlX+53TMDzXto5pNOnstJ0U8Gbcpk= X-HE-Tag: 1636184092-287531 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211106_003501_349660_93B3571A X-CRM114-Status: GOOD ( 19.23 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org On Fri, 2021-11-05 at 14:42 +0200, Andy Shevchenko wrote: > We have a few users already that basically want to have array of > sequential strings to be allocated and filled. > > Provide a helper for them (basically adjusted version from gpio-mockup.c). I think this is overkill and unnecessary bloat for the number of actual or possible in-tree uses. The devm_ variant too. And it'd be useful to have an 0/n patch cover letter describing why the patchset is useful so I could reply to that instead of the 1/n. > diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h [] > @@ -100,6 +100,7 @@ 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); > > +char **kasprintf_strarray(gfp_t gfp, const char *prefix, size_t n); > void kfree_strarray(char **array, size_t n); > > #endif > diff --git a/lib/string_helpers.c b/lib/string_helpers.c [] > @@ -674,6 +674,39 @@ char *kstrdup_quotable_file(struct file *file, gfp_t gfp) > } > EXPORT_SYMBOL_GPL(kstrdup_quotable_file); > > +/** > + * kasprintf_strarray - allocate and fill array of sequential strings > + * @gfp: flags for the slab allocator > + * @prefix: prefix to be used > + * @n: amount of lines to be allocated and filled > + * > + * Allocates and fills @n strings using pattern "%s-%zu", where prefix > + * is provided by caller. The caller is responsible to free them with > + * kfree_strarray() after use. > + * > + * Returns array of strings or NULL when memory can't be allocated. > + */ > +char **kasprintf_strarray(gfp_t gfp, const char *prefix, size_t n) > +{ > + char **names; > + size_t i; > + > + names = kcalloc(n + 1, sizeof(char *), gfp); > + if (!names) > + return NULL; > + > + for (i = 0; i < n; i++) { > + names[i] = kasprintf(gfp, "%s-%zu", prefix, i); > + if (!names[i]) { > + kfree_strarray(names, i); > + return NULL; > + } > + } > + > + return names; > +} > +EXPORT_SYMBOL_GPL(kasprintf_strarray); > + > /** > * kfree_strarray - free a number of dynamically allocated strings contained > * in an array and the array itself _______________________________________________ Linux-rockchip mailing list Linux-rockchip@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-rockchip From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2FF5EC433F5 for ; Sat, 6 Nov 2021 07:36:21 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DC5E6611CE for ; Sat, 6 Nov 2021 07:36:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org DC5E6611CE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=perches.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Date:Cc:To:From:Subject:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=VwJCb+3xOe0mnKjQbJJlsRAK40CyosplwiY1iUfAjog=; b=JvDU8KTq8EQsTW 0fQpoft5UNVrLBeDVGCXAFus653vmfB85FWwn1EdM8lGv/aCyWMqzjTtAs+Px/jvJeVhvDLzymk5g yCCBYlmpqN9Wkx5rTuqVjPJMtR4rGAOjI3eki+4bybMDfZQXF/6cYKwdcDR2w2NVnODisaxCb4V1U 4osyP3Ydhzdk0tgMfBUXS0OErwj22j9ljCk1vbQXV75pnJx7WCwnLL4a7FCjja5JpLMdqLst4mHSn ZblI48C6n0FjyCRQgX9tjpAdjgdt8QC9qOww6iAmuvOqZkG5NKqAOW2RP0+9WbOju0rIYA4NceyI0 YAjaXIV8FMphN8QSmeRQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mjGEC-00CkHU-FA; Sat, 06 Nov 2021 07:35:04 +0000 Received: from smtprelay0123.hostedemail.com ([216.40.44.123] helo=smtprelay.hostedemail.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mjGE9-00CkGg-6J; Sat, 06 Nov 2021 07:35:02 +0000 Received: from omf20.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay07.hostedemail.com (Postfix) with ESMTP id CD4F7181D2090; Sat, 6 Nov 2021 07:34:56 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf20.hostedemail.com (Postfix) with ESMTPA id EE66118A5F8; Sat, 6 Nov 2021 07:34:52 +0000 (UTC) Message-ID: <6f27043dc7c50a7447b8fdcb6126f4c67a5936a5.camel@perches.com> Subject: Re: [PATCH v1 01/19] lib/string_helpers: Introduce kasprintf_strarray() From: Joe Perches To: Andy Shevchenko , Bartosz Golaszewski , Jianqun Xu , Linus Walleij , Sai Krishna Potthuri , Andrew Morton , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org Cc: Bamvor Jian Zhang , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Heiko Stuebner , Patrice Chotard , Michal Simek , Andy Shevchenko Date: Sat, 06 Nov 2021 00:34:51 -0700 In-Reply-To: <20211105124242.27288-1-andriy.shevchenko@linux.intel.com> References: <20211105124242.27288-1-andriy.shevchenko@linux.intel.com> User-Agent: Evolution 3.40.4-1 MIME-Version: 1.0 X-Stat-Signature: 1ifh16fok5zodoyg17ub7y551gue9gq8 X-Rspamd-Server: rspamout03 X-Rspamd-Queue-Id: EE66118A5F8 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX1/zHRdlX+53TMDzXto5pNOnstJ0U8Gbcpk= X-HE-Tag: 1636184092-287531 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211106_003501_349660_93B3571A X-CRM114-Status: GOOD ( 19.23 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, 2021-11-05 at 14:42 +0200, Andy Shevchenko wrote: > We have a few users already that basically want to have array of > sequential strings to be allocated and filled. > > Provide a helper for them (basically adjusted version from gpio-mockup.c). I think this is overkill and unnecessary bloat for the number of actual or possible in-tree uses. The devm_ variant too. And it'd be useful to have an 0/n patch cover letter describing why the patchset is useful so I could reply to that instead of the 1/n. > diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h [] > @@ -100,6 +100,7 @@ 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); > > +char **kasprintf_strarray(gfp_t gfp, const char *prefix, size_t n); > void kfree_strarray(char **array, size_t n); > > #endif > diff --git a/lib/string_helpers.c b/lib/string_helpers.c [] > @@ -674,6 +674,39 @@ char *kstrdup_quotable_file(struct file *file, gfp_t gfp) > } > EXPORT_SYMBOL_GPL(kstrdup_quotable_file); > > +/** > + * kasprintf_strarray - allocate and fill array of sequential strings > + * @gfp: flags for the slab allocator > + * @prefix: prefix to be used > + * @n: amount of lines to be allocated and filled > + * > + * Allocates and fills @n strings using pattern "%s-%zu", where prefix > + * is provided by caller. The caller is responsible to free them with > + * kfree_strarray() after use. > + * > + * Returns array of strings or NULL when memory can't be allocated. > + */ > +char **kasprintf_strarray(gfp_t gfp, const char *prefix, size_t n) > +{ > + char **names; > + size_t i; > + > + names = kcalloc(n + 1, sizeof(char *), gfp); > + if (!names) > + return NULL; > + > + for (i = 0; i < n; i++) { > + names[i] = kasprintf(gfp, "%s-%zu", prefix, i); > + if (!names[i]) { > + kfree_strarray(names, i); > + return NULL; > + } > + } > + > + return names; > +} > +EXPORT_SYMBOL_GPL(kasprintf_strarray); > + > /** > * kfree_strarray - free a number of dynamically allocated strings contained > * in an array and the array itself _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel