remove duplicate ifdefs
Subsystems (5)
Shrikanth Hegde
reviewerv2 cover remove duplicate ifdefs
When going through the code observed a case in scheduler, where #ifdef CONFIG_SMP was used to inside an #ifdef CONFIG_SMP. That didn't make sense since first one is good enough and second one is a duplicate.
This could improve code readability. No functional change is intended.
Since this might be present in other code areas wrote a very basic python script which helps in finding these cases. It doesn't handle any complicated #defines or space separated "# if". At some places the log collected had to be manually corrected due to space separated ifdefs. Thats why its not a treewide change.
There might be an opportunity for other files as well.
Logic is very simple. If there is #ifdef or #if or #ifndef add that variable to list. Upon every subsequent #ifdef or #if or #ifndef check if the same variable is in the list. If yes flag
an error. Verification was done manually later checking for any #undef or any error due to script. These were the ones that flagged out and made sense after going through code.
More details about how the logs were collected and the script used for processing the logs are mentioned in v1 cover letter.
v2->v1:
split the fs change into two patches as suggested by Chandan Babu R.
v1: https://lore.kernel.org/all/[email protected]/
Shrikanth Hegde (4):
sched: remove duplicate ifdefs
xfs: remove duplicate ifdefs
ntfs: remove duplicate ifdefs
arch/powerpc: remove duplicate ifdefs
arch/powerpc/include/asm/paca.h | 4 ---- arch/powerpc/kernel/asm-offsets.c | 2 -- arch/powerpc/platforms/powermac/feature.c | 2 -- arch/powerpc/xmon/xmon.c | 2 -- fs/ntfs/inode.c | 2 -- fs/xfs/xfs_sysfs.c | 4 ---- kernel/sched/core.c | 4 +--- kernel/sched/fair.c | 2 -- 8 files changed, 1 insertion(+), 21 deletions(-)
--
2.39.3
Shrikanth Hegde
reviewerRFC PATCH v2 1/4 sched: remove duplicate ifdefs
when a ifdef is used in the below manner, second one could be considered as duplicate.
ifdef DEFINE_A
...code block...
ifdef DEFINE_A
...code block...
endif
...code block...
endif
In the scheduler code, there are two places where above pattern can be observed. Hence second ifdef is a duplicate and not needed. Plus a minor comment update to reflect the else case.
No functional change is intended here. It only aims to improve code readability.
--- kernel/sched/core.c | 4 +--- kernel/sched/fair.c | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-)
kernel/sched/core.c +1 -3
@@ -1792,7 +1792,6 @@ static void cpu_util_update_eff(struct cgroup_subsys_state *css);#endif #ifdef CONFIG_SYSCTL -#ifdef CONFIG_UCLAMP_TASK #ifdef CONFIG_UCLAMP_TASK_GROUP static void uclamp_update_root_tg(void) {
@@ -1898,7 +1897,6 @@ static int sysctl_sched_uclamp_handler(struct ctl_table *table, int write, return result; }#endif -#endif static int uclamp_validate (struct task_struct *p,const struct sched_attr *attr)
@@ -2065,7 +2063,7 @@ static void __init init_uclamp(void) } } -#else /* CONFIG_UCLAMP_TASK */ +#else /* !CONFIG_UCLAMP_TASK */ static inline void uclamp_rq_inc (struct rq *rq,struct task_struct *p) { }static inline void uclamp_rq_dec (struct rq *rq,struct task_struct *p) { } static inline int uclamp_validate(struct task_struct *p,
kernel/sched/fair.c +0 -2
@@ -10182,10 +10182,8 @@ static int idle_cpu_without(int cpu, struct task_struct *p)* be computed and tested before calling idle_cpu_without(). */ -#ifdef CONFIG_SMP if (rq->ttwu_pending)return 0 ; -#endif return 1 ; }
--
2.39.3
Shrikanth Hegde
reviewerRFC PATCH v2 2/4 xfs: remove duplicate ifdefs
In reply to Shrikanth Hegdewhen a ifdef is used in the below manner, second one could be considered as duplicate.
ifdef DEFINE_A
...code block...
ifdef DEFINE_A
...code block...
endif
...code block...
endif
In the xfs code two such patterns were seen. Hence removing these ifdefs. No functional change is intended here. It only aims to improve code readability.
--- fs/xfs/xfs_sysfs.c | 4 ---- 1 file changed, 4 deletions(-)
fs/xfs/xfs_sysfs.c +0 -4
@@ -193,7 +193,6 @@ always_cow_show( }XFS_SYSFS_ATTR_RW (always_cow); -#ifdef DEBUG /* * Override how many threads the parallel work queue is allowed to create. * This has to be a debug-only global (instead of an errortag) because one of
@@ -260,7 +259,6 @@ larp_show(return snprintf (buf,PAGE_SIZE ,"%d\n" , xfs_globals.larp); }XFS_SYSFS_ATTR_RW (larp); -#endif /* DEBUG */ STATIC ssize_t bload_leaf_slack_store(
@@ -319,10 +317,8 @@ static struct attribute *xfs_dbg_attrs[] = {ATTR_LIST (log_recovery_delay),ATTR_LIST (mount_delay),ATTR_LIST (always_cow), -#ifdef DEBUGATTR_LIST (pwork_threads),ATTR_LIST (larp), -#endifATTR_LIST (bload_leaf_slack),ATTR_LIST (bload_node_slack), NULL,
--
2.39.3
Shrikanth Hegde
reviewerRFC PATCH v2 3/4 ntfs: remove duplicate ifdefs
In reply to Shrikanth Hegdewhen a ifdef is used in the below manner, second one could be considered as duplicate.
ifdef DEFINE_A
...code block...
ifdef DEFINE_A
...code block...
endif
...code block...
endif
In the ntfs code, one such pattern was seen. Hence remove that duplicate ifdef.
No functional change is intended here. It only aims to improve code readability.
--- fs/ntfs/inode.c | 2 -- 1 file changed, 2 deletions(-)
fs/ntfs/inode.c +0 -2
@@ -2859,11 +2859,9 @@ int ntfs_truncate(struct inode *vi)* * See ntfs_truncate() description above for details. */ -#ifdef NTFS_RW void ntfs_truncate_vfs (struct inode *vi) {ntfs_truncate (vi); } -#endif /** * ntfs_setattr - called from notify_change() when an attribute is being changed
--
2.39.3
Shrikanth Hegde
reviewerRFC PATCH v2 4/4 arch/powerpc: remove duplicate ifdefs
In reply to Shrikanth Hegdewhen a ifdef is used in the below manner, second one could be considered as duplicate.
ifdef DEFINE_A
...code block...
ifdef DEFINE_A
...code block...
endif
...code block...
endif
few places in arch/powerpc where this pattern was seen. In addition to that in paca.h, CONFIG_PPC_BOOK3S_64 was defined back to back. merged the two ifdefs.
No functional change is intended here. It only aims to improve code readability.
--- arch/powerpc/include/asm/paca.h | 4 ---- arch/powerpc/kernel/asm-offsets.c | 2 -- arch/powerpc/platforms/powermac/feature.c | 2 -- arch/powerpc/xmon/xmon.c | 2 -- 4 files changed, 10 deletions(-)
arch/powerpc/include/asm/paca.h +0 -4
@@ -163,9 +163,7 @@ struct paca_struct {u64 kstack;/* Saved Kernel stack addr */ u64 saved_r1;/* r1 save for RTAS calls or PM or EE=0 */ u64 saved_msr;/* MSR saved here by enter_rtas */ -#ifdef CONFIG_PPC64 u64 exit_save_r1;/* Syscall/interrupt R1 save */ -#endif #ifdef CONFIG_PPC_BOOK3E_64 u16 trap_save;/* Used when bad stack is encountered */ #endif
@@ -214,8 +212,6 @@ struct paca_struct {/* Non-maskable exceptions that are not performance critical */ u64 exnmi[EX_SIZE ];/* used for system reset (nmi) */ u64 exmc[EX_SIZE ];/* used for machine checks */ -#endif -#ifdef CONFIG_PPC_BOOK3S_64 /* Exclusive stacks for system reset and machine check exception. */ void *nmi_emergency_sp;void *mc_emergency_sp;
arch/powerpc/kernel/asm-offsets.c +0 -2
@@ -246,9 +246,7 @@ int main(void)OFFSET (PACAHWCPUID , paca_struct, hw_cpu_id);OFFSET (PACAKEXECSTATE , paca_struct, kexec_state);OFFSET (PACA_DSCR_DEFAULT , paca_struct, dscr_default); -#ifdef CONFIG_PPC64 OFFSET (PACA_EXIT_SAVE_R1 , paca_struct, exit_save_r1); -#endif #ifdef CONFIG_PPC_BOOK3E_64 OFFSET (PACA_TRAP_SAVE , paca_struct, trap_save);#endif
arch/powerpc/platforms/powermac/feature.c +0 -2
@@ -2333,7 +2333,6 @@ static struct pmac_mb_def pmac_mb_defs[] = {PMAC_TYPE_POWERMAC_G5 , g5_features,0 , }, -#ifdef CONFIG_PPC64 { "PowerMac7,3", "PowerMac G5",PMAC_TYPE_POWERMAC_G5 , g5_features, 0,
@@ -2359,7 +2358,6 @@ static struct pmac_mb_def pmac_mb_defs[] = { 0, },#endif /* CONFIG_PPC64 */ -#endif /* CONFIG_PPC64 */ };/*
arch/powerpc/xmon/xmon.c +0 -2
@@ -643,10 +643,8 @@ static int xmon_core(struct pt_regs *regs, volatile int fromipi)touch_nmi_watchdog (); }else { cmd =1 ; -#ifdef CONFIG_SMP if (xmon_batch) cmd =batch_cmds (regs); -#endif if (!locked_down && cmd) cmd =cmds (regs);if (locked_down || cmd !=0 ) {
--
2.39.3