Skip to content

Commit

Permalink
Merge branch 'mlxsw-annotate-structs-with-__counted_by'
Browse files Browse the repository at this point in the history
Kees Cook says:

====================
mlxsw: Annotate structs with __counted_by

This annotates several mlxsw structures with the coming __counted_by attribute
for bounds checking of flexible arrays at run-time. For more details, see
commit dd06e72 ("Compiler Attributes: Add __counted_by macro").
====================

Link: https://lore.kernel.org/r/20230929180611.work.870-kees@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed Oct 2, 2023
2 parents 6d6e40e + 18cee9d commit af54c19
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion drivers/net/ethernet/mellanox/mlxsw/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ struct mlxsw_linecards {
struct mlxsw_linecard_types_info *types_info;
struct list_head event_ops_list;
struct mutex event_ops_list_lock; /* Locks accesses to event ops list */
struct mlxsw_linecard linecards[];
struct mlxsw_linecard linecards[] __counted_by(count);
};

static inline struct mlxsw_linecard *
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ethernet/mellanox/mlxsw/core_env.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct mlxsw_env {
u8 num_of_slots; /* Including the main board. */
u8 max_eeprom_len; /* Maximum module EEPROM transaction length. */
struct mutex line_cards_lock; /* Protects line cards. */
struct mlxsw_env_line_card *line_cards[];
struct mlxsw_env_line_card *line_cards[] __counted_by(num_of_slots);
};

static bool __mlxsw_env_linecard_is_active(struct mlxsw_env *mlxsw_env,
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ethernet/mellanox/mlxsw/spectrum_cnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct mlxsw_sp_counter_pool {
spinlock_t counter_pool_lock; /* Protects counter pool allocations */
atomic_t active_entries_count;
unsigned int sub_pools_count;
struct mlxsw_sp_counter_sub_pool sub_pools[];
struct mlxsw_sp_counter_sub_pool sub_pools[] __counted_by(sub_pools_count);
};

static const struct mlxsw_sp_counter_sub_pool mlxsw_sp_counter_sub_pools[] = {
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
Original file line number Diff line number Diff line change
Expand Up @@ -3107,7 +3107,7 @@ struct mlxsw_sp_nexthop_group_info {
gateway:1, /* routes using the group use a gateway */
is_resilient:1;
struct list_head list; /* member in nh_res_grp_list */
struct mlxsw_sp_nexthop nexthops[];
struct mlxsw_sp_nexthop nexthops[] __counted_by(count);
};

static struct mlxsw_sp_rif *
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct mlxsw_sp_span {
refcount_t policer_id_base_ref_count;
atomic_t active_entries_count;
int entries_count;
struct mlxsw_sp_span_entry entries[];
struct mlxsw_sp_span_entry entries[] __counted_by(entries_count);
};

struct mlxsw_sp_span_analyzed_port {
Expand Down

0 comments on commit af54c19

Please sign in to comment.