Message ID | 2aabebd619b65416a6cd2ca7058ca85fa3656958.1723229941.git.robin.murphy@arm.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | perf/arm-cmn: Fixes and updates | expand |
On Fri, Aug 09, 2024 at 08:15:43PM +0100, Robin Murphy wrote: > These days we can use static_assert() in the logical place rather than > jamming a BUILD_BUG_ON() into the nearest function scope. And since it > is now so convenient to do so, let's add an extra one to reinforce the > dtm_idx bitmap as well. > > Signed-off-by: Robin Murphy <robin.murphy@arm.com> > --- > drivers/perf/arm-cmn.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/perf/arm-cmn.c b/drivers/perf/arm-cmn.c > index c9a2b21a7aec..8f7a1a6f8ab7 100644 > --- a/drivers/perf/arm-cmn.c > +++ b/drivers/perf/arm-cmn.c > @@ -577,6 +577,9 @@ struct arm_cmn_hw_event { > bool wide_sel; > enum cmn_filter_select filter_sel; > }; > +static_assert(sizeof(struct arm_cmn_hw_event) <= offsetof(struct hw_perf_event, target)); Moving this out seems fine. > +/* Currently XPs are the node type we can have most of; others top out at 128 */ > +static_assert(sizeof_field(struct arm_cmn_hw_event, dtm_idx) >= CMN_MAX_XPS / 4); I reckon we can make this true by construction (as on the last patch), and avoid the need for the assert entirely. Mark. > > #define for_each_hw_dn(hw, dn, i) \ > for (i = 0, dn = hw->dn; i < hw->num_dns; i++, dn++) > @@ -587,7 +590,6 @@ struct arm_cmn_hw_event { > > static struct arm_cmn_hw_event *to_cmn_hw(struct perf_event *event) > { > - BUILD_BUG_ON(sizeof(struct arm_cmn_hw_event) > offsetof(struct hw_perf_event, target)); > return (struct arm_cmn_hw_event *)&event->hw; > } > > -- > 2.39.2.101.g768bb238c484.dirty >
diff --git a/drivers/perf/arm-cmn.c b/drivers/perf/arm-cmn.c index c9a2b21a7aec..8f7a1a6f8ab7 100644 --- a/drivers/perf/arm-cmn.c +++ b/drivers/perf/arm-cmn.c @@ -577,6 +577,9 @@ struct arm_cmn_hw_event { bool wide_sel; enum cmn_filter_select filter_sel; }; +static_assert(sizeof(struct arm_cmn_hw_event) <= offsetof(struct hw_perf_event, target)); +/* Currently XPs are the node type we can have most of; others top out at 128 */ +static_assert(sizeof_field(struct arm_cmn_hw_event, dtm_idx) >= CMN_MAX_XPS / 4); #define for_each_hw_dn(hw, dn, i) \ for (i = 0, dn = hw->dn; i < hw->num_dns; i++, dn++) @@ -587,7 +590,6 @@ struct arm_cmn_hw_event { static struct arm_cmn_hw_event *to_cmn_hw(struct perf_event *event) { - BUILD_BUG_ON(sizeof(struct arm_cmn_hw_event) > offsetof(struct hw_perf_event, target)); return (struct arm_cmn_hw_event *)&event->hw; }
These days we can use static_assert() in the logical place rather than jamming a BUILD_BUG_ON() into the nearest function scope. And since it is now so convenient to do so, let's add an extra one to reinforce the dtm_idx bitmap as well. Signed-off-by: Robin Murphy <robin.murphy@arm.com> --- drivers/perf/arm-cmn.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)