From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2BF43C4332F for ; Tue, 22 Nov 2022 12:43:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232625AbiKVMnc (ORCPT ); Tue, 22 Nov 2022 07:43:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231864AbiKVMnb (ORCPT ); Tue, 22 Nov 2022 07:43:31 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0AC164CC; Tue, 22 Nov 2022 04:43:30 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 6CD801F86C; Tue, 22 Nov 2022 12:43:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1669121009; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+LttO4rwpoEUKx+mKrlRotB9foBpDXaTdB6zGT0DKgM=; b=ECk0gdBvt1mE2jQiltgYhsFiQNQPIPXHcekRdV1hpQDSitwE3iuuWa2Nl+Yuv4JL+Xb7qX wgSOiTlj8GL42umxGL1Ajp3XsnlksRR9pDJV92RYvqEHo1At21rVmtPN7zv9gZ3FI/qxdB 0bICCWaFXg9/uyIBG8u7x6+OEwXd3k8= Received: from suse.cz (unknown [10.100.201.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id C30942C142; Tue, 22 Nov 2022 12:43:28 +0000 (UTC) Date: Tue, 22 Nov 2022 13:43:28 +0100 From: Petr Mladek To: "Russell King (Oracle)" Cc: Linus Walleij , Bartosz Golaszewski , Rob Herring , Lee Jones , Alyssa Rosenzweig , Andy Shevchenko , asahi@lists.linux.dev, devicetree@vger.kernel.org, Hector Martin , Jonathan Corbet , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-gpio@vger.kernel.org, Rasmus Villemoes , Sergey Senozhatsky , Steven Rostedt , Sven Peter Subject: Re: [PATCH v3 2/7] lib/vsprintf: Add support for generic FOURCCs by extending %p4cc Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org On Mon 2022-11-14 16:15:50, Russell King (Oracle) wrote: > On Mon, Nov 14, 2022 at 04:34:07PM +0100, Petr Mladek wrote: > > On Tue 2022-11-08 16:33:22, Russell King wrote: > > > From: Hector Martin > > > > > > %p4cc is designed for DRM/V4L2 FOURCCs with their specific quirks, but > > > it's useful to be able to print generic 4-character codes formatted as > > > an integer. Extend it to add format specifiers for printing generic > > > 32-bit FOURCCs with various endian semantics: > > > > > > %p4ch Host-endian > > > %p4cl Little-endian > > > %p4cb Big-endian > > > %p4cr Reverse-endian > > > > > > The endianness determines how bytes are interpreted as a u32, and the > > > FOURCC is then always printed MSByte-first (this is the opposite of > > > V4L/DRM FOURCCs). This covers most practical cases, e.g. %p4cr would > > > allow printing LSByte-first FOURCCs stored in host endian order > > > (other than the hex form being in character order, not the integer > > > value). > > > > > > Signed-off-by: Hector Martin > > > Signed-off-by: Russell King (Oracle) > > > > Reviewed-by: Petr Mladek > > > > See one nit below. > > > > > --- a/lib/vsprintf.c > > > +++ b/lib/vsprintf.c > > > @@ -1762,27 +1762,50 @@ char *fourcc_string(char *buf, char *end, const u32 *fourcc, > > > char output[sizeof("0123 little-endian (0x01234567)")]; > > > char *p = output; > > > unsigned int i; > > > + bool pixel_fmt = false; > > > u32 orig, val; > > > > > > - if (fmt[1] != 'c' || fmt[2] != 'c') > > > + if (fmt[1] != 'c') > > > return error_string(buf, end, "(%p4?)", spec); > > > > > > if (check_pointer(&buf, end, fourcc, spec)) > > > return buf; > > > > > > orig = get_unaligned(fourcc); > > > - val = orig & ~BIT(31); > > > + switch (fmt[2]) { > > > + case 'h': > > > + val = orig; > > > + break; > > > + case 'r': > > > + val = orig = swab32(orig); > > > > I do not like much these multi assignments. I think that the result > > was not even defined in some older C standards. Though, I can't find > > it now. And even make W=3 does not warn about it. > > Err. > > It's been supported for decades. I learnt about it back in 1992 when > I was introduced to C by another experienced C programmer. It's been > supported in ANSI C compilers. The Norcroft C compiler (which is > strict ANSI) on Acorn platforms back in the late 1980s/1990s even > supported it. Ah, the problem probably was with a more complicated assignment. For example, the result of the following code is not obvious: a = b = a++; Best Regards, Petr