xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] include/checkpatch: Prefer __scanf to __attribute__((format(scanf, ...)
@ 2012-01-21  0:01 Joe Perches
  2012-01-24  1:47 ` [Xen-devel] " Konrad Rzeszutek Wilk
  0 siblings, 1 reply; 3+ messages in thread
From: Joe Perches @ 2012-01-21  0:01 UTC (permalink / raw)
  To: Andrew Morton, Konrad Rzeszutek Wilk, Jeremy Fitzhardinge,
	Andy Whitcroft
  Cc: xen-devel, linux-kernel, virtualization

It's equivalent to __printf, so prefer __scanf.

Signed-off-by: Joe Perches <joe@perches.com>
---
 include/linux/compiler-gcc.h |    3 ++-
 include/linux/kernel.h       |    8 ++++----
 include/xen/xenbus.h         |    4 ++--
 scripts/checkpatch.pl        |    6 ++++++
 4 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 3fd17c2..e5834aa 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -87,7 +87,8 @@
  */
 #define __pure				__attribute__((pure))
 #define __aligned(x)			__attribute__((aligned(x)))
-#define __printf(a,b)			__attribute__((format(printf,a,b)))
+#define __printf(a, b)			__attribute__((format(printf, a, b)))
+#define __scanf(a, b)			__attribute__((format(scanf, a, b)))
 #define  noinline			__attribute__((noinline))
 #define __attribute_const__		__attribute__((__const__))
 #define __maybe_unused			__attribute__((unused))
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index e834342..30f21ec 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -315,10 +315,10 @@ extern __printf(2, 3)
 char *kasprintf(gfp_t gfp, const char *fmt, ...);
 extern char *kvasprintf(gfp_t gfp, const char *fmt, va_list args);
 
-extern int sscanf(const char *, const char *, ...)
-	__attribute__ ((format (scanf, 2, 3)));
-extern int vsscanf(const char *, const char *, va_list)
-	__attribute__ ((format (scanf, 2, 0)));
+extern __scanf(2, 3)
+int sscanf(const char *, const char *, ...);
+extern __scanf(2, 0)
+int vsscanf(const char *, const char *, va_list);
 
 extern int get_option(char **str, int *pint);
 extern char *get_options(const char *str, int nints, int *ints);
diff --git a/include/xen/xenbus.h b/include/xen/xenbus.h
index e8c599b..0a7515c 100644
--- a/include/xen/xenbus.h
+++ b/include/xen/xenbus.h
@@ -139,9 +139,9 @@ int xenbus_transaction_start(struct xenbus_transaction *t);
 int xenbus_transaction_end(struct xenbus_transaction t, int abort);
 
 /* Single read and scanf: returns -errno or num scanned if > 0. */
+__scanf(4, 5)
 int xenbus_scanf(struct xenbus_transaction t,
-		 const char *dir, const char *node, const char *fmt, ...)
-	__attribute__((format(scanf, 4, 5)));
+		 const char *dir, const char *node, const char *fmt, ...);
 
 /* Single printf and write: returns -errno or 0. */
 __printf(4, 5)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index e3bfcbe..2b52aeb 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3117,6 +3117,12 @@ sub process {
 			     "__printf(string-index, first-to-check) is preferred over __attribute__((format(printf, string-index, first-to-check)))\n" . $herecurr);
 		}
 
+# Check for __attribute__ format(scanf, prefer __scanf
+		if ($line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\b/) {
+			WARN("PREFER_SCANF",
+			     "__scanf(string-index, first-to-check) is preferred over __attribute__((format(scanf, string-index, first-to-check)))\n" . $herecurr);
+		}
+
 # check for sizeof(&)
 		if ($line =~ /\bsizeof\s*\(\s*\&/) {
 			WARN("SIZEOF_ADDRESS",
-- 
1.7.8.111.gad25c.dirty

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Xen-devel] [PATCH] include/checkpatch: Prefer __scanf to __attribute__((format(scanf, ...)
  2012-01-21  0:01 [PATCH] include/checkpatch: Prefer __scanf to __attribute__((format(scanf, ...) Joe Perches
@ 2012-01-24  1:47 ` Konrad Rzeszutek Wilk
  2012-01-24  2:00   ` Joe Perches
  0 siblings, 1 reply; 3+ messages in thread
From: Konrad Rzeszutek Wilk @ 2012-01-24  1:47 UTC (permalink / raw)
  To: Joe Perches
  Cc: Jeremy Fitzhardinge, xen-devel, Konrad Rzeszutek Wilk,
	linux-kernel, virtualization, Andy Whitcroft, Andrew Morton

On Fri, Jan 20, 2012 at 04:01:12PM -0800, Joe Perches wrote:
> It's equivalent to __printf, so prefer __scanf.

So ... looking at this patch it just seems to macro-fy the
__printf and __scanf attributes. Is this required to make
cleanpatch.pl work easier?

And there is also some checkpatch.pl features. Should that part
be in a seperate patch?

> Signed-off-by: Joe Perches <joe@perches.com>
> ---
>  include/linux/compiler-gcc.h |    3 ++-
>  include/linux/kernel.h       |    8 ++++----
>  include/xen/xenbus.h         |    4 ++--
>  scripts/checkpatch.pl        |    6 ++++++
>  4 files changed, 14 insertions(+), 7 deletions(-)
> 
> diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
> index 3fd17c2..e5834aa 100644
> --- a/include/linux/compiler-gcc.h
> +++ b/include/linux/compiler-gcc.h
> @@ -87,7 +87,8 @@
>   */
>  #define __pure				__attribute__((pure))
>  #define __aligned(x)			__attribute__((aligned(x)))
> -#define __printf(a,b)			__attribute__((format(printf,a,b)))
> +#define __printf(a, b)			__attribute__((format(printf, a, b)))
> +#define __scanf(a, b)			__attribute__((format(scanf, a, b)))
>  #define  noinline			__attribute__((noinline))
>  #define __attribute_const__		__attribute__((__const__))
>  #define __maybe_unused			__attribute__((unused))
> diff --git a/include/linux/kernel.h b/include/linux/kernel.h
> index e834342..30f21ec 100644
> --- a/include/linux/kernel.h
> +++ b/include/linux/kernel.h
> @@ -315,10 +315,10 @@ extern __printf(2, 3)
>  char *kasprintf(gfp_t gfp, const char *fmt, ...);
>  extern char *kvasprintf(gfp_t gfp, const char *fmt, va_list args);
>  
> -extern int sscanf(const char *, const char *, ...)
> -	__attribute__ ((format (scanf, 2, 3)));
> -extern int vsscanf(const char *, const char *, va_list)
> -	__attribute__ ((format (scanf, 2, 0)));
> +extern __scanf(2, 3)
> +int sscanf(const char *, const char *, ...);
> +extern __scanf(2, 0)
> +int vsscanf(const char *, const char *, va_list);
>  
>  extern int get_option(char **str, int *pint);
>  extern char *get_options(const char *str, int nints, int *ints);
> diff --git a/include/xen/xenbus.h b/include/xen/xenbus.h
> index e8c599b..0a7515c 100644
> --- a/include/xen/xenbus.h
> +++ b/include/xen/xenbus.h
> @@ -139,9 +139,9 @@ int xenbus_transaction_start(struct xenbus_transaction *t);
>  int xenbus_transaction_end(struct xenbus_transaction t, int abort);
>  
>  /* Single read and scanf: returns -errno or num scanned if > 0. */
> +__scanf(4, 5)
>  int xenbus_scanf(struct xenbus_transaction t,
> -		 const char *dir, const char *node, const char *fmt, ...)
> -	__attribute__((format(scanf, 4, 5)));
> +		 const char *dir, const char *node, const char *fmt, ...);
>  
>  /* Single printf and write: returns -errno or 0. */
>  __printf(4, 5)
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index e3bfcbe..2b52aeb 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -3117,6 +3117,12 @@ sub process {
>  			     "__printf(string-index, first-to-check) is preferred over __attribute__((format(printf, string-index, first-to-check)))\n" . $herecurr);
>  		}
>  
> +# Check for __attribute__ format(scanf, prefer __scanf
> +		if ($line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\b/) {
> +			WARN("PREFER_SCANF",
> +			     "__scanf(string-index, first-to-check) is preferred over __attribute__((format(scanf, string-index, first-to-check)))\n" . $herecurr);
> +		}
> +
>  # check for sizeof(&)
>  		if ($line =~ /\bsizeof\s*\(\s*\&/) {
>  			WARN("SIZEOF_ADDRESS",
> -- 
> 1.7.8.111.gad25c.dirty
> 
> 
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xensource.com
> http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Xen-devel] [PATCH] include/checkpatch: Prefer __scanf to __attribute__((format(scanf, ...)
  2012-01-24  1:47 ` [Xen-devel] " Konrad Rzeszutek Wilk
@ 2012-01-24  2:00   ` Joe Perches
  0 siblings, 0 replies; 3+ messages in thread
From: Joe Perches @ 2012-01-24  2:00 UTC (permalink / raw)
  To: Konrad Rzeszutek Wilk
  Cc: Jeremy Fitzhardinge, xen-devel, Konrad Rzeszutek Wilk,
	linux-kernel, virtualization, Andy Whitcroft, Andrew Morton

On Mon, 2012-01-23 at 21:47 -0400, Konrad Rzeszutek Wilk wrote:
> On Fri, Jan 20, 2012 at 04:01:12PM -0800, Joe Perches wrote:
> > It's equivalent to __printf, so prefer __scanf.
> So ... looking at this patch it just seems to macro-fy the
> __printf and __scanf attributes.

It's just for __scanf.  The __printf change is just
a neatening/spacing change.

> Is this required to make
> cleanpatch.pl work easier?

No.  It's a trivial symmetry patch added to
make fewer uses of __attribute__((format(...)
similar to the __printf commit from awhile ago.

commit b9075fa968a0a4347aef35e235e2995c0e57dddd

> And there is also some checkpatch.pl features. Should that part
> be in a seperate patch?

I think it's OK to do the whole thing at once.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-01-24  2:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-21  0:01 [PATCH] include/checkpatch: Prefer __scanf to __attribute__((format(scanf, ...) Joe Perches
2012-01-24  1:47 ` [Xen-devel] " Konrad Rzeszutek Wilk
2012-01-24  2:00   ` Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).