From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752212AbdKUM4O (ORCPT ); Tue, 21 Nov 2017 07:56:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:53524 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752008AbdKUM4M (ORCPT ); Tue, 21 Nov 2017 07:56:12 -0500 DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BDF082192B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=goodmis.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=rostedt@goodmis.org Date: Tue, 21 Nov 2017 07:56:09 -0500 From: Steven Rostedt To: Jiri Kosina Cc: Thomas Gleixner , luca abeni , Peter Zijlstra , Daniel Bristot de Oliveira , Juri Lelli , Linus Torvalds , Mathieu Poirier , Mike Galbraith , linux-kernel@vger.kernel.org Subject: Re: [PATCH] sched/deadline: Use bools for the state flags Message-ID: <20171121075609.1384b92e@gandalf.local.home> In-Reply-To: References: X-Mailer: Claws Mail 3.14.0 (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 21 Nov 2017 12:43:53 +0100 (CET) Jiri Kosina wrote: > On Tue, 21 Nov 2017, Thomas Gleixner wrote: > > > > Commit > > > > > > 799ba82de01e ("sched/deadline: Use C bitfields for the state flags") > > > > > > converted state flags into one-bit signed int. Signed one-bit type can be > > > either 0 or -1, which is going to cause a problem once 1 is assigned to it > > > and then the value later tested against 1. > > > > > > The current code is okay, as all the checks are (non-)zero check, but I > > > believe that we'd rather be safe than sorry here; remove the fragility by > > > converting the state flags to bool. > > > > > > This also silences annoying sparse complaints about this very issue when > > > compiling any code that includes sched.h. > > > > What's wrong with making these bitfields 'unsigned int' ? > > Surely that works as well. I chose bool as that's in line with the actual > semantics, but I can of course resend with unsigned type if that's > preferred for one reason or another. Note, bool is different, as it must take up at least one byte, and up to 4 bytes on different architectures. A bool variable needs to be able to be stored without modifying anything else. Thus, changing: int a : 1; int b : 1; int c : 1; int d : 1; to bool a; bool b; bool c; bool d; at best increases the size required from 1 byte to 4 bytes, and at worse, it increases it from one byte to 16 bytes. -- Steve