Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fc00721e authored by Sravankumar bijili's avatar Sravankumar bijili
Browse files

msm: kgsl: Fix NULL pointer dereference of of_match_device()



There is a posibility that of_match_device() can return NULL
and can be dereferenced. To avoid this, a safety check is added
in adreno_probe() and adreno_remove().

Change-Id: I7fb68db3cd4f898d87d07f2434fb7c9ce2f4e7e5
Signed-off-by: default avatarSravankumar bijili <csbijil@codeaurora.org>
parent 8ca6d749
Loading
Loading
Loading
Loading
+22 −9
Original line number Diff line number Diff line
@@ -1310,12 +1310,18 @@ static int adreno_read_speed_bin(struct platform_device *pdev,

static int adreno_probe(struct platform_device *pdev)
{
	const struct of_device_id *of_id =
		of_match_device(adreno_match_table, &pdev->dev);
	struct adreno_device *adreno_dev = (struct adreno_device *) of_id->data;
	struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
	const struct of_device_id *of_id;
	struct adreno_device *adreno_dev;
	struct kgsl_device *device;
	int status;

	of_id = of_match_device(adreno_match_table, &pdev->dev);
	if (!of_id)
		return -EINVAL;

	adreno_dev = (struct adreno_device *) of_id->data;
	device = KGSL_DEVICE(adreno_dev);

	device->pdev = pdev;

	if (adreno_is_gpu_disabled(adreno_dev)) {
@@ -1473,11 +1479,18 @@ static void _adreno_free_memories(struct adreno_device *adreno_dev)

static int adreno_remove(struct platform_device *pdev)
{
	const struct of_device_id *of_id =
		of_match_device(adreno_match_table, &pdev->dev);
	struct adreno_device *adreno_dev = (struct adreno_device *) of_id->data;
	struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
	struct adreno_gpudev *gpudev = ADRENO_GPU_DEVICE(adreno_dev);
	const struct of_device_id *of_id;
	struct adreno_device *adreno_dev;
	struct kgsl_device *device;
	struct adreno_gpudev *gpudev;

	of_id = of_match_device(adreno_match_table, &pdev->dev);
	if (!of_id)
		return -EINVAL;

	adreno_dev = (struct adreno_device *) of_id->data;
	device = KGSL_DEVICE(adreno_dev);
	gpudev = ADRENO_GPU_DEVICE(adreno_dev);

	if (gpudev->remove != NULL)
		gpudev->remove(adreno_dev);