mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tejun Heo <tj@home-tj.org>
To: rusty@rustcorp.com.au, mochel@osdl.org
Cc: linux-kernel@vger.kernel.org
Subject: [RFC/PATCH] Per-device parameter support (3/16)
Date: Sat, 23 Oct 2004 13:25:02 +0900	[thread overview]
Message-ID: <20041023042502.GD3456@home-tj.org> (raw)

 dp_03_module_param_flag.diff

 This is the 3rd patch of 16 patches for devparam.

 This patch implements module_param_flag() and module_param_invflag().
They appear as boolean parameter to the outside, and bitwise OR the
specified flag to flags when the specified boolean value is 1 and 0
respectively.


Signed-off-by: Tejun Heo <tj@home-tj.org>


Index: linux-devparam-export/include/linux/moduleparam.h
===================================================================
--- linux-devparam-export.orig/include/linux/moduleparam.h	2004-10-22 17:13:33.000000000 +0900
+++ linux-devparam-export/include/linux/moduleparam.h	2004-10-23 11:09:28.000000000 +0900
@@ -45,6 +45,12 @@ struct kparam_array
 	void *elem;
 };
 
+/* Special one for flags */
+struct kparam_flag
+{
+	unsigned int *pflags, flag, inv;
+};
+
 /* This is the fundamental function for registering boot/module
    parameters.  perm sets the visibility in driverfs: 000 means it's
    not there, read bits mean it's readable, write bits mean it's
@@ -76,6 +82,20 @@ struct kparam_array
 	module_param_call(name, param_set_copystring, param_get_string,	\
 		   &__param_string_##name, perm)
 
+/* Bit flag */
+#define __module_param_flag(name, flags, flag, inv, perm)		\
+	param_check_uint(name, &(flags));				\
+	static struct kparam_flag __param_flag_##name			\
+	= { &(flags), flag, inv };					\
+	module_param_call(name, param_set_flag, param_get_flag,		\
+			  &__param_flag_##name, perm)
+
+#define module_param_flag(name, flags, flag, perm)			\
+	__module_param_flag(name, flags, flag, 0, perm)
+
+#define module_param_invflag(name, flags, flag, perm)			\
+	__module_param_flag(name, flags, flag, 1, perm)
+
 /* Called on module insert or kernel boot */
 extern int parse_args(const char *name,
 		      char *args,
@@ -146,6 +166,9 @@ extern int param_array_get(char *buffer,
 extern int param_set_copystring(const char *val, struct kernel_param *kp);
 extern int param_get_string(char *buffer, struct kernel_param *kp);
 
+extern int param_set_flag(const char *val, struct kernel_param *kp);
+extern int param_get_flag(char *buffer, struct kernel_param *kp);
+
 int param_array(const char *name,
 		const char *val,
 		unsigned int min, unsigned int max,
Index: linux-devparam-export/kernel/params.c
===================================================================
--- linux-devparam-export.orig/kernel/params.c	2004-10-23 11:09:28.000000000 +0900
+++ linux-devparam-export/kernel/params.c	2004-10-23 11:09:28.000000000 +0900
@@ -347,6 +347,32 @@ int param_get_string(char *buffer, struc
 	return strlcpy(buffer, kps->string, kps->maxlen);
 }
 
+int param_set_flag(const char *val, struct kernel_param *kp)
+{
+	struct kparam_flag *kflag = kp->arg;
+	int boolval, ret;
+	struct kernel_param dummy = { .arg = &boolval };
+
+	ret = param_set_bool(val, &dummy);
+	if (ret == 0) {
+		if (boolval ^ kflag->inv)
+			*kflag->pflags |= kflag->flag;
+		else
+			*kflag->pflags &= ~kflag->flag;
+	}
+	return ret;
+}
+
+int param_get_flag(char *buffer, struct kernel_param *kp)
+{
+	struct kparam_flag *kflag = kp->arg;
+	int val;
+	struct kernel_param dummy = { .arg = &val };
+
+	val = (!!(*kflag->pflags & kflag->flag)) ^ kflag->inv;
+	return param_get_bool(buffer, &dummy);
+}
+
 EXPORT_SYMBOL(param_set_byte);
 EXPORT_SYMBOL(param_get_byte);
 EXPORT_SYMBOL(param_set_short);
@@ -371,3 +397,5 @@ EXPORT_SYMBOL(param_array_set);
 EXPORT_SYMBOL(param_array_get);
 EXPORT_SYMBOL(param_set_copystring);
 EXPORT_SYMBOL(param_get_string);
+EXPORT_SYMBOL(param_set_flag);
+EXPORT_SYMBOL(param_get_flag);

                 reply	other threads:[~2004-10-23  5:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20041023042502.GD3456@home-tj.org \
    --to=tj@home-tj.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mochel@osdl.org \
    --cc=rusty@rustcorp.com.au \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®