All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ath9k: Add cast to u8 to FREQ2FBIN macro
@ 2017-04-06 21:21 Matthias Kaehlcke
  2017-04-06 21:29 ` Joe Perches
  2017-04-19 14:01 ` Kalle Valo
  0 siblings, 2 replies; 7+ messages in thread
From: Matthias Kaehlcke @ 2017-04-06 21:21 UTC (permalink / raw)
  To: Kalle Valo, ath9k Development
  Cc: linux-kernel, linux-wireless, netdev, Grant Grundler, Matthias Kaehlcke

The macro results are assigned to u8 variables/fields. Adding the cast
fixes plenty of clang warnings about "implicit conversion from 'int' to
'u8'".

Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
 drivers/net/wireless/ath/ath9k/eeprom.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/wireless/ath/ath9k/eeprom.h b/drivers/net/wireless/ath/ath9k/eeprom.h
index 30bf722e33ed..31390af6c33e 100644
--- a/drivers/net/wireless/ath/ath9k/eeprom.h
+++ b/drivers/net/wireless/ath/ath9k/eeprom.h
@@ -106,7 +106,7 @@
 #define AR9285_RDEXT_DEFAULT    0x1F
 
 #define ATH9K_POW_SM(_r, _s)	(((_r) & 0x3f) << (_s))
-#define FREQ2FBIN(x, y)		((y) ? ((x) - 2300) : (((x) - 4800) / 5))
+#define FREQ2FBIN(x, y)		(u8)((y) ? ((x) - 2300) : (((x) - 4800) / 5))
 #define FBIN2FREQ(x, y)		((y) ? (2300 + x) : (4800 + 5 * x))
 #define ath9k_hw_use_flash(_ah)	(!(_ah->ah_flags & AH_USE_EEPROM))
 
-- 
2.12.2.715.g7642488e1d-goog

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

* Re: [PATCH] ath9k: Add cast to u8 to FREQ2FBIN macro
  2017-04-06 21:21 [PATCH] ath9k: Add cast to u8 to FREQ2FBIN macro Matthias Kaehlcke
@ 2017-04-06 21:29 ` Joe Perches
  2017-04-06 23:54     ` Matthias Kaehlcke
  2017-04-19 14:01 ` Kalle Valo
  1 sibling, 1 reply; 7+ messages in thread
From: Joe Perches @ 2017-04-06 21:29 UTC (permalink / raw)
  To: Matthias Kaehlcke, Kalle Valo, ath9k Development
  Cc: linux-kernel, linux-wireless, netdev, Grant Grundler

On Thu, 2017-04-06 at 14:21 -0700, Matthias Kaehlcke wrote:
> The macro results are assigned to u8 variables/fields. Adding the cast
> fixes plenty of clang warnings about "implicit conversion from 'int' to
> 'u8'".
> 
> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
> ---
>  drivers/net/wireless/ath/ath9k/eeprom.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/wireless/ath/ath9k/eeprom.h b/drivers/net/wireless/ath/ath9k/eeprom.h
> index 30bf722e33ed..31390af6c33e 100644
> --- a/drivers/net/wireless/ath/ath9k/eeprom.h
> +++ b/drivers/net/wireless/ath/ath9k/eeprom.h
> @@ -106,7 +106,7 @@
>  #define AR9285_RDEXT_DEFAULT    0x1F
>  
>  #define ATH9K_POW_SM(_r, _s)	(((_r) & 0x3f) << (_s))
> -#define FREQ2FBIN(x, y)		((y) ? ((x) - 2300) : (((x) - 4800) / 5))
> +#define FREQ2FBIN(x, y)		(u8)((y) ? ((x) - 2300) : (((x) - 4800) / 5))

Maybe better to use:

static inline u8 FREQ2FBIN(int x, int y)
{
	if (y)
		return x - 2300;
	return (x - 4800) / 5;
}

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

* Re: [PATCH] ath9k: Add cast to u8 to FREQ2FBIN macro
@ 2017-04-06 23:54     ` Matthias Kaehlcke
  0 siblings, 0 replies; 7+ messages in thread
