linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: dwc2: hcd_queue: Fix use of floating point literal
@ 2021-11-04 21:59 Nathan Chancellor
  2021-11-04 23:29 ` Nick Desaulniers
  2021-11-05 13:08 ` John Keeping
  0 siblings, 2 replies; 6+ messages in thread
From: Nathan Chancellor @ 2021-11-04 21:59 UTC (permalink / raw)
  To: Minas Harutyunyan, Greg Kroah-Hartman
  Cc: Nick Desaulniers, linux-usb, linux-kernel, llvm, Nathan Chancellor

A new commit in LLVM causes an error on the use of 'long double' when
'-mno-x87' is used, which the kernel does through an alias,
'-mno-80387' (see the LLVM commit below for more details around why it
does this).

 drivers/usb/dwc2/hcd_queue.c:1744:25: error: expression requires  'long double' type support, but target 'x86_64-unknown-linux-gnu' does not support it
                         delay = ktime_set(0, DWC2_RETRY_WAIT_DELAY);
                                             ^
 drivers/usb/dwc2/hcd_queue.c:62:34: note: expanded from macro 'DWC2_RETRY_WAIT_DELAY'
 #define DWC2_RETRY_WAIT_DELAY (1 * 1E6L)
                                 ^
 1 error generated.

This happens due to the use of a 'long double' literal. The 'E6' part of
'1E6L' causes the literal to be a 'double' then the 'L' suffix promotes
it to 'long double'.

There is no visible reason for a floating point value in this driver, as
the value is only used as a parameter to a function that expects an
integer type.  Use USEC_PER_SEC, which is the same integer value as
'1E6L', to avoid changing functionality but fix the error.

Fixes: 6ed30a7d8ec2 ("usb: dwc2: host: use hrtimer for NAK retries")
Link: https://github.com/ClangBuiltLinux/linux/issues/1497
Link: https://github.com/llvm/llvm-project/commit/a8083d42b1c346e21623a1d36d1f0cadd7801d83
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 drivers/usb/dwc2/hcd_queue.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/dwc2/hcd_queue.c b/drivers/usb/dwc2/hcd_queue.c
index 89a788326c56..bdf1927e1be1 100644
--- a/drivers/usb/dwc2/hcd_queue.c
+++ b/drivers/usb/dwc2/hcd_queue.c
@@ -59,7 +59,7 @@
 #define DWC2_UNRESERVE_DELAY (msecs_to_jiffies(5))
 
 /* If we get a NAK, wait this long before retrying */
