[PATCH 3/4] misc: Clean up includes

Peter Maydell posted 4 patches 3 weeks ago
Maintainers: Magnus Kulke <magnus.kulke@linux.microsoft.com>, Wei Liu <wei.liu@kernel.org>, Warner Losh <imp@bsdimp.com>, Kyle Evans <kevans@freebsd.org>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Yanan Wang <wangyanan55@huawei.com>, Zhao Liu <zhao1.liu@intel.com>, Paolo Bonzini <pbonzini@redhat.com>, Fam Zheng <fam@euphon.net>, Richard Henderson <richard.henderson@linaro.org>, Helge Deller <deller@gmx.de>, "Michael S. Tsirkin" <mst@redhat.com>, Nicholas Piggin <npiggin@gmail.com>, Harsh Prateek Bora <harshpb@linux.ibm.com>, Aditya Gupta <adityag@linux.ibm.com>, Sourabh Jain <sourabhjain@linux.ibm.com>, Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <dbarboza@ventanamicro.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, Laurent Vivier <laurent@vivier.eu>, Michael Roth <michael.roth@amd.com>, Kostiantyn Kostiuk <kkostiuk@redhat.com>, "Alex Bennée" <alex.bennee@linaro.org>, Peter Maydell <peter.maydell@linaro.org>, Marcelo Tosatti <mtosatti@redhat.com>, Song Gao <gaosong@loongson.cn>
[PATCH 3/4] misc: Clean up includes
Posted by Peter Maydell 3 weeks ago
This commit deals with various .c files that included system
headers that are already pulled in by osdep.h, where the .c
file includes osdep.h already itself.

This commit was created with scripts/clean-includes:
 ./scripts/clean-includes '--git' 'misc' 'hw/core' 'semihosting' 'target/arm' 'target/i386/kvm/kvm.c' 'target/loongarch' 'target/riscv' 'tools' 'util'

All .c should include qemu/osdep.h first.  The script performs three
related cleanups:

* Ensure .c files include qemu/osdep.h first.
* Including it in a .h is redundant, since the .c  already includes
  it.  Drop such inclusions.
* Likewise, including headers qemu/osdep.h includes is redundant.
  Drop these, too.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 hw/core/machine-qmp-cmds.c         | 1 -
 semihosting/arm-compat-semi-stub.c | 1 -
 target/arm/cpu32-stubs.c           | 1 -
 target/i386/kvm/kvm.c              | 1 -
 target/loongarch/csr.c             | 1 -
 target/riscv/csr.c                 | 1 -
 tools/i386/qemu-vmsr-helper.c      | 1 -
 util/cpuinfo-aarch64.c             | 1 -
 8 files changed, 8 deletions(-)

diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
index 79cbcdd63e..e62cb4ec88 100644
--- a/hw/core/machine-qmp-cmds.c
+++ b/hw/core/machine-qmp-cmds.c
@@ -30,7 +30,6 @@
 #include "system/runstate.h"
 #include "system/system.h"
 #include "hw/s390x/storage-keys.h"
-#include <sys/stat.h>
 
 /*
  * QMP query for enabled and present accelerators
diff --git a/semihosting/arm-compat-semi-stub.c b/semihosting/arm-compat-semi-stub.c
index bfa3681e26..40199c9842 100644
--- a/semihosting/arm-compat-semi-stub.c
+++ b/semihosting/arm-compat-semi-stub.c
@@ -6,7 +6,6 @@
 
 #include "qemu/osdep.h"
 #include "semihosting/semihost.h"
-#include <glib.h>
 
 bool semihosting_arm_compatible(void)
 {
diff --git a/target/arm/cpu32-stubs.c b/target/arm/cpu32-stubs.c
index f0ce159572..9e50bb1b0b 100644
--- a/target/arm/cpu32-stubs.c
+++ b/target/arm/cpu32-stubs.c
@@ -3,7 +3,6 @@
 #include "qemu/osdep.h"
 #include "target/arm/cpu.h"
 #include "target/arm/internals.h"
-#include <glib.h>
 
 void arm_cpu_sme_finalize(ARMCPU *cpu, Error **errp)
 {
diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index 7b9b740a8e..0c940d4b64 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -21,7 +21,6 @@
 #include <sys/utsname.h>
 #include <sys/syscall.h>
 #include <sys/resource.h>
-#include <sys/time.h>
 
 #include <linux/kvm.h>
 #include <linux/kvm_para.h>
diff --git a/target/loongarch/csr.c b/target/loongarch/csr.c
index 332a1396cc..fff2312f87 100644
--- a/target/loongarch/csr.c
+++ b/target/loongarch/csr.c
@@ -2,7 +2,6 @@
 /*
  * Copyright (c) 2025 Loongson Technology Corporation Limited
  */
