Skip to contentSkip to conversation

drm/dp: annotate implicit fall throughs

bug report Dan Carpenter 2 participants 3 messages Aug 25, 2020 – Aug 31, 2020

lore
Share & tools
lore
#0 lore raw

Hello Mathieu Malaterre,

The patch e9c0c874711b: "drm/dp: annotate implicit fall throughs" from Jan 14, 2019, leads to the following static checker warning:

	drivers/gpu/drm/drm_dp_helper.c:495 drm_dp_downstream_max_bpc()
	warn: ignoring unreachable code.

drivers/gpu/drm/drm_dp_helper.c
467 int drm_dp_downstream_max_bpc(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
468 const u8 port_cap[4])
469 {
470 int type = port_cap[0] & DP_DS_PORT_TYPE_MASK;
471 bool detailed_cap_info = dpcd[DP_DOWNSTREAMPORT_PRESENT] &
472 DP_DETAILED_CAP_INFO_AVAILABLE;
473 int bpc;
474
475 if (!detailed_cap_info)
476 return 0;
477

   478          switch (type) {
   479          case DP_DS_PORT_TYPE_VGA:
   480          case DP_DS_PORT_TYPE_DVI:
   481          case DP_DS_PORT_TYPE_HDMI:
   482          case DP_DS_PORT_TYPE_DP_DUALMODE:
   483                  bpc = port_cap[2] & DP_DS_MAX_BPC_MASK;
                                            ^^^^^^^^^^^^^^^^^^

This is 0x3.

   484  
   485                  switch (bpc) {
   486                  case DP_DS_8BPC:
   487                          return 8;
   488                  case DP_DS_10BPC:
   489                          return 10;
   490                  case DP_DS_12BPC:
   491                          return 12;
   492                  case DP_DS_16BPC:
   493                          return 16;
   494                  }
   495                  fallthrough;

This fallthrough is impossible. Probably the way to work around the bogus warning is the change the fallthough to "return 0; /* impossible */" otherwise the fallthrough is sort of misleading...

496 default:
497 return 0;
498 }
499 }

regards,
dan carpenter
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#1 lore raw
Quoted 42 lines · Dan Carpenter

Hello Mathieu Malaterre,

The patch e9c0c874711b: "drm/dp: annotate implicit fall throughs" from Jan 14, 2019, leads to the following static checker warning:

	drivers/gpu/drm/drm_dp_helper.c:495 drm_dp_downstream_max_bpc()
	warn: ignoring unreachable code.

drivers/gpu/drm/drm_dp_helper.c
467 int drm_dp_downstream_max_bpc(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
468 const u8 port_cap[4])

   469  {
   470          int type = port_cap[0] & DP_DS_PORT_TYPE_MASK;
   471          bool detailed_cap_info = dpcd[DP_DOWNSTREAMPORT_PRESENT] &
   472                  DP_DETAILED_CAP_INFO_AVAILABLE;
   473          int bpc;
   474  
   475          if (!detailed_cap_info)
   476                  return 0;
   477  
   478          switch (type) {
   479          case DP_DS_PORT_TYPE_VGA:
   480          case DP_DS_PORT_TYPE_DVI:
   481          case DP_DS_PORT_TYPE_HDMI:
   482          case DP_DS_PORT_TYPE_DP_DUALMODE:
   483                  bpc = port_cap[2] & DP_DS_MAX_BPC_MASK;
                                            ^^^^^^^^^^^^^^^^^^

This is 0x3.

   484  
   485                  switch (bpc) {
   486                  case DP_DS_8BPC:
   487                          return 8;
   488                  case DP_DS_10BPC:
   489                          return 10;
   490                  case DP_DS_12BPC:
   491                          return 12;
   492                  case DP_DS_16BPC:
   493                          return 16;
   494                  }
   495                  fallthrough;
Quoted 3 lines

This fallthrough is impossible. Probably the way to work around the bogus warning is the change the fallthough to "return 0; /* impossible */" otherwise the fallthrough is sort of misleading...

Won't that be unreachable as well?

Maybe just add the default label to switch (bpc)?

BR,
Jani.

Quoted 12 lines
   496          default:
   497                  return 0;
   498          }
   499  }

regards,
dan carpenter
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Signature · 5 lines
Jani Nikula, Intel Open Source Graphics Center
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw
Quoted 43 lines · Jani Nikula
Quoted 42 lines · Dan Carpenter

Hello Mathieu Malaterre,

The patch e9c0c874711b: "drm/dp: annotate implicit fall throughs" from Jan 14, 2019, leads to the following static checker warning:

	drivers/gpu/drm/drm_dp_helper.c:495 drm_dp_downstream_max_bpc()
	warn: ignoring unreachable code.

drivers/gpu/drm/drm_dp_helper.c
467 int drm_dp_downstream_max_bpc(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
468 const u8 port_cap[4])

   469  {
   470          int type = port_cap[0] & DP_DS_PORT_TYPE_MASK;
   471          bool detailed_cap_info = dpcd[DP_DOWNSTREAMPORT_PRESENT] &
   472                  DP_DETAILED_CAP_INFO_AVAILABLE;
   473          int bpc;
   474  
   475          if (!detailed_cap_info)
   476                  return 0;
   477  
   478          switch (type) {
   479          case DP_DS_PORT_TYPE_VGA:
   480          case DP_DS_PORT_TYPE_DVI:
   481          case DP_DS_PORT_TYPE_HDMI:
   482          case DP_DS_PORT_TYPE_DP_DUALMODE:
   483                  bpc = port_cap[2] & DP_DS_MAX_BPC_MASK;
                                            ^^^^^^^^^^^^^^^^^^

This is 0x3.

   484  
   485                  switch (bpc) {
   486                  case DP_DS_8BPC:
   487                          return 8;
   488                  case DP_DS_10BPC:
   489                          return 10;
   490                  case DP_DS_12BPC:
   491                          return 12;
   492                  case DP_DS_16BPC:
   493                          return 16;
   494                  }
   495                  fallthrough;
Quoted 7 lines
Quoted 3 lines

This fallthrough is impossible. Probably the way to work around the bogus warning is the change the fallthough to "return 0; /* impossible */" otherwise the fallthrough is sort of misleading...

Won't that be unreachable as well?

Maybe just add the default label to switch (bpc)?

A default switch is going to be unreachable as well... But adding a return 0 is the older more traditional ways way of marking these so people and checkers are used to it.

regards,
dan carpenter

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel