Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp572882imm; Wed, 22 Aug 2018 08:59:03 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwVo5+3RE0IJSGIHoeoxbIH4+o3AQw4RzZL7LaPL1ClxTL7q9iQJQnP/XIFIY4jw0FrcpiV X-Received: by 2002:a17:902:8494:: with SMTP id c20-v6mr54909784plo.336.1534953543122; Wed, 22 Aug 2018 08:59:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534953543; cv=none; d=google.com; s=arc-20160816; b=qhvQ1sFELtZFsa7TpqwsO5GogOVBbTOauPLaCxsDK+2y9Wl02sHPMEIQMqUNRQb7bl o8YgLcDqwFnLMB3H+Osjx4XMKtQS9ASiRW7x27Y69KU4v5ENeYNnJzCwoYe8tcHIgBC3 DysR1mqFY+p1L1gCXxiObQsUNrUhiPHXgkq12WtPJs0LJKClfezAKQSQSy7++nwbO+dM rc2Q7Jou/ZDi2/D6uwkLsQbOKJMFzIgkB0JizGdEoCwRSL6AaUWdos2BA8KBsVx6VuWe sgLzQ+4NCPMlElb1wyh65IUFaBc7Sn3rZ3ZLkcgakvtkFkmuSnj4JPXXuDwKC0GKnaAU Ho0w== 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=yh54iSAUCs6wa3hymOw7NULgkIKaGB5pe5EQbS5582s=; b=ksTi+ijSWC2ltDuaIy4OlBuOklZHdYzC7PFc06VtxmVlZt4Uo8PIa0TiV5rzDDGKjd FBRmOldqpLrovbBGYigdFFvs3wJJiewAKIy5Cu258TyeIIE2NmypghHrtR7WUBJZEph+ knQ6GeXng9yRpy477W0ajBjoxK3WastglJ7A6l+uRgv5vjfrEKdyR3/KajRxYt4f1H0g brjx1mY4xOeyHeqgHYBuZ4KlGUinZwZKiqr7uJcnp1WKZfYTHZdL4CGEGN8Mmt3mBdIg U7pF/dhoR3q3Xq0Fr/ffrpokezMPVuO2IqZK2t/PFQQFuO2EnbNYapuZEnWBZ9IcS6Yt 7XqQ== 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 8-v6si2177982pfw.89.2018.08.22.08.58.47; Wed, 22 Aug 2018 08:59:03 -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 S1729429AbeHVTXI (ORCPT + 99 others); Wed, 22 Aug 2018 15:23:08 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:34982 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729153AbeHVTXI (ORCPT ); Wed, 22 Aug 2018 15:23:08 -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 C9E5680D; Wed, 22 Aug 2018 08:57:40 -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 B82EA3F2EA; Wed, 22 Aug 2018 08:57:38 -0700 (PDT) Date: Wed, 22 Aug 2018 16:57:33 +0100 From: Brian Starkey To: Daniel Vetter Cc: Eric Engestrom , Matthew Wilcox , 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: <20180822155732.GA39066@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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: 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, 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: >>> Hi Matthew, >>> >>> On Tue, Aug 21, 2018 at 09:26:39AM -0700, Matthew Wilcox wrote: >>> > On Tue, Aug 21, 2018 at 05:16:11PM +0100, Brian Starkey wrote: >>> > > There's a number of things which haven't previously been documented >>> > > around the usage of format modifiers. Capture the current >>> > > understanding in an overview comment and add it to the rst >>> > > documentation. >>> > > >>> > > Ideally, the generated documentation would also include documentation >>> > > of all of the #defines, but the kernel-doc system doesn't currently >>> > > support kernel-doc comments on #define constants. >>> > >>> > Can you turn them into enums? This seems to work ok: >>> > >>> > -/* color index */ >>> > -#define DRM_FORMAT_C8 fourcc_code('C', '8', ' ', ' ') /* [7:0] C */ >>> > - >>> > -/* 8 bpp Red */ >>> > -#define DRM_FORMAT_R8 fourcc_code('R', '8', ' ', ' ') /* [7:0] R */ >>> > +enum { >>> > + /* color index */ >>> > + DRM_FORMAT_C8 = fourcc_code('C', '8', ' ', ' '), /* [7:0] C */ >>> > + /* 8 bpp Red */ >>> > + DRM_FORMAT_R8 = fourcc_code('R', '8', ' ', ' '), /* [7:0] R */ >>> > +}; >>> > >>> > but I appreciate this is user API and maybe there's some code out there >>> > that does #ifndef DRM_FORMAT_C8 ... >>> >>> Thanks for the suggestion, Daniel did mention the same. However, >>> unfortunately I don't think we can safely change the UAPI header in >>> this manner. >> >> You could get the best of both worlds by doing both: >> >> enum { >> foo = fourcc(...), >> bar = fourcc(...), >> } >> #define foo foo >> #define bar bar >> >> It would mean a bit more code though, but that way these would now be >> enums (with all the advantages of enums vs plain literals) and still >> pass #ifdef checks :) >> >> (BTW, on the "maybe there's some code that does #ifdef": I can tell you >> there is indeed, having written this myself for an out-of-tree driver >> for customer-modified kernels that may contain additional formats) > >Looks reasonable. I'd even put the #define right within each enum line >(as a reminder so people don't forget to add them. Would happily ack a >patch to mass-convert, if that ups the odds of good kerneldoc for all >this. > >enum also should support the inline style of kerneldoc (otherwise I >guess we'd need to fix that first, or it just makes no sense at all). >-Daniel 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... Cheers, -Brian >-- >Daniel Vetter >Software Engineer, Intel Corporation >+41 (0) 79 365 57 48 - http://blog.ffwll.ch