All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] locking: type cleanup when accessing fast_read_ctr
@ 2015-05-18 17:48 Nicholas Mc Guire
  2015-05-19 11:11 ` Peter Zijlstra
  0 siblings, 1 reply; 9+ messages in thread
From: Nicholas Mc Guire @ 2015-05-18 17:48 UTC (permalink / raw)
  To: Peter Zijlstra; +Cc: Ingo Molnar, linux-kernel, Nicholas Mc Guire

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


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-05-25  5:47 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-18 17:48 [PATCH] locking: type cleanup when accessing fast_read_ctr Nicholas Mc Guire
2015-05-19 11:11 ` Peter Zijlstra
2015-05-19 11:25   ` Nicholas Mc Guire
2015-05-20 17:44     ` Oleg Nesterov
2015-05-23  6:46       ` Nicholas Mc Guire
2015-05-23  9:23       ` Nicholas Mc Guire
2015-05-24 18:18         ` Oleg Nesterov
2015-05-25  5:46           ` Nicholas Mc Guire
2015-05-20 17:42   ` Oleg Nesterov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.