]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdadm: Fix compilation for 32-bit arch
authorBlazej Kucman <blazej.kucman@intel.com>
Wed, 15 May 2024 11:26:28 +0000 (13:26 +0200)
committerMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Thu, 16 May 2024 09:30:06 +0000 (11:30 +0200)
Casting void pointer to __u64 works for 64-bit arch but fails to compile
on 32-bit arch like i686.

Fail on i686 platform:
drive_encryption.c: In function ‘nvme_security_recv_ioctl’:
drive_encryption.c:236:25: error: cast from pointer to integer of
different size [-Werror=pointer-to-int-cast]
  236 |         nvme_cmd.addr = (__u64)response_buffer;
      |                         ^
drive_encryption.c: In function ‘nvme_identify_ioctl’:
drive_encryption.c:271:25: error: cast from pointer to integer of
different size [-Werror=pointer-to-int-cast]
  271 |         nvme_cmd.addr = (__u64)response_buffer;
      |                         ^
cc1: all warnings being treated as errors
make: *** [Makefile:211: drive_encryption.o] Error 1

This change adds cast void pointer to uintptr_t first to ensure that
proper pointer size is used for casting from pointer type. Then is safe to
cast it to __u64 because it is tracked as u_int, regardless it is 32-bit
or 64-bit arch.

Reported-by: Xiao Ni <xni@redhat.com>
Fixes: cc48406887b3 ("Add reading Opal NVMe encryption information")
Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
drive_encryption.c

index 27da962165c75e65f2e08988fd752398b280aa50..a4ad799f698cb682071372ba4a21de5dfb60b589 100644 (file)
@@ -233,7 +233,7 @@ nvme_security_recv_ioctl(int disk_fd, __u8 sec_protocol, __u16 comm_id, void *re
        nvme_cmd.cdw10 = sec_protocol << 24 | comm_id << 8;
        nvme_cmd.cdw11 = buf_size;
        nvme_cmd.data_len = buf_size;
-       nvme_cmd.addr = (__u64)response_buffer;
+       nvme_cmd.addr = (__u64)(uintptr_t)response_buffer;
 
        status = ioctl(disk_fd, NVME_IOCTL_ADMIN_CMD, &nvme_cmd);
        if (status != 0) {
@@ -268,7 +268,7 @@ nvme_identify_ioctl(int disk_fd, void *response_buffer, size_t buf_size, const i
        nvme_cmd.opcode = NVME_IDENTIFY;
        nvme_cmd.cdw10 = NVME_IDENTIFY_CONTROLLER_DATA;
        nvme_cmd.data_len = buf_size;
-       nvme_cmd.addr = (__u64)response_buffer;
+       nvme_cmd.addr = (__u64)(uintptr_t)response_buffer;
 
        status = ioctl(disk_fd, NVME_IOCTL_ADMIN_CMD, &nvme_cmd);
        if (status != 0) {