mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 12:43:29 +02:00
netlink: introduce bigendian integer types
Jakub reported that the addition of the "network_byte_order"
member in struct nla_policy increases size of 32bit platforms.
Instead of scraping the bit from elsewhere Johannes suggested
to add explicit NLA_BE types instead, so do this here.
NLA_POLICY_MAX_BE() macro is removed again, there is no need
for it: NLA_POLICY_MAX(NLA_BE.., ..) will do the right thing.
NLA_BE64 can be added later.
Fixes: 08724ef699
("netlink: introduce NLA_POLICY_MAX_BE")
Reported-by: Jakub Kicinski <kuba@kernel.org>
Suggested-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: Florian Westphal <fw@strlen.de>
Link: https://lore.kernel.org/r/20221031123407.9158-1-fw@strlen.de
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
committed by
Jakub Kicinski
parent
fc57062f98
commit
ecaf75ffd5
41
lib/nlattr.c
41
lib/nlattr.c
@@ -124,10 +124,12 @@ void nla_get_range_unsigned(const struct nla_policy *pt,
|
||||
range->max = U8_MAX;
|
||||
break;
|
||||
case NLA_U16:
|
||||
case NLA_BE16:
|
||||
case NLA_BINARY:
|
||||
range->max = U16_MAX;
|
||||
break;
|
||||
case NLA_U32:
|
||||
case NLA_BE32:
|
||||
range->max = U32_MAX;
|
||||
break;
|
||||
case NLA_U64:
|
||||
@@ -159,31 +161,6 @@ void nla_get_range_unsigned(const struct nla_policy *pt,
|
||||
}
|
||||
}
|
||||
|
||||
static u64 nla_get_attr_bo(const struct nla_policy *pt,
|
||||
const struct nlattr *nla)
|
||||
{
|
||||
switch (pt->type) {
|
||||
case NLA_U16:
|
||||
if (pt->network_byte_order)
|
||||
return ntohs(nla_get_be16(nla));
|
||||
|
||||
return nla_get_u16(nla);
|
||||
case NLA_U32:
|
||||
if (pt->network_byte_order)
|
||||
return ntohl(nla_get_be32(nla));
|
||||
|
||||
return nla_get_u32(nla);
|
||||
case NLA_U64:
|
||||
if (pt->network_byte_order)
|
||||
return be64_to_cpu(nla_get_be64(nla));
|
||||
|
||||
return nla_get_u64(nla);
|
||||
}
|
||||
|
||||
WARN_ON_ONCE(1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int nla_validate_range_unsigned(const struct nla_policy *pt,
|
||||
const struct nlattr *nla,
|
||||
struct netlink_ext_ack *extack,
|
||||
@@ -197,9 +174,13 @@ static int nla_validate_range_unsigned(const struct nla_policy *pt,
|
||||
value = nla_get_u8(nla);
|
||||
break;
|
||||
case NLA_U16:
|
||||
value = nla_get_u16(nla);
|
||||
break;
|
||||
case NLA_U32:
|
||||
value = nla_get_u32(nla);
|
||||
break;
|
||||
case NLA_U64:
|
||||
value = nla_get_attr_bo(pt, nla);
|
||||
value = nla_get_u64(nla);
|
||||
break;
|
||||
case NLA_MSECS:
|
||||
value = nla_get_u64(nla);
|
||||
@@ -207,6 +188,12 @@ static int nla_validate_range_unsigned(const struct nla_policy *pt,
|
||||
case NLA_BINARY:
|
||||
value = nla_len(nla);
|
||||
break;
|
||||
case NLA_BE16:
|
||||
value = ntohs(nla_get_be16(nla));
|
||||
break;
|
||||
case NLA_BE32:
|
||||
value = ntohl(nla_get_be32(nla));
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -334,6 +321,8 @@ static int nla_validate_int_range(const struct nla_policy *pt,
|
||||
case NLA_U64:
|
||||
case NLA_MSECS:
|
||||
case NLA_BINARY:
|
||||
case NLA_BE16:
|
||||
case NLA_BE32:
|
||||
return nla_validate_range_unsigned(pt, nla, extack, validate);
|
||||
case NLA_S8:
|
||||
case NLA_S16:
|
||||
|
Reference in New Issue
Block a user