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 X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2AE18C43331 for ; Wed, 1 Apr 2020 14:14:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 02818206F6 for ; Wed, 1 Apr 2020 14:14:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=xs4all.nl header.i=@xs4all.nl header.b="IyNSd6it" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732927AbgDAOOD (ORCPT ); Wed, 1 Apr 2020 10:14:03 -0400 Received: from lb1-smtp-cloud8.xs4all.net ([194.109.24.21]:48239 "EHLO lb1-smtp-cloud8.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732858AbgDAOOB (ORCPT ); Wed, 1 Apr 2020 10:14:01 -0400 Received: from [192.168.2.10] ([46.9.234.233]) by smtp-cloud8.xs4all.net with ESMTPA id Je7rjWPinBr2bJe7vjkqWT; Wed, 01 Apr 2020 16:13:59 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xs4all.nl; s=s1; t=1585750439; bh=4Z1xsv5MJPNLqbY2JbEN3CWbNZXwsTFDoO6fRUQq8Z8=; h=Subject:To:From:Message-ID:Date:MIME-Version:Content-Type:From: Subject; b=IyNSd6itD/wGS7WzJWs/dM4HUrhm4dr8re8yF3KX4FCoMbbHfexrnHpYLL/AqOn15 7Lfo2bscJ5Tv+wtt0xoYuI0IbfO9NGo00WyjUGXOuMePe19bSb+rcaPnHd3sLipLQg 5WTK2oPH6Q3jLG8+EpWuCh+vD3EFZdkq95zWUJZ68iSo1U9Jx1dm0Yv4U/LKEniKLv USlJDTN5j3fjSech4lWAie2R6+CcS+eDMlV09WLUE86/Pp4Rm1ejPnuKuhAS67NZsK COwfjQx3JKInzAy8KrHtdfsO/atELkmg3UgVeybrFuPhGh3QnzHe8CcJzDuREe1z7X U7R0WvPawuwTg== Subject: Re: [PATCH 1/1] lib/vsprintf: Add support for printing V4L2 and DRM fourccs To: Sakari Ailus , Petr Mladek Cc: Andy Shevchenko , linux-media@vger.kernel.org, Dave Stevenson , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, laurent.pinchart@ideasonboard.com, mchehab@kernel.org, Sergey Senozhatsky , Steven Rostedt References: <20200401140522.966-1-sakari.ailus@linux.intel.com> From: Hans Verkuil Message-ID: <080ddddf-717e-61dc-8522-fbdbe52da94a@xs4all.nl> Date: Wed, 1 Apr 2020 16:13:51 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200401140522.966-1-sakari.ailus@linux.intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4wfMk1IXknwDM4YmvP/lQa3Wn+ijgDMHwhGqoI8aB+utiUiu9Lnc6n4h2UYXu7wz51oBsvbGHGG9TYwjhRmL+0U2byi27gti5Dkl55B8z7c+AVv/Q9XHj1 o/WnC3Z/PeC0XuFKPI6wwfAhSw0G1DoS9bvK6u0X80y37pJZKxeeRwud/rg0zhMTw4O5OXrISijVnxaVcTi4HtTe0MNdDvmnfWuChnnJFTZ106nv/u6n5/9X lMlaHzccOrMOEYV7bCN+/KXb5yNzJcuI/8XsdTD+bjwK+BFN0AaoM0E/ek4zTkHj1Po4DKYE3oSUu+8q7AFoqQtEfRRquooJP7G7QuRmKa3XFvDz08P4XwWf x+YpcqQfYb8iFogqPzJVZ92BU/oVR83DeurZ80tQvCmYccUbqZVBvsAHbUGAlBTc9/MH4ygNdo8EamET9yVN5wlRVj4Xb5W6LFrq59KhLOq4KAi9m7IU65vA 2FO9WahGnoWuDUL/ObJyXeILYTKOF4oiV1ULv5cUH98wdR1BcfJdlBDcWed+zhkFcO1rIUePwIZzZNv1oX1qEqoAAg2KknknJiVIJPWxNfUcUbD+lfFSjjHc BAk= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/1/20 4:05 PM, 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 > --- > 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. FourCC appears to be the more-or-less official name (https://en.wikipedia.org/wiki/FourCC) I would explain about the -BE suffix for bigendian fourcc variants. > + > +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 }; This can just be '{ };' > + 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); You need to AND with 0x7f, otherwise a big endian fourcc (bit 31 is set) will look wrong. Also, each character is standard 7 bit ascii, bit 7 isn't used except to indicate a BE variant. > + 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. I'd say 'FourCC format' instead of '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': > Regards, Hans