Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1834769imm; Thu, 23 Aug 2018 09:30:13 -0700 (PDT) X-Google-Smtp-Source: AA+uWPw1qPVlXtO4ZUdALlTBmzMwsZ3RF2eUnzJ9NvRKzxKw1k7SgUFEjkDTAOwy6uaRzI4YOBj3 X-Received: by 2002:a63:6283:: with SMTP id w125-v6mr23425396pgb.83.1535041813541; Thu, 23 Aug 2018 09:30:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535041813; cv=none; d=google.com; s=arc-20160816; b=scw8lPirDfdfpUT/tc2MwCUxt8JQ9jz9+eJqmWTnwN9b+CvAZJ2su7LLHeu+OknDoM trSTUtBNRvv0gur+Lr2jajTePpdZP7WoC+r/vOVpv8sBNkBbIesdRGOWKF9AIWMVyein XiuzBAaccRPT1zE2pBEeiEw4Cr3B9ScLzvAnriINDgGqDf/Fbg1tEz2ZViFtLfbMToz4 NL27vcmeDh/4SepT25DPzR5hHkBM2PTjEMx3ULL1WOSeSVM3hCvvqu5n8+SkTYlWjeaH EdGzXU8AQNFOwhCJPFxyXtQbuYUUqp84fGBKM4WlcIQ8j3hEJ6anz3WkRE1gL/AHXCmh 4fFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=rx16VTOg9CqqsL8lbtFcos436iSBIqMgl6m06eBJfbY=; b=napGYcPBzRGq2VW8AStC6R9Hw41HJEq8yv8KFGy52zLy2od8pYEMM5Sgbc0Auooudp mAeLlv4yLzH3fZtNXcKA/RilEix0kzVk4iXLVf+Tjqm3Ppa96k21t217s/8fAtzyV/ex A2qjUUFsaF5C8JVlXenngnyagTxNv74Hy6gq1lrObm70cie0KhTPnHh7iVdsnTLKU9AY a9esPwewrTDP0EiLKjQwwYLERMexqMQON+ke+dA0ii6m9jYyd7EjRs6TfVyKqwI/Cdyg QHwEKL4RpkdizlfBpAg223y4LrpG82iYBeT+e1BFIJN8OAK5cQhlfx+E9EDVgihzvPJp XiAg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k6-v6si4465481plt.111.2018.08.23.09.29.58; Thu, 23 Aug 2018 09:30:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728017AbeHWTKm (ORCPT + 99 others); Thu, 23 Aug 2018 15:10:42 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:48484 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727881AbeHWTKm (ORCPT ); Thu, 23 Aug 2018 15:10:42 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 85F327A9; Thu, 23 Aug 2018 08:40:30 -0700 (PDT) Received: from e107564-lin.cambridge.arm.com (e107564-lin.cambridge.arm.com [10.2.131.9]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 755863F2EA; Thu, 23 Aug 2018 08:40:28 -0700 (PDT) Date: Thu, 23 Aug 2018 16:40:22 +0100 From: Brian Starkey To: Matthew Wilcox Cc: Daniel Vetter , Eric Engestrom , Alexandru-Cosmin Gheorghe , Jonathan Corbet , Dave Airlie , Linux Doc Mailing List , Linux Kernel Mailing List , dri-devel , Sean Paul , Liviu Dudau , Ayan Kumar Halder Subject: Re: [PATCH] drm/fourcc: Add DOC: overview comment Message-ID: <20180823154022.GA6535@e107564-lin.cambridge.arm.com> References: <20180821161611.10424-1-brian.starkey@arm.com> <20180821162639.GA21697@bombadil.infradead.org> <20180821164416.GA11553@e107564-lin.cambridge.arm.com> <20180822145924.GA13763@intel.com> <20180822155732.GA39066@e107564-lin.cambridge.arm.com> <20180823143445.GA26109@bombadil.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20180823143445.GA26109@bombadil.infradead.org> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Matthew, On Thu, Aug 23, 2018 at 07:34:45AM -0700, Matthew Wilcox wrote: >On Wed, Aug 22, 2018 at 04:57:33PM +0100, Brian Starkey wrote: >> On Wed, Aug 22, 2018 at 05:11:55PM +0200, Daniel Vetter wrote: >> > On Wed, Aug 22, 2018 at 4:59 PM, Eric Engestrom >> > wrote: >> > > On Tuesday, 2018-08-21 17:44:17 +0100, Brian Starkey wrote: >> > > > On Tue, Aug 21, 2018 at 09:26:39AM -0700, Matthew Wilcox wrote: >> > > > > Can you turn them into enums? This seems to work ok: >> >> I'm not sure that swapping out explicit 32-bit unsigned integers for >> enums (unspecified width, signed integers) is necessarily a good idea, >> it seems like Bad Things could happen. >> >> The C spec says: >> >> "the value of an enumeration constant shall be an integer constant >> expression that has a value representable as an int" >> >> Which likely gives us 4 bytes to play with on all machines >> that run Linux, but if drm_fourcc.h is ever going to be some kind of >> standard reference, making it non-portable seems like a fail. >> >> And even if you do have 4 bytes in an enum, signed integers act >> differently from unsigned ones, and compilers do love to invoke the UB >> clause... > >I think you're exaggerating how much latitude C compilers have here. >Further down in 6.7.2.2, it says: > > Each enumerated type shall be compatible with char, a signed > integer type, or an unsigned integer type. The choice of type is > implementation-defined, but shall be capable of representing the values > of all the members of the enumeration. > >So if we include an integer which isn't representable in a plain int, >then the compiler _must_ choose a larger type. I don't think so... the sentence I pasted says that including a value which isn't representable in a plain int would be illegal, and so the compiler doesn't _have_ to do anything (nasal demons, right?). >It could choose a >signed-64-bit type rather than an unsigned-32-bit type, but I can't >imagine any compiler being quite so insane. The paragraph about the implementation choosing a representation is separate from the valid range of values - the compiler can pick whatever storage it likes (smaller or even larger than an int), so long as that storage can fit all the defined values. However, providing a value in an enum definition which is not representable as an int would still be invalid (irrespective of how large the storage is) - it's a separate restriction. Anyhow, I'm not dying to replace all the current definitions with enums, so if someone else wants to pick that up, be my guest. Cheers, -Brian