diff mbox series

[1/2] perf/smmuv3: Validate group size

Message ID 7108cdcc6fdce8dd1cfd869849bd78d05bac870f.1564580090.git.robin.murphy@arm.com (mailing list archive)
State New, archived
Headers show
Series [1/2] perf/smmuv3: Validate group size | expand

Commit Message

Robin Murphy July 31, 2019, 1:37 p.m. UTC
Ensure that a group will actually fit into the available counters.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
---
 drivers/perf/arm_smmuv3_pmu.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Will Deacon Aug. 1, 2019, 11:32 a.m. UTC | #1
On Wed, Jul 31, 2019 at 02:37:41PM +0100, Robin Murphy wrote:
> Ensure that a group will actually fit into the available counters.
> 
> Signed-off-by: Robin Murphy <robin.murphy@arm.com>
> ---
>  drivers/perf/arm_smmuv3_pmu.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/perf/arm_smmuv3_pmu.c b/drivers/perf/arm_smmuv3_pmu.c
> index da71c741cb46..dd40df2ac895 100644
> --- a/drivers/perf/arm_smmuv3_pmu.c
> +++ b/drivers/perf/arm_smmuv3_pmu.c
> @@ -323,6 +323,7 @@ static int smmu_pmu_event_init(struct perf_event *event)
>  	struct smmu_pmu *smmu_pmu = to_smmu_pmu(event->pmu);
>  	struct device *dev = smmu_pmu->dev;
>  	struct perf_event *sibling;
> +	int group_num_events = 1;
>  	u16 event_id;
>  
>  	if (event->attr.type != event->pmu->type)
> @@ -359,6 +360,9 @@ static int smmu_pmu_event_init(struct perf_event *event)
>  			dev_dbg(dev, "Can't create mixed PMU group\n");
>  			return -EINVAL;
>  		}
> +
> +		if (++group_num_events >= smmu_pmu->num_counters)
> +			return -EINVAL;

Did you forget to update the condition when you changed your mind about the
count?

;)

Will
diff mbox series

Patch

diff --git a/drivers/perf/arm_smmuv3_pmu.c b/drivers/perf/arm_smmuv3_pmu.c
index da71c741cb46..dd40df2ac895 100644
--- a/drivers/perf/arm_smmuv3_pmu.c
+++ b/drivers/perf/arm_smmuv3_pmu.c
@@ -323,6 +323,7 @@  static int smmu_pmu_event_init(struct perf_event *event)
 	struct smmu_pmu *smmu_pmu = to_smmu_pmu(event->pmu);
 	struct device *dev = smmu_pmu->dev;
 	struct perf_event *sibling;
+	int group_num_events = 1;
 	u16 event_id;
 
 	if (event->attr.type != event->pmu->type)
@@ -359,6 +360,9 @@  static int smmu_pmu_event_init(struct perf_event *event)
 			dev_dbg(dev, "Can't create mixed PMU group\n");
 			return -EINVAL;
 		}
+
+		if (++group_num_events >= smmu_pmu->num_counters)
+			return -EINVAL;
 	}
 
 	hwc->idx = -1;