lkml.org 
[lkml]   [2022]   [Jun]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 5.18 193/879] can: mcp251xfd: silence clangs -Wunaligned-access warning
    Date
    From: Vincent Mailhol <mailhol.vincent@wanadoo.fr>

    [ Upstream commit 1a6dd9996699889313327be03981716a8337656b ]

    clang emits a -Wunaligned-access warning on union
    mcp251xfd_tx_ojb_load_buf.

    The reason is that field hw_tx_obj (not declared as packed) is being
    packed right after a 16 bits field inside a packed struct:

    | union mcp251xfd_tx_obj_load_buf {
    | struct __packed {
    | struct mcp251xfd_buf_cmd cmd;
    | /* ^ 16 bits fields */
    | struct mcp251xfd_hw_tx_obj_raw hw_tx_obj;
    | /* ^ not declared as packed */
    | } nocrc;
    | struct __packed {
    | struct mcp251xfd_buf_cmd_crc cmd;
    | struct mcp251xfd_hw_tx_obj_raw hw_tx_obj;
    | __be16 crc;
    | } crc;
    | } ____cacheline_aligned;

    Starting from LLVM 14, having an unpacked struct nested in a packed
    struct triggers a warning. c.f. [1].

    This is a false positive because the field is always being accessed
    with the relevant put_unaligned_*() function. Adding __packed to the
    structure declaration silences the warning.

    [1] https://github.com/llvm/llvm-project/issues/55520

    Link: https://lore.kernel.org/all/20220518114357.55452-1-mailhol.vincent@wanadoo.fr
    Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
    Reported-by: kernel test robot <lkp@intel.com>
    Tested-by: Nathan Chancellor <nathan@kernel.org> # build
    Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
    Signed-off-by: Sasha Levin <sashal@kernel.org>
    ---
    drivers/net/can/spi/mcp251xfd/mcp251xfd.h | 2 +-
    1 file changed, 1 insertion(+), 1 deletion(-)

    diff --git a/drivers/net/can/spi/mcp251xfd/mcp251xfd.h b/drivers/net/can/spi/mcp251xfd/mcp251xfd.h
    index 9cb6b5ad8dda..60e56fa4601d 100644
    --- a/drivers/net/can/spi/mcp251xfd/mcp251xfd.h
    +++ b/drivers/net/can/spi/mcp251xfd/mcp251xfd.h
    @@ -441,7 +441,7 @@ struct mcp251xfd_hw_tef_obj {
    /* The tx_obj_raw version is used in spi async, i.e. without
    * regmap. We have to take care of endianness ourselves.
    */
    -struct mcp251xfd_hw_tx_obj_raw {
    +struct __packed mcp251xfd_hw_tx_obj_raw {
    __le32 id;
    __le32 flags;
    u8 data[sizeof_field(struct canfd_frame, data)];
    --
    2.35.1


    \
     
     \ /
      Last update: 2022-06-08 00:22    [W:2.462 / U:0.092 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site