Skip to content

Commit

Permalink
netlink: make range pointers in policies const
Browse files Browse the repository at this point in the history
struct nla_policy is usually constant itself, but unless
we make the ranges inside constant we won't be able to
make range structs const. The ranges are not modified
by the core.

Reviewed-by: Johannes Berg <johannes@sipsolutions.net>
Reviewed-by: David Ahern <dsahern@kernel.org>
Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Link: https://lore.kernel.org/r/20231025162204.132528-1-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed Oct 26, 2023
1 parent 5af8d8c commit ea23fbd
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion drivers/net/bonding/bond_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static int bond_fill_slave_info(struct sk_buff *skb,
}

/* Limit the max delay range to 300s */
static struct netlink_range_validation delay_range = {
static const struct netlink_range_validation delay_range = {
.max = 300000,
};

Expand Down
2 changes: 1 addition & 1 deletion drivers/net/vxlan/vxlan_mdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ vxlan_mdbe_src_list_pol[MDBE_SRC_LIST_MAX + 1] = {
[MDBE_SRC_LIST_ENTRY] = NLA_POLICY_NESTED(vxlan_mdbe_src_list_entry_pol),
};

static struct netlink_range_validation vni_range = {
static const struct netlink_range_validation vni_range = {
.max = VXLAN_N_VID - 1,
};

Expand Down
4 changes: 2 additions & 2 deletions include/net/netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ struct nla_policy {
const u32 mask;
const char *reject_message;
const struct nla_policy *nested_policy;
struct netlink_range_validation *range;
struct netlink_range_validation_signed *range_signed;
const struct netlink_range_validation *range;
const struct netlink_range_validation_signed *range_signed;
struct {
s16 min, max;
};
Expand Down
2 changes: 1 addition & 1 deletion net/ipv6/ioam6_iptunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct ioam6_lwt {
struct ioam6_lwt_encap tuninfo;
};

static struct netlink_range_validation freq_range = {
static const struct netlink_range_validation freq_range = {
.min = IOAM6_IPTUNNEL_FREQ_MIN,
.max = IOAM6_IPTUNNEL_FREQ_MAX,
};
Expand Down
2 changes: 1 addition & 1 deletion net/sched/sch_fq.c
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ static int fq_resize(struct Qdisc *sch, u32 log)
return 0;
}

static struct netlink_range_validation iq_range = {
static const struct netlink_range_validation iq_range = {
.max = INT_MAX,
};

Expand Down
2 changes: 1 addition & 1 deletion net/sched/sch_fq_pie.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ static int fq_pie_qdisc_enqueue(struct sk_buff *skb, struct Qdisc *sch,
return NET_XMIT_CN;
}

static struct netlink_range_validation fq_pie_q_range = {
static const struct netlink_range_validation fq_pie_q_range = {
.min = 1,
.max = 1 << 20,
};
Expand Down
2 changes: 1 addition & 1 deletion net/sched/sch_qfq.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ static struct qfq_class *qfq_find_class(struct Qdisc *sch, u32 classid)
return container_of(clc, struct qfq_class, common);
}

static struct netlink_range_validation lmax_range = {
static const struct netlink_range_validation lmax_range = {
.min = QFQ_MIN_LMAX,
.max = QFQ_MAX_LMAX,
};
Expand Down
2 changes: 1 addition & 1 deletion net/sched/sch_taprio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ static const struct nla_policy taprio_tc_policy[TCA_TAPRIO_TC_ENTRY_MAX + 1] = {
TC_FP_PREEMPTIBLE),
};

static struct netlink_range_validation_signed taprio_cycle_time_range = {
static const struct netlink_range_validation_signed taprio_cycle_time_range = {
.min = 0,
.max = INT_MAX,
};
Expand Down
2 changes: 1 addition & 1 deletion net/wireless/nl80211.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
[NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
};

static struct netlink_range_validation nl80211_punct_bitmap_range = {
static const struct netlink_range_validation nl80211_punct_bitmap_range = {
.min = 0,
.max = 0xffff,
};
Expand Down
2 changes: 1 addition & 1 deletion tools/net/ynl/ynl-gen-c.py
Original file line number Diff line number Diff line change
Expand Up @@ -2038,7 +2038,7 @@ def print_kernel_policy_ranges(family, cw):
first = False

sign = '' if attr.type[0] == 'u' else '_signed'
cw.block_start(line=f'struct netlink_range_validation{sign} {c_lower(attr.enum_name)}_range =')
cw.block_start(line=f'static const struct netlink_range_validation{sign} {c_lower(attr.enum_name)}_range =')
members = []
if 'min' in attr.checks:
members.append(('min', attr.get_limit('min')))
Expand Down

0 comments on commit ea23fbd

Please sign in to comment.