drm: xlnx: zynqmp: Use switch - case for link rate downshift
Subsystems (4)
PATCH v2 1/1 drm: xlnx: zynqmp: Use switch - case for link rate downshift
Use switch - case to downshift from the current link rate. It's a small loop now, so fine to be replaced with switch - case. With a loop, it is confusing and hard to follow as reported below.
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
---
v2
- Convert the for loop into switch - case
---
--- drivers/gpu/drm/xlnx/zynqmp_dp.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-)
drivers/gpu/drm/xlnx/zynqmp_dp.c +16 -13
@@ -567,34 +567,37 @@ static int zynqmp_dp_mode_configure(struct zynqmp_dp *dp, int pclock, u8 current_bw) {int max_rate = dp->link_config.max_rate; -u8 bws[3 ] = {DP_LINK_BW_1_62 ,DP_LINK_BW_2_7 ,DP_LINK_BW_5_4 }; +u8 bw_code;u8 max_lanes = dp->link_config.max_lanes;u8 max_link_rate_code =drm_dp_link_rate_to_bw_code (max_rate);u8 bpp = dp->config.bpp;u8 lane_cnt; -s8 i; -if (current_bw ==DP_LINK_BW_1_62 ) { +/* Downshift from current one */ +switch (current_bw) { +case DP_LINK_BW_5_4 : + bw_code =DP_LINK_BW_2_7 ; +break ; +case DP_LINK_BW_2_7 : + bw_code =DP_LINK_BW_1_62 ; +break ; +case DP_LINK_BW_1_62 :dev_err (dp->dev,"can't downshift. already lowest link rate\n" );return -EINVAL ; - } - -for (i =ARRAY_SIZE (bws) -1 ; i >=0 ; i--) { -if (current_bw && bws[i] >= current_bw) -continue ; - -if (bws[i] <= max_link_rate_code) -break ; +default : +/* If not given, start with max supported */ + bw_code = max_link_rate_code; +break ; }for (lane_cnt =1 ; lane_cnt <= max_lanes; lane_cnt <<=1 ) {int bw;u32 rate; - bw =drm_dp_bw_code_to_link_rate (bws[i]); + bw =drm_dp_bw_code_to_link_rate (bw_code); rate =zynqmp_dp_max_rate (bw, lane_cnt, bpp);if (pclock <= rate) { - dp->mode.bw_code = bws[i]; + dp->mode.bw_code = bw_code; dp->mode.lane_cnt = lane_cnt; dp->mode.pclock = pclock;return dp->mode.bw_code;
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Hi Hyun,
Thank you for the patch.
Quoted 29 lines · Hyun Kwon
Use switch - case to downshift from the current link rate. It's a small loop now, so fine to be replaced with switch - case. With a loop, it is confusing and hard to follow as reported below.
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]>---
v2
- Convert the for loop into switch - case
------ drivers/gpu/drm/xlnx/zynqmp_dp.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-)drivers/gpu/drm/xlnx/zynqmp_dp.c +0
-0@@ -567,34 +567,37 @@ static int zynqmp_dp_mode_configure(struct zynqmp_dp *dp, int pclock, u8 current_bw) {int max_rate = dp->link_config.max_rate;
drivers/gpu/drm/xlnx/zynqmp_dp.c static int zynqmp_dp_mode_configure(struct zynqmp_dp *dp, int pclock, · line 576
Quoted 10 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c +2
-3-u8 bws[3 ] = {DP_LINK_BW_1_62 ,DP_LINK_BW_2_7 ,DP_LINK_BW_5_4 }; +u8 bw_code;u8 max_lanes = dp->link_config.max_lanes;u8 max_link_rate_code =drm_dp_link_rate_to_bw_code (max_rate);u8 bpp = dp->config.bpp;u8 lane_cnt; -s8 i; -if (current_bw ==DP_LINK_BW_1_62 ) { +/* Downshift from current one */
Maybe "Downshift from the current bandwidth" ?
Quoted 37 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c +14
-10+switch (current_bw) { +case DP_LINK_BW_5_4 : + bw_code =DP_LINK_BW_2_7 ; +break ; +case DP_LINK_BW_2_7 : + bw_code =DP_LINK_BW_1_62 ; +break ; +case DP_LINK_BW_1_62 :dev_err (dp->dev,"can't downshift. already lowest link rate\n" );return -EINVAL ; - } - -for (i =ARRAY_SIZE (bws) -1 ; i >=0 ; i--) { -if (current_bw && bws[i] >= current_bw) -continue ; - -if (bws[i] <= max_link_rate_code) -break ; +default : +/* If not given, start with max supported */ + bw_code = max_link_rate_code; +break ; }for (lane_cnt =1 ; lane_cnt <= max_lanes; lane_cnt <<=1 ) {int bw;u32 rate; - bw =drm_dp_bw_code_to_link_rate (bws[i]); + bw =drm_dp_bw_code_to_link_rate (bw_code); rate =zynqmp_dp_max_rate (bw, lane_cnt, bpp);if (pclock <= rate) { - dp->mode.bw_code = bws[i]; + dp->mode.bw_code = bw_code; dp->mode.lane_cnt = lane_cnt; dp->mode.pclock = pclock;return dp->mode.bw_code;
Signature · 7 lines
Regards, Laurent Pinchart _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Hi Laurent,
Thanks for the comment.
Quoted 42 lines · Laurent Pinchart
Hi Hyun,
Thank you for the patch.
Quoted 37 lines · Hyun Kwon
Use switch - case to downshift from the current link rate. It's a small loop now, so fine to be replaced with switch - case. With a loop, it is confusing and hard to follow as reported below.
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]>---
v2
- Convert the for loop into switch - case
------ drivers/gpu/drm/xlnx/zynqmp_dp.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-)drivers/gpu/drm/xlnx/zynqmp_dp.c +1
-2@@ -567,34 +567,37 @@ static int zynqmp_dp_mode_configure(struct zynqmp_dp *dp, int pclock, u8 current_bw) {int max_rate = dp->link_config.max_rate; -u8 bws[3 ] = {DP_LINK_BW_1_62 ,DP_LINK_BW_2_7 ,DP_LINK_BW_5_4 }; +u8 bw_code;u8 max_lanes = dp->link_config.max_lanes;u8 max_link_rate_code =drm_dp_link_rate_to_bw_code (max_rate);u8 bpp = dp->config.bpp;u8 lane_cnt; -s8 i;
Quoted 7 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c static int zynqmp_dp_mode_configure(struct zynqmp_dp *dp, int pclock, · line 576
Quoted 2 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c +1
-1-if (current_bw ==DP_LINK_BW_1_62 ) { +/* Downshift from current one */ Maybe "Downshift from the current bandwidth" ?
Reviewed-by Laurent Pinchart <[email protected]>
I agree. I'll fix and add the tag.
Thanks!
-hyun
Quoted 28 lines
Quoted 28 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c +12
-8+switch (current_bw) { +case DP_LINK_BW_5_4 : + bw_code =DP_LINK_BW_2_7 ; +break ; +case DP_LINK_BW_2_7 : + bw_code =DP_LINK_BW_1_62 ; +break ; +case DP_LINK_BW_1_62 :dev_err (dp->dev,"can't downshift. already lowest link rate\n" );return -EINVAL ; - } - -for (i =ARRAY_SIZE (bws) -1 ; i >=0 ; i--) { -if (current_bw && bws[i] >= current_bw) -continue ; - -if (bws[i] <= max_link_rate_code) -break ; +default : +/* If not given, start with max supported */ + bw_code = max_link_rate_code; +break ; }for (lane_cnt =1 ; lane_cnt <= max_lanes; lane_cnt <<=1 ) {int bw;u32 rate;
Quoted 14 lines
Quoted 9 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c +2
-2- bw =drm_dp_bw_code_to_link_rate (bws[i]); + bw =drm_dp_bw_code_to_link_rate (bw_code); rate =zynqmp_dp_max_rate (bw, lane_cnt, bpp);if (pclock <= rate) { - dp->mode.bw_code = bws[i]; + dp->mode.bw_code = bw_code; dp->mode.lane_cnt = lane_cnt; dp->mode.pclock = pclock;return dp->mode.bw_code;Signature · 3 lines
Regards, Laurent Pinchart
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Hyun Kwon
AppliedQuoted 66 lines
-----Original Message-----
From: dri-devel <[email protected]> On Behalf Of Hyun Kwon
Sent: Thursday, July 30, 2020 7:33 PM
To: Laurent Pinchart <[email protected]>
Cc: Dan Carpenter <[email protected]>; dri- [email protected]; Daniel Vetter <[email protected]>
Subject: Re: [PATCH v2 1/1] drm: xlnx: zynqmp: Use switch - case for link rate downshiftHi Laurent,
Thanks for the comment.
Quoted 26 lines · Laurent Pinchart
Hi Hyun,
Thank you for the patch.
Quoted 21 lines · Hyun Kwon
Use switch - case to downshift from the current link rate. It's a small loop now, so fine to be replaced with switch - case. With a loop, it is confusing and hard to follow as reported below.
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]>---
v2
- Convert the for loop into switch - case
------ drivers/gpu/drm/xlnx/zynqmp_dp.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-)Quoted 1 line
Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/gpu/drm/xlnx/zynqmp_dp.cQuoted 4 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c static int zynqmp_dp_mode_configure(struct
Quoted 4 lines
index b735072..5d6adeaa 100644
drivers/gpu/drm/xlnx/zynqmp_dp.c +0
-0@@ -567,34 +567,37 @@ static int zynqmp_dp_mode_configure(struct
zynqmp_dp*dp, int pclock,Quoted 4 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c static int zynqmp_dp_mode_configure(struct zynqmp_dp *dp, int pclock,
Quoted 4 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c +0
-1u8 current_bw) {int max_rate = dp->link_config.max_rate; -u8 bws[3 ] = {DP_LINK_BW_1_62 ,DP_LINK_BW_2_7 ,
DP_LINK_BW_5_4};Quoted 12 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c static int zynqmp_dp_mode_configure(struct zynqmp_dp *dp, int pclock, · line 576
Quoted 9 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c +2
-2+u8 bw_code;u8 max_lanes = dp->link_config.max_lanes;u8 max_link_rate_code =drm_dp_link_rate_to_bw_code (max_rate);u8 bpp = dp->config.bpp;u8 lane_cnt; -s8 i; -if (current_bw ==DP_LINK_BW_1_62 ) { +/* Downshift from current one */ Maybe "Downshift from the current bandwidth" ?
Quoted 5 lines
Quoted 2 lines
Reviewed-by Laurent Pinchart <[email protected]>I agree. I'll fix and add the tag.
Applied to drm-misc-next-fixes.
Thanks,
-hyun
Quoted 45 lines
Thanks!
-hyun
Quoted 41 lines
Quoted 27 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c +12
-8+switch (current_bw) { +case DP_LINK_BW_5_4 : + bw_code =DP_LINK_BW_2_7 ; +break ; +case DP_LINK_BW_2_7 : + bw_code =DP_LINK_BW_1_62 ; +break ; +case DP_LINK_BW_1_62 :dev_err (dp->dev,"can't downshift. already lowest link rate\n" );return -EINVAL ; - } - -for (i =ARRAY_SIZE (bws) -1 ; i >=0 ; i--) { -if (current_bw && bws[i] >= current_bw) -continue ; - -if (bws[i] <= max_link_rate_code) -break ; +default : +/* If not given, start with max supported */ + bw_code = max_link_rate_code; +break ; }for (lane_cnt =1 ; lane_cnt <= max_lanes; lane_cnt <<=1 ) {int bw;u32 rate;drivers/gpu/drm/xlnx/zynqmp_dp.c static int zynqmp_dp_mode_configure(struct zynqmp_dp *dp, int pclock, · line 603
Quoted 10 lines
drivers/gpu/drm/xlnx/zynqmp_dp.c +2
-2- bw =drm_dp_bw_code_to_link_rate (bws[i]); + bw =drm_dp_bw_code_to_link_rate (bw_code); rate =zynqmp_dp_max_rate (bw, lane_cnt, bpp);if (pclock <= rate) { - dp->mode.bw_code = bws[i]; + dp->mode.bw_code = bw_code; dp->mode.lane_cnt = lane_cnt; dp->mode.pclock = pclock;return dp->mode.bw_code;--
Regards,
Quoted 5 lines
Quoted 1 line
Laurent Pinchart
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel