firmware: arm_ffa: Avoid string-fortify warning in export_uuid()
authorArnd Bergmann <arnd@arndb.de>
Mon, 9 Sep 2024 11:09:24 +0000 (11:09 +0000)
committerSudeep Holla <sudeep.holla@arm.com>
Mon, 14 Oct 2024 20:07:27 +0000 (21:07 +0100)
Copying to a 16 byte structure into an 8-byte struct member
causes a compile-time warning:

 | In file included from drivers/firmware/arm_ffa/driver.c:25:
 | In function 'fortify_memcpy_chk',
 |    inlined from 'export_uuid' at include/linux/uuid.h:88:2,
 |    inlined from 'ffa_msg_send_direct_req2' at drivers/firmware/arm_ffa/driver.c:488:2:
 | include/linux/fortify-string.h:571:25: error: call to '__write_overflow_field'
 |   declared with attribute warning: detected write beyond size of field
 |   (1st parameter); maybe use struct_group()? [-Werror=attribute-warning]
 |                         __write_overflow_field(p_size_field, size);

Use a union for the conversion instead and make sure the byte order
is fixed in the process.

Fixes: aaef3bc98129 ("firmware: arm_ffa: Add support for FFA_MSG_SEND_DIRECT_{REQ,RESP}2")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Message-Id: <20240909110938.247976-1-arnd@kernel.org>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
drivers/firmware/arm_ffa/driver.c

index 4d231bc..8dd81db 100644 (file)
@@ -481,11 +481,16 @@ static int ffa_msg_send_direct_req2(u16 src_id, u16 dst_id, const uuid_t *uuid,
                                    struct ffa_send_direct_data2 *data)
 {
        u32 src_dst_ids = PACK_TARGET_INFO(src_id, dst_id);
+       union {
+               uuid_t uuid;
+               __le64 regs[2];
+       } uuid_regs = { .uuid = *uuid };
        ffa_value_t ret, args = {
-               .a0 = FFA_MSG_SEND_DIRECT_REQ2, .a1 = src_dst_ids,
+               .a0 = FFA_MSG_SEND_DIRECT_REQ2,
+               .a1 = src_dst_ids,
+               .a2 = le64_to_cpu(uuid_regs.regs[0]),
+               .a3 = le64_to_cpu(uuid_regs.regs[1]),
        };
-
-       export_uuid((u8 *)&args.a2, uuid);
        memcpy((void *)&args + offsetof(ffa_value_t, a4), data, sizeof(*data));
 
        invoke_ffa_fn(args, &ret);