diff mbox series

[1/2] libswap: Move file & line macros to macros

Message ID 20240417123113.731780-1-pvorel@suse.cz
State Accepted
Headers show
Series [1/2] libswap: Move file & line macros to macros | expand

Commit Message

Petr Vorel April 17, 2024, 12:31 p.m. UTC
Having __FILE__ and __LINE__ in C function does not help,
they must be in macros to help identify the caller.

Therefore make_swapfile_() wrapper is not needed.

Fixes: f987ffff5 ("libswap: add two methods to create swapfile")
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 include/libswap.h         | 16 +++++-----------
 libs/libltpswap/libswap.c |  2 +-
 2 files changed, 6 insertions(+), 12 deletions(-)

Comments

Li Wang April 18, 2024, 5:32 a.m. UTC | #1
On Wed, Apr 17, 2024 at 8:31 PM Petr Vorel <pvorel@suse.cz> wrote:

> Having __FILE__ and __LINE__ in C function does not help,
> they must be in macros to help identify the caller.
>
> Therefore make_swapfile_() wrapper is not needed.
>
> Fixes: f987ffff5 ("libswap: add two methods to create swapfile")
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
>

Reviewed-by: Li Wang <liwang@redhat.com>


> ---
>  include/libswap.h         | 16 +++++-----------
>  libs/libltpswap/libswap.c |  2 +-
>  2 files changed, 6 insertions(+), 12 deletions(-)
>
> diff --git a/include/libswap.h b/include/libswap.h
> index 96e718542..87e32328e 100644
> --- a/include/libswap.h
> +++ b/include/libswap.h
> @@ -19,41 +19,35 @@ enum swapfile_method {
>  /*
>   * Create a swapfile of a specified size or number of blocks.
>   */
> -int make_swapfile_(const char *file, const int lineno,
> +int make_swapfile(const char *file, const int lineno,
>                         const char *swapfile, unsigned int num,
>                         int safe, enum swapfile_method method);
>
> -static inline int make_swapfile(const char *swapfile, unsigned int num,
> -                       int safe, enum swapfile_method method)
> -{
> -       return make_swapfile_(__FILE__, __LINE__, swapfile, num, safe,
> method);
> -}
> -
>  /**
>   * Macro to create swapfile size in megabytes (MB).
>   */
>  #define MAKE_SWAPFILE_SIZE(swapfile, size) \
> -    make_swapfile(swapfile, size, 0, SWAPFILE_BY_SIZE)
> +    make_swapfile(__FILE__, __LINE__, swapfile, size, 0, SWAPFILE_BY_SIZE)
>
>  /**
>   * Macro to create swapfile size in block numbers.
>   */
>  #define MAKE_SWAPFILE_BLKS(swapfile, blocks) \
> -    make_swapfile(swapfile, blocks, 0, SWAPFILE_BY_BLKS)
> +    make_swapfile(__FILE__, __LINE__, swapfile, blocks, 0,
> SWAPFILE_BY_BLKS)
>
>  /**
>   * Macro to safely create swapfile size in megabytes (MB).
>   * Includes safety checks to handle potential errors.
>   */
>  #define SAFE_MAKE_SWAPFILE_SIZE(swapfile, size) \
> -    make_swapfile(swapfile, size, 1, SWAPFILE_BY_SIZE)
> +    make_swapfile(__FILE__, __LINE__, swapfile, size, 1, SWAPFILE_BY_SIZE)
>
>  /**
>   * Macro to safely create swapfile size in block numbers.
>   * Includes safety checks to handle potential errors.
>   */
>  #define SAFE_MAKE_SWAPFILE_BLKS(swapfile, blocks) \
> -    make_swapfile(swapfile, blocks, 1, SWAPFILE_BY_BLKS)
> +    make_swapfile(__FILE__, __LINE__, swapfile, blocks, 1,
> SWAPFILE_BY_BLKS)
>
>  /*
>   * Check swapon/swapoff support status of filesystems or files
> diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c
> index 313a15f24..b4233be0d 100644
> --- a/libs/libltpswap/libswap.c
> +++ b/libs/libltpswap/libswap.c
> @@ -133,7 +133,7 @@ out:
>         return contiguous;
>  }
>
> -int make_swapfile_(const char *file, const int lineno,
> +int make_swapfile(const char *file, const int lineno,
>                         const char *swapfile, unsigned int num,
>                         int safe, enum swapfile_method method)
>  {
> --
> 2.43.0
>
>
Cyril Hrubis April 18, 2024, 11:23 a.m. UTC | #2
Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
diff mbox series

Patch

diff --git a/include/libswap.h b/include/libswap.h
index 96e718542..87e32328e 100644
--- a/include/libswap.h
+++ b/include/libswap.h
@@ -19,41 +19,35 @@  enum swapfile_method {
 /*
  * Create a swapfile of a specified size or number of blocks.
  */
-int make_swapfile_(const char *file, const int lineno,
+int make_swapfile(const char *file, const int lineno,
 			const char *swapfile, unsigned int num,
 			int safe, enum swapfile_method method);
 
-static inline int make_swapfile(const char *swapfile, unsigned int num,
-			int safe, enum swapfile_method method)
-{
-	return make_swapfile_(__FILE__, __LINE__, swapfile, num, safe, method);
-}
-
 /**
  * Macro to create swapfile size in megabytes (MB).
  */
 #define MAKE_SWAPFILE_SIZE(swapfile, size) \
-    make_swapfile(swapfile, size, 0, SWAPFILE_BY_SIZE)
+    make_swapfile(__FILE__, __LINE__, swapfile, size, 0, SWAPFILE_BY_SIZE)
 
 /**
  * Macro to create swapfile size in block numbers.
  */
 #define MAKE_SWAPFILE_BLKS(swapfile, blocks) \
-    make_swapfile(swapfile, blocks, 0, SWAPFILE_BY_BLKS)
+    make_swapfile(__FILE__, __LINE__, swapfile, blocks, 0, SWAPFILE_BY_BLKS)
 
 /**
  * Macro to safely create swapfile size in megabytes (MB).
  * Includes safety checks to handle potential errors.
  */
 #define SAFE_MAKE_SWAPFILE_SIZE(swapfile, size) \
-    make_swapfile(swapfile, size, 1, SWAPFILE_BY_SIZE)
+    make_swapfile(__FILE__, __LINE__, swapfile, size, 1, SWAPFILE_BY_SIZE)
 
 /**
  * Macro to safely create swapfile size in block numbers.
  * Includes safety checks to handle potential errors.
  */
 #define SAFE_MAKE_SWAPFILE_BLKS(swapfile, blocks) \
-    make_swapfile(swapfile, blocks, 1, SWAPFILE_BY_BLKS)
+    make_swapfile(__FILE__, __LINE__, swapfile, blocks, 1, SWAPFILE_BY_BLKS)
 
 /*
  * Check swapon/swapoff support status of filesystems or files
diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c
index 313a15f24..b4233be0d 100644
--- a/libs/libltpswap/libswap.c
+++ b/libs/libltpswap/libswap.c
@@ -133,7 +133,7 @@  out:
 	return contiguous;
 }
 
-int make_swapfile_(const char *file, const int lineno,
+int make_swapfile(const char *file, const int lineno,
 			const char *swapfile, unsigned int num,
 			int safe, enum swapfile_method method)
 {