Skip to contentSkip to conversation

arch/powerpc: Remove duplicate ifdefs

PATCH Applied Shrikanth Hegde 2 participants 2 messages Feb 16, 2024 – Feb 21, 2024

Subsystems (2)
lore
Share & tools
lore

Shrikanth Hegde

author reviewer
#0 lore raw

PATCH 1/1 arch/powerpc: 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 <-- This is a duplicate.
...code block...
endif
else
ifndef DEFINE_A <-- This is also duplicate.
...code block...
endif
endif
More details about the script and methods used to find these code patterns are in cover letter of [1]

Few places in arch/powerpc where this pattern was seen.
Hunk1: Code is under check of CONFIG_PPC64 from line 13 in arch/powerpc/include/asm/paca.h. Hence the second CONFIG_PPC64 at line 166 is a duplicate.
Hunk2: CONFIG_PPC_BOOK3S_64 was defined back to back. Merged the two ifdefs.
Hunk3: Code is under check of CONFIG_PPC64 from line 176 in arch/powerpc/kernel/asm-offsets.c. Hence second CONFIG_PPC64 at line 249 is a duplicate.
Hunk4: #ifndef CONFIG_PPC64 is used at line 2066 in arch/powerpc/platforms/powermac/feature.c. And then in #else again #ifdef CONFIG_PPC64 is used. Which is a duplicate since in #else means CONFIG_PPC64 is defined.
Hunk5: Code is under the check of CONFIG_SMP from line 521 in arch/powerpc/xmon/xmon.c. Hence the same check of CONFIG_SMP at line 646 is a duplicate.

No functional change is intended here. It only aims to improve code readability.
[1] https://lore.kernel.org/all/[email protected]/

---
Changes from v2:
- Converted from series to individual patches.
- Dropped RFC tag.
- Added more context on each hunk for review.

 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
index e667d455ecb4..1d58da946739 100644
@@ -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
index 9f14d95b8b32..f029755f9e69 100644
@@ -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
index 81c9fbae88b1..2cc257f75c50 100644
@@ -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
index b3b94cd37713..f413c220165c 100644
@@ -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

#1 lore raw
Quoted 16 lines · Shrikanth Hegde

When a ifdef is used in the below manner, second one could be considered as duplicate.

ifdef DEFINE_A
...code block...
ifdef DEFINE_A <-- This is a duplicate.
...code block...
endif
else
ifndef DEFINE_A <-- This is also duplicate.
...code block...
endif
endif
More details about the script and methods used to find these code patterns are in cover letter of [1]

Quoted 1 line

[...]

Applied to powerpc/next.

[1/1] arch/powerpc: Remove duplicate ifdefs

      https://git.kernel.org/powerpc/c/8c328de8fd5046eb3ec5a7ff7b682a8175e986c3

cheers