diff mbox series

mthca: work around -Wenum-conversion warning

Message ID 20201026211311.3887003-1-arnd@kernel.org (mailing list archive)
State Accepted
Delegated to: Jason Gunthorpe
Headers show
Series mthca: work around -Wenum-conversion warning | expand

Commit Message

Arnd Bergmann Oct. 26, 2020, 9:12 p.m. UTC
From: Arnd Bergmann <arnd@arndb.de>

gcc points out a suspicious mixing of enum types in a function that
converts from MTHCA_OPCODE_* values to IB_WC_* values:

drivers/infiniband/hw/mthca/mthca_cq.c: In function 'mthca_poll_one':
drivers/infiniband/hw/mthca/mthca_cq.c:607:21: warning: implicit conversion from 'enum <anonymous>' to 'enum ib_wc_opcode' [-Wenum-conversion]
  607 |    entry->opcode    = MTHCA_OPCODE_INVALID;

Nothing seems to ever check for MTHCA_OPCODE_INVALID again, no
idea if this is meaningful, but it seems harmless as it deals
with an invalid input.

Add a cast to suppress the warning.

Fixes: 2a4443a69934 ("[PATCH] IB/mthca: fill in opcode field for send completions")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/infiniband/hw/mthca/mthca_cq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jason Gunthorpe Nov. 12, 2020, 3:57 p.m. UTC | #1
On Mon, Oct 26, 2020 at 10:12:30PM +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> gcc points out a suspicious mixing of enum types in a function that
> converts from MTHCA_OPCODE_* values to IB_WC_* values:
> 
> drivers/infiniband/hw/mthca/mthca_cq.c: In function 'mthca_poll_one':
> drivers/infiniband/hw/mthca/mthca_cq.c:607:21: warning: implicit conversion from 'enum <anonymous>' to 'enum ib_wc_opcode' [-Wenum-conversion]
>   607 |    entry->opcode    = MTHCA_OPCODE_INVALID;
> 
> Nothing seems to ever check for MTHCA_OPCODE_INVALID again, no
> idea if this is meaningful, but it seems harmless as it deals
> with an invalid input.
> 
> Add a cast to suppress the warning.
> 
> Fixes: 2a4443a69934 ("[PATCH] IB/mthca: fill in opcode field for send completions")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>  drivers/infiniband/hw/mthca/mthca_cq.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/infiniband/hw/mthca/mthca_cq.c b/drivers/infiniband/hw/mthca/mthca_cq.c
> index c3cfea243af8..319b8aa63f36 100644
> +++ b/drivers/infiniband/hw/mthca/mthca_cq.c
> @@ -604,7 +604,7 @@ static inline int mthca_poll_one(struct mthca_dev *dev,
>  			entry->byte_len  = MTHCA_ATOMIC_BYTE_LEN;
>  			break;
>  		default:
> -			entry->opcode    = MTHCA_OPCODE_INVALID;
> +			entry->opcode    = (u8)MTHCA_OPCODE_INVALID;
>  			break;

This code is completely bogus, sigh

Is this OK as far as the warning goes?

diff --git a/drivers/infiniband/hw/mthca/mthca_cq.c b/drivers/infiniband/hw/mthca/mthca_cq.c
index 319b8aa63f3645..36416f937b696c 100644
--- a/drivers/infiniband/hw/mthca/mthca_cq.c
+++ b/drivers/infiniband/hw/mthca/mthca_cq.c
@@ -604,7 +604,7 @@ static inline int mthca_poll_one(struct mthca_dev *dev,
 			entry->byte_len  = MTHCA_ATOMIC_BYTE_LEN;
 			break;
 		default:
-			entry->opcode    = (u8)MTHCA_OPCODE_INVALID;
+			entry->opcode = 0xFF;
 			break;
 		}
 	} else {
diff --git a/drivers/infiniband/hw/mthca/mthca_dev.h b/drivers/infiniband/hw/mthca/mthca_dev.h
index 9dbbf4d16796a4..a445160de3e16c 100644
--- a/drivers/infiniband/hw/mthca/mthca_dev.h
+++ b/drivers/infiniband/hw/mthca/mthca_dev.h
@@ -105,7 +105,6 @@ enum {
 	MTHCA_OPCODE_ATOMIC_CS      = 0x11,
 	MTHCA_OPCODE_ATOMIC_FA      = 0x12,
 	MTHCA_OPCODE_BIND_MW        = 0x18,
-	MTHCA_OPCODE_INVALID        = 0xff
 };
 
 enum {
Arnd Bergmann Nov. 12, 2020, 4:45 p.m. UTC | #2
On Thu, Nov 12, 2020 at 4:57 PM Jason Gunthorpe <jgg@nvidia.com> wrote:
>
> On Mon, Oct 26, 2020 at 10:12:30PM +0100, Arnd Bergmann wrote:
> > From: Arnd Bergmann <arnd@arndb.de>
> >
> > gcc points out a suspicious mixing of enum types in a function that
> > converts from MTHCA_OPCODE_* values to IB_WC_* values:
> >
> > drivers/infiniband/hw/mthca/mthca_cq.c: In function 'mthca_poll_one':
> > drivers/infiniband/hw/mthca/mthca_cq.c:607:21: warning: implicit conversion from 'enum <anonymous>' to 'enum ib_wc_opcode' [-Wenum-conversion]
> >   607 |    entry->opcode    = MTHCA_OPCODE_INVALID;
> >
> > Nothing seems to ever check for MTHCA_OPCODE_INVALID again, no
> > idea if this is meaningful, but it seems harmless as it deals
> > with an invalid input.
> >
> > Add a cast to suppress the warning.
> >
> > Fixes: 2a4443a69934 ("[PATCH] IB/mthca: fill in opcode field for send completions")
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> >  drivers/infiniband/hw/mthca/mthca_cq.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/infiniband/hw/mthca/mthca_cq.c b/drivers/infiniband/hw/mthca/mthca_cq.c
> > index c3cfea243af8..319b8aa63f36 100644
> > +++ b/drivers/infiniband/hw/mthca/mthca_cq.c
> > @@ -604,7 +604,7 @@ static inline int mthca_poll_one(struct mthca_dev *dev,
> >                       entry->byte_len  = MTHCA_ATOMIC_BYTE_LEN;
> >                       break;
> >               default:
> > -                     entry->opcode    = MTHCA_OPCODE_INVALID;
> > +                     entry->opcode    = (u8)MTHCA_OPCODE_INVALID;
> >                       break;
>
> This code is completely bogus, sigh
>
> Is this OK as far as the warning goes?

Yes, I'm sure your patch fixes it and it makes more sense than my version.

Acked-by: Arnd Bergmann <arnd@arndb.de>
Jason Gunthorpe Nov. 12, 2020, 4:46 p.m. UTC | #3
On Thu, Nov 12, 2020 at 05:45:00PM +0100, Arnd Bergmann wrote:
> On Thu, Nov 12, 2020 at 4:57 PM Jason Gunthorpe <jgg@nvidia.com> wrote:
> >
> > On Mon, Oct 26, 2020 at 10:12:30PM +0100, Arnd Bergmann wrote:
> > > From: Arnd Bergmann <arnd@arndb.de>
> > >
> > > gcc points out a suspicious mixing of enum types in a function that
> > > converts from MTHCA_OPCODE_* values to IB_WC_* values:
> > >
> > > drivers/infiniband/hw/mthca/mthca_cq.c: In function 'mthca_poll_one':
> > > drivers/infiniband/hw/mthca/mthca_cq.c:607:21: warning: implicit conversion from 'enum <anonymous>' to 'enum ib_wc_opcode' [-Wenum-conversion]
> > >   607 |    entry->opcode    = MTHCA_OPCODE_INVALID;
> > >
> > > Nothing seems to ever check for MTHCA_OPCODE_INVALID again, no
> > > idea if this is meaningful, but it seems harmless as it deals
> > > with an invalid input.
> > >
> > > Add a cast to suppress the warning.
> > >
> > > Fixes: 2a4443a69934 ("[PATCH] IB/mthca: fill in opcode field for send completions")
> > > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> > >  drivers/infiniband/hw/mthca/mthca_cq.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/infiniband/hw/mthca/mthca_cq.c b/drivers/infiniband/hw/mthca/mthca_cq.c
> > > index c3cfea243af8..319b8aa63f36 100644
> > > +++ b/drivers/infiniband/hw/mthca/mthca_cq.c
> > > @@ -604,7 +604,7 @@ static inline int mthca_poll_one(struct mthca_dev *dev,
> > >                       entry->byte_len  = MTHCA_ATOMIC_BYTE_LEN;
> > >                       break;
> > >               default:
> > > -                     entry->opcode    = MTHCA_OPCODE_INVALID;
> > > +                     entry->opcode    = (u8)MTHCA_OPCODE_INVALID;
> > >                       break;
> >
> > This code is completely bogus, sigh
> >
> > Is this OK as far as the warning goes?
> 
> Yes, I'm sure your patch fixes it and it makes more sense than my version.
> 
> Acked-by: Arnd Bergmann <arnd@arndb.de>

Okay, I'll revise it, thanks

Jason
diff mbox series

Patch

diff --git a/drivers/infiniband/hw/mthca/mthca_cq.c b/drivers/infiniband/hw/mthca/mthca_cq.c
index c3cfea243af8..319b8aa63f36 100644
--- a/drivers/infiniband/hw/mthca/mthca_cq.c
+++ b/drivers/infiniband/hw/mthca/mthca_cq.c
@@ -604,7 +604,7 @@  static inline int mthca_poll_one(struct mthca_dev *dev,
 			entry->byte_len  = MTHCA_ATOMIC_BYTE_LEN;
 			break;
 		default:
-			entry->opcode    = MTHCA_OPCODE_INVALID;
+			entry->opcode    = (u8)MTHCA_OPCODE_INVALID;
 			break;
 		}
 	} else {