diff mbox

[net-next,1/4] netlink: fix test alignment in nla_align_64bit()

Message ID 1461142655-5067-2-git-send-email-nicolas.dichtel@6wind.com
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Nicolas Dichtel April 20, 2016, 8:57 a.m. UTC
IS_ALIGN() returns true when the alignment is as expected. The pad
attribute should be added only when the alignment is not 8.

Fixes: 35c5845957c7 ("net: Add helpers for 64-bit aligning netlink attributes.")
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
 include/net/netlink.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Eric Dumazet April 20, 2016, 9:33 a.m. UTC | #1
On Wed, 2016-04-20 at 10:57 +0200, Nicolas Dichtel wrote:
> IS_ALIGN() returns true when the alignment is as expected. The pad
> attribute should be added only when the alignment is not 8.
> 
> Fixes: 35c5845957c7 ("net: Add helpers for 64-bit aligning netlink attributes.")
> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
> ---
>  include/net/netlink.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/net/netlink.h b/include/net/netlink.h
> index e644b3489acf..694caac31d2c 100644
> --- a/include/net/netlink.h
> +++ b/include/net/netlink.h
> @@ -1245,7 +1245,7 @@ static inline int nla_validate_nested(const struct nlattr *start, int maxtype,
>  static inline int nla_align_64bit(struct sk_buff *skb, int padattr)
>  {
>  #ifndef HAVE_EFFICIENT_UNALIGNED_ACCESS
> -	if (IS_ALIGNED((unsigned long)skb->data, 8)) {
> +	if (!IS_ALIGNED((unsigned long)skb->data, 8)) {
>  		struct nlattr *attr = nla_reserve(skb, padattr, 0);
>  		if (!attr)
>  			return -EMSGSIZE;

This is silly.

How have you tested your patch exactly ?

I guess David should have copied his original comment here.

-        * The nlattr header is 4 bytes in size, that's why we test
-        * if the skb->data _is_ aligned.  This NOP attribute, plus
-        * nlattr header for IFLA_STATS64, will make nla_data() 8-byte
-        * aligned.
Nicolas Dichtel April 20, 2016, 9:44 a.m. UTC | #2
Le 20/04/2016 11:33, Eric Dumazet a écrit :
[snip]
> How have you tested your patch exactly ?
As stated in the cover letter, I didn't test it.

>
> I guess David should have copied his original comment here.
>
> -        * The nlattr header is 4 bytes in size, that's why we test
> -        * if the skb->data _is_ aligned.  This NOP attribute, plus
> -        * nlattr header for IFLA_STATS64, will make nla_data() 8-byte
> -        * aligned.
>
>
I knew I was missing something, thanks for the explanation.

All other patches of this series need to be updated, I will do it if there is
no other comment.
diff mbox

Patch

diff --git a/include/net/netlink.h b/include/net/netlink.h
index e644b3489acf..694caac31d2c 100644
--- a/include/net/netlink.h
+++ b/include/net/netlink.h
@@ -1245,7 +1245,7 @@  static inline int nla_validate_nested(const struct nlattr *start, int maxtype,
 static inline int nla_align_64bit(struct sk_buff *skb, int padattr)
 {
 #ifndef HAVE_EFFICIENT_UNALIGNED_ACCESS
-	if (IS_ALIGNED((unsigned long)skb->data, 8)) {
+	if (!IS_ALIGNED((unsigned long)skb->data, 8)) {
 		struct nlattr *attr = nla_reserve(skb, padattr, 0);
 		if (!attr)
 			return -EMSGSIZE;