* [PATCH] security: min_addr: use max() to improve code
@ 2025-08-14 14:26 Qianfeng Rong
2025-08-15 2:17 ` Paul Moore
0 siblings, 1 reply; 3+ messages in thread
From: Qianfeng Rong @ 2025-08-14 14:26 UTC (permalink / raw)
To: Paul Moore, James Morris, Serge E. Hallyn, linux-security-module,
linux-kernel
Cc: Qianfeng Rong
Use max() to reduce the code in update_mmap_min_addr() and improve its
readability.
Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
---
security/min_addr.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/security/min_addr.c b/security/min_addr.c
index df1bc643d886..50035bc9281c 100644
--- a/security/min_addr.c
+++ b/security/min_addr.c
@@ -16,10 +16,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
static void update_mmap_min_addr(void)
{
#ifdef CONFIG_LSM_MMAP_MIN_ADDR
- if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
- mmap_min_addr = dac_mmap_min_addr;
- else
- mmap_min_addr = CONFIG_LSM_MMAP_MIN_ADDR;
+ mmap_min_addr = max(dac_mmap_min_addr, CONFIG_LSM_MMAP_MIN_ADDR);
#else
mmap_min_addr = dac_mmap_min_addr;
#endif
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] security: min_addr: use max() to improve code
2025-08-14 14:26 [PATCH] security: min_addr: use max() to improve code Qianfeng Rong
@ 2025-08-15 2:17 ` Paul Moore
2025-08-15 3:39 ` Qianfeng Rong
0 siblings, 1 reply; 3+ messages in thread
From: Paul Moore @ 2025-08-15 2:17 UTC (permalink / raw)
To: Qianfeng Rong, James Morris, Serge E. Hallyn,
linux-security-module, linux-kernel
Cc: Qianfeng Rong
On Aug 14, 2025 Qianfeng Rong <rongqianfeng@vivo.com> wrote:
>
> Use max() to reduce the code in update_mmap_min_addr() and improve its
> readability.
>
> Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
> ---
> security/min_addr.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/security/min_addr.c b/security/min_addr.c
> index df1bc643d886..50035bc9281c 100644
> --- a/security/min_addr.c
> +++ b/security/min_addr.c
> @@ -16,10 +16,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
> static void update_mmap_min_addr(void)
> {
> #ifdef CONFIG_LSM_MMAP_MIN_ADDR
> - if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
> - mmap_min_addr = dac_mmap_min_addr;
> - else
> - mmap_min_addr = CONFIG_LSM_MMAP_MIN_ADDR;
> + mmap_min_addr = max(dac_mmap_min_addr, CONFIG_LSM_MMAP_MIN_ADDR);
It seems like the umax() macro would be a better choice here, yes?
It might also be a good idea to explicitly include the
include/linux/minmax.h header in this file.
> #else
> mmap_min_addr = dac_mmap_min_addr;
> #endif
> --
> 2.34.1
--
paul-moore.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] security: min_addr: use max() to improve code
2025-08-15 2:17 ` Paul Moore
@ 2025-08-15 3:39 ` Qianfeng Rong
0 siblings, 0 replies; 3+ messages in thread
From: Qianfeng Rong @ 2025-08-15 3:39 UTC (permalink / raw)
To: Paul Moore, James Morris, Serge E. Hallyn, linux-security-module,
linux-kernel
在 2025/8/15 10:17, Paul Moore 写道:
> On Aug 14, 2025 Qianfeng Rong <rongqianfeng@vivo.com> wrote:
>> Use max() to reduce the code in update_mmap_min_addr() and improve its
>> readability.
>>
>> Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
>> ---
>> security/min_addr.c | 5 +----
>> 1 file changed, 1 insertion(+), 4 deletions(-)
>>
>> diff --git a/security/min_addr.c b/security/min_addr.c
>> index df1bc643d886..50035bc9281c 100644
>> --- a/security/min_addr.c
>> +++ b/security/min_addr.c
>> @@ -16,10 +16,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
>> static void update_mmap_min_addr(void)
>> {
>> #ifdef CONFIG_LSM_MMAP_MIN_ADDR
>> - if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
>> - mmap_min_addr = dac_mmap_min_addr;
>> - else
>> - mmap_min_addr = CONFIG_LSM_MMAP_MIN_ADDR;
>> + mmap_min_addr = max(dac_mmap_min_addr, CONFIG_LSM_MMAP_MIN_ADDR);
> It seems like the umax() macro would be a better choice here, yes?
You are right, using umax() here makes the semantics clearer.
>
> It might also be a good idea to explicitly include the
> include/linux/minmax.h header in this file.
ok, Will do in the next version.
>
>> #else
>> mmap_min_addr = dac_mmap_min_addr;
>> #endif
>> --
>> 2.34.1
> --
> paul-moore.com
Best regards,
Qianfeng
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-08-15 3:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-14 14:26 [PATCH] security: min_addr: use max() to improve code Qianfeng Rong
2025-08-15 2:17 ` Paul Moore
2025-08-15 3:39 ` Qianfeng Rong
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).