From: Matthias Kaehlcke @ 2017-04-06 23:54 UTC (permalink / raw)
  To: Joe Perches
  Cc: Kalle Valo, ath9k Development, linux-kernel, linux-wireless,
	netdev, Grant Grundler

Hi Joe,

El Thu, Apr 06, 2017 at 02:29:20PM -0700 Joe Perches ha dit:

> On Thu, 2017-04-06 at 14:21 -0700, Matthias Kaehlcke wrote:
> > The macro results are assigned to u8 variables/fields. Adding the cast
> > fixes plenty of clang warnings about "implicit conversion from 'int' to
> > 'u8'".
> > 
> > Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
> > ---
> >  drivers/net/wireless/ath/ath9k/eeprom.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/net/wireless/ath/ath9k/eeprom.h b/drivers/net/wireless/ath/ath9k/eeprom.h
> > index 30bf722e33ed..31390af6c33e 100644
> > --- a/drivers/net/wireless/ath/ath9k/eeprom.h
> > +++ b/drivers/net/wireless/ath/ath9k/eeprom.h
> > @@ -106,7 +106,7 @@
> >  #define AR9285_RDEXT_DEFAULT    0x1F
> >  
> >  #define ATH9K_POW_SM(_r, _s)	(((_r) & 0x3f) << (_s))
> > -#define FREQ2FBIN(x, y)		((y) ? ((x) - 2300) : (((x) - 4800) / 5))
> > +#define FREQ2FBIN(x, y)		(u8)((y) ? ((x) - 2300) : (((x) - 4800) / 5))
> 
> Maybe better to use:
> 
> static inline u8 FREQ2FBIN(int x, int y)
> {
> 	if (y)
> 		return x - 2300;
> 	return (x - 4800) / 5;
> }

Thanks for your suggestion! Unfortunately in this case an inline
function is not suitable since FREQ2FBIN() is mostly used for
structure initialization:

