linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
To: Christoph Hellwig <hch@infradead.org>,
	Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Andrey Skvortsov <andrej.skvortzov@gmail.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCHv2] mm: do not export const kfree and kstrdup variants
Date: Tue, 24 Sep 2024 21:45:59 +0200	[thread overview]
Message-ID: <67060a27-5830-4ea1-955f-722f1d2c83b4@wanadoo.fr> (raw)
In-Reply-To: <ZvJkC_3cov1rfY0V@infradead.org>

Le 24/09/2024 à 09:02, Christoph Hellwig a écrit :
> On Tue, Sep 24, 2024 at 03:56:53PM +0900, Sergey Senozhatsky wrote:
>> Totally agree with all the points, I haven't looked at how
>> popular that API was before sending out the patch.  Is there
>> some sort of "built time const" but for strings that we, perhaps,
>> can add to kfree_const() (and make kfree_const() always inline)?
>> So that we can turn this
>>
>> 	str = "boom";
>> 	...
>> 	kfree_const(str);
>>
>> into a safe scenario for modules.
> 
> Not sure, but even then the API would be horrible as it still would
> not work for constants in other modules than the one calling it.
> 
> 

So, the best is to audit, at least code that can be built as a module 
for str = "boom" pattern, and fix relevant places?


Or, considering that these these _const() versions are only there to 
save a few bytes of memory, wonder if it really worth it?

In other word:
	1) apply something like the patch below
	2) remove the API


At a minimum, I think that devm_kstrdup_const() could be removed.

CJ


diff --git a/mm/util.c b/mm/util.c
index 4f1275023eb7..fd5e98fb6362 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -39,8 +39,7 @@
   */
  void kfree_const(const void *x)
  {
-       if (!is_kernel_rodata((unsigned long)x))
-               kfree(x);
+       kfree(x);
  }
  EXPORT_SYMBOL(kfree_const);

@@ -81,9 +80,6 @@ EXPORT_SYMBOL(kstrdup);
   */
  const char *kstrdup_const(const char *s, gfp_t gfp)
  {
-       if (is_kernel_rodata((unsigned long)s))
-               return s;
-
         return kstrdup(s, gfp);
  }
  EXPORT_SYMBOL(kstrdup_const);




  reply	other threads:[~2024-09-24 19:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-24  5:08 Sergey Senozhatsky
2024-09-24  6:14 ` Sergey Senozhatsky
2024-09-24  6:43 ` Christoph Hellwig
2024-09-24  6:56   ` Sergey Senozhatsky
2024-09-24  7:02     ` Christoph Hellwig
2024-09-24 19:45       ` Christophe JAILLET [this message]
2024-09-24 17:41 ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=67060a27-5830-4ea1-955f-722f1d2c83b4@wanadoo.fr \
    --to=christophe.jaillet@wanadoo.fr \
    --cc=akpm@linux-foundation.org \
    --cc=andrej.skvortzov@gmail.com \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=senozhatsky@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox