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=-3.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=no 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 10BBDC2D0A3 for ; Wed, 4 Nov 2020 08:22:43 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id ADC3020782 for ; Wed, 4 Nov 2020 08:22:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ADC3020782 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9C81F89487; Wed, 4 Nov 2020 08:22:15 +0000 (UTC) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9899F6ECCB for ; Tue, 3 Nov 2020 14:46:49 +0000 (UTC) IronPort-SDR: uKx5YM3oPNPBu7S6wLaSSC9rVe4I5Z1BIE1vqXyT9+RnjGtLOaXv9pOc5Yzoz7fNTuGxTod8PZ Oi1qaEND87Dg== X-IronPort-AV: E=McAfee;i="6000,8403,9793"; a="233228899" X-IronPort-AV: E=Sophos;i="5.77,448,1596524400"; d="scan'208";a="233228899" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2020 06:46:49 -0800 IronPort-SDR: EjuroLYVH7sHSk0NjvP6CMOCZ8CpZrUNGFwdHGgfnMFIKSpjRlD7oZbo5aBPd570P+gmrNS1Kv ie4tot7f/1nA== X-IronPort-AV: E=Sophos;i="5.77,448,1596524400"; d="scan'208";a="306065252" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2020 06:46:45 -0800 Received: from andy by smile with local (Exim 4.94) (envelope-from ) id 1kZxb9-003V4L-D1; Tue, 03 Nov 2020 16:47:47 +0200 Date: Tue, 3 Nov 2020 16:47:47 +0200 From: Andy Shevchenko To: Sakari Ailus Subject: Re: [PATCH v4 1/1] lib/vsprintf: Add support for printing V4L2 and DRM fourccs Message-ID: <20201103144747.GD4077@smile.fi.intel.com> References: <20201103133400.24805-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201103133400.24805-1-sakari.ailus@linux.intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-Mailman-Approved-At: Wed, 04 Nov 2020 08:22:13 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Petr Mladek , Dave Stevenson , Rasmus Villemoes , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, hverkuil@xs4all.nl, Sergey Senozhatsky , Steven Rostedt , laurent.pinchart@ideasonboard.com, Joe Perches , mchehab@kernel.org, linux-media@vger.kernel.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Tue, Nov 03, 2020 at 03:34:00PM +0200, 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. ... > +static noinline_for_stack > +char *fourcc_string(char *buf, char *end, const u32 *fourcc, > + struct printf_spec spec, const char *fmt) > +{ > + char output[sizeof("(xx)(xx)(xx)(xx) little-endian (0x01234567)")]; I would add a comment that there is another possibility, i.e. big-endian, but it occupies less space. > + char *p = output; > + unsigned int i; > + u32 val; > + > + if (fmt[1] != 'c' || fmt[2] != 'c') > + return error_string(output, end, "(%p4?)", spec); > + > + if (check_pointer(&buf, end, fourcc, spec)) > + return buf; > + > + val = *fourcc & ~BIT(31); > + > + for (i = 0; i < sizeof(*fourcc); i++) { > + unsigned char c = val >> (i * 8); > + > + /* Weed out spaces */ > + if (c == ' ') > + continue; > + > + /* Print non-control ASCII characters as-is */ > + if (isascii(c) && isprint(c)) { > + *p++ = c; > + continue; > + } > + > + *p++ = '('; > + p = hex_byte_pack(p, c); > + *p++ = ')'; > + } I guess above loop can be still optimized, but I have to think about it. > + strcpy(p, *fourcc & BIT(31) ? " big-endian" : " little-endian"); > + p += strlen(p); > + > + *p++ = ' '; > + *p++ = '('; > + /* subtract parenthesis and the space from the size */ This comment misleading. What you are subtracting is a room for closing parenthesis and NUL. > + p = special_hex_number(p, output + sizeof(output) - 2, *fourcc, > + sizeof(u32)); I would go with one line here. The (theoretical) problem is here that the case when buffer size is not enough to print a value will be like '(0xabc)' but should be rather '(0xabcd' like snprintf() does in general. > + *p++ = ')'; > + *p = '\0'; > + > + return string(buf, end, output, spec); > +} -- With Best Regards, Andy Shevchenko _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel 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=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 681C8C388F9 for ; Tue, 3 Nov 2020 14:47:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1EBFA2242C for ; Tue, 3 Nov 2020 14:47:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728192AbgKCOqw (ORCPT ); Tue, 3 Nov 2020 09:46:52 -0500 Received: from mga07.intel.com ([134.134.136.100]:42803 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728175AbgKCOqu (ORCPT ); Tue, 3 Nov 2020 09:46:50 -0500 IronPort-SDR: 0KIbBD6Qoc1C1i6cdvx+yJ9anRcz0GuIEtNWlQ6Hz3JU4clVzTh9bc3C3aLDkaaSyLA85ltbpj tb00dAAJzm5A== X-IronPort-AV: E=McAfee;i="6000,8403,9793"; a="233228898" X-IronPort-AV: E=Sophos;i="5.77,448,1596524400"; d="scan'208";a="233228898" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2020 06:46:49 -0800 IronPort-SDR: EjuroLYVH7sHSk0NjvP6CMOCZ8CpZrUNGFwdHGgfnMFIKSpjRlD7oZbo5aBPd570P+gmrNS1Kv ie4tot7f/1nA== X-IronPort-AV: E=Sophos;i="5.77,448,1596524400"; d="scan'208";a="306065252" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2020 06:46:45 -0800 Received: from andy by smile with local (Exim 4.94) (envelope-from ) id 1kZxb9-003V4L-D1; Tue, 03 Nov 2020 16:47:47 +0200 Date: Tue, 3 Nov 2020 16:47:47 +0200 From: Andy Shevchenko To: Sakari Ailus Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Petr Mladek , Dave Stevenson , dri-devel@lists.freedesktop.org, hverkuil@xs4all.nl, laurent.pinchart@ideasonboard.com, mchehab@kernel.org, Sergey Senozhatsky , Steven Rostedt , Joe Perches , Jani Nikula , Rasmus Villemoes Subject: Re: [PATCH v4 1/1] lib/vsprintf: Add support for printing V4L2 and DRM fourccs Message-ID: <20201103144747.GD4077@smile.fi.intel.com> References: <20201103133400.24805-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201103133400.24805-1-sakari.ailus@linux.intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org On Tue, Nov 03, 2020 at 03:34:00PM +0200, 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. ... > +static noinline_for_stack > +char *fourcc_string(char *buf, char *end, const u32 *fourcc, > + struct printf_spec spec, const char *fmt) > +{ > + char output[sizeof("(xx)(xx)(xx)(xx) little-endian (0x01234567)")]; I would add a comment that there is another possibility, i.e. big-endian, but it occupies less space. > + char *p = output; > + unsigned int i; > + u32 val; > + > + if (fmt[1] != 'c' || fmt[2] != 'c') > + return error_string(output, end, "(%p4?)", spec); > + > + if (check_pointer(&buf, end, fourcc, spec)) > + return buf; > + > + val = *fourcc & ~BIT(31); > + > + for (i = 0; i < sizeof(*fourcc); i++) { > + unsigned char c = val >> (i * 8); > + > + /* Weed out spaces */ > + if (c == ' ') > + continue; > + > + /* Print non-control ASCII characters as-is */ > + if (isascii(c) && isprint(c)) { > + *p++ = c; > + continue; > + } > + > + *p++ = '('; > + p = hex_byte_pack(p, c); > + *p++ = ')'; > + } I guess above loop can be still optimized, but I have to think about it. > + strcpy(p, *fourcc & BIT(31) ? " big-endian" : " little-endian"); > + p += strlen(p); > + > + *p++ = ' '; > + *p++ = '('; > + /* subtract parenthesis and the space from the size */ This comment misleading. What you are subtracting is a room for closing parenthesis and NUL. > + p = special_hex_number(p, output + sizeof(output) - 2, *fourcc, > + sizeof(u32)); I would go with one line here. The (theoretical) problem is here that the case when buffer size is not enough to print a value will be like '(0xabc)' but should be rather '(0xabcd' like snprintf() does in general. > + *p++ = ')'; > + *p = '\0'; > + > + return string(buf, end, output, spec); > +} -- With Best Regards, Andy Shevchenko