Messages in this thread Patch in this message | | | From | Nicholas Mc Guire <> | Subject | [PATCH] locking: type cleanup when accessing fast_read_ctr | Date | Mon, 18 May 2015 19:48:02 +0200 |
| |
static code checking with coccinelle was unhappy with: ./kernel/locking/percpu-rwsem.c:113 WARNING: return of wrong type int != unsigned int
current state:
include/linux/percpu-rwsem.h: struct percpu_rw_semaphore { unsigned int __percpu *fast_read_ctr; ... atomic_t slow_read_ctr;
allocated as int:
int __percpu_init_rwsem(struct percpu_rw_semaphore *brw, const char *name, struct lock_class_key *rwsem_key) { brw->fast_read_ctr = alloc_percpu(int);
used compliant with type int in:
static bool update_fast_ctr(struct percpu_rw_semaphore *brw, unsigned int val) usage (2): update_fast_ctr(brw, +1) update_fast_ctr(brw, -1) so val should be int here not unsigned int
static int clear_fast_ctr(struct percpu_rw_semaphore *brw) usage (1): atomic_add(clear_fast_ctr(brw), &brw->slow_read_ctr);
slow_read_ctr is atomic_t which is int so it would be consistent here to have fast_read_ctr being changed to int as well.
This patch changes: fast_read_ctr to int clear_fast_ctr():sum to int update_fast_ctr():val to int to make usage of fast_read_ctr consistent with respect to type.
( Patch was build tested with x86_64_defconfig + CONFIG_UPROBE_EVENT (implies CONFIG_PERCPU_RWSEM=y))
Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org> --- include/linux/percpu-rwsem.h | 2 +- kernel/locking/percpu-rwsem.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/linux/percpu-rwsem.h b/include/linux/percpu-rwsem.h index 3e88c9a..ba37dbe 100644 --- a/include/linux/percpu-rwsem.h +++ b/include/linux/percpu-rwsem.h @@ -8,7 +8,7 @@ #include <linux/lockdep.h> struct percpu_rw_semaphore { - unsigned int __percpu *fast_read_ctr; + int __percpu *fast_read_ctr; atomic_t write_ctr; struct rw_semaphore rw_sem; atomic_t slow_read_ctr; diff --git a/kernel/locking/percpu-rwsem.c b/kernel/locking/percpu-rwsem.c index 652a8ee..002837d 100644 --- a/kernel/locking/percpu-rwsem.c +++ b/kernel/locking/percpu-rwsem.c @@ -52,7 +52,7 @@ void percpu_free_rwsem(struct percpu_rw_semaphore *brw) * reader inside the critical section. See the comments in down_write and * up_write below. */ -static bool update_fast_ctr(struct percpu_rw_semaphore *brw, unsigned int val) +static bool update_fast_ctr(struct percpu_rw_semaphore *brw, int val) { bool success = false; @@ -102,7 +102,7 @@ void percpu_up_read(struct percpu_rw_semaphore *brw) static int clear_fast_ctr(struct percpu_rw_semaphore *brw) { - unsigned int sum = 0; + int sum = 0; int cpu; for_each_possible_cpu(cpu) { -- 1.7.10.4
| |