LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Rusty Russell <rusty@rustcorp.com.au>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 2/5] typesafe: Convert stop_machine
Date: Mon, 4 Feb 2008 23:16:02 +1100	[thread overview]
Message-ID: <200802042316.02963.rusty@rustcorp.com.au> (raw)
In-Reply-To: <200802042314.18738.rusty@rustcorp.com.au>

Using cast_if_type() we can have a callback funciton either of the
exactly correct type to take "data", or to take a void *.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

diff -r e279190b7b43 include/linux/stop_machine.h
--- a/include/linux/stop_machine.h	Mon Jan 21 14:42:54 2008 +1100
+++ b/include/linux/stop_machine.h	Mon Jan 21 15:04:00 2008 +1100
@@ -5,9 +5,9 @@
    (and more).  So the "read" side to such a lock is anything which
    diables preeempt. */
 #include <linux/cpu.h>
+#include <linux/compiler.h>
 #include <asm/system.h>
 
-#if defined(CONFIG_STOP_MACHINE) && defined(CONFIG_SMP)
 /**
  * stop_machine_run: freeze the machine on all CPUs and run this function
  * @fn: the function to run
@@ -21,7 +21,12 @@
  *
  * This can be thought of as a very heavy write lock, equivalent to
  * grabbing every spinlock in the kernel. */
-int stop_machine_run(int (*fn)(void *), void *data, unsigned int cpu);
+#define stop_machine_run(fn, data, cpu)					\
+	stop_machine_run_notype(cast_if_type((fn), int(*)(typeof(data)), \
+					     int(*)(void *)), (data), (cpu))
+
+#if defined(CONFIG_STOP_MACHINE) && defined(CONFIG_SMP)
+int stop_machine_run_notype(int (*fn)(void *), void *data, unsigned int cpu);
 
 /**
  * __stop_machine_run: freeze the machine on all CPUs and run this function
@@ -38,8 +46,8 @@ struct task_struct *__stop_machine_run(i
 
 #else
 
-static inline int stop_machine_run(int (*fn)(void *), void *data,
-				   unsigned int cpu)
+static inline int stop_machine_run_notype(int (*fn)(void *), void *data,
+					  unsigned int cpu)
 {
 	int ret;
 	local_irq_disable();
diff -r e279190b7b43 kernel/stop_machine.c
--- a/kernel/stop_machine.c	Mon Jan 21 14:42:54 2008 +1100
+++ b/kernel/stop_machine.c	Mon Jan 21 15:04:00 2008 +1100
@@ -197,7 +197,7 @@ struct task_struct *__stop_machine_run(i
 	return p;
 }
 
-int stop_machine_run(int (*fn)(void *), void *data, unsigned int cpu)
+int stop_machine_run_notype(int (*fn)(void *), void *data, unsigned int cpu)
 {
 	struct task_struct *p;
 	int ret;

  reply	other threads:[~2008-02-04 12:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-04 12:11 [PATCH 0/5] typesafe callbacks Rusty Russell
2008-02-04 12:14 ` [PATCH 1/5] cast_if_type: allow macros functions which take more than one type Rusty Russell
2008-02-04 12:16   ` Rusty Russell [this message]
2008-02-04 12:17     ` [PATCH 3/5] typesafe: kthread_create and kthread_run Rusty Russell
2008-02-04 12:18       ` [PATCH 4/5] typesafe: request_irq and devm_request_irq Rusty Russell
2008-02-04 12:19         ` [PATCH 5/5] typesafe: TIMER_INITIALIZER and setup_timer Rusty Russell
2008-02-04 14:57           ` Al Viro
2008-02-05  3:41             ` Rusty Russell
2008-03-05  2:55               ` Rusty Russell
2008-03-06 10:40                 ` Al Viro
2008-03-10  1:07                   ` Rusty Russell
2008-03-10  2:03                     ` Al Viro
2008-03-10  3:42                       ` Rusty Russell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200802042316.02963.rusty@rustcorp.com.au \
    --to=rusty@rustcorp.com.au \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --subject='Re: [PATCH 2/5] typesafe: Convert stop_machine' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).