backlight: pcf50633: pdata may be a null pointer, null pointer dereference cause crash
Subsystems (2)
PATCH 1/1 backlight: pcf50633: pdata may be a null pointer, null pointer dereference cause crash
--- drivers/video/backlight/pcf50633-backlight.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/video/backlight/pcf50633-backlight.c +2 -1
@@ -127,7 +127,8 @@ static int pcf50633_bl_probe(struct platform_device *pdev)platform_set_drvdata (pdev, pcf_bl); -pcf50633_reg_write (pcf_bl->pcf,PCF50633_REG_LEDDIM , pdata->ramp_time); +if (pdata) +pcf50633_reg_write (pcf_bl->pcf,PCF50633_REG_LEDDIM , pdata->ramp_time);/* * Should be different from bl_props.brightness, so we do not exit
Signature · 1 line
2.7.4
On Mon, 01 Feb 2021, Wenjia Zhao wrote:
Please provide a suitable commit messages.
Describe the problem.
Describe the issue was found.
Describe the solution.
Quoted 10 lines
Signed-off-by Wenjia Zhao <[email protected]>--- drivers/video/backlight/pcf50633-backlight.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/video/backlight/pcf50633-backlight.c +0
-0
drivers/video/backlight/pcf50633-backlight.c static int pcf50633_bl_probe(struct platform_device *pdev) · line 131
Quoted 6 lines
drivers/video/backlight/pcf50633-backlight.c +2
-1@@ -127,7 +127,8 @@ static int pcf50633_bl_probe(struct platform_device *pdev)platform_set_drvdata (pdev, pcf_bl); -pcf50633_reg_write (pcf_bl->pcf,PCF50633_REG_LEDDIM , pdata->ramp_time); +if (pdata) +pcf50633_reg_write (pcf_bl->pcf,PCF50633_REG_LEDDIM , pdata->ramp_time);
A tab should be 8 chars in Linux.
Quoted 2 lines
drivers/video/backlight/pcf50633-backlight.c +0
-0/* * Should be different from bl_props.brightness, so we do not exit
Signature · 8 lines
Lee Jones [李琼斯] Senior Technical Lead - Developer Services Linaro.org │ Open source software for Arm SoCs Follow Linaro: Facebook | Twitter | Blog _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 1 line · Wenjia Zhao
Signed-off-by Wenjia Zhao <[email protected]>
There should be a patch description here explaining why the patch is needed and how it works.
Quoted 9 lines
--- drivers/video/backlight/pcf50633-backlight.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/video/backlight/pcf50633-backlight.c +0
-0
drivers/video/backlight/pcf50633-backlight.c static int pcf50633_bl_probe(struct platform_device *pdev) · line 131
Quoted 6 lines
drivers/video/backlight/pcf50633-backlight.c +2
-1@@ -127,7 +127,8 @@ static int pcf50633_bl_probe(struct platform_device *pdev)platform_set_drvdata (pdev, pcf_bl); -pcf50633_reg_write (pcf_bl->pcf,PCF50633_REG_LEDDIM , pdata->ramp_time); +if (pdata) +pcf50633_reg_write (pcf_bl->pcf,PCF50633_REG_LEDDIM , pdata->ramp_time);
Assuming you found this issue using a static analyzer then I think it might be better to if an "if (!pdata) return -EINVAL" further up the file instead.
In other words it is better to "document" (via the return code) that the code does not support pdata == NULL than to add another untested code path.
Daniel.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Sorry about the missing description, I have a description at my local commit. But the commit description disappeared when I used git send-email to submit this patch.
backlight: pcf50633: pdata may be a null pointer, null pointer dereference causes crash
pdata has been checked at line 120 before dereference. However, it is used without check at line 130. So just add the check,
--- drivers/video/backlight/pcf50633-backlight.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
(quoted diff) +0 -0
b/drivers/video/backlight/pcf50633-backlight.c
index 540dd338..43267af 100644
drivers/video/backlight/pcf50633-backlight.c +0 -0
@@ -127,7 +127,8 @@ static int pcf50633_bl_probe(struct platform_device
*pdev)
platform_set_drvdata(pdev, pcf_bl);
- pcf50633_reg_write(pcf_bl->pcf, PCF50633_REG_LEDDIM,pdata->ramp_time);
+ if (pdata)
+ pcf50633_reg_write(pcf_bl->pcf, PCF50633_REG_LEDDIM, pdata->ramp_time);
/*
* Should be different from bl_props.brightness, so we do not exit
--
It is better to write a default value to the register if the ramp_time has a default value. Then it does not need to return -EINVAL. It will keep consistent with the behavior at line 120.
Quoted 31 lines · Daniel Thompson <[email protected]> 于2021年2月2日周二 上午3:25写道:
Quoted 1 line · Wenjia Zhao
Signed-off-by Wenjia Zhao <[email protected]>There should be a patch description here explaining why the patch is needed and how it works.
Review
Quoted 5 lines
--- drivers/video/backlight/pcf50633-backlight.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)(quoted diff) +0
-0
b/drivers/video/backlight/pcf50633-backlight.cdrivers/video/backlight/pcf50633-backlight.c static int pcf50633_bl_probe(struct platform_device
Quoted 4 lines
index 540dd338..43267af 100644
drivers/video/backlight/pcf50633-backlight.c +0
-0@@ -127,7 +127,8 @@ static int pcf50633_bl_probe(struct platform_device*pdev)
drivers/video/backlight/pcf50633-backlight.c static int pcf50633_bl_probe(struct platform_device · line 129
Quoted 4 lines
drivers/video/backlight/pcf50633-backlight.c +0
-1platform_set_drvdata (pdev, pcf_bl); - pcf50633_reg_write(pcf_bl->pcf, PCF50633_REG_LEDDIM,
pdata->ramp_time);drivers/video/backlight/pcf50633-backlight.c static int pcf50633_bl_probe(struct platform_device · line 130
Quoted 2 lines
drivers/video/backlight/pcf50633-backlight.c +2
-0+if (pdata) + pcf50633_reg_write(pcf_bl->pcf, PCF50633_REG_LEDDIM,
pdata->ramp_time);Assuming you found this issue using a static analyzer then I think it might be better to if an "if (!pdata) return
-EINVAL" further up the file instead.
Quoted 7 lines
In other words it is better to "document" (via the return code) that the code does not support pdata == NULL than to add another untested code path.
Daniel.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 8 lines · FUZZ DR
Sorry about the missing description, I have a description at my local commit. But the commit description disappeared when I used git send-email to submit this patch.
backlight: pcf50633: pdata may be a null pointer, null pointer dereference causes crash
pdata has been checked at line 120 before dereference. However, it is used without check at line 130. So just add the check,
To be clear what your analyzer is reporting is a mismatch of programmer intent.
In line 120 suggests a belief that pdata could be NULL whilst line 130 suggests a belief that pdata is never NULL. Your analyzer cannot not tell you which belief is incorrect, only that there is a mismatch.
Quoted 3 lines
It is better to write a default value to the register if the
ramp_timehas a default value. Then it does not need to return-EINVAL. It will keep consistent with the behavior at line 120.
I disagree.
You have assumed that line 120 is correct and that this code needs to support the case where pdata is NULL. However eleven years of history disprove this! This code is never called without valid platform data.
Therefore we should fix the assumption on line 120 by making it clear that this code code expects non-NULL platform data. Given there are developers working to eliminate this kind of platform data structure (by adopting device properties instead) I don't want to make their life harder by implementing unused and untested special cases that they would have to reason about.
Daniel.
Quoted 34 lines
Quoted 31 lines · Daniel Thompson <[email protected]> 于2021年2月2日周二 上午3:25写道:
Quoted 1 line · Wenjia Zhao
Signed-off-by Wenjia Zhao <[email protected]>There should be a patch description here explaining why the patch is needed and how it works.
Review
Quoted 5 lines
--- drivers/video/backlight/pcf50633-backlight.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)(quoted diff) +0
-0
b/drivers/video/backlight/pcf50633-backlight.cdrivers/video/backlight/pcf50633-backlight.c static int pcf50633_bl_probe(struct platform_device
Quoted 4 lines
index 540dd338..43267af 100644
drivers/video/backlight/pcf50633-backlight.c +0
-0@@ -127,7 +127,8 @@ static int pcf50633_bl_probe(struct platform_device*pdev)
drivers/video/backlight/pcf50633-backlight.c static int pcf50633_bl_probe(struct platform_device · line 129
Quoted 4 lines
drivers/video/backlight/pcf50633-backlight.c +0
-1platform_set_drvdata (pdev, pcf_bl); - pcf50633_reg_write(pcf_bl->pcf, PCF50633_REG_LEDDIM,
pdata->ramp_time);drivers/video/backlight/pcf50633-backlight.c static int pcf50633_bl_probe(struct platform_device · line 130
Quoted 2 lines
drivers/video/backlight/pcf50633-backlight.c +2
-0+if (pdata) + pcf50633_reg_write(pcf_bl->pcf, PCF50633_REG_LEDDIM,
pdata->ramp_time);Assuming you found this issue using a static analyzer then I think it might be better to if an "if (!pdata) return
-EINVAL" further up the file instead.
Quoted 7 lines
Quoted 7 lines
In other words it is better to "document" (via the return code) that the code does not support pdata == NULL than to add another untested code path.
Daniel.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel