All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched/deadline: Don't use dubious signed bitfields
@ 2017-10-13  7:01 ` Dan Carpenter
  0 siblings, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2017-10-13  7:01 UTC (permalink / raw)
  To: Ingo Molnar, luca abeni; +Cc: Peter Zijlstra, linux-kernel, kernel-janitors

It doesn't cause a run-time bug, but these bitfields should be unsigned.
When it's signed ->dl_throttled is set to either 0 or -1, instead of
0 and 1 as expected.  The sched.h file is included into tons of places
so Sparse generates a flood of warnings like this:

./include/linux/sched.h:477:54: error: dubious one-bit signed bitfield

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 0f897dfc195e..105eaff8a5e7 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -474,10 +474,10 @@ struct sched_dl_entity {
 	 * conditions between the inactive timer handler and the wakeup
 	 * code.
 	 */
-	int				dl_throttled      : 1;
-	int				dl_boosted        : 1;
-	int				dl_yielded        : 1;
-	int				dl_non_contending : 1;
+	unsigned int			dl_throttled      : 1;
+	unsigned int			dl_boosted        : 1;
+	unsigned int			dl_yielded        : 1;
+	unsigned int			dl_non_contending : 1;
 
 	/*
 	 * Bandwidth enforcement timer. Each -deadline task has its

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

* [PATCH] sched/deadline: Don't use dubious signed bitfields
@ 2017-10-13  7:01 ` Dan Carpenter
  0 siblings, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2017-10-13  7:01 UTC (permalink / raw)
  To: Ingo Molnar, luca abeni; +Cc: Peter Zijlstra, linux-kernel, kernel-janitors

It doesn't cause a run-time bug, but these bitfields should be unsigned.
When it's signed ->dl_throttled is set to either 0 or -1, instead of
0 and 1 as expected.  The sched.h file is included into tons of places
so Sparse generates a flood of warnings like this:

