Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp321724ybb; Fri, 3 Apr 2020 03:26:44 -0700 (PDT) X-Google-Smtp-Source: APiQypJcknUx6kVDA9ZUv9E0gr5ILsLZDTUMFB0akrFxUDOZ5zNf6LTl6aF9rs4FQrJlSOEbfTlK X-Received: by 2002:a05:6808:4d1:: with SMTP id a17mr2456427oie.39.1585909604488; Fri, 03 Apr 2020 03:26:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585909604; cv=none; d=google.com; s=arc-20160816; b=cLagWH1iufLl8ScIL7AsO1mUZBWTZBZxJLJYtdoxVPULDff9OOWbZ/N81Z3AxDlP2G uYWBRU9srdjsBQCEKcQbIdHJlWjLNH2cir9fPFFGky95CMk1/aL1iHeQ7Ovx/O2YjgIz viNNNRw/fiMJno1XsUv2vFj6LJQhqYIPcDznyZ8nOaR+bVgwvrI0e+TiH+ua2geyJM9u ghZebAA4nfnKocih8d35pDULOrDENR+gT3/NETjofpusd+lojSiyIcQy3ZH7EEr8TADR TdiMiQHdT6Ikgn/V2nYCU6Uc57r3dC626y17cKl65xOlyR21beMW9NelYsS8OnF+3Glk qirw== 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:dkim-signature; bh=ox9rS9yUwDPiS9zP9Le2IIMepg1rZz+GrbIdUhwbbuQ=; b=ksB/WWD938Ti1x7C88xqW6DeY/SigtQV+Yx7wvWx+hh5dOCXk/Uh/G+l5bKCZhGQ3l qrtCJPeSC+2FC8APghCJkt6kFfmLT+1hUNLiMIvLtMKvLjZrt1YZzZLwZrB9VwOS7gKq Zee/JsGkwR8mkN/nVU2FOUh0+1VIV9ouP980xdyc6Z2buMSjs+dki+sTznKy4JhtCJRW nPu9T8Uuk17NPUx5XHndauIG98zLn7pdZYxxV+GGgJPvaaTnexe4rH3ywo0jW6c1J0NA qphuCql0jVgfJ+HS2QoY69Tbjrf58731mC6uNxUNIg51g1zdxdlb2DkeocPzpf4RZgCv dVCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=iRiKiLFM; 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 z17si3634846oth.282.2020.04.03.03.26.31; Fri, 03 Apr 2020 03:26:44 -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; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=iRiKiLFM; 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 S2389998AbgDCKZA (ORCPT + 99 others); Fri, 3 Apr 2020 06:25:00 -0400 Received: from perceval.ideasonboard.com ([213.167.242.64]:42320 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727774AbgDCKZA (ORCPT ); Fri, 3 Apr 2020 06:25:00 -0400 Received: from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 762F3321; Fri, 3 Apr 2020 12:24:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1585909497; bh=6AoVQWC6bVmf4rPCkhV3E1jg4poMS4+qepNdH5JPhVA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=iRiKiLFMPN5UE41ZLkDupUaGCjHlB/2vNn4igBxHdgWI/tZM7dYRfx9D7Mr66RmCZ Jt5Jhn5PWoJpQFiEazxfqGbvL6VKGQDGFNqgJ9J4vVsgJJrbje+QDU78tcbC5j66so O+9JhRVhwejCsOa4CwMs4JaP8DARZdxgh1AcVfMY= Date: Fri, 3 Apr 2020 13:24:49 +0300 From: Laurent Pinchart To: Sakari Ailus 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: <20200403102449.GB4882@pendragon.ideasonboard.com> References: <20200403091156.7814-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200403091156.7814-1-sakari.ailus@linux.intel.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 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 ? > +} > + > static noinline_for_stack > char *address_val(char *buf, char *end, const void *addr, > struct printf_spec spec, const char *fmt) > @@ -2131,6 +2153,7 @@ char *fwnode_string(char *buf, char *end, struct fwnode_handle *fwnode, > * correctness of the format string and va_list arguments. > * - 'K' For a kernel pointer that should be hidden from unprivileged users > * - 'NF' For a netdev_features_t > + * - '4cc' V4L2 or DRM FourCC code, with "-BE" suffix on big endian formats. > * - 'h[CDN]' For a variable-length buffer, it prints it as a hex string with > * a certain separator (' ' by default): > * C colon > @@ -2223,6 +2246,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr, > return restricted_pointer(buf, end, ptr, spec); > case 'N': > return netdev_bits(buf, end, ptr, spec, fmt); > + case '4': > + return fourcc_string(buf, end, ptr, spec, fmt); > case 'a': > return address_val(buf, end, ptr, spec, fmt); > case 'd': -- Regards, Laurent Pinchart