Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4820094iob; Mon, 9 May 2022 02:21:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzM3HYUjjJ8Po4VZf1e0WuBAnn0UObadAyRa9tx0mUEW4eX0aErij5tRo4A1t6HfGrEgMBv X-Received: by 2002:a05:6a00:15c7:b0:510:48c9:f302 with SMTP id o7-20020a056a0015c700b0051048c9f302mr15226933pfu.23.1652088069054; Mon, 09 May 2022 02:21:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652088069; cv=none; d=google.com; s=arc-20160816; b=Saf3/3Wwfg21zEsZOteFATzM39MSR3UGyecbIv+O9R83fTKcMvSSwnlInnzA7dmXFR /hnYGkc85sFZqY7p3EoNAXPwxuHCibcmwE8Xxz8Q42EcIZgM0RG8XsiHbb5AT0lmItmw mHcNbfimY2jfaQhxEz6Y1QonE0dfKcNWb0TAAGKKDe41o80eGCzEIKbS3/nZ59H/V2w6 KC237sxgVb0jt7+QzHuJop8LgxCL6lFl1fBLKKhkwO9M4lfcUJZYN273NKOozTqZdhMe tPh+lUpDFWBDM8cqw+rMb9INzfk45A69e0W2hs+E1rm4ijZBcI4WmUG6x2UkskCGvGHf Rzwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=kmTZemi9FrrCEp2cm2hekEVoH6WOAmpPAOzY1HjnMhY=; b=cqgwbU22zxa34Sif/Ir9/j6PmL6xGRmCpzQwqdReya8XcxMG+Fm62J05wW2+bFuiiu Lw2vNmEUFqCQvrkAzBnDmxy5Q9b4gv8H9Iyey1lGX9A/ZGoYL9gUvFNWwjHdjVur46jg GsvdtV/ZmxzF8gkbzZMyuumq2qSrKwtd/zgFPeaiQja2Pt/AX47uQoa3ZXzFkP/0KfQR OvBG1ySIHRNGsVc+PU68iPeLxtwBWJHG41j4/nemdTnJUCUAMqXjnici8dBK1VrArijN mXRwcaCuLeaYJOSXMEQzYdQ0RWbFZW0GKIszJWv5WlhaW7/dSyA87RRp1a8tFh6DJ8mU XERA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AIjyiK3L; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id x190-20020a6386c7000000b003aaf5a2aa07si12668305pgd.502.2022.05.09.02.21.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 02:21:09 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AIjyiK3L; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 18376201C26; Mon, 9 May 2022 02:09:14 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441952AbiEFOGT (ORCPT + 99 others); Fri, 6 May 2022 10:06:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349347AbiEFOGR (ORCPT ); Fri, 6 May 2022 10:06:17 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E37B541AC for ; Fri, 6 May 2022 07:02:34 -0700 (PDT) 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 ams.source.kernel.org (Postfix) with ESMTPS id 27532B835D5 for ; Fri, 6 May 2022 14:02:33 +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-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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