Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3017456ybz; Mon, 27 Apr 2020 08:33:20 -0700 (PDT) X-Google-Smtp-Source: APiQypL/rYiSwRJVj/4ph0R58g7hHq/KwVzVaL/cDILqDGe+6gJ76ApknX5cU02+2M0xbAjODi1d X-Received: by 2002:a17:906:829a:: with SMTP id h26mr19647739ejx.133.1588001600427; Mon, 27 Apr 2020 08:33:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588001600; cv=none; d=google.com; s=arc-20160816; b=HkbV2IJk5oSwaRtEx4+dwnIZLckI8yGPE7pNFvq9o3qmhZQ9C38tfIppFibXz75JH5 smYT5cvM5nmDVe9OX+7u5dK+2tkmzJuDEIdmfUX3ujO/A8OeKpo67MBiQlXYYETaRuve vWcTqQNl6AhaJNeB8Qy8lhDT0exUAV5171HWO23ljIc2s1MfeybF4lBpQ8oDeNPXmmBG hWb82H2uXHq/md/vDt4nKXEFS6KZ5GF4XQKFr37D7OyUFjQNB1d2X1oaTWQxCxniCPri 3y20vUYOzl+HM1ScxbiW8pOM4iCCLh1o3Qu71IJuNVvNVwJnkHMCemEaDmAQihF+7IAU d/TA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=1nGyxN3FQ2mtRTG+Wo23ZyrC+IaTCSyjmaMS6FO5mFo=; b=xbHVsez/4/4jTfkDU3NcInlhQ2yeraJ0K6zZdVTmkPiwvhCX4rutkpJiwVEKbCvc5w f/6R3Q1sHnRt9wTORwwQi0QIGuAsQYH73+P9X28CjlpO+V9jvVBzY+O0n5PugpHblmxb x3AoXgHVJAaX6ZONDcfUuRg0lJ1GkTDXt/52dlEUeUsS6TmGZKZUZFKvKpAoFwSKEm0H BxlR6nytHRMB8TgaN3pZ93eVz2kjyKA2w1paTo4v5Q42yew3ymqQHNjVSZHDUJ0uw+Oe QmGkphg9E9IG5bgS6GqkXg+MaQNkkSfoAeOCF/jVljGXsfa8Fyu4InHPKlYaN6+ybOGP lLeQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id g15si2329566edu.131.2020.04.27.08.32.55; Mon, 27 Apr 2020 08:33:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728076AbgD0Pas (ORCPT + 99 others); Mon, 27 Apr 2020 11:30:48 -0400 Received: from mga11.intel.com ([192.55.52.93]:50188 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728021AbgD0Pas (ORCPT ); Mon, 27 Apr 2020 11:30:48 -0400 IronPort-SDR: 8tMmEonabBebIQtUWcVAK9+E4KlWVRyIH86DXF4vQVdchlWHhFtis0rTbQDy7ZA56vi+t8XkPQ yKOpF60aXPeA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Apr 2020 08:30:48 -0700 IronPort-SDR: GP3A3rfPMYdQpzYh2A4GAPQSDWg+are3wylGKVaQq4kEA+BeK88WkbqyFEkCwtaaKfarRcKcAw aZqyaUnWvt6w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,324,1583222400"; d="scan'208";a="431816249" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by orsmga005.jf.intel.com with ESMTP; 27 Apr 2020 08:30:44 -0700 Received: from andy by smile with local (Exim 4.93) (envelope-from ) id 1jT5iZ-003PtH-0X; Mon, 27 Apr 2020 18:30:47 +0300 Date: Mon, 27 Apr 2020 18:30:46 +0300 From: Andy Shevchenko To: Sakari Ailus Cc: Petr Mladek , 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 , Joe Perches , Jani Nikula Subject: Re: [RESEND PATCH v3 1/1] lib/vsprintf: Add support for printing V4L2 and DRM fourccs Message-ID: <20200427153046.GL185537@smile.fi.intel.com> References: <20200427145303.29943-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200427145303.29943-1-sakari.ailus@linux.intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 27, 2020 at 05:53:03PM +0300, Sakari Ailus wrote: > Add a printk modifier %p4cc (for pixel format) for printing V4L2 and DRM > pixel formats denoted by fourccs. The fourcc encoding is the same for both > so the same implementation can be used. 4cc is more generic than pixel format. ... > +V4L2 and DRM FourCC code (pixel format) > +--------------------------------------- > + > +:: > + > + %p4cc Missed examples. > +Print a FourCC code used by V4L2 or DRM, including format endianness and > +its numerical value as hexadecimal. ... > +static noinline_for_stack > +char *fourcc_string(char *buf, char *end, const u32 *__fourcc, > + struct printf_spec spec, const char *fmt) > +{ > +#define FOURCC_HEX_CHAR_STR "(xx)" > +#define FOURCC_BIG_ENDIAN_STR " big-endian" > +#define FOURCC_LITTLE_ENDIAN_STR " little-endian" > +#define FOURCC_HEX_NUMBER " (0x01234567)" Where are #undef:s? > +#define FOURCC_STRING_MAX \ > + FOURCC_HEX_CHAR_STR FOURCC_HEX_CHAR_STR FOURCC_HEX_CHAR_STR \ > + FOURCC_HEX_CHAR_STR FOURCC_LITTLE_ENDIAN_STR FOURCC_HEX_NUMBER > + struct printf_spec my_spec = { > + .type = FORMAT_TYPE_UINT, > + .field_width = 2, > + .flags = SMALL, > + .base = 16, > + .precision = -1, > + }; Seems like close enough to bus_spec. > + char __s[sizeof(FOURCC_STRING_MAX)]; > + char *s = __s; > + unsigned int i; > + /* > + * The 31st bit defines the endianness of the data, so save its printing > + * for later. > + */ > + u32 fourcc = *__fourcc & ~BIT(31); > + int ret; > + > + if (check_pointer(&buf, end, __fourcc, spec)) > + return buf; > + > + if (fmt[1] != 'c' || fmt[2] != 'c') > + return error_string(buf, end, "(%p4?)", spec); > + > + for (i = 0; i < sizeof(fourcc); i++, fourcc >>= 8) { > + unsigned char c = fourcc; > + > + /* Weed out spaces */ > + if (c == ' ') > + continue; > + > + /* Print non-control characters as-is */ > + if (c > ' ') { > + *s = c; > + s++; > + continue; > + } > + if (WARN_ON_ONCE(sizeof(__s) < > + (s - __s) + sizeof(FOURCC_HEX_CHAR_STR))) Why WARN?! > + break; > + > + *s = '('; > + s++; > + s = number(s, s + 2, c, my_spec); > + *s = ')'; > + s++; > + } > + > + ret = strscpy(s, *__fourcc & BIT(31) ? FOURCC_BIG_ENDIAN_STR > + : FOURCC_LITTLE_ENDIAN_STR, > + sizeof(__s) - (s - __s)); > + if (!WARN_ON_ONCE(ret < 0)) Ditto. > + s += ret; > + if (!WARN_ON_ONCE(sizeof(__s) < > + (s - __s) + sizeof(FOURCC_HEX_NUMBER))) { Ditto. > + *s = ' '; > + s++; > + *s = '('; > + s++; > + /* subtract parentheses and the space from the size */ > + special_hex_number(s, s + sizeof(FOURCC_HEX_NUMBER) - 3, > + *__fourcc, sizeof(u32)); > + s += sizeof(u32) * 2 + 2 /* 0x */; > + *s = ')'; > + s++; > + *s = '\0'; > + } > + > + return string(buf, end, __s, spec); This looks overengineered. Why everyone will need so long strings to be printed? > +} -- With Best Regards, Andy Shevchenko