linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] RDMA/irdma: Fix GCC 12 warning
@ 2022-02-10  0:33 Victor Erminpour
  2022-02-10 22:09 ` Saleem, Shiraz
  0 siblings, 1 reply; 3+ messages in thread
From: Victor Erminpour @ 2022-02-10  0:33 UTC (permalink / raw)
  To: mustafa.ismail
  Cc: shiraz.saleem, jgg, linux-rdma, linux-kernel, trivial, victor.erminpour

When building with automatic stack variable initialization, GCC 12
complains about variables defined outside of switch case statements.
Move the variable into the case that uses it, which silences the warning:

./drivers/infiniband/hw/irdma/hw.c:270:47: error: statement will never be executed [-Werror=switch-unreachable]
  270 |                         struct irdma_cm_node *cm_node;
      |

./drivers/infiniband/hw/irdma/utils.c:1215:50: error: statement will never be executed [-Werror=switch-unreachable]
  1215 |                         struct irdma_gen_ae_info ae_info;
       |

Signed-off-by: Victor Erminpour <victor.erminpour@oracle.com>
---
 drivers/infiniband/hw/irdma/hw.c    | 2 +-
 drivers/infiniband/hw/irdma/utils.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/hw/irdma/hw.c b/drivers/infiniband/hw/irdma/hw.c
index 89234d04cc65..a41a3b128d0d 100644
--- a/drivers/infiniband/hw/irdma/hw.c
+++ b/drivers/infiniband/hw/irdma/hw.c
@@ -267,8 +267,8 @@ static void irdma_process_aeq(struct irdma_pci_f *rf)
 		}
 
 		switch (info->ae_id) {
-			struct irdma_cm_node *cm_node;
 		case IRDMA_AE_LLP_CONNECTION_ESTABLISHED:
+			struct irdma_cm_node *cm_node;
 			cm_node = iwqp->cm_node;
 			if (cm_node->accept_pend) {
 				atomic_dec(&cm_node->listener->pend_accepts_cnt);
diff --git a/drivers/infiniband/hw/irdma/utils.c b/drivers/infiniband/hw/irdma/utils.c
index 398736d8c78a..16b65a6c7db1 100644
--- a/drivers/infiniband/hw/irdma/utils.c
+++ b/drivers/infiniband/hw/irdma/utils.c
@@ -1212,12 +1212,12 @@ enum irdma_status_code irdma_hw_modify_qp(struct irdma_device *iwdev,
 			return status;
 
 		switch (m_info->next_iwarp_state) {
-			struct irdma_gen_ae_info ae_info;
 
 		case IRDMA_QP_STATE_RTS:
 		case IRDMA_QP_STATE_IDLE:
 		case IRDMA_QP_STATE_TERMINATE:
 		case IRDMA_QP_STATE_CLOSING:
+			struct irdma_gen_ae_info ae_info;
 			if (info->curr_iwarp_state == IRDMA_QP_STATE_IDLE)
 				irdma_send_reset(iwqp->cm_node);
 			else

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [PATCH] RDMA/irdma: Fix GCC 12 warning
  2022-02-10  0:33 [PATCH] RDMA/irdma: Fix GCC 12 warning Victor Erminpour
@ 2022-02-10 22:09 ` Saleem, Shiraz
  2022-02-10 23:36   ` Jason Gunthorpe
  0 siblings, 1 reply; 3+ messages in thread
From: Saleem, Shiraz @ 2022-02-10 22:09 UTC (permalink / raw)
  To: Victor Erminpour, Ismail, Mustafa; +Cc: jgg, linux-rdma, linux-kernel, trivial

> Subject: [PATCH] RDMA/irdma: Fix GCC 12 warning
> 
> When building with automatic stack variable initialization, GCC 12 complains about
> variables defined outside of switch case statements.
> Move the variable into the case that uses it, which silences the warning:
> 
> ./drivers/infiniband/hw/irdma/hw.c:270:47: error: statement will never be executed [-
> Werror=switch-unreachable]
>   270 |                         struct irdma_cm_node *cm_node;
>       |
> 
> ./drivers/infiniband/hw/irdma/utils.c:1215:50: error: statement will never be executed
> [-Werror=switch-unreachable]
>   1215 |                         struct irdma_gen_ae_info ae_info;
>        |
> 
> Signed-off-by: Victor Erminpour <victor.erminpour@oracle.com>
> ---
>  drivers/infiniband/hw/irdma/hw.c    | 2 +-
>  drivers/infiniband/hw/irdma/utils.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/infiniband/hw/irdma/hw.c b/drivers/infiniband/hw/irdma/hw.c
> index 89234d04cc65..a41a3b128d0d 100644
> --- a/drivers/infiniband/hw/irdma/hw.c
> +++ b/drivers/infiniband/hw/irdma/hw.c
> @@ -267,8 +267,8 @@ static void irdma_process_aeq(struct irdma_pci_f *rf)
>  		}
> 
>  		switch (info->ae_id) {
> -			struct irdma_cm_node *cm_node;
>  		case IRDMA_AE_LLP_CONNECTION_ESTABLISHED:
> +			struct irdma_cm_node *cm_node;
>  			cm_node = iwqp->cm_node;
>  			if (cm_node->accept_pend) {
>  				atomic_dec(&cm_node->listener-

This doesn't compile.

drivers/infiniband/hw/irdma/hw.c: In function \u2018irdma_process_aeq\u2019:
drivers/infiniband/hw/irdma/hw.c:271:4: error: a label can only be part of a statement and a declaration is not a statement
  271 |    struct irdma_cm_node *cm_node;

Seems like we are accommodating for gcc12 bug since this C code is legit? 

Shiraz


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] RDMA/irdma: Fix GCC 12 warning
  2022-02-10 22:09 ` Saleem, Shiraz
