From nobody Sat Sep 21 04:18:46 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4X9bbp5G62z5XBwR; Sat, 21 Sep 2024 04:18:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4X9bbp3FB3z40Mj; Sat, 21 Sep 2024 04:18:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726892326; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iqwXvF4QZwGwAWPHMPJogBdwqtdY8+dgK0Hhxx1bKwQ=; b=r+/4dZ/k8N4JZL77Fg03S3CMgMqodjrv0utEI8AL6V2y0X/iiziVYsEqGPHAUUHc9QjMxI XSX+Tx9Thx6BgE0X9gEssDuQdzGJ/5RpJYQdQKt+oHP5YpLvlR7VbsmZ2DbqyQV5dZOF3S vAtrQtb8KGrcwvCkktp9vbXHtsRO8UBHYyJCEpt5noY0s/pBmzG9cK97q6ONfufQCD5tST u3CIFVIMj/u2jt4MBiymc7fcR2HZej2A1q0q1VskcxQLI74beL7e9rZy3uJ6/8xETYBaFi H1ZG+H4rdsgDJzJuCK8Eu91SdwkFODWcGCsE3hml7fs5y5SYEQwbp6nqILZY7A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1726892326; a=rsa-sha256; cv=none; b=F2sa+chg6zLVte1uPshGt0QUCtEWcID7Z8tDMCR3EGt5cYsEgy1mGlF/GwxcFnahq+L2UO 4pO8bDgc85VMcAwGk4jHfOt2joqDj2rqOJLkeQ5QB7SvLonzlvHqqil+SDIin7w6lZ4kDr J3EpYYHPckFcmGqNvSyw6KnWCbt+KNA/SlM75RBrolKxGjCyrXgoKiaBdHzC6FNAsvCYCD B4gL0pDBiNvMioS2ChIaw3XlSVJ3AgjNe26imUvGDKx96KUaqgp2oN9z5CCONJCmFQCodM YoVetWECQEcoZmwuVIcBgEvLpxH0fF3EzsMm4vbQF1MQ5aL8VQDmK85vYlalpw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726892326; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iqwXvF4QZwGwAWPHMPJogBdwqtdY8+dgK0Hhxx1bKwQ=; b=wtP7V2GRGWhrjb6Z/VdO2rcLsCXqe0lIhK8aztz7SmnIvNpOceeBDwRBXlPmoxeYVYzWNk MpoWa7QHKM/jdbHNfeBAc6mUvDZbWshqgKBWYB91Co9E4Hr2WABXA/dEOuHWf7Ijha/z+b yiMrYPmc/Mb8Bmtt/zBAQPsdVMk+AKEq5aUj5V4yCWDUWKB4FbvRM6aZUbKfUtqj53YrYp avytKz8+2PfE02LPLtpkCUPbiEWXezt0PIEcXBkeBzMMT0STMnouRR7slHGuTOv0S8lYoF 4IIVblDP1R0vkcpVmdAnw8q1yDvGG5UTbYfpx9H7OKGEs2qOH/S6yMhLm5zTtA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4X9bbp2h8szHgR; Sat, 21 Sep 2024 04:18:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 48L4IkwM010123; Sat, 21 Sep 2024 04:18:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48L4IkNV010120; Sat, 21 Sep 2024 04:18:46 GMT (envelope-from git) Date: Sat, 21 Sep 2024 04:18:46 GMT Message-Id: <202409210418.48L4IkNV010120@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Zhenlei Huang Subject: git: e38f24446f09 - stable/13 - kernel: Make some compile time constant variables const List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: zlei X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: e38f24446f09267647b3d893ae700c4c9e07bc78 Auto-Submitted: auto-generated The branch stable/13 has been updated by zlei: URL: https://cgit.FreeBSD.org/src/commit/?id=e38f24446f09267647b3d893ae700c4c9e07bc78 commit e38f24446f09267647b3d893ae700c4c9e07bc78 Author: Zhenlei Huang AuthorDate: 2024-08-30 10:26:30 +0000 Commit: Zhenlei Huang CommitDate: 2024-09-21 04:16:40 +0000 kernel: Make some compile time constant variables const Those variables are not going to be changed at runtime. Make them const to avoid potential overwriting. This will also help spotting accidental global variables shadowing, since the variable's name such as `version` is short and commonly used. This change was inspired by reviewing khng's work D44760. No functional change intended. MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D45227 (cherry picked from commit 356be1348dac94ba0d2dc1f479bc1f8a2ebaa03a) (cherry picked from commit 497f577f460ba93dda38910bf49b390fa610480f) --- sys/arm/arm/identcpu-v6.c | 6 +++--- sys/arm64/arm64/identcpu.c | 2 +- sys/conf/newvers.sh | 14 +++++++------- sys/kern/init_main.c | 24 ++++++++++++------------ sys/kern/kern_mib.c | 16 ++++++++-------- sys/powerpc/powerpc/machdep.c | 5 +++-- sys/riscv/riscv/identcpu.c | 6 +++--- sys/sys/copyright.h | 4 ++-- sys/sys/sysctl.h | 8 ++++---- sys/sys/systm.h | 8 ++++---- sys/x86/x86/identcpu.c | 6 +++--- 11 files changed, 50 insertions(+), 49 deletions(-) diff --git a/sys/arm/arm/identcpu-v6.c b/sys/arm/arm/identcpu-v6.c index 6293a5ccaceb..83e3e255d50e 100644 --- a/sys/arm/arm/identcpu-v6.c +++ b/sys/arm/arm/identcpu-v6.c @@ -50,10 +50,10 @@ #include #include -char machine[] = "arm"; +const char machine[] = "arm"; -SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD | CTLFLAG_CAPRD, - machine, 0, "Machine class"); +SYSCTL_CONST_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD | CTLFLAG_CAPRD, + machine, "Machine class"); static char cpu_model[64]; SYSCTL_STRING(_hw, HW_MODEL, model, CTLFLAG_RD | CTLFLAG_CAPRD, diff --git a/sys/arm64/arm64/identcpu.c b/sys/arm64/arm64/identcpu.c index e913154f9956..8cce4b8be409 100644 --- a/sys/arm64/arm64/identcpu.c +++ b/sys/arm64/arm64/identcpu.c @@ -52,7 +52,7 @@ static void print_cpu_caches(struct sbuf *sb, u_int); static u_long parse_cpu_features_hwcap32(void); #endif -char machine[] = "arm64"; +const char machine[] = "arm64"; #ifdef SCTL_MASK32 extern int adaptive_machine_arch; diff --git a/sys/conf/newvers.sh b/sys/conf/newvers.sh index b4872c14722a..b9f8da60411e 100644 --- a/sys/conf/newvers.sh +++ b/sys/conf/newvers.sh @@ -303,13 +303,13 @@ $COPYRIGHT #define VERSTR "${VERSTR}" #define RELSTR "${RELEASE}" -char sccs[sizeof(SCCSSTR) > 128 ? sizeof(SCCSSTR) : 128] = SCCSSTR; -char version[sizeof(VERSTR) > 256 ? sizeof(VERSTR) : 256] = VERSTR; -char compiler_version[] = "${compiler_v}"; -char ostype[] = "${TYPE}"; -char osrelease[sizeof(RELSTR) > 32 ? sizeof(RELSTR) : 32] = RELSTR; -int osreldate = ${RELDATE}; -char kern_ident[] = "${i}"; +const char sccs[sizeof(SCCSSTR) > 128 ? sizeof(SCCSSTR) : 128] = SCCSSTR; +const char version[sizeof(VERSTR) > 256 ? sizeof(VERSTR) : 256] = VERSTR; +const char compiler_version[] = "${compiler_v}"; +const char ostype[] = "${TYPE}"; +const char osrelease[sizeof(RELSTR) > 32 ? sizeof(RELSTR) : 32] = RELSTR; +const int osreldate = ${RELDATE}; +const char kern_ident[] = "${i}"; EOF ) vers_content_old=$(cat vers.c 2>/dev/null || true) diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index d2c87cf5b777..2c5ba59b92f3 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -362,36 +362,36 @@ print_version(const void *data __unused) printf("%s\n", compiler_version); } -SYSINIT(announce, SI_SUB_COPYRIGHT, SI_ORDER_FIRST, print_caddr_t, +C_SYSINIT(announce, SI_SUB_COPYRIGHT, SI_ORDER_FIRST, print_caddr_t, copyright); -SYSINIT(trademark, SI_SUB_COPYRIGHT, SI_ORDER_SECOND, print_caddr_t, +C_SYSINIT(trademark, SI_SUB_COPYRIGHT, SI_ORDER_SECOND, print_caddr_t, trademark); -SYSINIT(version, SI_SUB_COPYRIGHT, SI_ORDER_THIRD, print_version, NULL); +C_SYSINIT(version, SI_SUB_COPYRIGHT, SI_ORDER_THIRD, print_version, NULL); #ifdef WITNESS -static char wit_warn[] = +static const char wit_warn[] = "WARNING: WITNESS option enabled, expect reduced performance.\n"; -SYSINIT(witwarn, SI_SUB_COPYRIGHT, SI_ORDER_FOURTH, +C_SYSINIT(witwarn, SI_SUB_COPYRIGHT, SI_ORDER_FOURTH, print_caddr_t, wit_warn); -SYSINIT(witwarn2, SI_SUB_LAST, SI_ORDER_FOURTH, +C_SYSINIT(witwarn2, SI_SUB_LAST, SI_ORDER_FOURTH, print_caddr_t, wit_warn); #endif #ifdef DIAGNOSTIC -static char diag_warn[] = +static const char diag_warn[] = "WARNING: DIAGNOSTIC option enabled, expect reduced performance.\n"; -SYSINIT(diagwarn, SI_SUB_COPYRIGHT, SI_ORDER_FIFTH, +C_SYSINIT(diagwarn, SI_SUB_COPYRIGHT, SI_ORDER_FIFTH, print_caddr_t, diag_warn); -SYSINIT(diagwarn2, SI_SUB_LAST, SI_ORDER_FIFTH, +C_SYSINIT(diagwarn2, SI_SUB_LAST, SI_ORDER_FIFTH, print_caddr_t, diag_warn); #endif #if __SIZEOF_LONG__ == 4 -static char ilp32_warn[] = +static const char ilp32_warn[] = "WARNING: 32-bit kernels are deprecated and may be removed in FreeBSD 15.0.\n"; -SYSINIT(ilp32warn, SI_SUB_COPYRIGHT, SI_ORDER_FIFTH, +C_SYSINIT(ilp32warn, SI_SUB_COPYRIGHT, SI_ORDER_FIFTH, print_caddr_t, ilp32_warn); -SYSINIT(ilp32warn2, SI_SUB_LAST, SI_ORDER_FIFTH, +C_SYSINIT(ilp32warn2, SI_SUB_LAST, SI_ORDER_FIFTH, print_caddr_t, ilp32_warn); #endif diff --git a/sys/kern/kern_mib.c b/sys/kern/kern_mib.c index ee3e36c0b5a8..7238df89d833 100644 --- a/sys/kern/kern_mib.c +++ b/sys/kern/kern_mib.c @@ -94,20 +94,20 @@ SYSCTL_ROOT_NODE(OID_AUTO, regression, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, "Regression test MIB"); #endif -SYSCTL_STRING(_kern, OID_AUTO, ident, CTLFLAG_RD, - kern_ident, 0, "Kernel identifier"); +SYSCTL_CONST_STRING(_kern, OID_AUTO, ident, CTLFLAG_RD, + kern_ident, "Kernel identifier"); SYSCTL_INT(_kern, KERN_OSREV, osrevision, CTLFLAG_RD | CTLFLAG_CAPRD, SYSCTL_NULL_INT_PTR, BSD, "Operating system revision"); -SYSCTL_STRING(_kern, KERN_VERSION, version, CTLFLAG_RD, - version, 0, "Kernel version"); +SYSCTL_CONST_STRING(_kern, KERN_VERSION, version, CTLFLAG_RD, + version, "Kernel version"); -SYSCTL_STRING(_kern, OID_AUTO, compiler_version, CTLFLAG_RD, - compiler_version, 0, "Version of compiler used to compile kernel"); +SYSCTL_CONST_STRING(_kern, OID_AUTO, compiler_version, CTLFLAG_RD, + compiler_version, "Version of compiler used to compile kernel"); -SYSCTL_STRING(_kern, KERN_OSTYPE, ostype, CTLFLAG_RD | CTLFLAG_CAPRD, - ostype, 0, "Operating system type"); +SYSCTL_CONST_STRING(_kern, KERN_OSTYPE, ostype, CTLFLAG_RD | CTLFLAG_CAPRD, + ostype, "Operating system type"); SYSCTL_INT(_kern, KERN_MAXPROC, maxproc, CTLFLAG_RDTUN | CTLFLAG_NOFETCH, &maxproc, 0, "Maximum number of processes"); diff --git a/sys/powerpc/powerpc/machdep.c b/sys/powerpc/powerpc/machdep.c index 85d741d11b1a..af57a3c5f641 100644 --- a/sys/powerpc/powerpc/machdep.c +++ b/sys/powerpc/powerpc/machdep.c @@ -148,8 +148,9 @@ static char init_kenv[2048]; static struct trapframe frame0; -char machine[] = "powerpc"; -SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD | CTLFLAG_CAPRD, machine, 0, ""); +const char machine[] = "powerpc"; +SYSCTL_CONST_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD | CTLFLAG_CAPRD, + machine, "Machine class"); static void cpu_startup(void *); SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_startup, NULL); diff --git a/sys/riscv/riscv/identcpu.c b/sys/riscv/riscv/identcpu.c index 39bc0e3b91af..88b0b08c9f2c 100644 --- a/sys/riscv/riscv/identcpu.c +++ b/sys/riscv/riscv/identcpu.c @@ -60,10 +60,10 @@ #include #endif -char machine[] = "riscv"; +const char machine[] = "riscv"; -SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD | CTLFLAG_CAPRD, machine, 0, - "Machine class"); +SYSCTL_CONST_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD | CTLFLAG_CAPRD, + machine, "Machine class"); /* Hardware implementation info. These values may be empty. */ register_t mvendorid; /* The CPU's JEDEC vendor ID */ diff --git a/sys/sys/copyright.h b/sys/sys/copyright.h index 05e2309edd80..2b4a9f67bdf1 100644 --- a/sys/sys/copyright.h +++ b/sys/sys/copyright.h @@ -43,5 +43,5 @@ #define COPYRIGHT_UCB \ "Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994\n\tThe Regents of the University of California. All rights reserved.\n" -char copyright[] = COPYRIGHT_Vendor COPYRIGHT_FreeBSD COPYRIGHT_UCB; -char trademark[] = TRADEMARK_Foundation; +const char copyright[] = COPYRIGHT_Vendor COPYRIGHT_FreeBSD COPYRIGHT_UCB; +const char trademark[] = TRADEMARK_Foundation; diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h index ff87e32df2b7..45ee1a8b1c36 100644 --- a/sys/sys/sysctl.h +++ b/sys/sys/sysctl.h @@ -1135,10 +1135,10 @@ SYSCTL_DECL(_regression); SYSCTL_DECL(_security); SYSCTL_DECL(_security_bsd); -extern char machine[]; -extern char osrelease[]; -extern char ostype[]; -extern char kern_ident[]; +extern const char machine[]; +extern const char osrelease[]; +extern const char ostype[]; +extern const char kern_ident[]; /* Dynamic oid handling */ struct sysctl_oid *sysctl_add_oid(struct sysctl_ctx_list *clist, diff --git a/sys/sys/systm.h b/sys/sys/systm.h index ee432fb0d864..7dbdec0850eb 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -53,9 +53,9 @@ __NULLABILITY_PRAGMA_PUSH extern int cold; /* nonzero if we are doing a cold boot */ extern int suspend_blocked; /* block suspend due to pending shutdown */ extern int rebooting; /* kern_reboot() has been called. */ -extern char version[]; /* system version */ -extern char compiler_version[]; /* compiler version */ -extern char copyright[]; /* system copyright */ +extern const char version[]; /* system version */ +extern const char compiler_version[]; /* compiler version */ +extern const char copyright[]; /* system copyright */ extern int kstack_pages; /* number of kernel stack pages */ extern u_long pagesizes[]; /* supported page sizes */ @@ -113,7 +113,7 @@ struct ucred; }) #define SCHEDULER_STOPPED() SCHEDULER_STOPPED_TD(curthread) -extern int osreldate; +extern const int osreldate; extern const void *zero_region; /* address space maps to a zeroed page */ diff --git a/sys/x86/x86/identcpu.c b/sys/x86/x86/identcpu.c index 450df6807920..248be3730a5a 100644 --- a/sys/x86/x86/identcpu.c +++ b/sys/x86/x86/identcpu.c @@ -120,7 +120,7 @@ u_int cpu_power_eax; /* 06H: Power management leaf, %eax */ u_int cpu_power_ebx; /* 06H: Power management leaf, %ebx */ u_int cpu_power_ecx; /* 06H: Power management leaf, %ecx */ u_int cpu_power_edx; /* 06H: Power management leaf, %edx */ -char machine[] = MACHINE; +const char machine[] = MACHINE; SYSCTL_UINT(_hw, OID_AUTO, via_feature_rng, CTLFLAG_RD, &via_feature_rng, 0, @@ -154,8 +154,8 @@ sysctl_hw_machine(SYSCTL_HANDLER_ARGS) SYSCTL_PROC(_hw, HW_MACHINE, machine, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_CAPRD | CTLFLAG_MPSAFE, NULL, 0, sysctl_hw_machine, "A", "Machine class"); #else -SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD | CTLFLAG_CAPRD, - machine, 0, "Machine class"); +SYSCTL_CONST_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD | CTLFLAG_CAPRD, + machine, "Machine class"); #endif char cpu_model[128];