-#define DWC2_RETRY_WAIT_DELAY (1 * 1E6L)
+#define DWC2_RETRY_WAIT_DELAY (1 * USEC_PER_SEC)
 
 /**
  * dwc2_periodic_channel_available() - Checks that a channel is available for a

base-commit: d4439a1189f93d0ac1eaf0197db8e6b3e197d5c7
-- 
2.34.0.rc0


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

* Re: [PATCH] usb: dwc2: hcd_queue: Fix use of floating point literal
  2021-11-04 21:59 [PATCH] usb: dwc2: hcd_queue: Fix use of floating point literal Nathan Chancellor
@ 2021-11-04 23:29 ` Nick Desaulniers
  2021-11-04 23:33   ` Nick Desaulniers
  2021-11-05 13:08 ` John Keeping
  1 sibling, 1 reply; 6+ messages in thread
From: Nick Desaulniers @ 2021-11-04 23:29 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Minas Harutyunyan, Greg Kroah-Hartman, linux-usb, linux-kernel, llvm

On Thu, Nov 4, 2021 at 2:59 PM Nathan Chancellor <nathan@kernel.org> wrote:
>
> A new commit in LLVM causes an error on the use of 'long double' when
> '-mno-x87' is used, which the kernel does through an alias,
> '-mno-80387' (see the LLVM commit below for more details around why it
> does this).
>
>  drivers/usb/dwc2/hcd_queue.c:1744:25: error: expression requires  'long double' type support, but target 'x86_64-unknown-linux-gnu' does not support it
>                          delay = ktime_set(0, DWC2_RETRY_WAIT_DELAY);
>                                              ^
>  drivers/usb/dwc2/hcd_queue.c:62:34: note: expanded from macro 'DWC2_RETRY_WAIT_DELAY'
>  #define DWC2_RETRY_WAIT_DELAY (1 * 1E6L)
>                                  ^
>  1 error generated.
>
> This happens due to the use of a 'long double' literal. The 'E6' part of
> '1E6L' causes the literal to be a 'double' then the 'L' suffix promotes
> it to 'long double'.
>
> There is no visible reason for a floating point value in this driver, as
> the value is only used as a parameter to a function that expects an
> integer type.  Use USEC_PER_SEC, which is the same integer value as
> '1E6L', to avoid changing functionality but fix the error.
>
> Fixes: 6ed30a7d8ec2 ("usb: dwc2: host: use hrtimer for NAK retries")
> Link: https://github.com/ClangBuiltLinux/linux/issues/1497
> Link: https://github.com/llvm/llvm-project/commit/a8083d42b1c346e21623a1d36d1f0cadd7801d83
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>

Thanks for the patch!
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

> ---
>  drivers/usb/dwc2/hcd_queue.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/usb/dwc2/hcd_queue.c b/drivers/usb/dwc2/hcd_queue.c
> index 89a788326c56..bdf1927e1be1 100644
> --- a/drivers/usb/dwc2/hcd_queue.c
> +++ b/drivers/usb/dwc2/hcd_queue.c
> @@ -59,7 +59,7 @@
>  #define DWC2_UNRESERVE_DELAY (msecs_to_jiffies(5))
>
>  /* If we get a NAK, wait this long before retrying */
> -#define DWC2_RETRY_WAIT_DELAY (1 * 1E6L)
> +#define DWC2_RETRY_WAIT_DELAY (1 * USEC_PER_SEC)
>
>  /**
>   * dwc2_periodic_channel_available() - Checks that a channel is available for a
>
> base-commit: d4439a1189f93d0ac1eaf0197db8e6b3e197d5c7
> --
> 2.34.0.rc0
>


-- 
Thanks,
~Nick Desaulniers

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

* Re: [PATCH] usb: dwc2: hcd_queue: Fix use of floating point literal
  2021-11-04 23:29 ` Nick Desaulniers
@ 2021-11-04 23:33   ` Nick Desaulniers
  2021-11-04 23:59     ` Nathan Chancellor
  0 siblings, 1 reply; 6+ messages in thread
From: Nick Desaulniers @ 2021-11-04 23:33 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Minas Harutyunyan, Greg Kroah-Hartman, linux-usb, linux-kernel, llvm

On Thu, Nov 4, 2021 at 4:29 PM Nick Desaulniers <ndesaulniers@google.com> wrote:
>
> On Thu, Nov 4, 2021 at 2:59 PM Nathan Chancellor <nathan@kernel.org> wrote:
> >
> > A new commit in LLVM causes an error on the use of 'long double' when
> > '-mno-x87' is used, which the kernel does through an alias,
> > '-mno-80387' (see the LLVM commit below for more details around why it
> > does this).
> >
> >  drivers/usb/dwc2/hcd_queue.c:1744:25: error: expression requires  'long double' type support, but target 'x86_64-unknown-linux-gnu' does not support it
> >                          delay = ktime_set(0, DWC2_RETRY_WAIT_DELAY);
> >                                              ^
> >  drivers/usb/dwc2/hcd_queue.c:62:34: note: expanded from macro 'DWC2_RETRY_WAIT_DELAY'
> >  #define DWC2_RETRY_WAIT_DELAY (1 * 1E6L)
> >                                  ^
> >  1 error generated.
> >
> > This happens due to the use of a 'long double' literal. The 'E6' part of
> > '1E6L' causes the literal to be a 'double' then the 'L' suffix promotes
> > it to 'long double'.
> >
> > There is no visible reason for a floating point value in this driver, as
> > the value is only used as a parameter to a function that expects an
> > integer type.  Use USEC_PER_SEC, which is the same integer value as
> > '1E6L', to avoid changing functionality but fix the error.
> >
> > Fixes: 6ed30a7d8ec2 ("usb: dwc2: host: use hrtimer for NAK retries")
> > Link: https://github.com/ClangBuiltLinux/linux/issues/1497
> > Link: https://github.com/llvm/llvm-project/commit/a8083d42b1c346e21623a1d36d1f0cadd7801d83
> > Signed-off-by: Nathan Chancellor <nathan@kernel.org>
>
> Thanks for the patch!
> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

hmm...should we explicitly #include <vdso/time.h> for this
declaration?  It may work due to transitive includes, but that's
generally considered brittle should those transitive includes change
in the future.

>
> > ---
> >  drivers/usb/dwc2/hcd_queue.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/usb/dwc2/hcd_queue.c b/drivers/usb/dwc2/hcd_queue.c
> > index 89a788326c56..bdf1927e1be1 100644
> > --- a/drivers/usb/dwc2/hcd_queue.c
> > +++ b/drivers/usb/dwc2/hcd_queue.c
> > @@ -59,7 +59,7 @@
> >  #define DWC2_UNRESERVE_DELAY (msecs_to_jiffies(5))
> >
> >  /* If we get a NAK, wait this long before retrying */
> > -#define DWC2_RETRY_WAIT_DELAY (1 * 1E6L)
> > +#define DWC2_RETRY_WAIT_DELAY (1 * USEC_PER_SEC)
> >
> >  /**
> >   * dwc2_periodic_channel_available() - Checks that a channel is available for a
> >
> > base-commit: d4439a1189f93d0ac1eaf0197db8e6b3e197d5c7
> > --
> > 2.34.0.rc0
> >
>
>
> --
> Thanks,
> ~Nick Desaulniers



-- 
Thanks,
~Nick Desaulniers

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

* Re: [PATCH] usb: dwc2: hcd_queue: Fix use of floating point literal
  2021-11-04 23:33   ` Nick Desaulniers
@ 2021-11-04 23:59     ` Nathan Chancellor
  0 siblings, 0 replies; 6+ messages in thread
From: Nathan Chancellor @ 2021-11-04 23:59 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Minas Harutyunyan, Greg Kroah-Hartman, linux-usb, linux-kernel, llvm

On Thu, Nov 04, 2021 at 04:33:41PM -0700, Nick Desaulniers wrote:
> On Thu, Nov 4, 2021 at 4:29 PM Nick Desaulniers <ndesaulniers@google.com> wrote:
> >
> > On Thu, Nov 4, 2021 at 2:59 PM Nathan Chancellor <nathan@kernel.org> wrote:
> > >
> > > A new commit in LLVM causes an error on the use of 'long double' when
> > > '-mno-x87' is used, which the kernel does through an alias,
> > > '-mno-80387' (see the LLVM commit below for more details around why it
> > > does this).
> > >
> > >  drivers/usb/dwc2/hcd_queue.c:1744:25: error: expression requires  'long double' type support, but target 'x86_64-unknown-linux-gnu' does not support it
> > >                          delay = ktime_set(0, DWC2_RETRY_WAIT_DELAY);
> > >                                              ^
> > >  drivers/usb/dwc2/hcd_queue.c:62:34: note: expanded from macro 'DWC2_RETRY_WAIT_DELAY'
> > >  #define DWC2_RETRY_WAIT_DELAY (1 * 1E6L)
> > >                                  ^
> > >  1 error generated.
> > >
> > > This happens due to the use of a 'long double' literal. The 'E6' part of
> > > '1E6L' causes the literal to be a 'double' then the 'L' suffix promotes
> > > it to 'long double'.
> > >
> > > There is no visible reason for a floating point value in this driver, as
> > > the value is only used as a parameter to a function that expects an
> > > integer type.  Use USEC_PER_SEC, which is the same integer value as
> > > '1E6L', to avoid changing functionality but fix the error.
> > >
> > > Fixes: 6ed30a7d8ec2 ("usb: dwc2: host: use hrtimer for NAK retries")
> > > Link: https://github.com/ClangBuiltLinux/linux/issues/1497
> > > Link: https://github.com/llvm/llvm-project/commit/a8083d42b1c346e21623a1d36d1f0cadd7801d83
> > > Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> >
> > Thanks for the patch!
> > Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
> 
> hmm...should we explicitly #include <vdso/time.h> for this
> declaration?  It may work due to transitive includes, but that's
> generally considered brittle should those transitive includes change
> in the future.

This file uses ktime_t, which comes from include/linux/ktime.h, which
eventually includes include/vdso/time64.h. include/vdso/time64.h is only
included in three header files and no drivers so I do not think this is
that brittle. I am happy to change that if the maintainers feel it is
worth the extra include.

> >
> > > ---
> > >  drivers/usb/dwc2/hcd_queue.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/usb/dwc2/hcd_queue.c b/drivers/usb/dwc2/hcd_queue.c
> > > index 89a788326c56..bdf1927e1be1 100644
> > > --- a/drivers/usb/dwc2/hcd_queue.c
> > > +++ b/drivers/usb/dwc2/hcd_queue.c
> > > @@ -59,7 +59,7 @@
> > >  #define DWC2_UNRESERVE_DELAY (msecs_to_jiffies(5))
> > >
> > >  /* If we get a NAK, wait this long before retrying */
> > > -#define DWC2_RETRY_WAIT_DELAY (1 * 1E6L)
> > > +#define DWC2_RETRY_WAIT_DELAY (1 * USEC_PER_SEC)
> > >
> > >  /**
> > >   * dwc2_periodic_channel_available() - Checks that a channel is available for a
> > >
> > > base-commit: d4439a1189f93d0ac1eaf0197db8e6b3e197d5c7
> > > --
> > > 2.34.0.rc0
> > >
> >
> >
> > --
> > Thanks,
> > ~Nick Desaulniers
> 
> 
> 
> -- 
> Thanks,
> ~Nick Desaulniers

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

* Re: [PATCH] usb: dwc2: hcd_queue: Fix use of floating point literal
  2021-11-04 21:59 [PATCH] usb: dwc2: hcd_queue: Fix use of floating point literal Nathan Chancellor
  2021-11-04 23:29 ` Nick Desaulniers
@ 2021-11-05 13:08 ` John Keeping
  2021-11-05 14:56   ` Nathan Chancellor
  1 sibling, 1 reply; 6+ messages in thread
From: John Keeping @ 2021-11-05 13:08 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Minas Harutyunyan, Greg Kroah-Hartman, Nick Desaulniers,
	linux-usb, linux-kernel, llvm

On Thu, Nov 04, 2021 at 02:59:23PM -0700, Nathan Chancellor wrote:
> A new commit in LLVM causes an error on the use of 'long double' when
> '-mno-x87' is used, which the kernel does through an alias,
> '-mno-80387' (see the LLVM commit below for more details around why it
> does this).
> 
>  drivers/usb/dwc2/hcd_queue.c:1744:25: error: expression requires  'long double' type support, but target 'x86_64-unknown-linux-gnu' does not support it
>                          delay = ktime_set(0, DWC2_RETRY_WAIT_DELAY);
>                                              ^
>  drivers/usb/dwc2/hcd_queue.c:62:34: note: expanded from macro 'DWC2_RETRY_WAIT_DELAY'
>  #define DWC2_RETRY_WAIT_DELAY (1 * 1E6L)
>                                  ^
>  1 error generated.
> 
> This happens due to the use of a 'long double' literal. The 'E6' part of
> '1E6L' causes the literal to be a 'double' then the 'L' suffix promotes
> it to 'long double'.
> 
> There is no visible reason for a floating point value in this driver, as
> the value is only used as a parameter to a function that expects an
> integer type.  Use USEC_PER_SEC, which is the same integer value as
> '1E6L', to avoid changing functionality but fix the error.
> 
> Fixes: 6ed30a7d8ec2 ("usb: dwc2: host: use hrtimer for NAK retries")
> Link: https://github.com/ClangBuiltLinux/linux/issues/1497
> Link: https://github.com/llvm/llvm-project/commit/a8083d42b1c346e21623a1d36d1f0cadd7801d83
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> ---
>  drivers/usb/dwc2/hcd_queue.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/dwc2/hcd_queue.c b/drivers/usb/dwc2/hcd_queue.c
> index 89a788326c56..bdf1927e1be1 100644
> --- a/drivers/usb/dwc2/hcd_queue.c
> +++ b/drivers/usb/dwc2/hcd_queue.c
> @@ -59,7 +59,7 @@
>  #define DWC2_UNRESERVE_DELAY (msecs_to_jiffies(5))
>  
>  /* If we get a NAK, wait this long before retrying */
> -#define DWC2_RETRY_WAIT_DELAY (1 * 1E6L)
> +#define DWC2_RETRY_WAIT_DELAY (1 * USEC_PER_SEC)

