fsl/fman: use the ALIGN() macro
PATCH 1/1 fsl/fman: use the ALIGN() macro
The original code works fine but the issue is that static checkers complain about this:
~(u16)(OFFSET_UNITS - 1)
In that expression the cast to u16 is a no-op because we cast the value 15 to a u16 but then type promotion rules automatically cast it back to an int and then we do the bitwise negate.
It's cleaner to use the kernel's ALIGN() macro instead.
---
I think this patch is correct, but I haven't tested it, so please review carefully.
drivers/net/ethernet/freescale/fman/fman_sp.c +1 -5
@@ -92,11 +92,8 @@ int fman_sp_build_buffer_struct(struct fman_sp_int_context_data_copy *u32 tmp;/* Align start of internal context data to 16 byte */ - int_context_data_copy->ext_buf_offset = (u16) - ((buffer_prefix_content->priv_data_size & (OFFSET_UNITS -1 )) ? - ((buffer_prefix_content->priv_data_size +OFFSET_UNITS ) & - ~(u16)(OFFSET_UNITS -1 )) : - buffer_prefix_content->priv_data_size); + int_context_data_copy->ext_buf_offset + (u16 )ALIGN (buffer_prefix_content->priv_data_size,16 );/* Translate margin and int_context params to FM parameters */ /* Initialize with illegal value. Later we'll set legal values. */
David Miller
maintainerFrom: Dan Carpenter <[email protected]>
Date: Wed, 6 Jan 2016 13:03:08 +0300
Quoted 5 lines
drivers/net/ethernet/freescale/fman/fman_sp.c +0
-0
drivers/net/ethernet/freescale/fman/fman_sp.c int fman_sp_build_buffer_struct(struct fman_sp_int_context_data_copy * · line 95
Quoted 9 lines
drivers/net/ethernet/freescale/fman/fman_sp.c +1
-5@@ -92,11 +92,8 @@ int fman_sp_build_buffer_struct(struct fman_sp_int_context_data_copy *u32 tmp;/* Align start of internal context data to 16 byte */ - int_context_data_copy->ext_buf_offset = (u16) - ((buffer_prefix_content->priv_data_size & (OFFSET_UNITS -1 )) ? - ((buffer_prefix_content->priv_data_size +OFFSET_UNITS ) & - ~(u16)(OFFSET_UNITS -1 )) : - buffer_prefix_content->priv_data_size); + int_context_data_copy->ext_buf_offset > + (u16 )ALIGN (buffer_prefix_content->priv_data_size,16 );
Why are you using '16' instead of OFFSET_UNITS?
Unless you can come up with a good reason, please use OFFSET_UNITS instead of a magic constant.
Thanks!
Quoted 10 lines · David Miller
From: Dan Carpenter <[email protected]>
Date: Wed, 6 Jan 2016 13:03:08 +0300Quoted 7 lines
drivers/net/ethernet/freescale/fman/fman_sp.c +0
-0@@ -92,11 +92,8 @@ int fman_sp_build_buffer_struct(struct fman_sp_int_context_data_copy *u32 tmp;
Quoted 9 lines
drivers/net/ethernet/freescale/fman/fman_sp.c int fman_sp_build_buffer_struct(struct fman_sp_int_context_data_copy *
Quoted 7 lines
drivers/net/ethernet/freescale/fman/fman_sp.c +1
-5/* Align start of internal context data to 16 byte */ - int_context_data_copy->ext_buf_offset = (u16) - ((buffer_prefix_content->priv_data_size & (OFFSET_UNITS -1 )) ? - ((buffer_prefix_content->priv_data_size +OFFSET_UNITS ) & - ~(u16)(OFFSET_UNITS -1 )) : - buffer_prefix_content->priv_data_size); + int_context_data_copy->ext_buf_offset > > + (u16)ALIGN(buffer_prefix_content->priv_data_size, 16);Why are you using '16' instead of
OFFSET_UNITS?
I made a brain fart. :/ I'll resend. Thanks.
regards,
dan carpenter