* [RFC PATCH 0/3] remove duplicate ifdefs
@ 2024-01-18 8:03 Shrikanth Hegde
2024-01-18 8:03 ` [RFC PATCH 1/3] sched: " Shrikanth Hegde
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Shrikanth Hegde @ 2024-01-18 8:03 UTC (permalink / raw)
To: linux-kernel, linux-ntfs-dev, linux-xfs, linuxppc-dev
Cc: peterz, sshegde, mingo, anton, chandan.babu
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.
Maybe this is not an issue these days as language servers can parse
the config and users can read the code without bothering about
whats true and whats not.
Does this change makes sense?
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.
ifdefs were collected using grep in below way and that file was used as
the input to the script.
grep -rIwn --include="*.c*" --include="*.h" -e "#if" -e "#ifndef" -e "#ifdef" -e "#else" -e "#endif" * > /tmp/input.txt
---------------------------------------------------------------------
script used:
---------------------------------------------------------------------
import os
import argparse
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("--file",
help="file to input to script",
type=str)
parser.add_argument("--verbose",
help="Print additional debugging info, 0 to disable ",
type=int)
args = parser.parse_args()
return args
def parseFiles(args):
file_to_parse = open(args.file, "r")
lines = file_to_parse.readlines()
check_length = len(lines)
ifdefs_list = []
i=0
while i < check_length:
line = lines[i]
last_word = line.strip().split(":")[2]
last_word = last_word.split("/")[0]
if (args.verbose):
print(line)
last_word_splits = last_word.split()
if (args.verbose):
print(last_word_splits)
if last_word_splits[0] == "#ifdef" or last_word_splits[0] == "#ifndef" or last_word_splits[0] == "#if":
if last_word_splits[1] in ifdefs_list:
print("This is duplicate and may be fixed: %s, parent_list:\n" % (line))
print(ifdefs_list)
ifdefs_list.append(last_word_splits[1])
if last_word_splits[0] == "#endif"":
ifdefs_list.pop()
i=i+1
if __name__ == "__main__":
args = parse_args()
parseFiles(args)
-------------------------------------------------------------------------
Shrikanth Hegde (3):
sched: remove duplicate ifdefs
fs: remove depulicate 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* [RFC PATCH 1/3] sched: remove duplicate ifdefs
2024-01-18 8:03 [RFC PATCH 0/3] remove duplicate ifdefs Shrikanth Hegde
@ 2024-01-18 8:03 ` Shrikanth Hegde
2024-01-18 8:03 ` [RFC PATCH 2/3] fs: " Shrikanth Hegde
2024-01-18 8:03 ` [RFC PATCH 3/3] arch/powerpc: " Shrikanth Hegde
2 siblings, 0 replies; 7+ messages in thread
From: Shrikanth Hegde @ 2024-01-18 8:03 UTC (permalink / raw)
To: linux-kernel, linux-ntfs-dev, linux-xfs, linuxppc-dev
Cc: peterz, sshegde, mingo, anton, chandan.babu
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.
Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
---
kernel/sched/core.c | 4 +---
kernel/sched/fair.c | 2 --
2 files changed, 1 insertion(+), 5 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 038eeaf76d2d..1bfb186fd67f 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -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,
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index f2bb83675e4a..6158a6752c25 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -10166,10 +10166,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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [RFC PATCH 2/3] fs: remove duplicate ifdefs
2024-01-18 8:03 [RFC PATCH 0/3] remove duplicate ifdefs Shrikanth Hegde
2024-01-18 8:03 ` [RFC PATCH 1/3] sched: " Shrikanth Hegde
@ 2024-01-18 8:03 ` Shrikanth Hegde
2024-01-19 1:35 ` Darrick J. Wong
2024-01-22 12:50 ` Chandan Babu R
2024-01-18 8:03 ` [RFC PATCH 3/3] arch/powerpc: " Shrikanth Hegde
2 siblings, 2 replies; 7+ messages in thread
From: Shrikanth Hegde @ 2024-01-18 8:03 UTC (permalink / raw)
To: linux-kernel, linux-ntfs-dev, linux-xfs, linuxppc-dev
Cc: peterz, sshegde, mingo, anton, chandan.babu
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
There are few places in fs code where above pattern was seen.
No functional change is intended here. It only aims to improve code
readability.
Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
---
fs/ntfs/inode.c | 2 --
fs/xfs/xfs_sysfs.c | 4 ----
2 files changed, 6 deletions(-)
diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c
index aba1e22db4e9..d2c8622d53d1 100644
--- a/fs/ntfs/inode.c
+++ b/fs/ntfs/inode.c
@@ -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
diff --git a/fs/xfs/xfs_sysfs.c b/fs/xfs/xfs_sysfs.c
index 17485666b672..d2391eec37fe 100644
--- a/fs/xfs/xfs_sysfs.c
+++ b/fs/xfs/xfs_sysfs.c
@@ -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 DEBUG
ATTR_LIST(pwork_threads),
ATTR_LIST(larp),
-#endif
ATTR_LIST(bload_leaf_slack),
ATTR_LIST(bload_node_slack),
NULL,
--
2.39.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [RFC PATCH 3/3] arch/powerpc: remove duplicate ifdefs
2024-01-18 8:03 [RFC PATCH 0/3] remove duplicate ifdefs Shrikanth Hegde
2024-01-18 8:03 ` [RFC PATCH 1/3] sched: " Shrikanth Hegde
2024-01-18 8:03 ` [RFC PATCH 2/3] fs: " Shrikanth Hegde
@ 2024-01-18 8:03 ` Shrikanth Hegde
2 siblings, 0 replies; 7+ messages in thread
From: Shrikanth Hegde @ 2024-01-18 8:03 UTC (permalink / raw)
To: linux-kernel, linux-ntfs-dev, linux-xfs, linuxppc-dev
Cc: peterz, sshegde, mingo, anton, chandan.babu
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
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.
Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
---
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(-)
diff --git a/arch/powerpc/include/asm/paca.h b/arch/powerpc/include/asm/paca.h
index e667d455ecb4..1d58da946739 100644
--- a/arch/powerpc/include/asm/paca.h
+++ b/arch/powerpc/include/asm/paca.h
@@ -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;
diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c
index 9f14d95b8b32..f029755f9e69 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -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
diff --git a/arch/powerpc/platforms/powermac/feature.c b/arch/powerpc/platforms/powermac/feature.c
index 81c9fbae88b1..2cc257f75c50 100644
--- a/arch/powerpc/platforms/powermac/feature.c
+++ b/arch/powerpc/platforms/powermac/feature.c
@@ -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 */
};
/*
diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index b3b94cd37713..f413c220165c 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [RFC PATCH 2/3] fs: remove duplicate ifdefs
2024-01-18 8:03 ` [RFC PATCH 2/3] fs: " Shrikanth Hegde
@ 2024-01-19 1:35 ` Darrick J. Wong
2024-01-22 12:50 ` Chandan Babu R
1 sibling, 0 replies; 7+ messages in thread
From: Darrick J. Wong @ 2024-01-19 1:35 UTC (permalink / raw)
To: Shrikanth Hegde
Cc: linux-ntfs-dev, linux-kernel, linux-xfs, peterz, linuxppc-dev,
mingo, anton, chandan.babu
On Thu, Jan 18, 2024 at 01:33:25PM +0530, Shrikanth Hegde wrote:
> 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
>
> There are few places in fs code where above pattern was seen.
> No functional change is intended here. It only aims to improve code
> readability.
>
> Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
> ---
> fs/ntfs/inode.c | 2 --
> fs/xfs/xfs_sysfs.c | 4 ----
> 2 files changed, 6 deletions(-)
>
> diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c
> index aba1e22db4e9..d2c8622d53d1 100644
> --- a/fs/ntfs/inode.c
> +++ b/fs/ntfs/inode.c
> @@ -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
> diff --git a/fs/xfs/xfs_sysfs.c b/fs/xfs/xfs_sysfs.c
> index 17485666b672..d2391eec37fe 100644
> --- a/fs/xfs/xfs_sysfs.c
> +++ b/fs/xfs/xfs_sysfs.c
> @@ -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 DEBUG
> ATTR_LIST(pwork_threads),
> ATTR_LIST(larp),
> -#endif
The xfs part seems fine to me bcause I think some bot already
complained about this...
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
--D
> ATTR_LIST(bload_leaf_slack),
> ATTR_LIST(bload_node_slack),
> NULL,
> --
> 2.39.3
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC PATCH 2/3] fs: remove duplicate ifdefs
2024-01-18 8:03 ` [RFC PATCH 2/3] fs: " Shrikanth Hegde
2024-01-19 1:35 ` Darrick J. Wong
@ 2024-01-22 12:50 ` Chandan Babu R
2024-01-22 14:37 ` Shrikanth Hegde
1 sibling, 1 reply; 7+ messages in thread
From: Chandan Babu R @ 2024-01-22 12:50 UTC (permalink / raw)
To: Shrikanth Hegde
Cc: linux-ntfs-dev, linux-kernel, linux-xfs, peterz, linuxppc-dev,
mingo, anton
On Thu, Jan 18, 2024 at 01:33:25 PM +0530, Shrikanth Hegde wrote:
> 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
>
> There are few places in fs code where above pattern was seen.
> No functional change is intended here. It only aims to improve code
> readability.
>
Can you please post the xfs changes as a separate patch along with Darrick's
RVB tag? This will make it easy for me to apply the resulting patch to the XFS
tree.
--
Chandan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC PATCH 2/3] fs: remove duplicate ifdefs
2024-01-22 12:50 ` Chandan Babu R
@ 2024-01-22 14:37 ` Shrikanth Hegde
0 siblings, 0 replies; 7+ messages in thread
From: Shrikanth Hegde @ 2024-01-22 14:37 UTC (permalink / raw)
To: Chandan Babu R
Cc: linux-ntfs-dev, linux-kernel, linux-xfs, peterz, linuxppc-dev,
mingo, anton
On 1/22/24 6:20 PM, Chandan Babu R wrote:
> On Thu, Jan 18, 2024 at 01:33:25 PM +0530, Shrikanth Hegde wrote:
>> 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
>>
>> There are few places in fs code where above pattern was seen.
>> No functional change is intended here. It only aims to improve code
>> readability.
>>
>
> Can you please post the xfs changes as a separate patch along with Darrick's
> RVB tag? This will make it easy for me to apply the resulting patch to the XFS
> tree.
Ok. will split the fs patches into two and send v2 soon.
Thanks.
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-01-22 21:04 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-18 8:03 [RFC PATCH 0/3] remove duplicate ifdefs Shrikanth Hegde
2024-01-18 8:03 ` [RFC PATCH 1/3] sched: " Shrikanth Hegde
2024-01-18 8:03 ` [RFC PATCH 2/3] fs: " Shrikanth Hegde
2024-01-19 1:35 ` Darrick J. Wong
2024-01-22 12:50 ` Chandan Babu R
2024-01-22 14:37 ` Shrikanth Hegde
2024-01-18 8:03 ` [RFC PATCH 3/3] arch/powerpc: " Shrikanth Hegde
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).