gpu/drm/mgag200:remove break after return
Subsystems (3)
PATCH 1/1 gpu/drm/mgag200:remove break after return
In function mgag200_set_pci_regs, there are some switch cases returned, then break. These break will never run. This patch is to make the code a bit readable.
--- drivers/gpu/drm/mgag200/mgag200_mode.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/gpu/drm/mgag200/mgag200_mode.c +1 -4
@@ -794,20 +794,17 @@ static int mgag200_crtc_set_plls(struct mga_device *mdev, long clock)case G200_SE_A :case G200_SE_B :return mga_g200se_set_plls (mdev, clock); -break ;case G200_WB :case G200_EW3 :return mga_g200wb_set_plls (mdev, clock); -break ;case G200_EV :return mga_g200ev_set_plls (mdev, clock); -break ;case G200_EH :case G200_EH3 :return mga_g200eh_set_plls (mdev, clock); -break ;case G200_ER :return mga_g200er_set_plls (mdev, clock); +default :break ; }
Signature · 1 line
2.28.0
Thomas Zimmermann
maintainerHi
Quoted 22 lines · Bernard Zhao
In function
mgag200_set_pci_regs, there are some switch cases returned, then break. These break will never run. This patch is to make the code a bit readable.Signed-off-by Bernard Zhao <[email protected]>--- drivers/gpu/drm/mgag200/mgag200_mode.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)drivers/gpu/drm/mgag200/mgag200_mode.c +0
-2@@ -794,20 +794,17 @@ static int mgag200_crtc_set_plls(struct mga_device *mdev, long clock)case G200_SE_A :case G200_SE_B :return mga_g200se_set_plls (mdev, clock); -break ;case G200_WB :case G200_EW3 :return mga_g200wb_set_plls (mdev, clock); -break ;
drivers/gpu/drm/mgag200/mgag200_mode.c static int mgag200_crtc_set_plls(struct mga_device *mdev, long clock) · line 807
Quoted 10 lines
drivers/gpu/drm/mgag200/mgag200_mode.c +1
-2case G200_EV :return mga_g200ev_set_plls (mdev, clock); -break ;case G200_EH :case G200_EH3 :return mga_g200eh_set_plls (mdev, clock); -break ;case G200_ER :return mga_g200er_set_plls (mdev, clock); +default :
No default case here. If one of the enum values is not handled by the switch, the compiler should warn about it.
Best regards
Thomas
Quoted 4 lines
drivers/gpu/drm/mgag200/mgag200_mode.c +0
-0break ; }
Signature · 10 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
From: Thomas Zimmermann <[email protected]>
Date: 2020-10-23 15:13:30
To: Bernard Zhao <[email protected]>,Dave Airlie <[email protected]>,David Airlie <[email protected]>,Daniel Vetter <[email protected]>,[email protected],[email protected]
Cc: [email protected]
Subject: Re: [PATCH] gpu/drm/mgag200:remove break after return>Hi
Quoted 29 lines · Bernard Zhao
Quoted 27 lines
In function
mgag200_set_pci_regs, there are some switch cases returned, then break. These break will never run. This patch is to make the code a bit readable.Signed-off-by Bernard Zhao <[email protected]>--- drivers/gpu/drm/mgag200/mgag200_mode.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)drivers/gpu/drm/mgag200/mgag200_mode.c +0
-3@@ -794,20 +794,17 @@ static int mgag200_crtc_set_plls(struct mga_device *mdev, long clock)case G200_SE_A :case G200_SE_B :return mga_g200se_set_plls (mdev, clock); -break ;case G200_WB :case G200_EW3 :return mga_g200wb_set_plls (mdev, clock); -break ;case G200_EV :return mga_g200ev_set_plls (mdev, clock); -break ;case G200_EH :case G200_EH3 :
Quoted 8 lines
drivers/gpu/drm/mgag200/mgag200_mode.c static int mgag200_crtc_set_plls(struct mga_device *mdev, long clock) · line 807
Quoted 5 lines
drivers/gpu/drm/mgag200/mgag200_mode.c +1
-1return mga_g200eh_set_plls (mdev, clock); -break ;case G200_ER :return mga_g200er_set_plls (mdev, clock); +default :No default case here. If one of the enum values is not handled by the switch, the compiler should warn about it.
Hi
For this point I was a little confused, about this switch variable "mdev->type", my understanding is that this variable`s value can be certain only when the code is running. How does the compiler warn this("If one of the enum values is not handled") before the code runs?
BR//Bernard
Quoted 15 lines
Best regards
ThomasQuoted 4 lines
drivers/gpu/drm/mgag200/mgag200_mode.c +0
-0break ; }Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
Thomas Zimmermann
maintainerHi
Quoted 45 lines · Bernard
From: Thomas Zimmermann <[email protected]>
Date: 2020-10-23 15:13:30
To: Bernard Zhao <[email protected]>,Dave Airlie <[email protected]>,David Airlie <[email protected]>,Daniel Vetter <[email protected]>,[email protected],[email protected]
Cc: [email protected]
Subject: Re: [PATCH] gpu/drm/mgag200:remove break after return>HiQuoted 29 lines · Bernard Zhao
Quoted 27 lines
In function
mgag200_set_pci_regs, there are some switch cases returned, then break. These break will never run. This patch is to make the code a bit readable.Signed-off-by Bernard Zhao <[email protected]>--- drivers/gpu/drm/mgag200/mgag200_mode.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)drivers/gpu/drm/mgag200/mgag200_mode.c +0
-3@@ -794,20 +794,17 @@ static int mgag200_crtc_set_plls(struct mga_device *mdev, long clock)case G200_SE_A :case G200_SE_B :return mga_g200se_set_plls (mdev, clock); -break ;case G200_WB :case G200_EW3 :return mga_g200wb_set_plls (mdev, clock); -break ;case G200_EV :return mga_g200ev_set_plls (mdev, clock); -break ;case G200_EH :case G200_EH3 :Quoted 8 lines
drivers/gpu/drm/mgag200/mgag200_mode.c static int mgag200_crtc_set_plls(struct mga_device *mdev, long clock) · line 807
Quoted 5 lines
drivers/gpu/drm/mgag200/mgag200_mode.c +1
-1return mga_g200eh_set_plls (mdev, clock); -break ;case G200_ER :return mga_g200er_set_plls (mdev, clock); +default :No default case here. If one of the enum values is not handled by the switch, the compiler should warn about it.
Quoted 4 lines
Hi
For this point I was a little confused, about this switch variable "
mdev->type", my understanding is that this variable`s value can be certain only when the code is running. How does the compiler warnthis("If one of the enum values is not handled")before the code runs?
The enum mga_type {} has values (G200_ER, G200_WB, etc) that are known to the compiler. If one of those values does not show up in the switch statement, the compiler warns. Adding default would silence this warning.
In principle, mdev->type could contain any value that fits into an int. But assigning anything that is not listed in enum mga_type {} is considered an error as well.
Best regards
Thomas
Quoted 20 lines
BR//Bernard
Quoted 15 lines
Best regards
ThomasQuoted 4 lines
drivers/gpu/drm/mgag200/mgag200_mode.c +0
-0break ; }Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
Signature · 10 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Hi Bernard.
Quoted 45 lines · Bernard
From: Thomas Zimmermann <[email protected]>
Date: 2020-10-23 15:13:30
To: Bernard Zhao <[email protected]>,Dave Airlie <[email protected]>,David Airlie <[email protected]>,Daniel Vetter <[email protected]>,[email protected],[email protected]
Cc: [email protected]
Subject: Re: [PATCH] gpu/drm/mgag200:remove break after return>HiQuoted 29 lines · Bernard Zhao
Quoted 27 lines
In function
mgag200_set_pci_regs, there are some switch cases returned, then break. These break will never run. This patch is to make the code a bit readable.Signed-off-by Bernard Zhao <[email protected]>--- drivers/gpu/drm/mgag200/mgag200_mode.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)drivers/gpu/drm/mgag200/mgag200_mode.c +0
-3@@ -794,20 +794,17 @@ static int mgag200_crtc_set_plls(struct mga_device *mdev, long clock)case G200_SE_A :case G200_SE_B :return mga_g200se_set_plls (mdev, clock); -break ;case G200_WB :case G200_EW3 :return mga_g200wb_set_plls (mdev, clock); -break ;case G200_EV :return mga_g200ev_set_plls (mdev, clock); -break ;case G200_EH :case G200_EH3 :Quoted 8 lines
drivers/gpu/drm/mgag200/mgag200_mode.c static int mgag200_crtc_set_plls(struct mga_device *mdev, long clock) · line 807
Quoted 5 lines
drivers/gpu/drm/mgag200/mgag200_mode.c +1
-1return mga_g200eh_set_plls (mdev, clock); -break ;case G200_ER :return mga_g200er_set_plls (mdev, clock); +default :No default case here. If one of the enum values is not handled by the switch, the compiler should warn about it.
Quoted 4 lines
Hi
For this point I was a little confused, about this switch variable "
mdev->type", my understanding is that this variable`s value can be certain only when the code is running. How does the compiler warnthis("If one of the enum values is not handled")before the code runs?
If the switch/case does not include "G200_ER" then the compiler can see one enum value is missing from the list and can warn.
As a test - Try to drop the default and drop G200_ER - then the compiler (hopefully) will warn.
Sam
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
From: Sam Ravnborg <[email protected]>
Date: 2020-10-25 01:14:57
To: Bernard <[email protected]>
Cc: Thomas Zimmermann <[email protected]>,[email protected],David Airlie <[email protected]>,[email protected],[email protected],Dave Airlie <[email protected]>
Subject: Re: Re: [PATCH] gpu/drm/mgag200:remove break after return>Hi Bernard.
Quoted 49 lines · Bernard
Quoted 47 lines
From: Thomas Zimmermann <[email protected]>
Date: 2020-10-23 15:13:30
To: Bernard Zhao <[email protected]>,Dave Airlie <[email protected]>,David Airlie <[email protected]>,Daniel Vetter <[email protected]>,[email protected],[email protected]
Cc: [email protected]
Subject: Re: [PATCH] gpu/drm/mgag200:remove break after return>HiQuoted 29 lines · Bernard Zhao
Quoted 27 lines
In function
mgag200_set_pci_regs, there are some switch cases returned, then break. These break will never run. This patch is to make the code a bit readable.Signed-off-by Bernard Zhao <[email protected]>--- drivers/gpu/drm/mgag200/mgag200_mode.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)drivers/gpu/drm/mgag200/mgag200_mode.c +0
-3@@ -794,20 +794,17 @@ static int mgag200_crtc_set_plls(struct mga_device *mdev, long clock)case G200_SE_A :case G200_SE_B :return mga_g200se_set_plls (mdev, clock); -break ;case G200_WB :case G200_EW3 :return mga_g200wb_set_plls (mdev, clock); -break ;case G200_EV :return mga_g200ev_set_plls (mdev, clock); -break ;case G200_EH :case G200_EH3 :Quoted 8 lines
drivers/gpu/drm/mgag200/mgag200_mode.c static int mgag200_crtc_set_plls(struct mga_device *mdev, long clock) · line 807
Quoted 5 lines
drivers/gpu/drm/mgag200/mgag200_mode.c +1
-1return mga_g200eh_set_plls (mdev, clock); -break ;case G200_ER :return mga_g200er_set_plls (mdev, clock); +default :No default case here. If one of the enum values is not handled by the switch, the compiler should warn about it.
Hi
Quoted 7 lines
Quoted 2 lines
For this point I was a little confused, about this switch variable "
mdev->type", my understanding is that this variable`s value can be certain only when the code is running. How does the compiler warnthis("If one of the enum values is not handled")before the code runs?If the switch/case does not include "
G200_ER" then the compiler can see one enum value is missing from the list and can warn.
As a test - Try to drop the default and dropG200_ER- then the compiler (hopefully) will warn.
Hi, Sam & Thomas:
Thank you very much for your kind comments, I learned new useful knowledge. I will resubmit the patch.
BR//Bernard
Quoted 1 line
Sam