qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 29/43] checkpatch: adapt some tests to QEMU
Date: Wed,  9 Sep 2015 15:49:59 +0200	[thread overview]
Message-ID: <1441806613-13775-30-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1441806613-13775-1-git-send-email-pbonzini@redhat.com>

Mostly change severity levels, but some tests can also be adjusted to refer
to QEMU APIs or data structures.

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 scripts/checkpatch.pl | 141 +++++++++++++++++++++-----------------------------
 1 file changed, 60 insertions(+), 81 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 7f0aae9..f553082 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -152,33 +152,18 @@ our $Sparse	= qr{
 		}x;
 
 # Notes to $Attribute:
-# We need \b after 'init' otherwise 'initconst' will cause a false positive in a check
 our $Attribute	= qr{
 			const|
-			__percpu|
-			__nocast|
-			__safe|
-			__bitwise__|
-			__packed__|
-			__packed2__|
-			__naked|
-			__maybe_unused|
-			__always_unused|
-			__noreturn|
-			__used|
-			__cold|
-			__noclone|
-			__deprecated|
-			__read_mostly|
-			__kprobes|
-			__(?:mem|cpu|dev|)(?:initdata|initconst|init\b)|
-			____cacheline_aligned|
-			____cacheline_aligned_in_smp|
-			____cacheline_internodealigned_in_smp|
-			__weak
+			volatile|
+			QEMU_NORETURN|
+			QEMU_WARN_UNUSED_RESULT|
+			QEMU_SENTINEL|
+			QEMU_ARTIFICIAL|
+			QEMU_PACKED|
+			GCC_FMT_ATTR
 		  }x;
 our $Modifier;
-our $Inline	= qr{inline|__always_inline|noinline};
+our $Inline	= qr{inline};
 our $Member	= qr{->$Ident|\.$Ident|\[[^]]*\]};
 our $Lval	= qr{$Ident(?:$Member)*};
 
