diff mbox

[1/4] kpartx: Improve portability of set_loop()

Message ID 20170613163339.23005-2-bart.vanassche@sandisk.com (mailing list archive)
State Not Applicable, archived
Delegated to: Mike Snitzer
Headers show

Commit Message

Bart Van Assche June 13, 2017, 4:33 p.m. UTC
Because macros like __x86_64__ are not defined by the C standard
and because it is easy to convert the int2ptr() macro into
standard C, use (void*)(uintptr_t) instead of int2ptr(). Inline
this macro because it only has one user. This patch does not
change any functionality.

Reported-by: Xose Vazquez Perez <xose.vazquez@gmail.com>
Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Cc: Xose Vazquez Perez <xose.vazquez@gmail.com>
---
 kpartx/lopart.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

Comments

Martin Wilck June 13, 2017, 7:33 p.m. UTC | #1
On Tue, 2017-06-13 at 09:33 -0700, Bart Van Assche wrote:
> Because macros like __x86_64__ are not defined by the C standard
> and because it is easy to convert the int2ptr() macro into
> standard C, use (void*)(uintptr_t) instead of int2ptr(). Inline
> this macro because it only has one user. This patch does not
> change any functionality.
> 
> Reported-by: Xose Vazquez Perez <xose.vazquez@gmail.com>
> Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
> Cc: Xose Vazquez Perez <xose.vazquez@gmail.com>
> ---
>  kpartx/lopart.c | 10 ++--------
>  1 file changed, 2 insertions(+), 8 deletions(-)
> 
Reviewed-by: Martin Wilck <mwilck@suse.com>
diff mbox

Patch

diff --git a/kpartx/lopart.c b/kpartx/lopart.c
index 70054459..f7ab91b5 100644
--- a/kpartx/lopart.c
+++ b/kpartx/lopart.c
@@ -21,6 +21,7 @@ 
 #include <fcntl.h>
 #include <errno.h>
 #include <stdlib.h>
+#include <stdint.h>
 #include <unistd.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
@@ -37,13 +38,6 @@ 
 #define LOOP_CTL_GET_FREE       0x4C82
 #endif
 
-#if !defined (__alpha__) && !defined (__ia64__) && !defined (__x86_64__) \
-	&& !defined (__s390x__)
-#define int2ptr(x)	((void *) ((int) x))
-#else
-#define int2ptr(x)	((void *) ((long) x))
-#endif
-
 static char *
 xstrdup (const char *s)
 {
@@ -249,7 +243,7 @@  int set_loop(const char *device, const char *file, int offset, int *loopro)
 	loopinfo.lo_encrypt_type = LO_CRYPT_NONE;
 	loopinfo.lo_encrypt_key_size = 0;
 
-	if (ioctl (fd, LOOP_SET_FD, int2ptr(ffd)) < 0) {
+	if (ioctl(fd, LOOP_SET_FD, (void*)(uintptr_t)(ffd)) < 0) {
 		perror ("ioctl: LOOP_SET_FD");
 		close (fd);
 		close (ffd);