[PATCH 4/4] perf/smmuv3: fix crash when platdata not specified
Robin Murphy
robin.murphy at arm.com
Mon Jul 13 05:46:06 EDT 2020
On 2020-07-12 17:33, Ajay Kumar wrote:
> The arm_smmuv3_pmu driver assumes platform data is always
> available and exposes a possible NULL pointer deferencing
> at the below line.
>
> model = *(u32 *)dev_get_platdata(smmu_pmu->dev);
>
> This patch fixes the bug by adding a check prior to the
> deferencing of the platform data pointer.
>
> Signed-off-by: Ajay Kumar <ajaykumar.rs at samsung.com>
> ---
> drivers/perf/arm_smmuv3_pmu.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/perf/arm_smmuv3_pmu.c b/drivers/perf/arm_smmuv3_pmu.c
> index 25feab718c20..f7a27ae2f8d8 100644
> --- a/drivers/perf/arm_smmuv3_pmu.c
> +++ b/drivers/perf/arm_smmuv3_pmu.c
> @@ -710,9 +710,10 @@ static void smmu_pmu_reset(struct smmu_pmu *smmu_pmu)
>
> static void smmu_pmu_get_acpi_options(struct smmu_pmu *smmu_pmu)
> {
> - u32 model;
> + u32 model = 0;
>
> - model = *(u32 *)dev_get_platdata(smmu_pmu->dev);
> + if (dev_get_platdata(smmu_pmu->dev))
> + model = *(u32 *)dev_get_platdata(smmu_pmu->dev);
As I commented on the other series, ideally this could be something like:
if (dev->of_node)
model = of_device_get_match_data(dev->of_node);
else
model = *(u32 *)dev_get_platdata(dev); /* from IORT */
(and lose the "acpi_" from the function name, obviously)
Robin.
>
> switch (model) {
> case IORT_SMMU_V3_PMCG_HISI_HIP08:
>
More information about the linux-arm-kernel
mailing list