All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Julia Lawall <julia.lawall@lip6.fr>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Andy Whitcroft <apw@canonical.com>,
	Dan Carpenter <error27@gmail.com>,
	kernel-janitors <kernel-janitors@vger.kernel.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH V2] checkpatch: Check output format style of __func__ uses
Date: Mon, 14 Mar 2016 14:07:38 +0000	[thread overview]
Message-ID: <1457964458.11972.89.camel@perches.com> (raw)
In-Reply-To: <alpine.DEB.2.10.1603140929150.2688@hadrien>

On Mon, 2016-03-14 at 09:29 +0100, Julia Lawall wrote:
> On Mon, 14 Mar 2016, Joe Perches wrote:
> > On Mon, 2016-03-14 at 06:19 +0100, Julia Lawall wrote:
> > > On Sun, 13 Mar 2016, Joe Perches wrote:
> > > > Loggng messages that emit function names have many different forms.
> > > > Perhaps it'd be better for logging consistency and grep ease to
> > > > exclusively use "%s:"
> > > > 
> > > > As well, function tracing logging uses are generally unnecessary given
> > > > the kernel's function tracing (ftrace) capability.
> > > > 
> > > > Right now, grep shows these mixtures of forms:
> > > > 
> > > > 13704 "%s:"
> > > > 3839  "%s "
> > > > 2787  "%s()"
> > > > 
> > > > Some of these are macros definitions of various styles.
> > > > 
> > > > Unfortunately, given the complexity of these macro definition styles,
> > > > checkpatch isn't an ideal tool to find these macros.
> > > > 
> > > > Maybe a coccinelle script might be better suited to find and fix all
> > > > the various types of uses.
> > > > 
> > > > Add a --fix option for these logging messages with __func__.
> > >
> > > I'm not good enough at perl to really understand this.  Coudl you give an 
> > > example of what it does, and of what it does not do?
> >
> > For instance, this could do simple conversions like:
> >
> > $ diff --git a/arch/arm/common/mcpm_entry.c b/arch/arm/common/mcpm_entry.c
> > @@ -416 +416 @@ int __init mcpm_loopback(void (*cache_disable)(void))
> > -               pr_err("%s returned %d\n", __func__, ret);
> > +               pr_err("%s: returned %d\n", __func__, ret);
> >
> > But it couldn't find/convert a string concatenation:
> >
> > #define pch_dbg(adap, fmt, arg...)  \
> >         dev_dbg(adap->pch_adapter.dev.parent, "%s :" fmt, __func__, ##arg)
> 
> OK, are there any thoughts about what to do when __func__ is not in the
> first position?

Hard to say,

Uses with any or all of __FILE__, __LINE__, or __func__
in various combinations might be standardized.

A lot of those are debugging style macro and probably
could be converted to dynamic_debug style uses without
any mention of __FILE__, __LINE__, or __func__ at all
as dynamic_debug can optionally output these.

For macros like:

drivers/mtd/ubi/ubi.h-#define ubi_err(ubi, fmt, ...) pr_err(UBI_NAME_STR "%d error: %s: " fmt "\n", \
drivers/mtd/ubi/ubi.h:				      ubi->ubi_num, __func__, ##__VA_ARGS__)

it might be best to leave it alone. as that lets
grep find these a bit easier using "^ubi" though
code style this might be nicer on 3 lines

#define ubi_err(ubi, fmt, ...)						\
	pr_err(UBI_NAME_STR "%d error: %s: " fmt "\n", 			\
	       ubi->ubi_num, __func__, ##__VA_ARGS__)

or maybe even as a function rather than a macro
if it saves code space.  __func__ could then be
converted to __builtin_return_address(0)

for instance: https://lkml.org/lkml/2016/2/25/554


--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

WARNING: multiple messages have this Message-ID (diff)
From: Joe Perches <joe@perches.com>
To: Julia Lawall <julia.lawall@lip6.fr>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Andy Whitcroft <apw@canonical.com>,
	Dan Carpenter <error27@gmail.com>,
	kernel-janitors <kernel-janitors@vger.kernel.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH V2] checkpatch: Check output format style of __func__ uses
Date: Mon, 14 Mar 2016 07:07:38 -0700	[thread overview]
Message-ID: <1457964458.11972.89.camel@perches.com> (raw)
In-Reply-To: <alpine.DEB.2.10.1603140929150.2688@hadrien>

On Mon, 2016-03-14 at 09:29 +0100, Julia Lawall wrote:
> On Mon, 14 Mar 2016, Joe Perches wrote:
> > On Mon, 2016-03-14 at 06:19 +0100, Julia Lawall wrote:
> > > On Sun, 13 Mar 2016, Joe Perches wrote:
> > > > Loggng messages that emit function names have many different forms.
> > > > Perhaps it'd be better for logging consistency and grep ease to
> > > > exclusively use "%s:"
> > > > 
> > > > As well, function tracing logging uses are generally unnecessary given
> > > > the kernel's function tracing (ftrace) capability.
> > > > 
> > > > Right now, grep shows these mixtures of forms:
> > > > 
> > > > 13704 "%s:"
> > > > 3839  "%s "
> > > > 2787  "%s()"
> > > > 
> > > > Some of these are macros definitions of various styles.
> > > > 
> > > > Unfortunately, given the complexity of these macro definition styles,
> > > > checkpatch isn't an ideal tool to find these macros.
> > > > 
> > > > Maybe a coccinelle script might be better suited to find and fix all
> > > > the various types of uses.
> > > > 
> > > > Add a --fix option for these logging messages with __func__.
> > >
> > > I'm not good enough at perl to really understand this.  Coudl you give an 
> > > example of what it does, and of what it does not do?
> >
> > For instance, this could do simple conversions like:
> >
> > $ diff --git a/arch/arm/common/mcpm_entry.c b/arch/arm/common/mcpm_entry.c
> > @@ -416 +416 @@ int __init mcpm_loopback(void (*cache_disable)(void))
> > -               pr_err("%s returned %d\n", __func__, ret);
> > +               pr_err("%s: returned %d\n", __func__, ret);
> >
> > But it couldn't find/convert a string concatenation:
> >
> > #define pch_dbg(adap, fmt, arg...)  \
> >         dev_dbg(adap->pch_adapter.dev.parent, "%s :" fmt, __func__, ##arg)
> 
> OK, are there any thoughts about what to do when __func__ is not in the
> first position?

Hard to say,

Uses with any or all of __FILE__, __LINE__, or __func__
in various combinations might be standardized.

A lot of those are debugging style macro and probably
could be converted to dynamic_debug style uses without
any mention of __FILE__, __LINE__, or __func__ at all
as dynamic_debug can optionally output these.

For macros like:

drivers/mtd/ubi/ubi.h-#define ubi_err(ubi, fmt, ...) pr_err(UBI_NAME_STR "%d error: %s: " fmt "\n", \
drivers/mtd/ubi/ubi.h:				      ubi->ubi_num, __func__, ##__VA_ARGS__)

it might be best to leave it alone. as that lets
grep find these a bit easier using "^ubi" though
code style this might be nicer on 3 lines

#define ubi_err(ubi, fmt, ...)						\
	pr_err(UBI_NAME_STR "%d error: %s: " fmt "\n", 			\
	       ubi->ubi_num, __func__, ##__VA_ARGS__)

or maybe even as a function rather than a macro
if it saves code space.  __func__ could then be
converted to __builtin_return_address(0)

for instance: https://lkml.org/lkml/2016/2/25/554

  reply	other threads:[~2016-03-14 14:07 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-13 19:19 [RFC PATCH] checkpatch: check formatting of __func__ output uses Joe Perches
2016-03-13 19:19 ` Joe Perches
2016-03-14  0:42 ` [RFC PATCH V2] checkpatch: Check output format style of __func__ uses Joe Perches
2016-03-14  0:42   ` Joe Perches
2016-03-14  5:19   ` Julia Lawall
2016-03-14  5:19     ` Julia Lawall
2016-03-14  7:35     ` Joe Perches
2016-03-14  7:35       ` Joe Perches
2016-03-14  8:29       ` Julia Lawall
2016-03-14  8:29         ` Julia Lawall
2016-03-14 14:07         ` Joe Perches [this message]
2016-03-14 14:07           ` Joe Perches

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=1457964458.11972.89.camel@perches.com \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=apw@canonical.com \
    --cc=error27@gmail.com \
    --cc=julia.lawall@lip6.fr \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.