diff mbox series

[RFC,v1,31/57] edac: Remove PAGE_SIZE compile-time constant assumption

Message ID 20241014105912.3207374-31-ryan.roberts@arm.com (mailing list archive)
State New
Headers show
Series None | expand

Commit Message

Ryan Roberts Oct. 14, 2024, 10:58 a.m. UTC
To prepare for supporting boot-time page size selection, refactor code
to remove assumptions about PAGE_SIZE being compile-time constant. Code
intended to be equivalent when compile-time page size is active.

Convert PAGES_TO_MiB() and MiB_TO_PAGES() to use the ternary operator so
that they continue to work with boot-time page size; Boot-time page size
can't be used with CPP because it's value is not known at compile time.
For compile-time page size builds, the compiler will dead code strip for
the same result.

Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
---

***NOTE***
Any confused maintainers may want to read the cover note here for context:
https://lore.kernel.org/all/20241014105514.3206191-1-ryan.roberts@arm.com/

 drivers/edac/edac_mc.h | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

Comments

Ryan Roberts Oct. 16, 2024, 2:46 p.m. UTC | #1
+ Borislav Petkov, Tony Luck

This was a rather tricky series to get the recipients correct for and my script
did not realize that "supporter" was a pseudonym for "maintainer" so you were
missed off the original post. Appologies!

More context in cover letter:
https://lore.kernel.org/all/20241014105514.3206191-1-ryan.roberts@arm.com/


On 14/10/2024 11:58, Ryan Roberts wrote:
> To prepare for supporting boot-time page size selection, refactor code
> to remove assumptions about PAGE_SIZE being compile-time constant. Code
> intended to be equivalent when compile-time page size is active.
> 
> Convert PAGES_TO_MiB() and MiB_TO_PAGES() to use the ternary operator so
> that they continue to work with boot-time page size; Boot-time page size
> can't be used with CPP because it's value is not known at compile time.
> For compile-time page size builds, the compiler will dead code strip for
> the same result.
> 
> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
> ---
> 
> ***NOTE***
> Any confused maintainers may want to read the cover note here for context:
> https://lore.kernel.org/all/20241014105514.3206191-1-ryan.roberts@arm.com/
> 
>  drivers/edac/edac_mc.h | 13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/edac/edac_mc.h b/drivers/edac/edac_mc.h
> index 881b00eadf7a5..22132ee86e953 100644
> --- a/drivers/edac/edac_mc.h
> +++ b/drivers/edac/edac_mc.h
> @@ -37,13 +37,12 @@
>  #include <linux/workqueue.h>
>  #include <linux/edac.h>
>  
> -#if PAGE_SHIFT < 20
> -#define PAGES_TO_MiB(pages)	((pages) >> (20 - PAGE_SHIFT))
> -#define MiB_TO_PAGES(mb)	((mb) << (20 - PAGE_SHIFT))
> -#else				/* PAGE_SHIFT > 20 */
> -#define PAGES_TO_MiB(pages)	((pages) << (PAGE_SHIFT - 20))
> -#define MiB_TO_PAGES(mb)	((mb) >> (PAGE_SHIFT - 20))
> -#endif
> +#define PAGES_TO_MiB(pages)	(PAGE_SHIFT < 20 ?			\
> +					((pages) >> (20 - PAGE_SHIFT)) :\
> +					((pages) << (PAGE_SHIFT - 20)))
> +#define MiB_TO_PAGES(mb)	(PAGE_SHIFT < 20 ?			\
> +					((mb) << (20 - PAGE_SHIFT)) :	\
> +					((mb) >> (PAGE_SHIFT - 20)))
>  
>  #define edac_printk(level, prefix, fmt, arg...) \
>  	printk(level "EDAC " prefix ": " fmt, ##arg)
diff mbox series

Patch

diff --git a/drivers/edac/edac_mc.h b/drivers/edac/edac_mc.h
index 881b00eadf7a5..22132ee86e953 100644
--- a/drivers/edac/edac_mc.h
+++ b/drivers/edac/edac_mc.h
@@ -37,13 +37,12 @@ 
 #include <linux/workqueue.h>
 #include <linux/edac.h>
 
-#if PAGE_SHIFT < 20
-#define PAGES_TO_MiB(pages)	((pages) >> (20 - PAGE_SHIFT))
-#define MiB_TO_PAGES(mb)	((mb) << (20 - PAGE_SHIFT))
-#else				/* PAGE_SHIFT > 20 */
-#define PAGES_TO_MiB(pages)	((pages) << (PAGE_SHIFT - 20))
-#define MiB_TO_PAGES(mb)	((mb) >> (PAGE_SHIFT - 20))
-#endif
+#define PAGES_TO_MiB(pages)	(PAGE_SHIFT < 20 ?			\
+					((pages) >> (20 - PAGE_SHIFT)) :\
+					((pages) << (PAGE_SHIFT - 20)))
+#define MiB_TO_PAGES(mb)	(PAGE_SHIFT < 20 ?			\
+					((mb) << (20 - PAGE_SHIFT)) :	\
+					((mb) >> (PAGE_SHIFT - 20)))
 
 #define edac_printk(level, prefix, fmt, arg...) \
 	printk(level "EDAC " prefix ": " fmt, ##arg)