BPF List
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Tom Rix <trix@redhat.com>, Simon Horman <simon.horman@netronome.com>
Cc: kuba@kernel.org, davem@davemloft.net, ast@kernel.org,
	daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com,
	songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com,
	kpsingh@kernel.org, gustavoars@kernel.org,
	louis.peens@netronome.com, netdev@vger.kernel.org,
	bpf@vger.kernel.org, oss-drivers@netronome.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] nfp: remove h from printk format specifier
Date: Thu, 24 Dec 2020 14:39:16 -0800	[thread overview]
Message-ID: <18c81854639aa21e76c8b26cc3e7999b0428cc4e.camel@perches.com> (raw)
In-Reply-To: <bac92bab-243b-ca48-647c-dad5688fa060@redhat.com>

On Thu, 2020-12-24 at 14:14 -0800, Tom Rix wrote:
> On 12/24/20 12:21 PM, Simon Horman wrote:
> > On Wed, Dec 23, 2020 at 12:20:53PM -0800, trix@redhat.com wrote:
> > > From: Tom Rix <trix@redhat.com>
> > > 
> > > This change fixes the checkpatch warning described in this commit
> > > commit cbacb5ab0aa0 ("docs: printk-formats: Stop encouraging use of unnecessary %h[xudi] and %hh[xudi]")
> > > 
> > > Standard integer promotion is already done and %hx and %hhx is useless
> > > so do not encourage the use of %hh[xudi] or %h[xudi].
> > > 
> > > Signed-off-by: Tom Rix <trix@redhat.com>
> > Hi Tom,
> > 
> > This patch looks appropriate for net-next, which is currently closed.
> > 
> > The changes look fine, but I'm curious to know if its intentionally that
> > the following was left alone in ethernet/netronome/nfp/nfp_net_ethtool.c:nfp_net_get_nspinfo()
> > 
> > 	snprintf(version, ETHTOOL_FWVERS_LEN, "%hu.%hu"
> 
> I am limiting changes to logging functions, what is roughly in checkpatch.
> 
> I can add this snprintf in if you want.

I'm a bit confused here Tom.

I thought your clang-tidy script was looking for anything marked with
__printf() that is using %h[idux] or %hh[idux].

Wouldn't snprintf qualify for this already?

include/linux/kernel.h-extern __printf(3, 4)
include/linux/kernel.h:int snprintf(char *buf, size_t size, const char *fmt, ...);

Kernel code doesn't use a signed char or short with %hx or %hu very often
but in case you didn't already know, any signed char/short emitted with
anything like %hx or %hu needs to be left alone as sign extension occurs so:

	signed char foo = -1;
	printk("%hx", foo);

emits ffff but

	printk("%x", foo);

emits ffffffff

An example:

$ gcc -x c -
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
	signed short i = -1;
	printf("hx: %hx\n", i);
	printf("x:  %x\n", i);
	printf("hu: %hu\n", i);
	printf("u:  %u\n", i);
	return 0;
}

$ ./a.out
hx: ffff
x:  ffffffff
hu: 65535
u:  4294967295

$



  reply	other threads:[~2020-12-24 22:40 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-23 20:20 [PATCH] nfp: remove h from printk format specifier trix
2020-12-24 20:21 ` Simon Horman
2020-12-24 22:14   ` Tom Rix
2020-12-24 22:39     ` Joe Perches [this message]
2020-12-25 14:56       ` Tom Rix
2020-12-25 17:06         ` Joe Perches
2020-12-25 22:13           ` Tom Rix
2020-12-25 23:00             ` Joe Perches
2020-12-26 20:40         ` David Laight

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=18c81854639aa21e76c8b26cc3e7999b0428cc4e.camel@perches.com \
    --to=joe@perches.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=gustavoars@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=louis.peens@netronome.com \
    --cc=netdev@vger.kernel.org \
    --cc=oss-drivers@netronome.com \
    --cc=simon.horman@netronome.com \
    --cc=songliubraving@fb.com \
    --cc=trix@redhat.com \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox