* [PATCH] mm/memfd: remove redundant casts
@ 2025-08-31 11:47 Joey Pabalinas
2025-08-31 19:34 ` Andrew Morton
0 siblings, 1 reply; 3+ messages in thread
From: Joey Pabalinas @ 2025-08-31 11:47 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, Andrew Morton, Baolin Wang, Hugh Dickins,
Joey Pabalinas
[-- Attachment #1: Type: text/plain, Size: 973 bytes --]
MFD_ALL_FLAGS is already an unsigned int. Remove redundant casts to
unsigned int.
Signed-off-by: Joey Pabalinas <joeypabalinas@gmail.com>
---
mm/memfd.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mm/memfd.c b/mm/memfd.c
index bbe679895ef6a191ba..1d109c1acf211b3c3c 100644
--- a/mm/memfd.c
+++ b/mm/memfd.c
@@ -383,15 +383,15 @@ int memfd_check_seals_mmap(struct file *file, vm_flags_t *vm_flags_ptr)
static int sanitize_flags(unsigned int *flags_ptr)
{
unsigned int flags = *flags_ptr;
if (!(flags & MFD_HUGETLB)) {
- if (flags & ~(unsigned int)MFD_ALL_FLAGS)
+ if (flags & ~MFD_ALL_FLAGS)
return -EINVAL;
} else {
/* Allow huge page size encoding in flags. */
- if (flags & ~(unsigned int)(MFD_ALL_FLAGS |
+ if (flags & ~(MFD_ALL_FLAGS |
(MFD_HUGE_MASK << MFD_HUGE_SHIFT)))
return -EINVAL;
}
/* Invalid if both EXEC and NOEXEC_SEAL are set.*/
--
Cheers,
Joey Pabalinas
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] mm/memfd: remove redundant casts
2025-08-31 11:47 [PATCH] mm/memfd: remove redundant casts Joey Pabalinas
@ 2025-08-31 19:34 ` Andrew Morton
2025-09-01 13:23 ` David Hildenbrand
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2025-08-31 19:34 UTC (permalink / raw)
To: Joey Pabalinas; +Cc: linux-kernel, linux-mm, Baolin Wang, Hugh Dickins
On Sun, 31 Aug 2025 01:47:48 -1000 Joey Pabalinas <joeypabalinas@gmail.com> wrote:
> MFD_ALL_FLAGS is already an unsigned int. Remove redundant casts to
> unsigned int.
lgtm.
It's rather annoying that the MFD_ALL_FLAGS definition is so far away
from the other MFD_* definitions. What do peope think of this little
cleanup?
From: Andrew Morton <akpm@linux-foundation.org>
Subject: memfd: move MFD_ALL_FLAGS definition to memfd.h
Date: Sun Aug 31 12:29:57 PM PDT 2025
It's not part of the UAPI, but putting it here is better from a
maintainability POV.
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
include/uapi/linux/memfd.h | 2 ++
mm/memfd.c | 2 --
2 files changed, 2 insertions(+), 2 deletions(-)
--- a/mm/memfd.c~memfd-move-mfd_all_flags-definition-to-memfdh
+++ a/mm/memfd.c
@@ -313,8 +313,6 @@ long memfd_fcntl(struct file *file, unsi
#define MFD_NAME_PREFIX_LEN (sizeof(MFD_NAME_PREFIX) - 1)
#define MFD_NAME_MAX_LEN (NAME_MAX - MFD_NAME_PREFIX_LEN)
-#define MFD_ALL_FLAGS (MFD_CLOEXEC | MFD_ALLOW_SEALING | MFD_HUGETLB | MFD_NOEXEC_SEAL | MFD_EXEC)
-
static int check_sysctl_memfd_noexec(unsigned int *flags)
{
#ifdef CONFIG_SYSCTL
--- a/include/uapi/linux/memfd.h~memfd-move-mfd_all_flags-definition-to-memfdh
+++ a/include/uapi/linux/memfd.h
@@ -12,6 +12,8 @@
#define MFD_NOEXEC_SEAL 0x0008U
/* executable */
#define MFD_EXEC 0x0010U
+#define MFD_ALL_FLAGS (MFD_CLOEXEC | MFD_ALLOW_SEALING | \
+ MFD_HUGETLB | MFD_NOEXEC_SEAL | MFD_EXEC)
/*
* Huge page size encoding when MFD_HUGETLB is specified, and a huge page
_
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mm/memfd: remove redundant casts
2025-08-31 19:34 ` Andrew Morton
@ 2025-09-01 13:23 ` David Hildenbrand
0 siblings, 0 replies; 3+ messages in thread
From: David Hildenbrand @ 2025-09-01 13:23 UTC (permalink / raw)
To: Andrew Morton, Joey Pabalinas
Cc: linux-kernel, linux-mm, Baolin Wang, Hugh Dickins
On 31.08.25 21:34, Andrew Morton wrote:
> On Sun, 31 Aug 2025 01:47:48 -1000 Joey Pabalinas <joeypabalinas@gmail.com> wrote:
>
>> MFD_ALL_FLAGS is already an unsigned int. Remove redundant casts to
>> unsigned int.
>
> lgtm.
>
> It's rather annoying that the MFD_ALL_FLAGS definition is so far away
> from the other MFD_* definitions. What do peope think of this little
> cleanup?
>
> From: Andrew Morton <akpm@linux-foundation.org>
> Subject: memfd: move MFD_ALL_FLAGS definition to memfd.h
> Date: Sun Aug 31 12:29:57 PM PDT 2025
>
> It's not part of the UAPI, but putting it here is better from a
> maintainability POV.
>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> ---
>
> include/uapi/linux/memfd.h | 2 ++
> mm/memfd.c | 2 --
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> --- a/mm/memfd.c~memfd-move-mfd_all_flags-definition-to-memfdh
> +++ a/mm/memfd.c
> @@ -313,8 +313,6 @@ long memfd_fcntl(struct file *file, unsi
> #define MFD_NAME_PREFIX_LEN (sizeof(MFD_NAME_PREFIX) - 1)
> #define MFD_NAME_MAX_LEN (NAME_MAX - MFD_NAME_PREFIX_LEN)
>
> -#define MFD_ALL_FLAGS (MFD_CLOEXEC | MFD_ALLOW_SEALING | MFD_HUGETLB | MFD_NOEXEC_SEAL | MFD_EXEC)
> -
> static int check_sysctl_memfd_noexec(unsigned int *flags)
> {
> #ifdef CONFIG_SYSCTL
> --- a/include/uapi/linux/memfd.h~memfd-move-mfd_all_flags-definition-to-memfdh
> +++ a/include/uapi/linux/memfd.h
> @@ -12,6 +12,8 @@
> #define MFD_NOEXEC_SEAL 0x0008U
> /* executable */
> #define MFD_EXEC 0x0010U
> +#define MFD_ALL_FLAGS (MFD_CLOEXEC | MFD_ALLOW_SEALING | \
> + MFD_HUGETLB | MFD_NOEXEC_SEAL | MFD_EXEC)
No strong opinion.
When we are exposing this through uapi, wondering if we should rename it
to something else that includes "MASK".
Quickly search for similar instances. For mmap we have the internal
"LEGACY_MAP_MASK", but that's also a bit different.
There is this oddity that we store the hugetlb size in the upper bits of
flags, masked by (MFD_HUGE_MASK << MFD_HUGE_SHIFT).
MFD_FLAGS_MASK maybe? not sure.
--
Cheers
David / dhildenb
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-09-01 13:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-31 11:47 [PATCH] mm/memfd: remove redundant casts Joey Pabalinas
2025-08-31 19:34 ` Andrew Morton
2025-09-01 13:23 ` David Hildenbrand
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).