linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Max Kellermann <max.kellermann@ionos.com>
To: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	david@redhat.com, Liam.Howlett@oracle.com,  vbabka@suse.cz,
	rppt@kernel.org, surenb@google.com, mhocko@suse.com,
	 linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm: add `const` to lots of pointer parameters
Date: Thu, 28 Aug 2025 14:16:42 +0200	[thread overview]
Message-ID: <CAKPOu+-0zuz-t22RmENiAT7SXTMyRVeHgkCrnLK-Xt-DDxHykQ@mail.gmail.com> (raw)
In-Reply-To: <74a33635-3348-4e70-8cdb-16307f839b79@lucifer.local>

On Thu, Aug 28, 2025 at 2:09 PM Lorenzo Stoakes
<lorenzo.stoakes@oracle.com> wrote:

> > I'd actually be in favor of making all incoming args const (C should
> > have made this the default).
> >
> > Because modifying an incoming arg is just obnoxious.  That value should
> > be viewed as part of the calling environment and should not be altered.
> >
> > Try modifying a lengthy function and wanting to get at an incoming arg
> > only to find that something in the preceding 100 lines has gone and
> > messed with it.  Or forget to check fr this and get a nasty surprise when
> > testing.
> >
> > Not that I'm suggesting that someone go in and make this change.
> >
> > On the other hand, it would be neat if gcc had an option to warn when
> > someone does this.  I bet it would be simple to add.
>
> This would break half the world, I've tried making parameters const, then
> finding basically every helper function doesn't function correctly with it
> + having to give up without needing to change half the code base.

Are you guys talking about making parameter values const (i.e. pointer
addresses if the parameter is a pointer) or making pointed-to values
const?
It seemed Andrew meant the former, but my patch was about the latter.

Yes, making parameters (not pointed-to values) const by default would
be a good default, but we're 50 years late for that, and
unfortunately, C's syntax for pointers with constant address is
awkwardly confusing. But adding "const" to parameter (values, not
pointed-to) should not break anything (unless the function really
changes parameter values - there may be good or bad reasons to do
that).

Making more pointed-to values const will break a lot, yes, because
this needs const-correctness in the whole callee space. This patch
here tries to do this for a low-level part of the kernel, to enable it
in higher-level parts. Long way to go.

Max


  reply	other threads:[~2025-08-28 12:16 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-27 19:22 Max Kellermann
2025-08-27 21:48 ` Andrew Morton
2025-08-28  1:48   ` Liam R. Howlett
2025-08-28  2:47     ` Andrew Morton
2025-08-28 12:09   ` Lorenzo Stoakes
2025-08-28 12:16     ` Max Kellermann [this message]
2025-08-28 12:35       ` Lorenzo Stoakes
2025-08-28 12:42         ` Max Kellermann
2025-08-28 12:49           ` Lorenzo Stoakes
2025-08-28 12:24 ` Lorenzo Stoakes
2025-08-28 12:28   ` David Hildenbrand
2025-08-28 12:40     ` Max Kellermann
2025-08-28 12:43       ` Lorenzo Stoakes
2025-08-28 12:51         ` Max Kellermann
2025-08-28 13:00       ` David Hildenbrand
2025-08-28 12:55 ` Lorenzo Stoakes

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=CAKPOu+-0zuz-t22RmENiAT7SXTMyRVeHgkCrnLK-Xt-DDxHykQ@mail.gmail.com \
    --to=max.kellermann@ionos.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mhocko@suse.com \
    --cc=rppt@kernel.org \
    --cc=surenb@google.com \
    --cc=vbabka@suse.cz \
    /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