| 1 |
// RUN: %check_clang_tidy %s linuxkernel-must-check-errs %t |
| 2 |
|
| 3 |
#define __must_check __attribute__((warn_unused_result)) |
| 4 |
|
| 5 |
// Prototypes of the error functions. |
| 6 |
void * __must_check ERR_PTR(long error); |
| 7 |
long __must_check PTR_ERR(const void *ptr); |
| 8 |
int __must_check IS_ERR(const void *ptr); |
| 9 |
int __must_check IS_ERR_OR_NULL(const void *ptr); |
| 10 |
void * __must_check ERR_CAST(const void *ptr); |
| 11 |
int __must_check PTR_ERR_OR_ZERO(const void *ptr); |
| 12 |
|
| 13 |
void f(void) { |
| 14 |
ERR_PTR(0); |
| 15 |
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: result from function 'ERR_PTR' is unused |
| 16 |
PTR_ERR((void *)0); |
| 17 |
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: result from function 'PTR_ERR' is unused |
| 18 |
IS_ERR((void *)0); |
| 19 |
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: result from function 'IS_ERR' is unused |
| 20 |
ERR_CAST((void *)0); |
| 21 |
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: result from function 'ERR_CAST' is unused |
| 22 |
out: |
| 23 |
PTR_ERR_OR_ZERO((void *)0); |
| 24 |
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: result from function 'PTR_ERR_OR_ZERO' is unused |
| 25 |
} |
| 26 |
|
| 27 |
void *f1(void) { |
| 28 |
return ERR_PTR(0); |
| 29 |
} |
| 30 |
|
| 31 |
long f2(void) { |
| 32 |
if (IS_ERR((void *)0)) { |
| 33 |
return PTR_ERR((void *)0); |
| 34 |
} |
| 35 |
return -1; |
| 36 |
} |
| 37 |
|
| 38 |
void f3(void) { |
| 39 |
f1(); |
| 40 |
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: result from function 'f1' is unused but represents an error value |
| 41 |
f2(); |
| 42 |
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: result from function 'f2' is unused but represents an error value |
| 43 |
} |