1 // SPDX-License-Identifier: GPL-2.0-only
2 ///Find conditions where if and else branch are functionally
5 // There can be false positives in cases where the positional
6 // information is used (as with lockdep) or where the identity
7 // is a placeholder for not yet handled cases.
8 // Unfortunately there also seems to be a tendency to use
9 // the last if else/else as a "default behavior" - which some
10 // might consider a legitimate coding pattern. From discussion
11 // on kernelnewbies though it seems that this is not really an
12 // accepted pattern and if at all it would need to be commented
14 // In the Linux kernel it does not seem to actually report
15 // false positives except for those that were documented as
17 // the two known cases are:
18 // arch/sh/kernel/traps_64.c:read_opcode()
19 // } else if ((pc & 1) == 0) {
21 // /* TODO : provide handling for this. We don't really support
22 // user-mode SHcompact yet, and for a kernel fault, this would
23 // have to come from a module built for SHcompact. */
29 // fs/kernfs/file.c:kernfs_fop_open()
30 // * Both paths of the branch look the same. They're supposed to
31 // * look that way and give @of->mutex different static lockdep keys.
34 // mutex_init(&of->mutex);
36 // mutex_init(&of->mutex);
38 // All other cases look like bugs or at least lack of documentation
40 // Confidence: Moderate
41 // Copyright: (C) 2016 Nicholas Mc Guire, OSADL.
43 // Options: --no-includes --include-headers
53 * if@p (...) S1 else S1
55 @script:python depends on org@
59 cocci.print_main("WARNING: possible condition with no effect (if == else)",p)
61 @script:python depends on report@
65 coccilib.report.print_report(p[0],"WARNING: possible condition with no effect (if == else)")