diff mbox series

[v1,3/5] lib/efi: Fix build warnings

Message ID dfa8943935c9c937bd7eef01cb31ab26a93199a3.1587958237.git.geoff@infradead.org
State New
Headers show
Series [v1,1/5] ncurses/nc-menu: Remove stray declaration | expand

Commit Message

Geoff Levand April 27, 2020, 3:38 a.m. UTC
Fixes build warnings like these when building as 32-bit:

  warning: format ‘%ld’ expects argument of type ‘long int’, but argument 4 has type ‘ssize_t’

Signed-off-by: Geoff Levand <geoff@infradead.org>
---
 lib/efi/efivar.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Jeremy Kerr May 3, 2020, 5:58 a.m. UTC | #1
Hi Geoff,

> Fixes build warnings like these when building as 32-bit:
> 
>   warning: format ‘%ld’ expects argument of type ‘long int’, but argument 4 has type ‘ssize_t’

Fixing these is great, but a few comments:

> @@ -71,7 +71,7 @@ bool efi_check_mount_magic(const struct efi_mount *efi_mount, bool check_magic)
>  		return false;
>  	}
>  
> -	if (check_magic && s.f_type != EFIVARFS_MAGIC) {
> +	if (check_magic && ((unsigned long)s.f_type != EFIVARFS_MAGIC)) {

It's moderately awful that f_type changes in signed-ness between
platforms, but the fix is good.

> @@ -183,12 +183,12 @@ int efi_get_variable(void *ctx, const struct efi_mount *efi_mount,
>  				continue;
>  
>  			pb_log("%s: read failed %s: (%ld) (%d) %s\n", __func__, path,
> -				count, errno, strerror(errno));
> +				(long int)count, errno, strerror(errno));

For these, can you change the format to %zd, rather than introduce the
cast?

Cheers,


Jeremy
diff mbox series

Patch

diff --git a/lib/efi/efivar.c b/lib/efi/efivar.c
index 37bb6d9..75863ba 100644
--- a/lib/efi/efivar.c
+++ b/lib/efi/efivar.c
@@ -34,7 +34,7 @@ 
 #include "talloc/talloc.h"
 
 #ifndef EFIVARFS_MAGIC
-#define EFIVARFS_MAGIC 0xde5e81e4
+#define EFIVARFS_MAGIC 0xde5e81e4UL
 #endif
 
 void efi_init_mount(struct efi_mount *efi_mount, const char *path,
@@ -71,7 +71,7 @@  bool efi_check_mount_magic(const struct efi_mount *efi_mount, bool check_magic)
 		return false;
 	}
 
-	if (check_magic && s.f_type != EFIVARFS_MAGIC) {
+	if (check_magic && ((unsigned long)s.f_type != EFIVARFS_MAGIC)) {
 		pb_debug_fn("Bad magic = 0x%lx\n", (unsigned long)s.f_type);
 		return false;
 	}
@@ -183,12 +183,12 @@  int efi_get_variable(void *ctx, const struct efi_mount *efi_mount,
 				continue;
 
 			pb_log("%s: read failed %s: (%ld) (%d) %s\n", __func__, path,
-				count, errno, strerror(errno));
+				(long int)count, errno, strerror(errno));
 			goto exit;
 		}
 		if (p >= (buf + sizeof(buf))) {
 			pb_log("%s: buffer full %s: (%ld)\n", __func__, path,
-				sizeof(buf));
+				(long int)sizeof(buf));
 			goto exit;
 		}
 		if (count == 0)
@@ -242,7 +242,7 @@  int efi_set_variable(const struct efi_mount *efi_mount, const char *name,
 	count = write(fd, buf, bufsize);
 	if ((size_t)count != bufsize) {
 		pb_log("%s: write failed %s: (%ld) (%d) %s\n", __func__, name,
-			count, errno, strerror(errno));
+			(long int)count, errno, strerror(errno));
 		goto exit;
 	}
 	rc = 0;