@@ -1367,7 +1352,7 @@ sub process {
 # Check for incorrect file permissions
 		if ($line =~ /^new (file )?mode.*[7531]\d{0,2}$/) {
 			my $permhere = $here . "FILE: $realfile\n";
-			if ($realfile =~ /(Makefile|Kconfig|\.c|\.cpp|\.h|\.S|\.tmpl)$/) {
+			if ($realfile =~ /(\bMakefile(?:\.objs)?|\.c|\.cc|\.cpp|\.h|\.mak|\.[sS])$/) {
 				ERROR("do not set execute permissions for source files\n" . $permhere);
 			}
 		}
@@ -1947,9 +1932,14 @@ sub process {
 			ERROR("open brace '{' following $1 go on the same line\n" . $hereprev);
 		}
 
+# ... however, open braces on typedef lines should be avoided.
+		if ($line =~ /^.\s*typedef\s+(enum|union|struct)(?:\s+$Ident\b)?.*[^;]$/) {
+			ERROR("typedefs should be separate from struct declaration\n" . $herecurr);
+		}
+
 # missing space after union, struct or enum definition
 		if ($line =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?(?:\s+$Ident)?[=\{]/) {
-		    WARN("missing space after $1 definition\n" . $herecurr);
+		    ERROR("missing space after $1 definition\n" . $herecurr);
 		}
 
 # check for spacing round square brackets; allowed:
@@ -2267,7 +2257,7 @@ sub process {
 		if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) {
 			my $name = $1;
 			if ($name ne 'EOF' && $name ne 'ERROR') {
-				CHK("return of an errno should typically be -ve (return -$1)\n" . $herecurr);
+				WARN("return of an errno should typically be -ve (return -$1)\n" . $herecurr);
 			}
 		}
 
@@ -2671,15 +2661,15 @@ sub process {
 
 # warn about #if 0
 		if ($line =~ /^.\s*\#\s*if\s+0\b/) {
-			CHK("if this code is redundant consider removing it\n" .
+			WARN("if this code is redundant consider removing it\n" .
 				$herecurr);
 		}
 
-# check for needless kfree() checks
+# check for needless g_free() checks
 		if ($prevline =~ /\bif\s*\(([^\)]*)\)/) {
 			my $expr = $1;
-			if ($line =~ /\bkfree\(\Q$expr\E\);/) {
-				WARN("kfree(NULL) is safe this check is probably not required\n" . $hereprev);
+			if ($line =~ /\bg_free\(\Q$expr\E\);/) {
+				WARN("g_free(NULL) is safe this check is probably not required\n" . $hereprev);
 			}
 		}
 # check for needless usb_free_urb() checks
@@ -2726,14 +2716,16 @@ sub process {
 			}
 		}
 # check for memory barriers without a comment.
-		if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
+		if ($line =~ /\b(smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
 			if (!ctx_has_comment($first_line, $linenr)) {
-				CHK("memory barrier without comment\n" . $herecurr);
+				WARN("memory barrier without comment\n" . $herecurr);
 			}
 		}
 # check of hardware specific defines
-		if ($line =~ m@^.\s*\#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@include/asm-@) {
-			CHK("architecture specific defines should be avoided\n" .  $herecurr);
+# we have e.g. CONFIG_LINUX and CONFIG_WIN32 for common cases
+# where they might be necessary.
+		if ($line =~ m@^.\s*\#\s*if.*\b__@) {
+			WARN("architecture specific defines should be avoided\n" .  $herecurr);
 		}
 
 # Check that the storage class is at the beginning of a declaration
@@ -2794,9 +2786,13 @@ sub process {
 			}
 		}
 
-# check for pointless casting of kmalloc return
-		if ($line =~ /\*\s*\)\s*k[czm]alloc\b/) {
-			WARN("unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
+# check for pointless casting of g_malloc return
+		if ($line =~ /\*\s*\)\s*g_(try)?(m|re)alloc(0?)(_n)?\b/) {
+			if ($2 == 'm') {
+				WARN("unnecessary cast may hide bugs, use g_$1new$3 instead\n" . $herecurr);
+			} else {
+				WARN("unnecessary cast may hide bugs, use g_$1renew$3 instead\n" . $herecurr);
+			}
 		}
 
 # check for gcc specific __FUNCTION__
@@ -2813,54 +2809,37 @@ sub process {
 			WARN("consider using a completion\n" . $herecurr);
 
 		}
-# recommend strict_strto* over simple_strto*
-		if ($line =~ /\bsimple_(strto.*?)\s*\(/) {
-			WARN("consider using strict_$1 in preference to simple_$1\n" . $herecurr);
+# recommend qemu_strto* over strto*
+		if ($line =~ /\b(strto.*?)\s*\(/) {
+			WARN("consider using qemu_$1 in preference to $1\n" . $herecurr);
 		}
-# check for __initcall(), use device_initcall() explicitly please
-		if ($line =~ /^.\s*__initcall\s*\(/) {
-			WARN("please use device_initcall() instead of __initcall()\n" . $herecurr);
+# check for module_init(), use category-specific init macros explicitly please
+		if ($line =~ /^module_init\s*\(/) {
+			WARN("please use block_init(), type_init() etc. instead of module_init()\n" . $herecurr);
 		}
 # check for various ops structs, ensure they are const.
-		my $struct_ops = qr{acpi_dock_ops|
-				address_space_operations|
-				backlight_ops|
-				block_device_operations|
-				dentry_operations|
-				dev_pm_ops|
-				dma_map_ops|
-				extent_io_ops|
-				file_lock_operations|
-				file_operations|
-				hv_ops|
-				ide_dma_ops|
-				intel_dvo_dev_ops|
-				item_operations|
-				iwl_ops|
-				kgdb_arch|
-				kgdb_io|
-				kset_uevent_ops|
-				lock_manager_operations|
-				microcode_ops|
-				mtrr_ops|
-				neigh_ops|
-				nlmsvc_binding|
-				pci_raw_ops|
-				pipe_buf_operations|
-				platform_hibernation_ops|
-				platform_suspend_ops|
-				proto_ops|
-				rpc_pipe_ops|
-				seq_operations|
-				snd_ac97_build_ops|
-				soc_pcmcia_socket_ops|
-				stacktrace_ops|
-				sysfs_ops|
-				tty_operations|
-				usb_mon_operations|
-				wd_ops}x;
+		my $struct_ops = qr{AIOCBInfo|
+				BdrvActionOps|
+				BlockDevOps|
+				BlockJobDriver|
+				DisplayChangeListenerOps|
+				GraphicHwOps|
+				IDEDMAOps|
+				KVMCapabilityInfo|
+				MemoryRegionIOMMUOps|
+				MemoryRegionOps|
+				MemoryRegionPortio|
+				QEMUFileOps|
+				SCSIBusInfo|
+				SCSIReqOps|
+				Spice[A-Z][a-zA-Z0-9]*Interface|
+				TPMDriverOps|
+				USBDesc[A-Z][a-zA-Z0-9]*|
+				VhostOps|
+				VMStateDescription|
+				VMStateInfo}x;
 		if ($line !~ /\bconst\b/ &&
-		    $line =~ /\bstruct\s+($struct_ops)\b/) {
+		    $line =~ /\b($struct_ops)\b/) {
 			WARN("struct $1 should normally be const\n" .
 				$herecurr);
 		}
-- 
2.4.3

  parent reply	other threads:[~2015-09-09 13:51 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-09 13:49 [Qemu-devel] [PULL 00/43] First batch of misc changes for 2.5 (2015-09-09) Paolo Bonzini
2015-09-09 13:49 ` [Qemu-devel] [PULL 01/43] qemu-thread: handle spurious futex_wait wakeups Paolo Bonzini
2015-09-09 13:49 ` [Qemu-devel] [PULL 02/43] seqlock: add missing 'inline' to seqlock_read_retry Paolo Bonzini
2015-09-09 13:49 ` [Qemu-devel] [PULL 03/43] seqlock: read sequence number atomically Paolo Bonzini
2015-09-09 13:49 ` [Qemu-devel] [PULL 04/43] cpus.c: qemu_mutex_lock_iothread fix race condition at cpu thread init Paolo Bonzini
2015-09-09 13:49 ` [Qemu-devel] [PULL 05/43] iohandler: Use aio API Paolo Bonzini
2015-09-09 13:49 ` [Qemu-devel] [PULL 06/43] block/iscsi: validate block size returned from target Paolo Bonzini
2015-09-09 13:49 ` [Qemu-devel] [PULL 07/43] Added generic panic handler qemu_system_guest_panicked() Paolo Bonzini
2015-09-09 13:49 ` [Qemu-devel] [PULL 08/43] i8257: rewrite DMA_schedule to avoid hooking into the CPU loop Paolo Bonzini
2015-09-09 13:49 ` [Qemu-devel] [PULL 09/43] i8257: remove cpu_request_exit irq Paolo Bonzini
2015-09-09 13:49 ` [Qemu-devel] [PULL 10/43] tcg: introduce tcg_current_cpu Paolo Bonzini
2015-09-09 13:49 ` [Qemu-devel] [PULL 11/43] remove qemu/tls.h Paolo Bonzini
2015-09-09 13:49 ` [Qemu-devel] [PULL 12/43] tcg: assign cpu->current_tb in a simpler place Paolo Bonzini
2015-09-09 13:49 ` [Qemu-devel] [PULL 13/43] tcg: synchronize cpu->exit_request and cpu->tcg_exit_req accesses Paolo Bonzini
2015-09-09 13:49 ` [Qemu-devel] [PULL 14/43] tcg: synchronize exit_request and tcg_current_cpu accesses Paolo Bonzini
2015-09-09 13:49 ` [Qemu-devel] [PULL 15/43] use qemu_cpu_kick instead of cpu_exit or qemu_cpu_kick_thread Paolo Bonzini
2015-09-09 13:49 ` [Qemu-devel] [PULL 16/43] tcg: signal-free qemu_cpu_kick Paolo Bonzini
2015-09-09 13:49 ` [Qemu-devel] [PULL 17/43] Move RAMBlock and ram_list to ram_addr.h Paolo Bonzini
2015-09-09 13:49 ` [Qemu-devel] [PULL 18/43] Makefile.target: include top level build dir in vpath Paolo Bonzini
2015-09-09 13:49 ` [Qemu-devel] [PULL 19/43] rcu: init rcu_registry_lock after fork Paolo Bonzini
2015-09-16 12:37   ` Gerd Hoffmann
2015-09-16 12:38     ` Paolo Bonzini
2015-09-09 13:49 ` [Qemu-devel] [PULL 20/43] rcu: fix comment with s/rcu_gp_lock/rcu_registry_lock/ Paolo Bonzini
2015-09-09 13:49 ` [Qemu-devel] [PULL 21/43] linux-user: call rcu_(un)register_thread on pthread_(exit|create) Paolo Bonzini
2015-09-09 13:49 ` [Qemu-devel] [PULL 22/43] translate-all: remove obsolete comment about l1_map Paolo Bonzini
2015-09-09 13:49 ` [Qemu-devel] [PULL 23/43] cutils: Add qemu_strtol() wrapper Paolo Bonzini
2015-09-09 13:49 ` [Qemu-devel] [PULL 24/43] cutils: Add qemu_strtoul() wrapper Paolo Bonzini
2015-09-09 13:49 ` [Qemu-devel] [PULL 25/43] cutils: Add qemu_strtoll() wrapper Paolo Bonzini
2015-09-09 13:49 ` [Qemu-devel] [PULL 26/43] cutils: Add qemu_strtoull() wrapper Paolo Bonzini
2015-09-09 13:49 ` [Qemu-devel] [PULL 27/43] qmp: Add example usage of strto*l() qemu wrapper Paolo Bonzini
2015-09-09 13:49 ` [Qemu-devel] [PULL 28/43] CODING_STYLE: update mixed declaration rules Paolo Bonzini
2015-09-09 13:49 ` Paolo Bonzini [this message]
2015-09-09 13:50 ` [Qemu-devel] [PULL 30/43] checkpatch: remove tests that are not relevant outside the kernel Paolo Bonzini
2015-09-09 13:50 ` [Qemu-devel] [PULL 31/43] vhost-scsi: fix wrong vhost-scsi firmware path Paolo Bonzini
2015-09-09 13:50 ` [Qemu-devel] [PULL 32/43] configure: factor out adding disas configure Paolo Bonzini
2015-09-09 13:50 ` [Qemu-devel] [PULL 33/43] add macro file for coccinelle Paolo Bonzini
2015-09-09 13:50 ` [Qemu-devel] [PULL 34/43] configure: Add support for jemalloc Paolo Bonzini
2015-09-09 13:50 ` [Qemu-devel] [PULL 35/43] scripts/dump-guest-memory.py: fix after RAMBlock change Paolo Bonzini
2015-09-09 13:50 ` [Qemu-devel] [PULL 36/43] cpus: protect work list with work_mutex Paolo Bonzini
2015-09-09 13:50 ` [Qemu-devel] [PULL 37/43] cpus: remove tcg_halt_cond and tcg_cpu_thread globals Paolo Bonzini
2015-09-09 13:50 ` [Qemu-devel] [PULL 38/43] replace spinlock by QemuMutex Paolo Bonzini
2015-09-09 13:50 ` [Qemu-devel] [PULL 39/43] remove unused spinlock Paolo Bonzini
2015-09-09 13:50 ` [Qemu-devel] [PULL 40/43] tcg: add memory barriers in page_find_alloc accesses Paolo Bonzini
2015-09-09 13:50 ` [Qemu-devel] [PULL 41/43] tcg: comment on which functions have to be called with mmap_lock held Paolo Bonzini
2015-09-09 13:50 ` [Qemu-devel] [PULL 42/43] exec: make mmap_lock/mmap_unlock globally available Paolo Bonzini
2015-09-09 13:50 ` [Qemu-devel] [PULL 43/43] cpu-exec: fix lock hierarchy for user-mode emulation Paolo Bonzini
2015-09-09 18:41 ` [Qemu-devel] [PULL 00/43] First batch of misc changes for 2.5 (2015-09-09) Peter Maydell
2015-09-09 19:25   ` Paolo Bonzini

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=1441806613-13775-30-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.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 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).