drm: xlnx: zynqmp: Stop the loop at lowest link rate without check
Subsystems (4)
PATCH 1/1 drm: xlnx: zynqmp: Stop the loop at lowest link rate without check
The loop should exit at the lowest link rate, so break the loop at the lowest link rate without check. The check is always true because lowest link rate is smaller than current one and maximum of current display. Otherwise, it may be seen as the loop can potentially result in negative array offset.
The patch d76271d22694: "drm: xlnx: DRM/KMS driver for Xilinx ZynqMP DisplayPort Subsystem" from Jul 7, 2018, leads to the following static checker warning:
drivers/gpu/drm/xlnx/zynqmp_dp.c:594 zynqmp_dp_mode_configure()
error: iterator underflow 'bws' (-1)-2
--- drivers/gpu/drm/xlnx/zynqmp_dp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/xlnx/zynqmp_dp.c +1 -1
@@ -579,7 +579,7 @@ static int zynqmp_dp_mode_configure(struct zynqmp_dp *dp, int pclock,return -EINVAL ; } -for (i =ARRAY_SIZE (bws) -1 ; i >=0 ; i--) { +for (i =ARRAY_SIZE (bws) -1 ; i >0 ; i--) {if (current_bw && bws[i] >= current_bw)continue ;
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 25 lines · Hyun Kwon
The loop should exit at the lowest link rate, so break the loop at the lowest link rate without check. The check is always true because lowest link rate is smaller than current one and maximum of current display. Otherwise, it may be seen as the loop can potentially result in negative array offset.
The patch
d76271d22694: "drm: xlnx: DRM/KMS driver for Xilinx ZynqMP DisplayPort Subsystem" from Jul 7, 2018, leads to the following static checker warning:
drivers/gpu/drm/xlnx/zynqmp_dp.c:594zynqmp_dp_mode_configure()
error: iterator underflow 'bws' (-1)-2Reported-by Dan Carpenter <[email protected]>Signed-off-by Hyun Kwon <[email protected]>--- drivers/gpu/drm/xlnx/zynqmp_dp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/xlnx/zynqmp_dp.c +0
-0
drivers/gpu/drm/xlnx/zynqmp_dp.c static int zynqmp_dp_mode_configure(struct zynqmp_dp *dp, int pclock, · line 582
Quoted 5 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c +1
-1@@ -579,7 +579,7 @@ static int zynqmp_dp_mode_configure(struct zynqmp_dp *dp, int pclock,return -EINVAL ; } -for (i =ARRAY_SIZE (bws) -1 ; i >=0 ; i--) { +for (i =ARRAY_SIZE (bws) -1 ; i >0 ; i--) {
But now we don't go through the lowest element anymore, which also looks wrong. Or I'm blind.
I think the problem is later on that we should bail out of the loop on the last iteration (when i == 0) before we decrement, since otherwise we then look at bws[-1] in the next loop, which is clearly wrong. I guess your code results in the same, but it's very confusing logic for me ...
-Daniel
Quoted 10 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c +0
-1if (current_bw && bws[i] >= current_bw)continue ; --2.7.4
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Hi Daniel,
Thanks for the review.
Quoted 29 lines · Daniel Vetter
Quoted 28 lines · Hyun Kwon
The loop should exit at the lowest link rate, so break the loop at the lowest link rate without check. The check is always true because lowest link rate is smaller than current one and maximum of current display. Otherwise, it may be seen as the loop can potentially result in negative array offset.
The patch
d76271d22694: "drm: xlnx: DRM/KMS driver for Xilinx ZynqMP DisplayPort Subsystem" from Jul 7, 2018, leads to the following static checker warning:
drivers/gpu/drm/xlnx/zynqmp_dp.c:594zynqmp_dp_mode_configure()
error: iterator underflow 'bws' (-1)-2Reported-by Dan Carpenter <[email protected]>Signed-off-by Hyun Kwon <[email protected]>--- drivers/gpu/drm/xlnx/zynqmp_dp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/xlnx/zynqmp_dp.c +0
-0@@ -579,7 +579,7 @@ static int zynqmp_dp_mode_configure(struct zynqmp_dp *dp, int pclock,return -EINVAL ; }
Quoted 6 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c static int zynqmp_dp_mode_configure(struct zynqmp_dp *dp, int pclock, · line 582
Quoted 2 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c +1
-1-for (i =ARRAY_SIZE (bws) -1 ; i >=0 ; i--) { +for (i =ARRAY_SIZE (bws) -1 ; i >0 ; i--) {But now we don't go through the lowest element anymore, which also looks wrong. Or I'm blind.
Currently, the lowest element always breaks without decrement by the check of the loop.
Quoted 5 lines
I think the problem is later on that we should bail out of the loop on the last iteration (when i == 0) before we decrement, since otherwise we then look at bws[-1] in the next loop, which is clearly wrong. I guess your code results in the same, but it's very confusing logic for me ...
Indeed. I can convert the for loop into switch - case in v2. Hope it makes less confusing. :)
Thanks,
-hyun
Quoted 5 lines
-Daniel
Quoted 3 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c +0
-0if (current_bw && bws[i] >= current_bw)continue ;
Quoted 14 lines
Quoted 7 lines
--
2.7.4_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-develSignature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel