netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch -next] fsl/fman: use the ALIGN() macro
@ 2016-01-06 10:03 Dan Carpenter
  2016-01-06 20:27 ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2016-01-06 10:03 UTC (permalink / raw)
  To: Igal Liberman; +Cc: netdev, kernel-janitors, David S. Miller

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.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
I think this patch is correct, but I haven't tested it, so please review
carefully.

diff --git a/drivers/net/ethernet/freescale/fman/fman_sp.c b/drivers/net/ethernet/freescale/fman/fman_sp.c
index f9e7aa3..b527da1 100644
--- a/drivers/net/ethernet/freescale/fman/fman_sp.c
+++ b/drivers/net/ethernet/freescale/fman/fman_sp.c
@@ -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. */

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [patch -next] fsl/fman: use the ALIGN() macro
  2016-01-06 10:03 [patch -next] fsl/fman: use the ALIGN() macro Dan Carpenter
@ 2016-01-06 20:27 ` David Miller
  2016-01-06 20:35   ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: David Miller @ 2016-01-06 20:27 UTC (permalink / raw)
  To: dan.carpenter; +Cc: igal.liberman, netdev, kernel-janitors

From: Dan Carpenter <dan.carpenter@oracle.com>
Date: Wed, 6 Jan 2016 13:03:08 +0300

> diff --git a/drivers/net/ethernet/freescale/fman/fman_sp.c b/drivers/net/ethernet/freescale/fman/fman_sp.c
> index f9e7aa3..b527da1 100644
> --- a/drivers/net/ethernet/freescale/fman/fman_sp.c
> +++ b/drivers/net/ethernet/freescale/fman/fman_sp.c
> @@ -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!

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch -next] fsl/fman: use the ALIGN() macro
  2016-01-06 20:27 ` David Miller
@ 2016-01-06 20:35   ` Dan Carpenter
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2016-01-06 20:35 UTC (permalink / raw)
  To: David Miller; +Cc: igal.liberman, netdev, kernel-janitors

On Wed, Jan 06, 2016 at 03:27:38PM -0500, David Miller wrote:
> From: Dan Carpenter <dan.carpenter@oracle.com>
> Date: Wed, 6 Jan 2016 13:03:08 +0300
> 
> > diff --git a/drivers/net/ethernet/freescale/fman/fman_sp.c b/drivers/net/ethernet/freescale/fman/fman_sp.c
> > index f9e7aa3..b527da1 100644
> > --- a/drivers/net/ethernet/freescale/fman/fman_sp.c
> > +++ b/drivers/net/ethernet/freescale/fman/fman_sp.c
> > @@ -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?

I made a brain fart.  :/  I'll resend.  Thanks.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-01-06 20:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-06 10:03 [patch -next] fsl/fman: use the ALIGN() macro Dan Carpenter
2016-01-06 20:27 ` David Miller
2016-01-06 20:35   ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).