Using USEC_PER_SEC here seems quite weird.  This is used as:

	delay = ktime_set(0, DWC2_RETRY_WAIT_DELAY);

so the units are nanoseconds.

Maybe NSEC_PER_MSEC would better indicate the intent here?

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

* Re: [PATCH] usb: dwc2: hcd_queue: Fix use of floating point literal
  2021-11-05 13:08 ` John Keeping
@ 2021-11-05 14:56   ` Nathan Chancellor
  0 siblings, 0 replies; 6+ messages in thread
From: Nathan Chancellor @ 2021-11-05 14:56 UTC (permalink / raw)
  To: John Keeping
  Cc: Minas Harutyunyan, Greg Kroah-Hartman, Nick Desaulniers,
	linux-usb, linux-kernel, llvm

On Fri, Nov 05, 2021 at 01:08:48PM +0000, John Keeping wrote:
> On Thu, Nov 04, 2021 at 02:59:23PM -0700, Nathan Chancellor wrote:
> > A new commit in LLVM causes an error on the use of 'long double' when
> > '-mno-x87' is used, which the kernel does through an alias,
> > '-mno-80387' (see the LLVM commit below for more details around why it
> > does this).
> > 
> >  drivers/usb/dwc2/hcd_queue.c:1744:25: error: expression requires  'long double' type support, but target 'x86_64-unknown-linux-gnu' does not support it
> >                          delay = ktime_set(0, DWC2_RETRY_WAIT_DELAY);
> >                                              ^
> >  drivers/usb/dwc2/hcd_queue.c:62:34: note: expanded from macro 'DWC2_RETRY_WAIT_DELAY'
> >  #define DWC2_RETRY_WAIT_DELAY (1 * 1E6L)
> >                                  ^
> >  1 error generated.
> > 
> > This happens due to the use of a 'long double' literal. The 'E6' part of
> > '1E6L' causes the literal to be a 'double' then the 'L' suffix promotes
> > it to 'long double'.
> > 
> > There is no visible reason for a floating point value in this driver, as
> > the value is only used as a parameter to a function that expects an
> > integer type.  Use USEC_PER_SEC, which is the same integer value as
> > '1E6L', to avoid changing functionality but fix the error.
> > 
> > Fixes: 6ed30a7d8ec2 ("usb: dwc2: host: use hrtimer for NAK retries")
> > Link: https://github.com/ClangBuiltLinux/linux/issues/1497
> > Link: https://github.com/llvm/llvm-project/commit/a8083d42b1c346e21623a1d36d1f0cadd7801d83
> > Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> > ---
> >  drivers/usb/dwc2/hcd_queue.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/usb/dwc2/hcd_queue.c b/drivers/usb/dwc2/hcd_queue.c
> > index 89a788326c56..bdf1927e1be1 100644
> > --- a/drivers/usb/dwc2/hcd_queue.c
> > +++ b/drivers/usb/dwc2/hcd_queue.c
> > @@ -59,7 +59,7 @@
> >  #define DWC2_UNRESERVE_DELAY (msecs_to_jiffies(5))
> >  
> >  /* If we get a NAK, wait this long before retrying */
> > -#define DWC2_RETRY_WAIT_DELAY (1 * 1E6L)
> > +#define DWC2_RETRY_WAIT_DELAY (1 * USEC_PER_SEC)
> 
> Using USEC_PER_SEC here seems quite weird.  This is used as:
> 
> 	delay = ktime_set(0, DWC2_RETRY_WAIT_DELAY);
> 
> so the units are nanoseconds.
> 
> Maybe NSEC_PER_MSEC would better indicate the intent here?

Yes, that seems reasonable. I will send a v2.

Cheers,
Nathan

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

end of thread, other threads:[~2021-11-05 14:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-04 21:59 [PATCH] usb: dwc2: hcd_queue: Fix use of floating point literal Nathan Chancellor
2021-11-04 23:29 ` Nick Desaulniers
2021-11-04 23:33   ` Nick Desaulniers
2021-11-04 23:59     ` Nathan Chancellor
2021-11-05 13:08 ` John Keeping
2021-11-05 14:56   ` Nathan Chancellor

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).