Skip to content

Commit 1cb49f3

Browse files
nxpfranklivinodkoul
authored andcommitted
dmaengine: imx-sdma: utilize compiler to calculate ADDRS_ARRAY_SIZE_V<n>
The macros SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V<n> actually related with the struct sdma_script_start_addrs. struct sdma_script_start_addrs { ... /* End of v1 array */ ... /* End of v2 array */ ... /* End of v3 array */ ... /* End of v4 array */ }; When add new field of sdma_script_start_addrs, it is easy to miss update SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V<n>. Employ offsetof for SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V<n> macros instead of hardcoding numbers. the preprocessing stage will calculate the size for each version automatically. Signed-off-by: Frank Li <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 458bb56 commit 1cb49f3

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

drivers/dma/imx-sdma.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -240,20 +240,21 @@ struct sdma_script_start_addrs {
240240
s32 utra_addr;
241241
s32 ram_code_start_addr;
242242
/* End of v1 array */
243-
s32 mcu_2_ssish_addr;
243+
union { s32 v1_end; s32 mcu_2_ssish_addr; };
244244
s32 ssish_2_mcu_addr;
245245
s32 hdmi_dma_addr;
246246
/* End of v2 array */
247-
s32 zcanfd_2_mcu_addr;
247+
union { s32 v2_end; s32 zcanfd_2_mcu_addr; };
248248
s32 zqspi_2_mcu_addr;
249249
s32 mcu_2_ecspi_addr;
250250
s32 mcu_2_sai_addr;
251251
s32 sai_2_mcu_addr;
252252
s32 uart_2_mcu_rom_addr;
253253
s32 uartsh_2_mcu_rom_addr;
254254
/* End of v3 array */
255-
s32 mcu_2_zqspi_addr;
255+
union { s32 v3_end; s32 mcu_2_zqspi_addr; };
256256
/* End of v4 array */
257+
s32 v4_end[0];
257258
};
258259

259260
/*
@@ -1915,10 +1916,17 @@ static void sdma_issue_pending(struct dma_chan *chan)
19151916
spin_unlock_irqrestore(&sdmac->vc.lock, flags);
19161917
}
19171918

1918-
#define SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V1 34
1919-
#define SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V2 38
1920-
#define SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V3 45
1921-
#define SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V4 46
1919+
#define SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V1 \
1920+
(offsetof(struct sdma_script_start_addrs, v1_end) / sizeof(s32))
1921+
1922+
#define SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V2 \
1923+
(offsetof(struct sdma_script_start_addrs, v2_end) / sizeof(s32))
1924+
1925+
#define SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V3 \
1926+
(offsetof(struct sdma_script_start_addrs, v3_end) / sizeof(s32))
1927+
1928+
#define SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V4 \
1929+
(offsetof(struct sdma_script_start_addrs, v4_end) / sizeof(s32))
19221930

19231931
static void sdma_add_scripts(struct sdma_engine *sdma,
19241932
const struct sdma_script_start_addrs *addr)

0 commit comments

Comments
 (0)