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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B00E2C433F5 for ; Fri, 6 May 2022 14:02:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 07BF06B0072; Fri, 6 May 2022 10:02:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 003676B0073; Fri, 6 May 2022 10:02:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE6EE6B0074; Fri, 6 May 2022 10:02:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id CBBAE6B0072 for ; Fri, 6 May 2022 10:02:37 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 8449C21571 for ; Fri, 6 May 2022 14:02:37 +0000 (UTC) X-FDA: 79435483554.05.9752C7B Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf13.hostedemail.com (Postfix) with ESMTP id 1A0EB200DC for ; Fri, 6 May 2022 14:02:19 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5D9CD620D8; Fri, 6 May 2022 14:02:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FB84C385A9; Fri, 6 May 2022 14:02:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1651845751; bh=ufq3bjZ09clzli8bz1S9ydGwiX1f3vkPaLVKdGK2X38=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=AIjyiK3LJEYMh9u5riG/w+6W71FZWhm9GwiLzD/PqHGj7+n4YWf2Zt2LwxlR7nZrZ dJyKt4cp0+BXZX7LnpYIEYoEUm6BZYuoUwla82J0ffo08XoLcyln0C8TSgu+p3Uhlf NNIHVq9JXan2diQ7g4s2arh2usiYD2k0RZIAF92U= Date: Fri, 6 May 2022 16:02:28 +0200 From: Greg KH To: Jagdish Gediya Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, rafael@kernel.org, akpm@linux-foundation.org, keescook@chromium.org, andriy.shevchenko@linux.intel.com, geert@linux-m68k.org, linux@roeck-us.net, adobriyan@gmail.com Subject: Re: [PATCH] kobject: Refactor kobject_set_name_vargs() Message-ID: References: <20220506133309.36794-1-jvgediya@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220506133309.36794-1-jvgediya@linux.ibm.com> X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 1A0EB200DC X-Stat-Signature: eka8jsdo5jjzt48dhfxgz6jk5hjen3ug X-Rspam-User: Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=AIjyiK3L; spf=pass (imf13.hostedemail.com: domain of gregkh@linuxfoundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org; dmarc=pass (policy=none) header.from=linuxfoundation.org X-HE-Tag: 1651845739-880985 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, May 06, 2022 at 07:03:09PM +0530, Jagdish Gediya wrote: > Setting name as per the format is not only useful for kobjects. > It can also be used to set name for other things for e.g. setting > the name of the struct attribute when multiple same kind of attributes > need to be created with some identifier in name, instead of managing > memory for names at such places case by case, it would be good if > something like current kobject_set_name_vargs() can be utilized. > > Refactor kobject_set_name_vargs(), Create a new generic function > set_name_vargs() which can be used for kobjects as well as at > other places. > > This patch doesn't introduce any functionality change. > > Signed-off-by: Jagdish Gediya > --- > include/linux/string.h | 1 + > lib/kobject.c | 30 +----------------------------- > mm/util.c | 40 ++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 42 insertions(+), 29 deletions(-) > > diff --git a/include/linux/string.h b/include/linux/string.h > index b6572aeca2f5..f329962e5ae9 100644 > --- a/include/linux/string.h > +++ b/include/linux/string.h > @@ -9,6 +9,7 @@ > #include > #include > > +int set_name_vargs(const char **name, const char *fmt, va_list vargs); > extern char *strndup_user(const char __user *, long); > extern void *memdup_user(const void __user *, size_t); > extern void *vmemdup_user(const void __user *, size_t); > diff --git a/lib/kobject.c b/lib/kobject.c > index 5f0e71ab292c..870d05971e3a 100644 > --- a/lib/kobject.c > +++ b/lib/kobject.c > @@ -249,35 +249,7 @@ static int kobject_add_internal(struct kobject *kobj) > int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, > va_list vargs) > { > - const char *s; > - > - if (kobj->name && !fmt) > - return 0; > - > - s = kvasprintf_const(GFP_KERNEL, fmt, vargs); > - if (!s) > - return -ENOMEM; > - > - /* > - * ewww... some of these buggers have '/' in the name ... If > - * that's the case, we need to make sure we have an actual > - * allocated copy to modify, since kvasprintf_const may have > - * returned something from .rodata. > - */ > - if (strchr(s, '/')) { > - char *t; > - > - t = kstrdup(s, GFP_KERNEL); > - kfree_const(s); > - if (!t) > - return -ENOMEM; > - strreplace(t, '/', '!'); > - s = t; > - } > - kfree_const(kobj->name); > - kobj->name = s; > - > - return 0; > + return set_name_vargs(&kobj->name, fmt, vargs); > } > > /** > diff --git a/mm/util.c b/mm/util.c > index 54e5e761a9a9..808d29b17ea7 100644 > --- a/mm/util.c > +++ b/mm/util.c > @@ -112,6 +112,46 @@ char *kstrndup(const char *s, size_t max, gfp_t gfp) > } > EXPORT_SYMBOL(kstrndup); > > +/** > + * set_name_vargs() - Set the name as per format > + * @name: pointer to point to the name as per format > + * @fmt: format string used to build the name > + * @vargs: vargs to format the string. > + */ > +int set_name_vargs(const char **name, const char *fmt, va_list vargs) Why is this a mm/ thing and not a lib/ thing? And who else will be needing to use this? Why the churn for no actual users? > +{ > + const char *s; > + > + if (*name && !fmt) > + return 0; > + > + s = kvasprintf_const(GFP_KERNEL, fmt, vargs); > + if (!s) > + return -ENOMEM; > + > + /* > + * ewww... some of these buggers have '/' in the name ... If > + * that's the case, we need to make sure we have an actual > + * allocated copy to modify, since kvasprintf_const may have > + * returned something from .rodata. > + */ > + if (strchr(s, '/')) { > + char *t; > + > + t = kstrdup(s, GFP_KERNEL); > + kfree_const(s); > + if (!t) > + return -ENOMEM; > + strreplace(t, '/', '!'); > + s = t; > + } > + kfree_const(*name); > + *name = s; > + > + return 0; > +} > +EXPORT_SYMBOL(set_name_vargs); No need to export this as there are no users in modules. And if there was, shouldn't it be EXPORT_SYMBOL_GPL() as that's what the kobject functions are exported as (most of them at least.) But again, why is this needed at all? thanks, greg k-h