Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
212 changes: 212 additions & 0 deletions Clang/Reports/Report_0001.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
# Warning Analysis Report

### General

**_Warning Type:_** -Wunused-parameter<br/>
**_Warning Explanation:_**

> In file included from ./include/linux/compiler.h:246:<br/>
./include/linux/kasan-checks.h:9:58: warning: unused parameter 'p' [-Wunused-parameter]<br/>
static inline void kasan_check_read(const volatile void *p, unsigned int size)<br/>
./include/linux/kasan-checks.h:9:74: warning: unused parameter 'size' [-Wunused-parameter]<br/>
static inline void kasan_check_read(const volatile void *p, unsigned int size)<br/>
./include/linux/kasan-checks.h:11:59: warning: unused parameter 'p' [-Wunused-parameter]<br/>
static inline void kasan_check_write(const volatile void *p, unsigned int size)<br/>
./include/linux/kasan-checks.h:11:75: warning: unused parameter 'size' [-Wunused-parameter]<br/>
static inline void kasan_check_write(const volatile void *p, unsigned int size)<br/>

### History

**_Introduced in version:_** v4.7-rc1<br/>
**_Date:_** 2016-05-20<br/>
**_Author:_** Andrey Ryabinin<br/>
**_Patch:_**
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=64f8ebaf115bcddc4aaa902f981c57ba6506bc42

#### Recent Changes

**_Date:_** 2017-06-22<br/>
**_Author:_** Dmitry Vyukov<br/>
**_Patch:_** https://patchwork.kernel.org/patch/9768477/

### Warning Assessment

**_File Location:_** include/linux/kasan-checks.h

```
#ifdef CONFIG_KASAN
void kasan_check_read(const volatile void *p, unsigned int size);
void kasan_check_write(const volatile void *p, unsigned int size);
#else
static inline void kasan_check_read(const volatile void *p, unsigned int size)
{ }
static inline void kasan_check_write(const volatile void *p, unsigned int size)
{ }
#endif
```

### Conclusion

Warning is true but the functions kasan_check_{read, write} were
purposefully made empty. So, ignore this warning.

### Observations

I checked few other warnings of the same type. If the file is located in
include directory, then most of them needs to be ignored due to one of
the following reasons:

1. If some macro is not defined then empty function with parameter is used.<br/>
The function is made purposefully empty as there are non empty functions<br/>
used when the macro is defined.

Example Warnings:

> In file included from ./include/linux/kernel.h:14:<br/>
./include/linux/printk.h:519:53: warning: unused parameter 'prefix_str' [-Wunused-parameter]<br/>
static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type,<br/>
./include/linux/printk.h:519:69: warning: unused parameter 'prefix_type' [-Wunused-parameter]<br/>
static inline void print_hex_dump_debug(const char *prefix_str, int prefix_type,<br/>
./include/linux/printk.h:520:10: warning: unused parameter 'rowsize' [-Wunused-parameter]<br/>
int rowsize, int groupsize,<br/>
./include/linux/printk.h:520:23: warning: unused parameter 'groupsize' [-Wunused-parameter]<br/>
int rowsize, int groupsize,<br/>
./include/linux/printk.h:521:18: warning: unused parameter 'buf' [-Wunused-parameter]<br/>
const void *buf, size_t len, bool ascii)<br/>
./include/linux/printk.h:521:30: warning: unused parameter 'len' [-Wunused-parameter]<br/>
const void *buf, size_t len, bool ascii)<br/>
./include/linux/printk.h:521:40: warning: unused parameter 'ascii' [-Wunused-parameter]<br/>
const void *buf, size_t len, bool ascii)

Patch which introduced the above lines<br/>
https://github.com/torvalds/linux/commit/cdf17449af1d9b596742c260134edd6c1fac2792

