[B/D/E,SRU,1/1] media: vimc: fix component match compare
diff mbox series

Message ID 20190814084803.7956-2-po-hsu.lin@canonical.com
State New
Headers show
Series
  • Fix for vimc null pointer dereference
Related show

Commit Message

Po-Hsu Lin Aug. 14, 2019, 8:48 a.m. UTC
From: Helen Koike <helen.koike@collabora.com>

BugLink: https://bugs.launchpad.net/bugs/1840028

If the system has other devices being registered in the component
framework, the compare function will be called with a device that
doesn't belong to vimc.
This device is not necessarily a platform_device, nor have a
platform_data (which causes a NULL pointer dereference error) and if it
does have a pdata, it is not necessarily type of struct vimc_platform_data.
So casting to any of these types is wrong.

Instead of expecting a given pdev with a given pdata, just expect for
the device it self. vimc-core is the one who creates them, we know in
advance exactly which object to expect in the match.

Fixes: 4a29b7090749 ("[media] vimc: Subdevices as modules")

Signed-off-by: Helen Koike <helen.koike@collabora.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Tested-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
(cherry picked from commit ee1c71a8e1456ab53fe667281d855849edf26a4d)
Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
---
 drivers/media/platform/vimc/vimc-core.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

Comments

Colin Ian King Aug. 14, 2019, 8:52 a.m. UTC | #1
On 14/08/2019 09:48, Po-Hsu Lin wrote:
> From: Helen Koike <helen.koike@collabora.com>
> 
> BugLink: https://bugs.launchpad.net/bugs/1840028
> 
> If the system has other devices being registered in the component
> framework, the compare function will be called with a device that
> doesn't belong to vimc.
> This device is not necessarily a platform_device, nor have a
> platform_data (which causes a NULL pointer dereference error) and if it
> does have a pdata, it is not necessarily type of struct vimc_platform_data.
> So casting to any of these types is wrong.
> 
> Instead of expecting a given pdev with a given pdata, just expect for
> the device it self. vimc-core is the one who creates them, we know in
> advance exactly which object to expect in the match.
> 
> Fixes: 4a29b7090749 ("[media] vimc: Subdevices as modules")
> 
> Signed-off-by: Helen Koike <helen.koike@collabora.com>
> Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
> Tested-by: Boris Brezillon <boris.brezillon@collabora.com>
> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
> (cherry picked from commit ee1c71a8e1456ab53fe667281d855849edf26a4d)
> Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
> ---
>  drivers/media/platform/vimc/vimc-core.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/media/platform/vimc/vimc-core.c b/drivers/media/platform/vimc/vimc-core.c
> index 64eb424..b48813e 100644
> --- a/drivers/media/platform/vimc/vimc-core.c
> +++ b/drivers/media/platform/vimc/vimc-core.c
> @@ -243,10 +243,7 @@ static void vimc_comp_unbind(struct device *master)
>  
>  static int vimc_comp_compare(struct device *comp, void *data)
>  {
> -	const struct platform_device *pdev = to_platform_device(comp);
> -	const char *name = data;
> -
> -	return !strcmp(pdev->dev.platform_data, name);
> +	return comp == data;
>  }
>  
>  static struct component_match *vimc_add_subdevs(struct vimc_device *vimc)
> @@ -276,7 +273,7 @@ static struct component_match *vimc_add_subdevs(struct vimc_device *vimc)
>  		}
>  
>  		component_match_add(&vimc->pdev.dev, &match, vimc_comp_compare,
> -				    (void *)vimc->pipe_cfg->ents[i].name);
> +				    &vimc->subdevs[i]->dev);
>  	}
>  
>  	return match;
> 
Clean cherry pick

Acked-by: Colin Ian King <colin.king@canonical.com>

Patch
diff mbox series

diff --git a/drivers/media/platform/vimc/vimc-core.c b/drivers/media/platform/vimc/vimc-core.c
index 64eb424..b48813e 100644
--- a/drivers/media/platform/vimc/vimc-core.c
+++ b/drivers/media/platform/vimc/vimc-core.c
@@ -243,10 +243,7 @@  static void vimc_comp_unbind(struct device *master)
 
 static int vimc_comp_compare(struct device *comp, void *data)
 {
-	const struct platform_device *pdev = to_platform_device(comp);
-	const char *name = data;
-
-	return !strcmp(pdev->dev.platform_data, name);
+	return comp == data;
 }
 
 static struct component_match *vimc_add_subdevs(struct vimc_device *vimc)
@@ -276,7 +273,7 @@  static struct component_match *vimc_add_subdevs(struct vimc_device *vimc)
 		}
 
 		component_match_add(&vimc->pdev.dev, &match, vimc_comp_compare,
-				    (void *)vimc->pipe_cfg->ents[i].name);
+				    &vimc->subdevs[i]->dev);
 	}
 
 	return match;