[PATCH next] drm/fsl-dcu: prevent error pointer dereference in fsl_dcu_load()

Dan Carpenter posted 1 patch 1 month ago
drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH next] drm/fsl-dcu: prevent error pointer dereference in fsl_dcu_load()
Posted by Dan Carpenter 1 month ago
The syscon_regmap_lookup_by_compatible() function returns -ENODEV if
there isn't a compatible for it or other error pointers on error.  This
code only checks for -ENODEV instead of checking for other errors so it
could lead to an error pointer dereference inside the regmap_update_bits()
function.

Fixes: ffcde9e44d3e ("drm: fsl-dcu: enable PIXCLK on LS1021A")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c
index 91a48d774cf7..5997d9b4a431 100644
--- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c
+++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c
@@ -109,7 +109,9 @@ static int fsl_dcu_load(struct drm_device *dev, unsigned long flags)
 		return dev_err_probe(dev->dev, ret, "failed to initialize mode setting\n");
 
 	scfg = syscon_regmap_lookup_by_compatible("fsl,ls1021a-scfg");
-	if (PTR_ERR(scfg) != -ENODEV) {
+	if (IS_ERR(scfg) && PTR_ERR(scfg) != -ENODEV)
+		return dev_err_probe(dev->dev, PTR_ERR(scfg), "failed to find regmap\n");
+	if (!IS_ERR(scfg)) {
 		/*
 		 * For simplicity, enable the PIXCLK unconditionally,
 		 * resulting in increased power consumption. Disabling
-- 
2.45.2
Re: [PATCH next] drm/fsl-dcu: prevent error pointer dereference in fsl_dcu_load()
Posted by Matthias Schiffer 1 month ago
On Wed, 2024-10-23 at 11:35 +0300, Dan Carpenter wrote:
> 
> The syscon_regmap_lookup_by_compatible() function returns -ENODEV if
> there isn't a compatible for it or other error pointers on error.  This
> code only checks for -ENODEV instead of checking for other errors so it
> could lead to an error pointer dereference inside the regmap_update_bits()
> function.
> 
> Fixes: ffcde9e44d3e ("drm: fsl-dcu: enable PIXCLK on LS1021A")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

Reviewed-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>



> ---
>  drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c
> index 91a48d774cf7..5997d9b4a431 100644
> --- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c
> +++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c
> @@ -109,7 +109,9 @@ static int fsl_dcu_load(struct drm_device *dev, unsigned long flags)
>  		return dev_err_probe(dev->dev, ret, "failed to initialize mode setting\n");
>  
>  	scfg = syscon_regmap_lookup_by_compatible("fsl,ls1021a-scfg");
> -	if (PTR_ERR(scfg) != -ENODEV) {
> +	if (IS_ERR(scfg) && PTR_ERR(scfg) != -ENODEV)
> +		return dev_err_probe(dev->dev, PTR_ERR(scfg), "failed to find regmap\n");
> +	if (!IS_ERR(scfg)) {
>  		/*
>  		 * For simplicity, enable the PIXCLK unconditionally,
>  		 * resulting in increased power consumption. Disabling

-- 
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
https://www.tq-group.com/