./include/linux/sched.h:477:54: error: dubious one-bit signed bitfield

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 0f897dfc195e..105eaff8a5e7 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -474,10 +474,10 @@ struct sched_dl_entity {
 	 * conditions between the inactive timer handler and the wakeup
 	 * code.
 	 */
-	int				dl_throttled      : 1;
-	int				dl_boosted        : 1;
-	int				dl_yielded        : 1;
-	int				dl_non_contending : 1;
+	unsigned int			dl_throttled      : 1;
+	unsigned int			dl_boosted        : 1;
+	unsigned int			dl_yielded        : 1;
+	unsigned int			dl_non_contending : 1;
 
 	/*
 	 * Bandwidth enforcement timer. Each -deadline task has its

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

* Re: [PATCH] sched/deadline: Don't use dubious signed bitfields
  2017-10-13  7:01 ` Dan Carpenter
@ 2017-10-13  7:36   ` Luca Abeni
  -1 siblings, 0 replies; 7+ messages in thread
From: Luca Abeni @ 2017-10-13  7:36 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Ingo Molnar, Peter Zijlstra, linux-kernel, kernel-janitors

Hi,

On Fri, 13 Oct 2017 10:01:22 +0300
Dan Carpenter <dan.carpenter@oracle.com> wrote:

> It doesn't cause a run-time bug, but these bitfields should be unsigned.
> When it's signed ->dl_throttled is set to either 0 or -1, instead of
> 0 and 1 as expected.  The sched.h file is included into tons of places
> so Sparse generates a flood of warnings like this:
> 
> ./include/linux/sched.h:477:54: error: dubious one-bit signed bitfield
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

I did not notice any issue when testing, but if "unsigned int" is the
common practice for bitfields, I agree with the change.

Reviewed-by: Luca Abeni <luca.abeni@santannapisa.it>


			Thanks,
				Luca
> 
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index 0f897dfc195e..105eaff8a5e7 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -474,10 +474,10 @@ struct sched_dl_entity {
>  	 * conditions between the inactive timer handler and the wakeup
>  	 * code.
>  	 */
> -	int				dl_throttled      : 1;
> -	int				dl_boosted        : 1;
> -	int				dl_yielded        : 1;
> -	int				dl_non_contending : 1;
> +	unsigned int			dl_throttled      : 1;
> +	unsigned int			dl_boosted        : 1;
> +	unsigned int			dl_yielded        : 1;
> +	unsigned int			dl_non_contending : 1;
>  
>  	/*
>  	 * Bandwidth enforcement timer. Each -deadline task has its


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

* Re: [PATCH] sched/deadline: Don't use dubious signed bitfields
@ 2017-10-13  7:36   ` Luca Abeni
  0 siblings, 0 replies; 7+ messages in thread
From: Luca Abeni @ 2017-10-13  7:36 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Ingo Molnar, Peter Zijlstra, linux-kernel, kernel-janitors

Hi,

On Fri, 13 Oct 2017 10:01:22 +0300
Dan Carpenter <dan.carpenter@oracle.com> wrote:

> It doesn't cause a run-time bug, but these bitfields should be unsigned.
> When it's signed ->dl_throttled is set to either 0 or -1, instead of
> 0 and 1 as expected.  The sched.h file is included into tons of places
> so Sparse generates a flood of warnings like this:
> 
> ./include/linux/sched.h:477:54: error: dubious one-bit signed bitfield
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

I did not notice any issue when testing, but if "unsigned int" is the
common practice for bitfields, I agree with the change.

Reviewed-by: Luca Abeni <luca.abeni@santannapisa.it>


			Thanks,
				Luca
> 
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index 0f897dfc195e..105eaff8a5e7 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -474,10 +474,10 @@ struct sched_dl_entity {
>  	 * conditions between the inactive timer handler and the wakeup
>  	 * code.
>  	 */
> -	int				dl_throttled      : 1;
> -	int				dl_boosted        : 1;
> -	int				dl_yielded        : 1;
> -	int				dl_non_contending : 1;
> +	unsigned int			dl_throttled      : 1;
> +	unsigned int			dl_boosted        : 1;
> +	unsigned int			dl_yielded        : 1;
> +	unsigned int			dl_non_contending : 1;
>  
>  	/*
>  	 * Bandwidth enforcement timer. Each -deadline task has its

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

* Re: [PATCH] sched/deadline: Don't use dubious signed bitfields
  2017-10-13  7:36   ` Luca Abeni
@ 2017-10-13 10:36     ` Dan Carpenter
  -1 siblings, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2017-10-13 10:36 UTC (permalink / raw)
  To: Luca Abeni; +Cc: Ingo Molnar, Peter Zijlstra, linux-kernel, kernel-janitors

On Fri, Oct 13, 2017 at 09:36:06AM +0200, Luca Abeni wrote:
> Hi,
> 
> On Fri, 13 Oct 2017 10:01:22 +0300
> Dan Carpenter <dan.carpenter@oracle.com> wrote:
> 
> > It doesn't cause a run-time bug, but these bitfields should be unsigned.
> > When it's signed ->dl_throttled is set to either 0 or -1, instead of
> > 0 and 1 as expected.  The sched.h file is included into tons of places
> > so Sparse generates a flood of warnings like this:
> > 
> > ./include/linux/sched.h:477:54: error: dubious one-bit signed bitfield
> > 
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> I did not notice any issue when testing

Correct.  It would only cause a bug if we had a condition like:

	if (foo->dl_throttled = 1) {

That would be impossible because ->dl_throttled = -1, but since the
conditions are all in the form:

	if (foo->dl_throttled) {

Then that works for both 1 and -1.

regards,
dan carpenter


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

* Re: [PATCH] sched/deadline: Don't use dubious signed bitfields
@ 2017-10-13 10:36     ` Dan Carpenter
  0 siblings, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2017-10-13 10:36 UTC (permalink / raw)
  To: Luca Abeni; +Cc: Ingo Molnar, Peter Zijlstra, linux-kernel, kernel-janitors

On Fri, Oct 13, 2017 at 09:36:06AM +0200, Luca Abeni wrote:
> Hi,
> 
> On Fri, 13 Oct 2017 10:01:22 +0300
> Dan Carpenter <dan.carpenter@oracle.com> wrote:
> 
> > It doesn't cause a run-time bug, but these bitfields should be unsigned.
> > When it's signed ->dl_throttled is set to either 0 or -1, instead of
> > 0 and 1 as expected.  The sched.h file is included into tons of places
> > so Sparse generates a flood of warnings like this:
> > 
> > ./include/linux/sched.h:477:54: error: dubious one-bit signed bitfield
> > 
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> I did not notice any issue when testing

Correct.  It would only cause a bug if we had a condition like:

	if (foo->dl_throttled == 1) {

That would be impossible because ->dl_throttled == -1, but since the
conditions are all in the form:

	if (foo->dl_throttled) {

Then that works for both 1 and -1.

regards,
dan carpenter

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

* [tip:sched/urgent] sched/deadline: Don't use dubious signed bitfields
  2017-10-13  7:01 ` Dan Carpenter
  (?)
  (?)
@ 2017-11-21  8:30 ` tip-bot for Dan Carpenter
  -1 siblings, 0 replies; 7+ messages in thread
From: tip-bot for Dan Carpenter @ 2017-11-21  8:30 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, peterz, mingo, linux-kernel, lucien.xin, luca.abeni,
	dan.carpenter, willy, hpa, torvalds

Commit-ID:  aa5222e92f8000ed3c1c38dddf11c83222aadfb3
Gitweb:     https://git.kernel.org/tip/aa5222e92f8000ed3c1c38dddf11c83222aadfb3
Author:     Dan Carpenter <dan.carpenter@oracle.com>
AuthorDate: Fri, 13 Oct 2017 10:01:22 +0300
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 21 Nov 2017 09:25:01 +0100

sched/deadline: Don't use dubious signed bitfields

It doesn't cause a run-time bug, but these bitfields should be unsigned.
When it's signed ->dl_throttled is set to either 0 or -1, instead of
0 and 1 as expected.

The sched.h file is included into tons of places so Sparse generates
a flood of warnings like this:

  ./include/linux/sched.h:477:54: error: dubious one-bit signed bitfield

Reported-by: Matthew Wilcox <willy@infradead.org>
Reported-by: Xin Long <lucien.xin@gmail.com>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Luca Abeni <luca.abeni@santannapisa.it>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: kernel-janitors@vger.kernel.org
Cc: luca abeni <luca.abeni@santannapisa.it>
Link: http://lkml.kernel.org/r/20171013070121.dzcncojuj2f4utij@mwanda
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 include/linux/sched.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index a5dc7c9..21991d6 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -473,10 +473,10 @@ struct sched_dl_entity {
 	 * conditions between the inactive timer handler and the wakeup
 	 * code.
 	 */
-	int				dl_throttled      : 1;
-	int				dl_boosted        : 1;
-	int				dl_yielded        : 1;
-	int				dl_non_contending : 1;
+	unsigned int			dl_throttled      : 1;
+	unsigned int			dl_boosted        : 1;
+	unsigned int			dl_yielded        : 1;
+	unsigned int			dl_non_contending : 1;
 
 	/*
 	 * Bandwidth enforcement timer. Each -deadline task has its

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

end of thread, other threads:[~2017-11-21  8:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-13  7:01 [PATCH] sched/deadline: Don't use dubious signed bitfields Dan Carpenter
2017-10-13  7:01 ` Dan Carpenter
2017-10-13  7:36 ` Luca Abeni
2017-10-13  7:36   ` Luca Abeni
2017-10-13 10:36   ` Dan Carpenter
2017-10-13 10:36     ` Dan Carpenter
2017-11-21  8:30 ` [tip:sched/urgent] " tip-bot for Dan Carpenter

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.