Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp346867ybb; Fri, 3 Apr 2020 04:00:38 -0700 (PDT) X-Google-Smtp-Source: APiQypJlTOAyLfQr2GmcZtQEn2bA/sG2sHtn9rfc7D09oES9Fp7mAttKNfbXI3qs1J96tVnEoYWG X-Received: by 2002:a05:6830:146:: with SMTP id j6mr5756176otp.117.1585911638481; Fri, 03 Apr 2020 04:00:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585911638; cv=none; d=google.com; s=arc-20160816; b=Gy9P4QKG+Zxdt6j5Feueq5mf7vro8DTwyvxO8xbxiRCFi4iioXsEdnbIH0hVDerXpt hyA77WllQJju0FnIeZMBm33R76SfzSZ8UdJYcaKMzTXp1j6t6/I5+p3MVExFgv+9gddV xyrXL1SQGKPfUDRqj6v+vYc43PwCh9HJY8goUmNRgjzridQHkfSXmaTgyPWpGTN6WGI6 ugwgs9uV2+6kPYiY26pHiNp58z0JDmK403g51svBUG8+FKIEUzHzlHFle6MQkXFc5RDl xj39o+wpLRYxgN9yHCusW0Dvq1OsYJXOHXUgY1SET4cTgFCh8dixGHQ2XRJXSbFR4SFL 9bdw== 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:ironport-sdr:ironport-sdr; bh=5YOAtG6UNSORPiRbiSIeYaZb/x6Ze6ptSzJEomL4yxY=; b=hKRqhgjCRudBtMPTDRAxB+rUaUJPqUlUJ2wyo398wVX3CZR+EO9BQhCYB/SVBJmOcM LFn0DCNQk30RaTzSgZHPMiMKAfb6crFV3SAW3zFUE4EZiVLhzMIcEdRyYeUjrqKQfVoq jZAyOynfAunnQjPwrQ1NpLTaDC94x4OXD2hoGvTV2tBP6m2OutNGEtOyNUcAAHOUPn5Y Ouo4J66wiIKmk73fINaaIBEEUEop/zytJk1Ls1SW34vCbFkATFs1iUquQSAV0e4KZ/sj 8K4y6svyx6ksE1tB72upbbKZB3mOI72N1ymAY8LCf1hZbAZTOPgn24C+pka1L29z+eRj QtaQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k13si3497713otr.165.2020.04.03.04.00.22; Fri, 03 Apr 2020 04:00:38 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727956AbgDCKrM (ORCPT + 99 others); Fri, 3 Apr 2020 06:47:12 -0400 Received: from mga18.intel.com ([134.134.136.126]:51370 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727792AbgDCKrL (ORCPT ); Fri, 3 Apr 2020 06:47:11 -0400 IronPort-SDR: 7kUbTwD6ao1lMSZbezKXj2bn24mwYfEyPu6b+8p9yOfk8di16VpsDNk+KPtEcKv7pfMjo/VAsc RAc0IG1hUuZw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Apr 2020 03:47:10 -0700 IronPort-SDR: 8ti4Qol5gbB/MXswR0sGQ9fX6aCU580MMij4U73bTkAipfBPgWDTHjcfnIYtRY7sCvhQJ6msMf oWSzhTIMCqlA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,339,1580803200"; d="scan'208";a="273909028" Received: from seemahan-mobl.ger.corp.intel.com (HELO kekkonen.fi.intel.com) ([10.249.38.56]) by fmsmga004.fm.intel.com with ESMTP; 03 Apr 2020 03:47:07 -0700 Received: by kekkonen.fi.intel.com (Postfix, from userid 1000) id 3EF0F21F19; Fri, 3 Apr 2020 13:47:02 +0300 (EEST) Date: Fri, 3 Apr 2020 13:47:02 +0300 From: Sakari Ailus To: Laurent Pinchart Cc: Petr Mladek , Andy Shevchenko , linux-media@vger.kernel.org, Dave Stevenson , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, hverkuil@xs4all.nl, mchehab@kernel.org, Sergey Senozhatsky , Steven Rostedt , Joe Perches , Jani Nikula Subject: Re: [PATCH v2 1/1] lib/vsprintf: Add support for printing V4L2 and DRM fourccs Message-ID: <20200403104701.GC3172@kekkonen.localdomain> References: <20200403091156.7814-1-sakari.ailus@linux.intel.com> <20200403102449.GB4882@pendragon.ideasonboard.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200403102449.GB4882@pendragon.ideasonboard.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Laurent, Thanks for the comments. On Fri, Apr 03, 2020 at 01:24:49PM +0300, Laurent Pinchart wrote: > Hi Sakari, > > Thank you for the patch. > > On Fri, Apr 03, 2020 at 12:11:56PM +0300, Sakari Ailus wrote: > > Add a printk modifier %ppf (for pixel format) for printing V4L2 and DRM > > pixel formats denoted by 4ccs. The 4cc encoding is the same for both so > > the same implementation can be used. > > > > Suggested-by: Mauro Carvalho Chehab > > Signed-off-by: Sakari Ailus > > --- > > since v1: > > > > - Improve documentation (add -BE suffix, refer to "FourCC". > > > > - Use '%p4cc' conversion specifier instead of '%ppf'. > > > > - Fix 31st bit handling in printing FourCC codes. > > > > - Use string() correctly, to allow e.g. proper field width handling. > > > > - Remove loop, use put_unaligned_le32() instead. > > > > Documentation/core-api/printk-formats.rst | 12 +++++++++++ > > lib/vsprintf.c | 25 +++++++++++++++++++++++ > > 2 files changed, 37 insertions(+) > > > > diff --git a/Documentation/core-api/printk-formats.rst b/Documentation/core-api/printk-formats.rst > > index 8ebe46b1af39..550568520ab6 100644 > > --- a/Documentation/core-api/printk-formats.rst > > +++ b/Documentation/core-api/printk-formats.rst > > @@ -545,6 +545,18 @@ For printing netdev_features_t. > > > > Passed by reference. > > > > +V4L2 and DRM FourCC code (pixel format) > > +--------------------------------------- > > + > > +:: > > + > > + %p4cc > > + > > +Print a FourCC code used by V4L2 or DRM. The "-BE" suffix is added on big endian > > +formats. > > + > > +Passed by reference. > > + > > Thanks > > ====== > > > > diff --git a/lib/vsprintf.c b/lib/vsprintf.c > > index 7c488a1ce318..93eea6a320da 100644 > > --- a/lib/vsprintf.c > > +++ b/lib/vsprintf.c > > @@ -1721,6 +1721,28 @@ char *netdev_bits(char *buf, char *end, const void *addr, > > return special_hex_number(buf, end, num, size); > > } > > > > +static noinline_for_stack > > +char *fourcc_string(char *buf, char *end, const u32 *fourcc, > > + struct printf_spec spec, const char *fmt) > > +{ > > +#define FOURCC_STRING_BE "-BE" > > + char s[sizeof(*fourcc) + sizeof(FOURCC_STRING_BE)] = { 0 }; > > + > > + if (check_pointer(&buf, end, fourcc, spec)) > > + return buf; > > + > > + if (fmt[1] != 'c' || fmt[2] != 'c') > > + return error_string(buf, end, "(%p4?)", spec); > > + > > + put_unaligned_le32(*fourcc & ~BIT(31), s); > > + > > + if (*fourcc & BIT(31)) > > + strscpy(s + sizeof(*fourcc), FOURCC_STRING_BE, > > + sizeof(FOURCC_STRING_BE)); > > + > > + return string(buf, end, s, spec); > > Taking V4L2_PIX_FMT_Y16_BE as an example, this will print 'Y16 -BE' > (without quotes). There are other 4CCs that contain spaces and would > suffer from a similar issue. Even in little-endian format, it would > result in additional spaces in the output string. Is this what we want ? > Should the caller always enclose the 4CC in quotes or brackets for > clarity ? Or should still be done here ? Good question. Space is indeed a valid character in a 4cc code. If I omit one or more spaces, it will no longer be a 4cc, but a 3cc or even a 2cc. Jokes aside, there are probably fair arguments both ways. I presume there's no 4cc code where the location of a space would make a difference but all of the spaces are trailing spaces. It's also worth noting that the formats printed are mostly for debugging purpose and thus even getting a hypothetical case wrong is not a grave issue. This would also support just printing them as-is though. I'm leaning slightly towards omitting any spaces if the code has them. This is something that couldn't be done by using a macro... -- Regards, Sakari Ailus