-#include <stddef.h>
 #include "qemu/osdep.h"
 #include "cpu.h"
 #include "csr.h"
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
index 05c7ec8352..5064483917 100644
--- a/target/riscv/csr.c
+++ b/target/riscv/csr.c
@@ -31,7 +31,6 @@
 #include "qapi/error.h"
 #include "tcg/insn-start-words.h"
 #include "internals.h"
-#include <stdbool.h>
 
 /* CSR function table public API */
 void riscv_get_csr_ops(int csrno, riscv_csr_operations *ops)
diff --git a/tools/i386/qemu-vmsr-helper.c b/tools/i386/qemu-vmsr-helper.c
index 6c0f4fe870..f12fd3c3e8 100644
--- a/tools/i386/qemu-vmsr-helper.c
+++ b/tools/i386/qemu-vmsr-helper.c
@@ -20,7 +20,6 @@
 
 #include "qemu/osdep.h"
 #include <getopt.h>
-#include <stdbool.h>
 #include <sys/ioctl.h>
 #ifdef CONFIG_LIBCAP_NG
 #include <cap-ng.h>
diff --git a/util/cpuinfo-aarch64.c b/util/cpuinfo-aarch64.c
index 57468890c3..288074c08f 100644
--- a/util/cpuinfo-aarch64.c
+++ b/util/cpuinfo-aarch64.c
@@ -26,7 +26,6 @@
 #if defined(__OpenBSD__) && !defined(CONFIG_ELF_AUX_INFO)
 # include <machine/armreg.h>
 # include <machine/cpu.h>
-# include <sys/types.h>
 # include <sys/sysctl.h>
 #endif
 
-- 
2.47.3
Re: [PATCH 3/4] misc: Clean up includes
Posted by Philippe Mathieu-Daudé 3 weeks ago
On 16/1/26 13:58, Peter Maydell wrote:
> This commit deals with various .c files that included system
> headers that are already pulled in by osdep.h, where the .c
> file includes osdep.h already itself.
> 
> This commit was created with scripts/clean-includes:
>   ./scripts/clean-includes '--git' 'misc' 'hw/core' 'semihosting' 'target/arm' 'target/i386/kvm/kvm.c' 'target/loongarch' 'target/riscv' 'tools' 'util'
> 
> All .c should include qemu/osdep.h first.  The script performs three
> related cleanups:
> 
> * Ensure .c files include qemu/osdep.h first.
> * Including it in a .h is redundant, since the .c  already includes
>    it.  Drop such inclusions.
> * Likewise, including headers qemu/osdep.h includes is redundant.
>    Drop these, too.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   hw/core/machine-qmp-cmds.c         | 1 -
>   semihosting/arm-compat-semi-stub.c | 1 -
>   target/arm/cpu32-stubs.c           | 1 -
>   target/i386/kvm/kvm.c              | 1 -
>   target/loongarch/csr.c             | 1 -
>   target/riscv/csr.c                 | 1 -
>   tools/i386/qemu-vmsr-helper.c      | 1 -
>   util/cpuinfo-aarch64.c             | 1 -
>   8 files changed, 8 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Re: [PATCH 3/4] misc: Clean up includes
Posted by Markus Armbruster 3 weeks ago
Peter Maydell <peter.maydell@linaro.org> writes:

> This commit deals with various .c files that included system
> headers that are already pulled in by osdep.h, where the .c
> file includes osdep.h already itself.
>
> This commit was created with scripts/clean-includes:
>  ./scripts/clean-includes '--git' 'misc' 'hw/core' 'semihosting' 'target/arm' 'target/i386/kvm/kvm.c' 'target/loongarch' 'target/riscv' 'tools' 'util'
>
> All .c should include qemu/osdep.h first.  The script performs three
> related cleanups:
>
> * Ensure .c files include qemu/osdep.h first.
> * Including it in a .h is redundant, since the .c  already includes
>   it.  Drop such inclusions.
> * Likewise, including headers qemu/osdep.h includes is redundant.
>   Drop these, too.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Reviewed-by: Markus Armbruster <armbru@redhat.com>