> ./include/linux/kernel.h:230:49: warning: unused parameter 'file' [-Wunused-parameter]<br/>
static inline void ___might_sleep(const char *file, int line,<br/>
./include/linux/kernel.h:230:59: warning: unused parameter 'line' [-Wunused-parameter]<br/>
static inline void ___might_sleep(const char *file, int line,<br/>
./include/linux/kernel.h:231:12: warning: unused parameter 'preempt_offset' [-Wunused-parameter]<br/>
int preempt_offset) { }<br/>
./include/linux/kernel.h:232:48: warning: unused parameter 'file' [-Wunused-parameter]<br/>
static inline void __might_sleep(const char *file, int line,<br/>
./include/linux/kernel.h:232:58: warning: unused parameter 'line' [-Wunused-parameter]<br/>
static inline void __might_sleep(const char *file, int line,<br/>
./include/linux/kernel.h:233:12: warning: unused parameter 'preempt_offset' [-Wunused-parameter]<br/>
int preempt_offset) { }<br/>

> In file included from ./arch/x86/include/asm/string_64.h:6:<br/>
./include/linux/jump_label.h:233:50: warning: unused parameter 'start' [-Wunused-parameter]<br/>
static inline int jump_label_text_reserved(void *start, void *end)<br/>
./include/linux/jump_label.h:233:63: warning: unused parameter 'end' [-Wunused-parameter]<br/>
static inline int jump_label_text_reserved(void *start, void *end)<br/>

```
static inline int jump_label_text_reserved(void *start, void *end)
{
return 0;
}
```

> In file included from ./arch/x86/include/asm/string_64.h:6:<br/>
./include/linux/jump_label.h:241:56: warning: unused parameter 'mod' [-Wunused-parameter]<br/>
static inline int jump_label_apply_nops(struct module *mod)

Patches which introduced the above lines<br/>
https://github.com/torvalds/linux/commit/d430d3d7e646eb1eac2bb4aa244a644312e67c76<br/>
https://github.com/torvalds/linux/commit/4c3ef6d79328c0e23ade60cbfc8d496123a6855c

2. Empty functions to annotate something. This too is purposefully added.

Example Warnings:

> In file included from ./include/linux/spinlock_types.h:18:<br/>
./include/linux/lockdep.h:475:49: warning: unused parameter 'force' [-Wunused-parameter]<br/>
static inline void lockdep_invariant_state(bool force) {}<br/>

Patch: https://github.com/torvalds/linux/commit/f52be5708076b75a045ac52c6fef3fffb8300525

> In file included from ./include/linux/spinlock_types.h:18:<br/>
./include/linux/lockdep.h:476:58: warning: unused parameter 'task' [-Wunused-parameter]<br/>
static inline void lockdep_init_task(struct task_struct *task) {}<br/>
>
> In file included from ./include/linux/spinlock_types.h:18:<br/>
./include/linux/lockdep.h:477:58: warning: unused parameter 'task' [-Wunused-parameter]<br/>
static inline void lockdep_free_task(struct task_struct *task) {}<br/>

Patch: https://github.com/torvalds/linux/commit/b09be676e0ff25bd6d2e7637e26d349f9109ad75

> In file included from ./include/linux/spinlock_types.h:18:<br/>
./include/linux/lockdep.h:622:36: warning: unused parameter 'file' [-Wunused-parameter]<br/>
lockdep_rcu_suspicious(const char *file, const int line, const char *s)<br/>
./include/linux/lockdep.h:622:52: warning: unused parameter 'line' [-Wunused-parameter]<br/>
lockdep_rcu_suspicious(const char *file, const int line, const char *s)<br/>
./include/linux/lockdep.h:622:70: warning: unused parameter 's' [-Wunused-parameter]<br/>
lockdep_rcu_suspicious(const char *file, const int line, const char *s)<br/>

Patch: https://github.com/torvalds/linux/commit/d24209bb689e2c7f7418faec9b4a948e922d24da

3. Empty function will be updated in future.

Example Warning:

> In file included from ./arch/x86/include/asm/processor.h:19:<br/>
./arch/x86/include/asm/pgtable_types.h:361:43: warning: unused parameter 'p4d' [-Wunused-parameter]<br/>
static inline p4dval_t p4d_pfn_mask(p4d_t p4d)

References<br/>
https://lwn.net/Articles/708526/<br/>
https://github.com/torvalds/linux/commit/fe1e8c3e9634071ac608172e29bf997596d17c7c<br/>

There can be warnings of which are true and needs to be fixed but I did<br/>
not find any till now.<br/>

Also, there are warnings which are false positive, the parameters are<br/>
used but clang did not understand their usage.<br/>

Example Warning:

> In file included from ./include/linux/compiler.h:246:<br/>
./include/linux/kasan-checks.h:9:58: warning: unused parameter 'p' [-Wunused-parameter]<br/>
static inline void kasan_check_read(const volatile void *p, unsigned int size)<br/>

There is one more category of **legacy code**, the warning in this code needs to be<br/>
ignored.<br/>

Example Warning:
```
In file included from scripts/kconfig/conf.c:19:
scripts/kconfig/lkc.h:158:56: warning: unused parameter 'ch' [-Wunused-parameter]
static inline bool sym_set_choice_value(struct symbol *ch, struct symbol *chval)
^
1 warning generated.
HOSTCC scripts/kconfig/zconf.tab.o
In file included from scripts/kconfig/zconf.tab.c:79:
scripts/kconfig/lkc.h:158:56: warning: unused parameter 'ch' [-Wunused-parameter]
static inline bool sym_set_choice_value(struct symbol *ch, struct symbol *chval)
```

Patch: https://github.com/torvalds/linux/commit/1da177e4c3f41524e886b7f1b8a0c1fc7321cac2

```
In file included from scripts/kconfig/zconf.tab.c:2486:
scripts/kconfig/expr.c:1282:63: warning: unused parameter 'sym' [-Wunused-parameter]
static void expr_print_file_helper(void *data, struct symbol *sym, const char *str)
^

scripts/kconfig/expr.c:1282:static void expr_print_file_helper(void *data, struct symbol *sym, const char *str)
scripts/kconfig/expr.c:1289: expr_print(e, expr_print_file_helper, out, E_NONE);
```

Patch: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ab45d190fd4acf0b0e5d307294ce24a90a69cc23

Another category where knowingly the parameter is not used.

Example Warning:

```
scripts/mod/file2alias.c:909:40: warning: unused parameter 'filename' [-Wunused-parameter]
static int do_virtio_entry(const char *filename, void *symval,
^
```

Patch: https://lists.linuxfoundation.org/pipermail/virtualization/2007-September/008955.html
71 changes: 71 additions & 0 deletions Clang/Reports/Report_0002.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Warning Analysis Report

### General

**Warning Type:** Wparentheses-equality<br/>
**Warning Explanation:**
```
drivers/crypto/cavium/zip/zip_regs.h:820:15: warning: equality comparison with
extraneous parentheses [-Wparentheses-equality]
if (((param1 == 0)))
~~~~~~~^~~~
drivers/crypto/cavium/zip/zip_regs.h:820:15: note: remove extraneous parentheses
around the comparison to silence this warning
if (((param1 == 0)))
~ ^ ~
drivers/crypto/cavium/zip/zip_regs.h:820:15: note: use '=' to turn this equality
comparison into an assignment
if (((param1 == 0)))
```
### History

**Date:** 2017-02-15<br/>
**Version:** v4.12-rc1<br/>
**Author:** Mahipal Challa<br/>
Patch: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=640035a2dc5534b49cd64580e41874b71f131a1c

### Warning Assessment

**File Location:** drivers/crypto/cavium/zip/zip_regs.h
```
static inline u64 ZIP_MSIX_PBAX(u64 param1)
{
if (((param1 == 0)))
return 0x0000838000FF0000ull;
pr_err("ZIP_MSIX_PBAX: %llu\n", param1);
return 0;
}
```
The warning is true. There are few other places in the same file, where
extra parentheses is used. One of them is in ZIP_MSIX_VECX_ADDR
function.
```
static inline u64 ZIP_MSIX_VECX_ADDR(u64 param1)
{
if (((param1 <= 17)))
return 0x0000838000F00000ull + (param1 & 31) * 0x10ull;
pr_err("ZIP_MSIX_VECX_ADDR: %llu\n", param1);
return 0;
}
```
### Solution

Use the following Coccinelle script to remove extra parentheses.
```
@@
identifier i;
constant c;
expression e;
@@
(
!((e))
|
-((
\(i == c\|i != c\|i <= c\|i < c\|i >= c\|i > c\)
-))
)
```
### Accepted Patch
Commit Id: 5b0aa2556<br/>
Link: https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git/commit/?id=5b0aa2556ec9ea98f98e2a802818f75827896d25

62 changes: 62 additions & 0 deletions Clang/Reports/Report_0003.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Warning Analysis Report

### General

**Warning Type:** -Wsometimes-uninitialized

**Warning Explanation:**
```
drivers/gpu/drm/i915/intel_pm.c:4670:6: warning: variable 'trans_min' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
if (INTEL_GEN(dev_priv) >= 10)
^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/i915/i915_drv.h:2535:29: note: expanded from macro 'INTEL_GEN'
#define INTEL_GEN(dev_priv) ((dev_priv)->info.gen)
^
drivers/gpu/drm/i915/intel_pm.c:4673:19: note: uninitialized use occurs here
trans_offset_b = trans_min + trans_amount;
^~~~~~~~~
drivers/gpu/drm/i915/intel_pm.c:4670:2: note: remove the 'if' if its condition is always true
if (INTEL_GEN(dev_priv) >= 10)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/i915/intel_pm.c:4655:20: note: initialize the variable 'trans_min' to silence this warning
uint16_t trans_min, trans_y_tile_min;
^
= 0
```
### History

**Introduced in version:** v4.15-rc1<br/>
**Date:** 2017-08-17<br/>
**Author:** Kumar, Mahesh<br/>
**Patch:** https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ca47667f523e588318f89c735e127c256de6cb16

### Warning Assessment

**File Location:** drivers/gpu/drm/i915/intel_pm.c

The variable trans_min is declared in the function<br/>
skl_compute_transition_wm
```
uint16_t trans_min, trans_y_tile_min;
```
This variable is initialized only if the following condition is true.
```
if (INTEL_GEN(dev_priv) >= 10)
trans_min = 4;
```
The variable is used in two places, one within the if condition and <br/>
other is outside the condition. The trans_offset_b can have garbage <br/>
value if the trans_min is not initialized during declaration. <br/>
```
trans_offset_b = trans_min + trans_amount;
```
### Conclusion

Clang warning is true in this case.<br/>
The variable needs to be initialised to zero.<br/>

### Fixed By

**Author:** Chris Wilson<br/>
**Date:** 2017-11-15<br/>
**Patch:** https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/gpu/drm/i915/intel_pm.c?id=be3fa66857051e2943960a06f8046e8445cdfe6e
Loading