@ 2022-02-10 23:36   ` Jason Gunthorpe
  0 siblings, 0 replies; 3+ messages in thread
From: Jason Gunthorpe @ 2022-02-10 23:36 UTC (permalink / raw)
  To: Saleem, Shiraz
  Cc: Victor Erminpour, Ismail, Mustafa, linux-rdma, linux-kernel, trivial

On Thu, Feb 10, 2022 at 10:09:18PM +0000, Saleem, Shiraz wrote:
> > Subject: [PATCH] RDMA/irdma: Fix GCC 12 warning
> > 
> > When building with automatic stack variable initialization, GCC 12 complains about
> > variables defined outside of switch case statements.
> > Move the variable into the case that uses it, which silences the warning:
> > 
> > ./drivers/infiniband/hw/irdma/hw.c:270:47: error: statement will never be executed [-
> > Werror=switch-unreachable]
> >   270 |                         struct irdma_cm_node *cm_node;
> >       |
> > 
> > ./drivers/infiniband/hw/irdma/utils.c:1215:50: error: statement will never be executed
> > [-Werror=switch-unreachable]
> >   1215 |                         struct irdma_gen_ae_info ae_info;
> >        |
> > 
> > Signed-off-by: Victor Erminpour <victor.erminpour@oracle.com>
> >  drivers/infiniband/hw/irdma/hw.c    | 2 +-
> >  drivers/infiniband/hw/irdma/utils.c | 2 +-
> >  2 files changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/infiniband/hw/irdma/hw.c b/drivers/infiniband/hw/irdma/hw.c
> > index 89234d04cc65..a41a3b128d0d 100644
> > +++ b/drivers/infiniband/hw/irdma/hw.c
> > @@ -267,8 +267,8 @@ static void irdma_process_aeq(struct irdma_pci_f *rf)
> >  		}
> > 
> >  		switch (info->ae_id) {
> > -			struct irdma_cm_node *cm_node;
> >  		case IRDMA_AE_LLP_CONNECTION_ESTABLISHED:
> > +			struct irdma_cm_node *cm_node;
> >  			cm_node = iwqp->cm_node;
> >  			if (cm_node->accept_pend) {
> >  				atomic_dec(&cm_node->listener-
> 
> This doesn't compile.
> 
> drivers/infiniband/hw/irdma/hw.c: In function \u2018irdma_process_aeq\u2019:
> drivers/infiniband/hw/irdma/hw.c:271:4: error: a label can only be part of a statement and a declaration is not a statement
>   271 |    struct irdma_cm_node *cm_node;
> 
> Seems like we are accommodating for gcc12 bug since this C code is
> legit?

It might be legit, but it is nutzo and not our coding style.

If the variable is used by many branches it should be declared at the
top of the function.

If it is used in one branch it should be as above, with the missing {}
added.

Jason

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-02-10 23:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-10  0:33 [PATCH] RDMA/irdma: Fix GCC 12 warning Victor Erminpour
2022-02-10 22:09 ` Saleem, Shiraz
2022-02-10 23:36   ` Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).