static const struct ar9300_eeprom ar9300_default = {
...
        .calFreqPier2G = {
                FREQ2FBIN(2412, 1),
                FREQ2FBIN(2437, 1),
                FREQ2FBIN(2472, 1),
        },
...

Cheers

Matthias

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

* Re: [PATCH] ath9k: Add cast to u8 to FREQ2FBIN macro
@ 2017-04-06 23:54     ` Matthias Kaehlcke
  0 siblings, 0 replies; 7+ messages in thread
From: Matthias Kaehlcke @ 2017-04-06 23:54 UTC (permalink / raw)
  To: Joe Perches
  Cc: Kalle Valo, ath9k Development,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-wireless-u79uwXL29TY76Z2rM5mHXA,
	netdev-u79uwXL29TY76Z2rM5mHXA, Grant Grundler

Hi Joe,

El Thu, Apr 06, 2017 at 02:29:20PM -0700 Joe Perches ha dit:

> On Thu, 2017-04-06 at 14:21 -0700, Matthias Kaehlcke wrote:
> > The macro results are assigned to u8 variables/fields. Adding the cast
> > fixes plenty of clang warnings about "implicit conversion from 'int' to
> > 'u8'".
> > 
> > Signed-off-by: Matthias Kaehlcke <mka-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
> > ---
> >  drivers/net/wireless/ath/ath9k/eeprom.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/net/wireless/ath/ath9k/eeprom.h b/drivers/net/wireless/ath/ath9k/eeprom.h
> > index 30bf722e33ed..31390af6c33e 100644
> > --- a/drivers/net/wireless/ath/ath9k/eeprom.h
> > +++ b/drivers/net/wireless/ath/ath9k/eeprom.h
> > @@ -106,7 +106,7 @@
> >  #define AR9285_RDEXT_DEFAULT    0x1F
> >  
> >  #define ATH9K_POW_SM(_r, _s)	(((_r) & 0x3f) << (_s))
> > -#define FREQ2FBIN(x, y)		((y) ? ((x) - 2300) : (((x) - 4800) / 5))
> > +#define FREQ2FBIN(x, y)		(u8)((y) ? ((x) - 2300) : (((x) - 4800) / 5))
> 
> Maybe better to use:
> 
> static inline u8 FREQ2FBIN(int x, int y)
> {
> 	if (y)
> 		return x - 2300;
> 	return (x - 4800) / 5;
> }

Thanks for your suggestion! Unfortunately in this case an inline
function is not suitable since FREQ2FBIN() is mostly used for
structure initialization:

static const struct ar9300_eeprom ar9300_default = {
...
        .calFreqPier2G = {
                FREQ2FBIN(2412, 1),
                FREQ2FBIN(2437, 1),
                FREQ2FBIN(2472, 1),
        },
...

Cheers

Matthias

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

* Re: [PATCH] ath9k: Add cast to u8 to FREQ2FBIN macro
@ 2017-04-07  2:36       ` Joe Perches
  0 siblings, 0 replies; 7+ messages in thread
From: Joe Perches @ 2017-04-07  2:36 UTC (permalink / raw)
  To: Matthias Kaehlcke
  Cc: Kalle Valo, ath9k Development, linux-kernel, linux-wireless,
	netdev, Grant Grundler

On Thu, 2017-04-06 at 16:54 -0700, Matthias Kaehlcke wrote:
> Hi Joe,
> 
> El Thu, Apr 06, 2017 at 02:29:20PM -0700 Joe Perches ha dit:
> 
> > On Thu, 2017-04-06 at 14:21 -0700, Matthias Kaehlcke wrote:
> > > The macro results are assigned to u8 variables/fields. Adding the cast
> > > fixes plenty of clang warnings about "implicit conversion from 'int' to
> > > 'u8'".
> > > 
> > > Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
> > > ---
> > >  drivers/net/wireless/ath/ath9k/eeprom.h | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/net/wireless/ath/ath9k/eeprom.h b/drivers/net/wireless/ath/ath9k/eeprom.h
> > > index 30bf722e33ed..31390af6c33e 100644
> > > --- a/drivers/net/wireless/ath/ath9k/eeprom.h
> > > +++ b/drivers/net/wireless/ath/ath9k/eeprom.h
> > > @@ -106,7 +106,7 @@
> > >  #define AR9285_RDEXT_DEFAULT    0x1F
> > >  
> > >  #define ATH9K_POW_SM(_r, _s)	(((_r) & 0x3f) << (_s))
> > > -#define FREQ2FBIN(x, y)		((y) ? ((x) - 2300) : (((x) - 4800) / 5))
> > > +#define FREQ2FBIN(x, y)		(u8)((y) ? ((x) - 2300) : (((x) - 4800) / 5))
> > 
> > Maybe better to use:
> > 
> > static inline u8 FREQ2FBIN(int x, int y)
> > {
> > 	if (y)
> > 		return x - 2300;
> > 	return (x - 4800) / 5;
> > }
> 
> Thanks for your suggestion! Unfortunately in this case an inline
> function is not suitable since FREQ2FBIN() is mostly used for
> structure initialization:
> 
> static const struct ar9300_eeprom ar9300_default = {
> ...
>         .calFreqPier2G = {
>                 FREQ2FBIN(2412, 1),
>                 FREQ2FBIN(2437, 1),
>                 FREQ2FBIN(2472, 1)
>         },
> ...

Maybe it's better to remove the second argument and write
something like:

#define FREQ2FBIN(x) \
	(u8)(((x) >= 2300 && (x) <= 2555) ? (x) - 2300 : \
	     ((x) >= 4800 && (x) <= 4800 + (256 * 5) ? ((x) - 4800) / 5) : \
	     __builtin_const_p(x) ? BUILD_BUG_ON(1) : 0)

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

* Re: [PATCH] ath9k: Add cast to u8 to FREQ2FBIN macro
@ 2017-04-07  2:36       ` Joe Perches
  0 siblings, 0 replies; 7+ messages in thread
From: Joe Perches @ 2017-04-07  2:36 UTC (permalink / raw)
  To: Matthias Kaehlcke
  Cc: Kalle Valo, ath9k Development,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-wireless-u79uwXL29TY76Z2rM5mHXA,
	netdev-u79uwXL29TY76Z2rM5mHXA, Grant Grundler

On Thu, 2017-04-06 at 16:54 -0700, Matthias Kaehlcke wrote:
> Hi Joe,
> 
> El Thu, Apr 06, 2017 at 02:29:20PM -0700 Joe Perches ha dit:
> 
> > On Thu, 2017-04-06 at 14:21 -0700, Matthias Kaehlcke wrote:
> > > The macro results are assigned to u8 variables/fields. Adding the cast
> > > fixes plenty of clang warnings about "implicit conversion from 'int' to
> > > 'u8'".
> > > 
> > > Signed-off-by: Matthias Kaehlcke <mka-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
> > > ---
> > >  drivers/net/wireless/ath/ath9k/eeprom.h | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/net/wireless/ath/ath9k/eeprom.h b/drivers/net/wireless/ath/ath9k/eeprom.h
> > > index 30bf722e33ed..31390af6c33e 100644
> > > --- a/drivers/net/wireless/ath/ath9k/eeprom.h
> > > +++ b/drivers/net/wireless/ath/ath9k/eeprom.h
> > > @@ -106,7 +106,7 @@
> > >  #define AR9285_RDEXT_DEFAULT    0x1F
> > >  
> > >  #define ATH9K_POW_SM(_r, _s)	(((_r) & 0x3f) << (_s))
> > > -#define FREQ2FBIN(x, y)		((y) ? ((x) - 2300) : (((x) - 4800) / 5))
> > > +#define FREQ2FBIN(x, y)		(u8)((y) ? ((x) - 2300) : (((x) - 4800) / 5))
> > 
> > Maybe better to use:
> > 
> > static inline u8 FREQ2FBIN(int x, int y)
> > {
> > 	if (y)
> > 		return x - 2300;
> > 	return (x - 4800) / 5;
> > }
> 
> Thanks for your suggestion! Unfortunately in this case an inline
> function is not suitable since FREQ2FBIN() is mostly used for
> structure initialization:
> 
> static const struct ar9300_eeprom ar9300_default = {
> ...
>         .calFreqPier2G = {
>                 FREQ2FBIN(2412, 1),
>                 FREQ2FBIN(2437, 1),
>                 FREQ2FBIN(2472, 1)
>         },
> ...

Maybe it's better to remove the second argument and write
something like:

#define FREQ2FBIN(x) \
	(u8)(((x) >= 2300 && (x) <= 2555) ? (x) - 2300 : \
	     ((x) >= 4800 && (x) <= 4800 + (256 * 5) ? ((x) - 4800) / 5) : \
	     __builtin_const_p(x) ? BUILD_BUG_ON(1) : 0)

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

* Re: ath9k: Add cast to u8 to FREQ2FBIN macro
  2017-04-06 21:21 [PATCH] ath9k: Add cast to u8 to FREQ2FBIN macro Matthias Kaehlcke
  2017-04-06 21:29 ` Joe Perches
@ 2017-04-19 14:01 ` Kalle Valo
  1 sibling, 0 replies; 7+ messages in thread
From: Kalle Valo @ 2017-04-19 14:01 UTC (permalink / raw)
  To: Matthias Kaehlcke
  Cc: Kalle Valo, ath9k Development, linux-kernel, linux-wireless,
	netdev, Grant Grundler, Matthias Kaehlcke

Matthias Kaehlcke <mka@chromium.org> wrote:
> The macro results are assigned to u8 variables/fields. Adding the cast
> fixes plenty of clang warnings about "implicit conversion from 'int' to
> 'u8'".
> 
> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>

Patch applied to ath-next branch of ath.git, thanks.

627871b71c89 ath9k: Add cast to u8 to FREQ2FBIN macro

-- 
https://patchwork.kernel.org/patch/9668479/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

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

end of thread, other threads:[~2017-04-19 14:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-06 21:21 [PATCH] ath9k: Add cast to u8 to FREQ2FBIN macro Matthias Kaehlcke
2017-04-06 21:29 ` Joe Perches
2017-04-06 23:54   ` Matthias Kaehlcke
2017-04-06 23:54     ` Matthias Kaehlcke
2017-04-07  2:36     ` Joe Perches
2017-04-07  2:36       ` Joe Perches
2017-04-19 14:01 ` Kalle Valo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.