Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp703437ybb; Wed, 1 Apr 2020 08:08:36 -0700 (PDT) X-Google-Smtp-Source: ADFU+vulPX8Qqd+fUZLUsA6V70YbN4I5XmMYRTTC3WktlyMMa3tBl3tCIg4sz1MWdfduSSA5sNN1 X-Received: by 2002:a9d:356:: with SMTP id 80mr16580234otv.15.1585753716395; Wed, 01 Apr 2020 08:08:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585753716; cv=none; d=google.com; s=arc-20160816; b=Mc8d6cQikJTxivToFUn8j8O/wEnjHXzPvUhzfosTBS4K49uzPhjclonjanh3YxFAMd CwjeUz0PUCWPywUNeXA2hqbQkfdMmJDtTULr3+9Jf5cmptGkcXTi3FVa5HwJSdT4gxPb hlM0QudOafuAkd7BiCcYAqwX8MSI0Lj09A+U0PnpTpL36Eo+yBF2Oq8ZdmFFsDvlf6En JIU9OPKVEgY035ED3utcfZ6aJikfY738cMJlcZvQlE598fqIziY3PRqXmnK8ZKmTGieN sGCdvkootFymMZUfJOYTX591kxpMKeqbZ8ih7gVi5F3avwdlKMhFQZiqImk4atzoLMSh mNPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=sZD1pnfqJXlvQ8oyoCnkB+rCciT1KfDdmAqLsxXOTm0=; b=tlMBXD7eUwbQGHFyuIWMmudBoJUhf5aQGkDxm7lluRQGQsucO30vLJ8Dq/Z3w5DcjL h0x+9hkDq9zuWFTKFbOx8YTpIPOtjfccObjcKW+Dnau5KEwEmnKCU+cFO61AA+t0HcWZ vMXP/OUNQ5LMhCwahTvEktUdlH79umoOlISMKbeqIVoRyhmZN68QdM++xR1K6cgOu406 6lMonRp+3/986ig0Pzatw8U9f+BXaBN/ehxbny0FlavLYNElDl+3XJcJ/o4wo3j3O5IW SwnVj3cbscy/d/O9Tsrvi/Z2LFiw3YDrz2Mbbhy8ccM4aAiRGUpRi9k7YQuOK9YMQqFP 7TbQ== 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 u28si1039297otg.14.2020.04.01.08.08.07; Wed, 01 Apr 2020 08:08:36 -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 S1732874AbgDAOF0 (ORCPT + 99 others); Wed, 1 Apr 2020 10:05:26 -0400 Received: from retiisi.org.uk ([95.216.213.190]:59294 "EHLO hillosipuli.retiisi.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732791AbgDAOFZ (ORCPT ); Wed, 1 Apr 2020 10:05:25 -0400 Received: from lanttu.localdomain (lanttu-e.localdomain [192.168.1.64]) by hillosipuli.retiisi.org.uk (Postfix) with ESMTP id 51CD1634C87; Wed, 1 Apr 2020 17:04:41 +0300 (EEST) From: Sakari Ailus To: Petr Mladek Cc: Andy Shevchenko , linux-media@vger.kernel.org, Dave Stevenson , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, hverkuil@xs4all.nl, laurent.pinchart@ideasonboard.com, mchehab@kernel.org, Sergey Senozhatsky , Steven Rostedt Subject: [PATCH 1/1] lib/vsprintf: Add support for printing V4L2 and DRM fourccs Date: Wed, 1 Apr 2020 17:05:22 +0300 Message-Id: <20200401140522.966-1-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- Documentation/core-api/printk-formats.rst | 11 +++++++++ lib/vsprintf.c | 29 +++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/Documentation/core-api/printk-formats.rst b/Documentation/core-api/printk-formats.rst index 8ebe46b1af39..b6249f513c09 100644 --- a/Documentation/core-api/printk-formats.rst +++ b/Documentation/core-api/printk-formats.rst @@ -545,6 +545,17 @@ For printing netdev_features_t. Passed by reference. +V4L2 and DRM fourcc code (pixel format) +--------------------------------------- + +:: + + %ppf + +Print a 4cc code used by V4L2 or DRM. + +Passed by reference. + Thanks ====== diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 7c488a1ce318..b39f0ac317c5 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -1721,6 +1721,32 @@ char *netdev_bits(char *buf, char *end, const void *addr, return special_hex_number(buf, end, num, size); } +static noinline_for_stack +char *pixel_format_string(char *buf, char *end, const u32 *fourcc, + struct printf_spec spec, const char *fmt) +{ + char ch[2] = { 0 }; + unsigned int i; + + if (check_pointer(&buf, end, fourcc, spec)) + return buf; + + switch (fmt[1]) { + case 'f': + for (i = 0; i < sizeof(*fourcc); i++) { + ch[0] = *fourcc >> (i << 3); + buf = string(buf, end, ch, spec); + } + + if (*fourcc & BIT(31)) + buf = string(buf, end, "-BE", spec); + + return buf; + default: + return error_string(buf, end, "(%pp?)", spec); + } +} + static noinline_for_stack char *address_val(char *buf, char *end, const void *addr, struct printf_spec spec, const char *fmt) @@ -2131,6 +2157,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 + * - 'pf' V4L2 or DRM pixel format. * - 'h[CDN]' For a variable-length buffer, it prints it as a hex string with * a certain separator (' ' by default): * C colon @@ -2223,6 +2250,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 'p': + return pixel_format_string(buf, end, ptr, spec, fmt); case 'a': return address_val(buf, end, ptr, spec, fmt); case 'd': -- 2.20.1