LKML Archive on lore.kernel.org
 help / color / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
						download: 
* Re: [PATCH BUGFIX -rc3] Smack: Don't register smackfs if we're not loaded
  @ 2008-03-04 18:24 92%   ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2008-03-04 18:24 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Casey Schaufler, LKML, Stephen Smalley, James Morris, Eric Paris

Hi Linus,

[Adding SELinux devs to CC list, please follow to the SELinux point.]

On Tue, Mar 04, 2008 at 09:21:19AM -0800, Linus Torvalds wrote:
> 
> 
> On Tue, 4 Mar 2008, Ahmed S. Darwish wrote:
> > 
> > Smackfs initialization without an enabled Smack leads to
> > an early Oops that renders the system unusable.
> 
> I really think this is bogus. Global enables like this are just wrong, and 
> a sign that something else bad is going on.
> 
> What is the oops? Why does it happen?
> 

The problem occurs when Smack is built-in the kernel but not chosen
to register itself on boot. Smack was not chosen on boot cause either
security=AnotherLSM or security=NonExistentLSM.

In all cases, init_smk_fs() ,which registers smackfs, got called
cause it's an __initcall(init_smack_fs). 
This include the cases where smack __was not__ chosen on boot.

Making smackfs mountable when Smack is not registered leads to:

1- an Oops by dereferncing the NULL security pointer: current->security (*)

2- Smackfs code got executed though naturally all the code assumes
   that smack is already registered with the security system leading
   to several problems.

3- The bogus idea of having a subsystem interface available when the
   subsystem itself is not available!

So the global is used in init_smk_fs to not register smackfs if
Smack wasn't enabled on boot.

---- SELinux:

I think the SELinux folks faced the same problem too. In my first 
local iteration of the security= parameter patch, I forgot to set 
`selinux_disable = 1' if SELinux wasn't chosen on boot.

This led to dozen of SELinux Udev events and also led to selinuxfs 
being available even though SELinux hooks _weren't_ registered.

Regards,

(*) 
    Could not save the oops cause it occured too early, but
    it was like this:

    __init_call
    init_smk_fs(void)
    smk_unlbl_ambient(NULL)
    /* 
     * Here: current->security = NULL, cause SMACK initial setup
     * was not executed.
     */
    smack_to_secid(current->security) 
    strncmp(.., current->security, ..) 
    
-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 92%]

* Re: [BUG + PATCH/Bugfix] x86/lguest: fix pgdir pmd index calculation
  @ 2008-03-04 15:11 99%   ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2008-03-04 15:11 UTC (permalink / raw)
  To: Rusty Russell
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, LKML, lguest, akpm

On Tue, Mar 04, 2008 at 11:55:10PM +1100, Rusty Russell wrote:
> On Monday 25 February 2008 02:55:15 Ahmed S. Darwish wrote:
> > Hi all,
> >
> > Beginning from commits close to v2.6.25-rc2, running lguest always oopses
> > the host kernel. Oops is at [1].
> 
> OK, whatever the guest does should not break the host.  So your patch can't be
> the whole solution.
> 
> > static void lguest_set_pmd(pmd_t *pmdp, pmd_t pmdval)
> > {
> > 	*pmdp = pmdval;
> > 	lazy_hcall(LHCALL_SET_PMD, __pa(pmdp)&PAGE_MASK,
> > 		   (__pa(pmdp)&(PAGE_SIZE-1))/4, 0);
> > }
> >
> > The first hcall parameter is global pgdir which looks fine. The second
> > parameter is the pmd index in the pgdir which is suspectful.
> >
> > AFAIK, calculating the index of pmd does not need a divisoin over four.
> > Removing the division made lguest work fine again . Patch is at [2].
> 
> Each pmd is 4 bytes long, so the divide by 4 gives the index into the (top
> level) page. ie. a number in the range 0 to 1023.
> 

aha, now it's clear. 

>
> Indeed, here's the correct fix.  Does it work for you?
> 

Yes it does (after removing the unrelated TSC-if-pentium+ checks). 

Thank you

-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 99%]

* [PATCH -rc3] Security: Introduce security= boot parameter
  2008-03-04 13:10 91% [PATCH BUGFIX -rc3] Smack: Don't register smackfs if we're not loaded Ahmed S. Darwish
@ 2008-03-04 13:58 69% ` Ahmed S. Darwish
    1 sibling, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2008-03-04 13:58 UTC (permalink / raw)
  To: Chris Wright, Stephen Smalley, James Morris, Eric Paris,
	Casey Schaufler, Paul Moore, Alexey Dobriyan, Andrew Morton,
	Linus
  Cc: LKML, LSM-ML

Hi all,

[
    Sending as a reply to the above Smack bugfix cause the bug 
    is triggered by this patch.

    Please merge the bugfix before this.

    IMHO this patch (or similar) is needed before the release
    to avoid useless panics. Also as noted by Alexey, current
    allyesconfig kernels panics cause of the same problem which
    means less testing before hitting 2.6.25 .

    Thanks!
]

-->

Add the security= boot parameter. This is done to avoid LSM 
registration clashes in case of more than one bult-in module.

User can choose a security module to enable at boot. If no 
security= boot parameter is specified, only the first LSM 
asking for registration will be loaded. An invalid security 
module name will be treated as if no module has been chosen.

LSM modules must check now if they are allowed to register
by calling security_module_enable(ops) first. Modify SELinux 
and SMACK to do so.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
Acked-by: James Morris <jmorris@namei.org>
Reported-by: Alexey Dobriyan <adobriyan@sw.ru>
---

[James ACKed the -mm version, but this patch is exactly the same]

 Documentation/kernel-parameters.txt |    6 ++++
 include/linux/security.h            |   12 +++++++++
 security/dummy.c                    |    2 -
 security/security.c                 |   46 +++++++++++++++++++++++++++++++++++-
 security/selinux/hooks.c            |    7 +++++
 security/smack/smack_lsm.c          |    5 +++
 6 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 9a5b665..64efbdc 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -374,6 +374,12 @@ and is between 256 and 4096 characters. It is defined in the file
 			possible to determine what the correct size should be.
 			This option provides an override for these situations.
 
+	security=	[SECURITY] Choose a security module to enable at boot. 
+			If this boot parameter is not specified, only the first 
+			security module asking for security registration will be
+			loaded. An invalid security module name will be treated
+			as if no module has been chosen.
+
 	capability.disable=
 			[SECURITY] Disable capabilities.  This would normally
 			be used only if an alternative security model is to be
diff --git a/include/linux/security.h b/include/linux/security.h
index fe52cde..801c9ad 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -42,6 +42,9 @@
 
 extern unsigned securebits;
 
+/* Maximum number of letters for an LSM name string */
+#define SECURITY_NAME_MAX	10
+
 struct ctl_table;
 
 /*
@@ -117,6 +120,12 @@ struct request_sock;
 /**
  * struct security_operations - main security structure
  *
+ * Security module identifier.
+ *
+ * @name:
+ *	A string that acts as a unique identifeir for the LSM with max number
+ *	of characters = SECURITY_NAME_MAX.
+ *
  * Security hooks for program execution operations.
  *
  * @bprm_alloc_security:
@@ -1207,6 +1216,8 @@ struct request_sock;
  * This is the main security structure.
  */
 struct security_operations {
+	char name[SECURITY_NAME_MAX + 1];
+
 	int (*ptrace) (struct task_struct * parent, struct task_struct * child);
 	int (*capget) (struct task_struct * target,
 		       kernel_cap_t * effective,
@@ -1466,6 +1477,7 @@ struct security_operations {
 
 /* prototypes */
 extern int security_init	(void);
+extern int security_module_enable(struct security_operations *ops);
 extern int register_security	(struct security_operations *ops);
 extern int mod_reg_security	(const char *name, struct security_operations *ops);
 extern struct dentry *securityfs_create_file(const char *name, mode_t mode,
diff --git a/security/dummy.c b/security/dummy.c
index 649326b..96d196f 100644
--- a/security/dummy.c
+++ b/security/dummy.c
@@ -979,7 +979,7 @@ static inline int dummy_key_permission(key_ref_t key_ref,
 }
 #endif /* CONFIG_KEYS */
 
-struct security_operations dummy_security_ops;
+struct security_operations dummy_security_ops = { "dummy" };
 
 #define set_to_dummy_if_null(ops, function)				\
 	do {								\
diff --git a/security/security.c b/security/security.c
index d15e56c..f188672 100644
--- a/security/security.c
+++ b/security/security.c
@@ -17,6 +17,9 @@
 #include <linux/kernel.h>
 #include <linux/security.h>
 
+/* Boot-time LSM user choice */
+static spinlock_t chosen_lsm_lock;
+static char chosen_lsm[SECURITY_NAME_MAX + 1];
 
 /* things that live in dummy.c */
 extern struct security_operations dummy_security_ops;
@@ -62,18 +65,59 @@ int __init security_init(void)
 	}
 
 	security_ops = &dummy_security_ops;
+	spin_lock_init(&chosen_lsm_lock);
 	do_security_initcalls();
 
 	return 0;
 }
 
+/* Save user chosen LSM */
+static int __init choose_lsm(char *str)
+{
+	strncpy(chosen_lsm, str, SECURITY_NAME_MAX);
+	return 1;
+}
+__setup("security=", choose_lsm);
+
+/**
+ * security_module_enable - Load given security module on boot ?
+ * @ops: a pointer to the struct security_operations that is to be checked.
+ *
+ * Each LSM must pass this method before registering its own operations
+ * to avoid security registration races.
+ *
+ * Return true if:
+ *	-The passed LSM is the one chosen by user at boot time,
+ *	-or user didsn't specify a specific LSM and we're the first to ask
+ *	 for registeration permissoin.
+ * Otherwise, return false.
+ */
+int security_module_enable(struct security_operations *ops)
+{
+	int rc = 1;
+
+	spin_lock(&chosen_lsm_lock);
+	if (!*chosen_lsm)
+		strncpy(chosen_lsm, ops->name, SECURITY_NAME_MAX);
+	else if (strncmp(ops->name, chosen_lsm, SECURITY_NAME_MAX))
+		rc = 0;
+	spin_unlock(&chosen_lsm_lock);
+
+	if (rc)
+		printk(KERN_INFO "Security: Loading '%s' security module.\n",
+		       ops->name);
+
+	return rc;
+}
+
 /**
  * register_security - registers a security framework with the kernel
  * @ops: a pointer to the struct security_options that is to be registered
  *
  * This function is to allow a security module to register itself with the
  * kernel security subsystem.  Some rudimentary checking is done on the @ops
- * value passed to this function.
+ * value passed to this function. You'll need to check first if your LSM
+ * is allowed to register its @ops by calling security_module_enable(@ops).
  *
  * If there is already a security module registered with the kernel,
  * an error will be returned.  Otherwise 0 is returned on success.
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 75c2e99..49709a4 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -5219,6 +5219,8 @@ static int selinux_key_permission(key_ref_t key_ref,
 #endif
 
 static struct security_operations selinux_ops = {
+	.name =				"selinux",
+
 	.ptrace =			selinux_ptrace,
 	.capget =			selinux_capget,
 	.capset_check =			selinux_capset_check,
@@ -5405,6 +5407,11 @@ static __init int selinux_init(void)
 {
 	struct task_security_struct *tsec;
 
+	if (!security_module_enable(&selinux_ops)) {
+		selinux_enabled = 0;
+		return 0;
+	}
+
 	if (!selinux_enabled) {
 		printk(KERN_INFO "SELinux:  Disabled at boot.\n");
 		return 0;
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 6fe7869..ecf1d16 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -2436,6 +2436,8 @@ static void smack_release_secctx(char *secdata, u32 seclen)
 }
 
 static struct security_operations smack_ops = {
+	.name =				"smack",
+
 	.ptrace = 			smack_ptrace,
 	.capget = 			cap_capget,
 	.capset_check = 		cap_capset_check,
@@ -2568,6 +2570,9 @@ static struct security_operations smack_ops = {
  */
 static __init int smack_init(void)
 {
+	if (!security_module_enable(&smack_ops))
+		return 0;
+
 	printk(KERN_INFO "Smack:  Initializing.\n");
 
 	/*


If you read till here, Thank you for the review ;)
Regards,

-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 69%]

* [PATCH BUGFIX -rc3] Smack: Don't register smackfs if we're not loaded
@ 2008-03-04 13:10 91% Ahmed S. Darwish
  2008-03-04 13:58 69% ` [PATCH -rc3] Security: Introduce security= boot parameter Ahmed S. Darwish
    0 siblings, 2 replies; 200+ results
From: Ahmed S. Darwish @ 2008-03-04 13:10 UTC (permalink / raw)
  To: Casey Schaufler; +Cc: LKML, Linus

Hi all,

Smackfs initialization without an enabled Smack leads to
an early Oops that renders the system unusable.

Introduce a global smack_enabled variable that will be used
to make sure that no smack components will be registered 
(ala smackfs) if we are not already enabled.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

The Oops is triggered by the security= patch that will be sent
soon.

I can't imagine an SELinux guru finding /smackfs instead of 
his usual /selinuxfs when he hits a tab completion after 's' ;).
As a bonus, this patch will handle that case too.

 smack.h     |    9 +++++++++
 smack_lsm.c |    8 ++++++++
 smackfs.c   |    3 +++

 3 files changed, 20 insertions(+)

diff --git a/security/smack/smack.h b/security/smack/smack.h
index a21a0e9..17c55ad 100644
--- a/security/smack/smack.h
+++ b/security/smack/smack.h
@@ -18,6 +18,15 @@
 #include <net/netlabel.h>
 
 /*
+ * We must not bother the rest of the kernel by exporting our
+ * own stuff if we are not already enabled. We may not be loaded
+ * if another or no LSM was chosen on boot.
+ * Smackfs is currently the only exported component, but this
+ * may change in the future.
+ */
+extern int smack_enabled;
+
+/*
  * Why 23? CIPSO is constrained to 30, so a 32 byte buffer is
  * bigger than can be used, and 24 is the next lower multiple
  * of 8, and there are too many issues if there isn't space set
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 770eb06..6fe7869 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -36,6 +36,8 @@
 #define SOCKFS_MAGIC		0x534F434B
 #define TMPFS_MAGIC		0x01021994
 
+int smack_enabled;
+
 /**
  * smk_fetch - Fetch the smack label from a file.
  * @ip: a pointer to the inode
@@ -2589,6 +2591,12 @@ static __init int smack_init(void)
 	if (register_security(&smack_ops))
 		panic("smack: Unable to register with kernel.\n");
 
+	/*
+	 * Notify other Smack components that it's now safe to
+	 * to register themselves.
+	 */
+	smack_enabled = 1;
+
 	return 0;
 }
 
diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c
index 358c92c..e1687c0 100644
--- a/security/smack/smackfs.c
+++ b/security/smack/smackfs.c
@@ -992,6 +992,9 @@ static int __init init_smk_fs(void)
 {
 	int err;
 
+	if (!smack_enabled)
+		return 0;
+
 	err = register_filesystem(&smk_fs_type);
 	if (!err) {
 		smackfs_mount = kern_mount(&smk_fs_type);

-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 91%]

* Re: [PATCH 7/9] Audit: internally use the new LSM audit hooks
  @ 2008-03-04  3:31 99%     ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2008-03-04  3:31 UTC (permalink / raw)
  To: Paul Moore
  Cc: Chris Wright, Stephen Smalley, James Morris, Eric Paris,
	Casey Schaufler, David Woodhouse, Andrew Morton, LKML, Audit-ML,
	LSM-ML

On Mon, Mar 03, 2008 at 06:51:41PM -0500, Paul Moore wrote:
> On Saturday 01 March 2008 3:01:11 pm Ahmed S. Darwish wrote:
...
> >
> >  audit.c       |    7 ------
> >  auditfilter.c |   61
> > ++++++++++++++++------------------------------------------ auditsc.c 
> >    |    9 +++-----
> >  3 files changed, 22 insertions(+), 55 deletions(-)
> 
> For some reason some of your patches are not coming through with correct 
> diffstats (notice the lack of a path relative to the kernel base?).  
> Don't worry too much about it as it's not grounds to reject the patch 
> (at least in my mind) but it's worth looking into on your end for the 
> next time you submit patches.
> 

Yes, it's something weird. I've generated all of those diffstats (including
the right ones) in the same way. Luckily the problem is reproduceable,
I'll check the latest upstream diffstat version and see what happens.

> > Andrew, please atomically merge patch #7 and patch #8. Although
> > a system with patch7 and without patch8 will be compiled fine,
> > the SELinux Audit hooks are not set up yet. This means below
> > audit hooks will point to the dummy hooks instead of SELinux
> > ones even if SELinux is enabled.
> >
> > I could not setup the SELinux hooks first cause they have
> > the same name of the old exported SELinux interface with a
> > difference of one parameter.
> 
> In cases like this where you need patches applied atomically to ensure 
> correct operation you can always combine the two patches into one 
> (assuming they are still small enough to be posted, which shouldn't be 
> a problem here).  Small patches are nice and easy to review, but that 
> doesn't mean you have to break everything up if it is awkward.
> 

I'll keep that in mind.

> I've looked over patches #7, #8, and #9 and they look okay to me, but 
> I'm not tagging them 'Reviewed-by' because they go beyond areas of the 
> kernel that I feel comfortable reviewing at this point.  Rest assured 
> there are other on the To/CC line that can help you out (I see James 
> Morris already Ack'd your entire patch set).
> 
> Thanks for all your work on this, it's a nice improvement.
> 

I'm also very thankful for such a nice review and caring explanations!.

Best,

-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 99%]

* [PATCH -v5 -mm] LSM: Add security= boot parameter
  @ 2008-03-04  3:04 71%                   ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2008-03-04  3:04 UTC (permalink / raw)
  To: James Morris
  Cc: Stephen Smalley, Casey Schaufler, Adrian Bunk, Chris Wright,
	Eric Paris, Alexey Dobriyan, LKML, LSM-ML, Anrew Morton

Hi!,

[ 
Fix stuff mentioned by James in parent mail:
- use spinlocks instead of atomic counter (yes, this is clearer).
- remove redundant BUG_ON
- don't let LSMs loudly complain when they aren't chosen.
]

-->

Add the security= boot parameter. This is done to avoid LSM 
registration clashes in case of more than one bult-in module.

User can choose a security module to enable at boot. If no 
security= boot parameter is specified, only the first LSM 
asking for registration will be loaded. An invalid security 
module name will be treated as if no module has been chosen.

LSM modules must check now if they are allowed to register
by calling security_module_enable(ops) first. Modify SELinux 
and SMACK to do so.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

 Documentation/kernel-parameters.txt |    6 ++++
 include/linux/security.h            |   12 +++++++++
 security/dummy.c                    |    2 -
 security/security.c                 |   46 +++++++++++++++++++++++++++++++++++-
 security/selinux/hooks.c            |    7 +++++
 security/smack/smack_lsm.c          |    5 +++

 6 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index c64dfd7..85044e8 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -374,6 +374,12 @@ and is between 256 and 4096 characters. It is defined in the file
 			possible to determine what the correct size should be.
 			This option provides an override for these situations.
 
+	security=	[SECURITY] Choose a security module to enable at boot. 
+			If this boot parameter is not specified, only the first 
+			security module asking for security registration will be
+			loaded. An invalid security module name will be treated
+			as if no module has been chosen.
+
 	capability.disable=
 			[SECURITY] Disable capabilities.  This would normally
 			be used only if an alternative security model is to be
diff --git a/include/linux/security.h b/include/linux/security.h
index eb663e5..3db2819 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -42,6 +42,9 @@
 
 extern unsigned securebits;
 
+/* Maximum number of letters for an LSM name string */
+#define SECURITY_NAME_MAX	10
+
 struct ctl_table;
 struct audit_krule;
 
@@ -118,6 +121,12 @@ struct request_sock;
 /**
  * struct security_operations - main security structure
  *
+ * Security module identifier.
+ *
+ * @name:
+ *	A string that acts as a unique identifeir for the LSM with max number
+ *	of characters = SECURITY_NAME_MAX.
+ *
  * Security hooks for program execution operations.
  *
  * @bprm_alloc_security:
@@ -1262,6 +1271,8 @@ struct request_sock;
  * This is the main security structure.
  */
 struct security_operations {
+	char name[SECURITY_NAME_MAX + 1];
+
 	int (*ptrace) (struct task_struct * parent, struct task_struct * child);
 	int (*capget) (struct task_struct * target,
 		       kernel_cap_t * effective,
@@ -1530,6 +1541,7 @@ struct security_operations {
 
 /* prototypes */
 extern int security_init	(void);
+extern int security_module_enable(struct security_operations *ops);
 extern int register_security	(struct security_operations *ops);
 extern int mod_reg_security	(const char *name, struct security_operations *ops);
 extern struct dentry *securityfs_create_file(const char *name, mode_t mode,
diff --git a/security/dummy.c b/security/dummy.c
index 241ab20..d081699 100644
--- a/security/dummy.c
+++ b/security/dummy.c
@@ -1022,7 +1022,7 @@ static inline void dummy_audit_rule_free(void *lsmrule)
 
 #endif /* CONFIG_AUDIT */
 
-struct security_operations dummy_security_ops;
+struct security_operations dummy_security_ops = { "dummy" };
 
 #define set_to_dummy_if_null(ops, function)				\
 	do {								\
diff --git a/security/security.c b/security/security.c
index 1bf2ee4..def9fc0 100644
--- a/security/security.c
+++ b/security/security.c
@@ -17,6 +17,9 @@
 #include <linux/kernel.h>
 #include <linux/security.h>
 
+/* Boot-time LSM user choice */
+static spinlock_t chosen_lsm_lock;
+static char chosen_lsm[SECURITY_NAME_MAX + 1];
 
 /* things that live in dummy.c */
 extern struct security_operations dummy_security_ops;
@@ -62,18 +65,59 @@ int __init security_init(void)
 	}
 
 	security_ops = &dummy_security_ops;
+	spin_lock_init(&chosen_lsm_lock);
 	do_security_initcalls();
 
 	return 0;
 }
 
+/* Save user chosen LSM */
+static int __init choose_lsm(char *str)
+{
+	strncpy(chosen_lsm, str, SECURITY_NAME_MAX);
+	return 1;
+}
+__setup("security=", choose_lsm);
+
+/**
+ * security_module_enable - Load given security module on boot ?
+ * @ops: a pointer to the struct security_operations that is to be checked.
+ *
+ * Each LSM must pass this method before registering its own operations
+ * to avoid security registration races.
+ *
+ * Return true if:
+ *	-The passed LSM is the one chosen by user at boot time,
+ *	-or user didsn't specify a specific LSM and we're the first to ask
+ *	 for registeration permissoin.
+ * Otherwise, return false.
+ */
+int security_module_enable(struct security_operations *ops)
+{
+	int rc = 1;
+
+	spin_lock(&chosen_lsm_lock);
+	if (!*chosen_lsm)
+		strncpy(chosen_lsm, ops->name, SECURITY_NAME_MAX);
+	else if (strncmp(ops->name, chosen_lsm, SECURITY_NAME_MAX))
+		rc = 0;
+	spin_unlock(&chosen_lsm_lock);
+
+	if (rc)
+		printk(KERN_INFO "Security: Loading '%s' security module.\n",
+		       ops->name);
+
+	return rc;
+}
+
 /**
  * register_security - registers a security framework with the kernel
  * @ops: a pointer to the struct security_options that is to be registered
  *
  * This function is to allow a security module to register itself with the
  * kernel security subsystem.  Some rudimentary checking is done on the @ops
- * value passed to this function.
+ * value passed to this function. You'll need to check first if your LSM
+ * is allowed to register its @ops by calling security_module_enable(@ops).
  *
  * If there is already a security module registered with the kernel,
  * an error will be returned.  Otherwise 0 is returned on success.
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index bef1834..52aaf10 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -5247,6 +5247,8 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
 #endif
 
 static struct security_operations selinux_ops = {
+	.name =				"selinux",
+
 	.ptrace =			selinux_ptrace,
 	.capget =			selinux_capget,
 	.capset_check =			selinux_capset_check,
@@ -5443,6 +5445,11 @@ static __init int selinux_init(void)
 {
 	struct task_security_struct *tsec;
 
+	if (!security_module_enable(&selinux_ops)) {
+		selinux_enabled = 0;
+		return 0;
+	}
+
 	if (!selinux_enabled) {
 		printk(KERN_INFO "SELinux:  Disabled at boot.\n");
 		return 0;
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 2b5d6f7..9464185 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -2358,6 +2358,8 @@ static void smack_release_secctx(char *secdata, u32 seclen)
 }
 
 static struct security_operations smack_ops = {
+	.name =				"smack",
+
 	.ptrace = 			smack_ptrace,
 	.capget = 			cap_capget,
 	.capset_check = 		cap_capset_check,
@@ -2485,6 +2487,9 @@ static struct security_operations smack_ops = {
  */
 static __init int smack_init(void)
 {
+	if (!security_module_enable(&smack_ops))
+		return 0;
+
 	printk(KERN_INFO "Smack:  Initializing.\n");
 
 	/*

-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 71%]

* [PATCH -v4 -mm] LSM: Add security= boot parameter
  @ 2008-03-03 21:24 67%               ` Ahmed S. Darwish
    0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2008-03-03 21:24 UTC (permalink / raw)
  To: Stephen Smalley
  Cc: James Morris, Casey Schaufler, Adrian Bunk, Chris Wright,
	Eric Paris, Alexey Dobriyan, LKML, LSM-ML, Anrew Morton

Hi!,

On Mon, Mar 03, 2008 at 10:54:02AM -0500, Stephen Smalley wrote:
> 
> On Mon, 2008-03-03 at 17:35 +0200, Ahmed S. Darwish wrote:
> > Hi James,
> > 
....
> > 
> > SElinux (As you already know ;)) does the security setup of the initial 
> > task before calling register_security. Would it be safe to do this
> > setup after registeration ?
> 
> I wouldn't recommend it - the hook functions presume that the initial
> task security blob has been set up already, and that other dependencies
> like the inode security cache and access vector cache have been created
> and can be used.  We have to assume that the security hooks can start
> being invoked as soon as we call register_security(), even if in
> practice it won't happen until after the init function completes.
>

OK, the patch will stick with the two-stage registration model to give
a safe initialization time for LSMs.

james: Could you please make it OK to use the atomic counter instead of
       the spinlock ? It'll just add unneeded complexity. We only set
       `chosen_lsm' once at the parameters parsing time. 

Changes (per James suggestions):
- Added a BUG_ON(!ops->name).
- Removed a redundant setting of last string character to NULL.

Sample Output:
[    0.065487] SELinux:  Initializing.
[    0.067115] SELinux:  Starting in permissive mode
[    0.067186] Smack:  Another security module was chosen.
[    0.067345] Smack:  Use security=smack to force loading Smack on boot.

-->

Add the security= boot parameter. This is done to avoid LSM 
registration clashes in case of more than one bult-in module.

User can choose a security module to enable at boot. If no 
security= boot parameter is specified, only the first LSM 
asking for registration will be loaded. An invalid security 
module name will be treated as if no module has been chosen.

LSM modules must check now if they are allowed to register
by calling security_module_enable(ops) first. Modify SELinux 
and SMACK to do so.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

 Documentation/kernel-parameters.txt |    6 ++++
 include/linux/security.h            |   12 +++++++++
 security/dummy.c                    |    2 -+
 security/security.c                 |   45 ++++++++++++++++++++++++++++++++++--
 security/selinux/hooks.c            |   10 ++++++++
 security/smack/smack_lsm.c          |    9 +++++++

 6 files changed, 81 insertions(+), 3 deletions(-)

diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index c64dfd7..85044e8 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -374,6 +374,12 @@ and is between 256 and 4096 characters. It is defined in the file
 			possible to determine what the correct size should be.
 			This option provides an override for these situations.
 
+	security=	[SECURITY] Choose a security module to enable at boot. 
+			If this boot parameter is not specified, only the first 
+			security module asking for security registration will be
+			loaded. An invalid security module name will be treated
+			as if no module has been chosen.
+
 	capability.disable=
 			[SECURITY] Disable capabilities.  This would normally
 			be used only if an alternative security model is to be
diff --git a/include/linux/security.h b/include/linux/security.h
index eb663e5..3db2819 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -42,6 +42,9 @@
 
 extern unsigned securebits;
 
+/* Maximum number of letters for an LSM name string */
+#define SECURITY_NAME_MAX	10
+
 struct ctl_table;
 struct audit_krule;
 
@@ -118,6 +121,12 @@ struct request_sock;
 /**
  * struct security_operations - main security structure
  *
+ * Security module identifier.
+ *
+ * @name:
+ *	A string that acts as a unique identifeir for the LSM with max number
+ *	of characters = SECURITY_NAME_MAX.
+ *
  * Security hooks for program execution operations.
  *
  * @bprm_alloc_security:
@@ -1262,6 +1271,8 @@ struct request_sock;
  * This is the main security structure.
  */
 struct security_operations {
+	char name[SECURITY_NAME_MAX + 1];
+
 	int (*ptrace) (struct task_struct * parent, struct task_struct * child);
 	int (*capget) (struct task_struct * target,
 		       kernel_cap_t * effective,
@@ -1530,6 +1541,7 @@ struct security_operations {
 
 /* prototypes */
 extern int security_init	(void);
+extern int security_module_enable(struct security_operations *ops);
 extern int register_security	(struct security_operations *ops);
 extern int mod_reg_security	(const char *name, struct security_operations *ops);
 extern struct dentry *securityfs_create_file(const char *name, mode_t mode,
diff --git a/security/dummy.c b/security/dummy.c
index 241ab20..d081699 100644
--- a/security/dummy.c
+++ b/security/dummy.c
@@ -1022,7 +1022,7 @@ static inline void dummy_audit_rule_free(void *lsmrule)
 
 #endif /* CONFIG_AUDIT */
 
-struct security_operations dummy_security_ops;
+struct security_operations dummy_security_ops = { "dummy" };
 
 #define set_to_dummy_if_null(ops, function)				\
 	do {								\
diff --git a/security/security.c b/security/security.c
index 1bf2ee4..5419fec 100644
--- a/security/security.c
+++ b/security/security.c
@@ -17,6 +17,9 @@
 #include <linux/kernel.h>
 #include <linux/security.h>
 
+/* Boot-time LSM user choice */
+static char chosen_lsm[SECURITY_NAME_MAX + 1];
+static atomic_t security_ops_enabled = ATOMIC_INIT(-1);
 
 /* things that live in dummy.c */
 extern struct security_operations dummy_security_ops;
@@ -30,7 +33,7 @@ unsigned long mmap_min_addr = CONFIG_SECURITY_DEFAULT_MMAP_MIN_ADDR;
 static inline int verify(struct security_operations *ops)
 {
 	/* verify the security_operations structure exists */
-	if (!ops)
+	if (!ops || !ops->name)
 		return -EINVAL;
 	security_fixup_ops(ops);
 	return 0;
@@ -67,13 +70,51 @@ int __init security_init(void)
 	return 0;
 }
 
+/* Save user chosen LSM */
+static int __init choose_lsm(char *str)
+{
+	strncpy(chosen_lsm, str, SECURITY_NAME_MAX);
+	return 1;
+}
+__setup("security=", choose_lsm);
+
+/**
+ * security_module_enable - Load given security module on boot ?
+ * @ops: a pointer to the struct security_operations that is to be checked.
+ *
+ * Each LSM must pass this method before registering its own operations
+ * to avoid security registration races.
+ *
+ * Return true if:
+ *	-The passed LSM is the one chosen by user at boot time,
+ *	-or user didsn't specify a specific LSM and we're the first to ask
+ *	 for registeration permissoin.
+ * Otherwise, return false.
+ */
+int security_module_enable(struct security_operations *ops)
+{
+	if (!ops || !ops->name) {
+		BUG();
+		return 0;
+	}
+
+	if (!*chosen_lsm && atomic_inc_and_test(&security_ops_enabled))
+		return 1;
+
+	if (!strncmp(ops->name, chosen_lsm, SECURITY_NAME_MAX))
+		return 1;
+
+	return 0;
+}
+
 /**
  * register_security - registers a security framework with the kernel
  * @ops: a pointer to the struct security_options that is to be registered
  *
  * This function is to allow a security module to register itself with the
  * kernel security subsystem.  Some rudimentary checking is done on the @ops
- * value passed to this function.
+ * value passed to this function. You'll need to check first if your LSM
+ * is allowed to register its @ops by calling security_module_enable(@ops).
  *
  * If there is already a security module registered with the kernel,
  * an error will be returned.  Otherwise 0 is returned on success.
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index bef1834..c3a52a8 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -5247,6 +5247,8 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
 #endif
 
 static struct security_operations selinux_ops = {
+	.name =				"selinux",
+
 	.ptrace =			selinux_ptrace,
 	.capget =			selinux_capget,
 	.capset_check =			selinux_capset_check,
@@ -5448,6 +5450,14 @@ static __init int selinux_init(void)
 		return 0;
 	}
 
+	if (!security_module_enable(&selinux_ops)) {
+		selinux_enabled = 0;
+		printk(KERN_INFO "SELinux:  Another security module was chosen.\n");
+		printk(KERN_INFO "SELinux:  Use security=%s to force loading "
+		       "SELinux on boot.\n", selinux_ops.name);
+		return 0;
+	}
+
 	printk(KERN_INFO "SELinux:  Initializing.\n");
 
 	/* Set the security state for the initial task. */
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 2b5d6f7..ad31819 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -2358,6 +2358,8 @@ static void smack_release_secctx(char *secdata, u32 seclen)
 }
 
 static struct security_operations smack_ops = {
+	.name =				"smack",
+
 	.ptrace = 			smack_ptrace,
 	.capget = 			cap_capget,
 	.capset_check = 		cap_capset_check,
@@ -2485,6 +2487,13 @@ static struct security_operations smack_ops = {
  */
 static __init int smack_init(void)
 {
+	if (!security_module_enable(&smack_ops)) {
+		printk(KERN_INFO "Smack:  Another security module was chosen.\n");
+		printk(KERN_INFO "Smack:  Use security=%s to force loading "
+		       "Smack on boot.\n", smack_ops.name);
+		return 0;
+	}
+
 	printk(KERN_INFO "Smack:  Initializing.\n");
 
 	/*

-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 67%]

* Re: [PATCH -v3 -mm] LSM: Add security= boot parameter
  @ 2008-03-03 15:35 98%           ` Ahmed S. Darwish
    0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2008-03-03 15:35 UTC (permalink / raw)
  To: James Morris
  Cc: Casey Schaufler, Adrian Bunk, Chris Wright, Stephen Smalley,
	Eric Paris, Alexey Dobriyan, LKML, LSM-ML, Anrew Morton

Hi James,

On Mon, Mar 03, 2008 at 07:29:22PM +1100, James Morris wrote:
> On Sun, 2 Mar 2008, Ahmed S. Darwish wrote:
> 
> > Add the security= boot parameter. This is done to avoid LSM 
> > registration clashes in case of more than one bult-in module.
> > 
> > User can choose a security module to enable at boot. If no 
> > security= boot parameter is specified, only the first LSM 
> > asking for registration will be loaded. An invalid security 
> > module name will be treated as if no module has been chosen.
> > 
> > LSM modules must check now if they are allowed to register
> > by calling security_module_enable(ops) first. Modify SELinux 
> > and SMACK to do so.
> 
> I think this can be simplified by folding the logic into 
> register_security(), rather than having a two-stage LSM registration 
> process.
> 
> So, this function would now look like
> 
> 	int register_security(ops, *status);
> 
> and set *status to LSM_WAS_CHOSEN (or similar) if the module being 
> registered was also chosen via the security= parameter.  If there is no 
> value for the parameter, the first module to register is automatically 
> chosen, to preserve existing behavior.
> 
> The calling code can then decide what to do, e.g. not panic if 
> registration failed and the LSM was not chosen; panic on failure when it 
> was chosen.
> 

I liked to do it like that at first, but I faced two problems:

SElinux (As you already know ;)) does the security setup of the initial 
task before calling register_security. Would it be safe to do this
setup after registeration ?

Same case occurs for Smack, it does some locking initializations and
setup initial task's security before registration.

Personally, I feel that it's nicer to let the LSM know if it's
OK to initialize itself before hitting _the point of no return_ (registration).

Anyway, I have no problem to implement it using *status if my 
concerns are wrong.

> > +static atomic_t security_ops_enabled = ATOMIC_INIT(-1);
> 
> I'd suggest getting rid of this atomic and using a spinlock to protect the 
> global chosen_lsm string, which is always filled when an LSM registers.
> 
> >  
> > +/* Save user chosen LSM */
> > +static int __init choose_lsm(char *str)
> > +{
> > +	strncpy(chosen_lsm, str, SECURITY_NAME_MAX);
> > +	chosen_lsm[SECURITY_NAME_MAX] = NULL;
> 
> You should never need to set the last byte to NULL -- it's initialized to 
> that and by definition should never be overwritten.
> 
> > +int security_module_enable(struct security_operations *ops)
> > +{
> > +	if (!ops || !ops->name)
> > +		return 0;
> 
> Lack of ops->name during registration needs to be a BUG_ON.
> 

You'll find above three points fixed the next send. Thank you.

Regards,

-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 98%]

* [PATCH -v3 -mm] LSM: Add security= boot parameter
  2008-03-02  7:49 99%     ` Ahmed S. Darwish
@ 2008-03-02 10:59 67%       ` Ahmed S. Darwish
    0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2008-03-02 10:59 UTC (permalink / raw)
  To: Casey Schaufler
  Cc: Adrian Bunk, Chris Wright, Stephen Smalley, James Morris,
	Eric Paris, Alexey Dobriyan, LKML, LSM-ML, Anrew Morton

Hi!,

[
Fixed two bugs:
       - concurrency: incrementing and testing atomic_t in different places.
       - overflow: not ending string with NULL after using strncpy().
       - I'll never write a patch when I'm asleep, sorry :(

Added more verbose messages to SMACK and SELinux if they were not 
chosen on boot.

Casey: Failing to take permission to register an LSM does not mean that 
       the other has registered its security_ops yet. It just means that
       the other asked for allowance to call register_security(). It's 
       not yet guraranteed that this registration succeeded.

       This means that adding "SELinux: failed to load, LSM %s is loaded"
       may lead to %s = "dummy" in case of a highly concurrent SMP system.
]

-->

Add the security= boot parameter. This is done to avoid LSM 
registration clashes in case of more than one bult-in module.

User can choose a security module to enable at boot. If no 
security= boot parameter is specified, only the first LSM 
asking for registration will be loaded. An invalid security 
module name will be treated as if no module has been chosen.

LSM modules must check now if they are allowed to register
by calling security_module_enable(ops) first. Modify SELinux 
and SMACK to do so.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

 Documentation/kernel-parameters.txt |    6 ++++
 include/linux/security.h            |   12 +++++++++
 security/dummy.c                    |    2 -
 security/security.c                 |   46 +++++++++++++++++++++++++++++++++---
 security/selinux/hooks.c            |   12 +++++++++
 security/smack/smack_lsm.c          |   11 ++++++++

 6 files changed, 85 insertions(+), 4 deletions(-)

diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index c64dfd7..85044e8 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -374,6 +374,12 @@ and is between 256 and 4096 characters. It is defined in the file
 			possible to determine what the correct size should be.
 			This option provides an override for these situations.
 
+	security=	[SECURITY] Choose a security module to enable at boot. 
+			If this boot parameter is not specified, only the first 
+			security module asking for security registration will be
+			loaded. An invalid security module name will be treated
+			as if no module has been chosen.
+
 	capability.disable=
 			[SECURITY] Disable capabilities.  This would normally
 			be used only if an alternative security model is to be
diff --git a/include/linux/security.h b/include/linux/security.h
index a33fd03..601318a 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -42,6 +42,9 @@
 
 extern unsigned securebits;
 
+/* Maximum number of letters for an LSM name string */
+#define SECURITY_NAME_MAX	10
+
 struct ctl_table;
 
 /*
@@ -117,6 +120,12 @@ struct request_sock;
 /**
  * struct security_operations - main security structure
  *
+ * Security module identifier.
+ *
+ * @name:
+ *	A string that acts as a unique identifeir for the LSM with max number 
+ *	of characters = SECURITY_NAME_MAX.
+ *
  * Security hooks for program execution operations.
  *
  * @bprm_alloc_security:
@@ -1218,6 +1227,8 @@ struct request_sock;
  * This is the main security structure.
  */
 struct security_operations {
+	char name[SECURITY_NAME_MAX + 1];
+
 	int (*ptrace) (struct task_struct * parent, struct task_struct * child);
 	int (*capget) (struct task_struct * target,
 		       kernel_cap_t * effective,
@@ -1477,6 +1488,7 @@ struct security_operations {
 
 /* prototypes */
 extern int security_init	(void);
+extern int security_module_enable(struct security_operations *ops);
 extern int register_security	(struct security_operations *ops);
 extern int mod_reg_security	(const char *name, struct security_operations *ops);
 extern struct dentry *securityfs_create_file(const char *name, mode_t mode,
diff --git a/security/dummy.c b/security/dummy.c
index 6a0056b..d0910f2 100644
--- a/security/dummy.c
+++ b/security/dummy.c
@@ -986,7 +986,7 @@ static int dummy_key_getsecurity(struct key *key, char **_buffer)
 
 #endif /* CONFIG_KEYS */
 
-struct security_operations dummy_security_ops;
+struct security_operations dummy_security_ops = { "dummy" };
 
 #define set_to_dummy_if_null(ops, function)				\
 	do {								\
diff --git a/security/security.c b/security/security.c
index 3e75b90..6f2df1a 100644
--- a/security/security.c
+++ b/security/security.c
@@ -17,6 +17,9 @@
 #include <linux/kernel.h>
 #include <linux/security.h>
 
+/* Boot-time LSM user choice */
+static char chosen_lsm[SECURITY_NAME_MAX + 1];
+static atomic_t security_ops_enabled = ATOMIC_INIT(-1);
 
 /* things that live in dummy.c */
 extern struct security_operations dummy_security_ops;
@@ -30,7 +33,7 @@ unsigned long mmap_min_addr = CONFIG_SECURITY_DEFAULT_MMAP_MIN_ADDR;
 static inline int verify(struct security_operations *ops)
 {
 	/* verify the security_operations structure exists */
-	if (!ops)
+	if (!ops || !ops->name)
 		return -EINVAL;
 	security_fixup_ops(ops);
 	return 0;
@@ -67,13 +70,51 @@ int __init security_init(void)
 	return 0;
 }
 
+/* Save user chosen LSM */
+static int __init choose_lsm(char *str)
+{
+	strncpy(chosen_lsm, str, SECURITY_NAME_MAX);
+	chosen_lsm[SECURITY_NAME_MAX] = NULL;
+
+	return 1;
+}
+__setup("security=", choose_lsm);
+
+/**
+ * security_module_enable - Load given security module on boot ?
+ * @ops: a pointer to the struct security_operations that is to be checked.
+ *
+ * Each LSM must pass this method before registering its own operations
+ * to avoid security registration races.
+ *
+ * Return true if:
+ *	-The passed LSM is the one chosen by user at boot time,
+ *	-or user didsn't specify a specific LSM and we're the first to ask
+ *	 for registeration permissoin.
+ * Otherwise, return false.
+ */
+int security_module_enable(struct security_operations *ops)
+{
+	if (!ops || !ops->name)
+		return 0;
+
+	if (!*chosen_lsm && atomic_inc_and_test(&security_ops_enabled))
+		return 1;
+
+	if (!strncmp(ops->name, chosen_lsm, SECURITY_NAME_MAX))
+		return 1;
+	
+	return 0;
+}
+
 /**
  * register_security - registers a security framework with the kernel
  * @ops: a pointer to the struct security_options that is to be registered
  *
  * This function is to allow a security module to register itself with the
  * kernel security subsystem.  Some rudimentary checking is done on the @ops
- * value passed to this function.
+ * value passed to this function. You'll need to check first if your LSM
+ * is allowed to register its @ops by calling security_module_enable(@ops).
  *
  * If there is already a security module registered with the kernel,
  * an error will be returned.  Otherwise 0 is returned on success.
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index f42ebfc..b507977 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -5233,6 +5233,8 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
 #endif
 
 static struct security_operations selinux_ops = {
+	.name =				"selinux",
+
 	.ptrace =			selinux_ptrace,
 	.capget =			selinux_capget,
 	.capset_check =			selinux_capset_check,
@@ -5425,6 +5427,15 @@ static __init int selinux_init(void)
 		return 0;
 	}
 
+	if (!security_module_enable(&selinux_ops)) {
+		selinux_enabled = 0;
+		printk(KERN_INFO "SELinux:  Security registration was not allowed.\n");
+		printk(KERN_INFO "SELinux:  Another security module was chosen.\n");
+		printk(KERN_INFO "SELinux:  Use security=%s to force choosing "
+		       "SELinux on boot.\n", selinux_ops.name);
+		return 0;
+	}
+
 	printk(KERN_INFO "SELinux:  Initializing.\n");
 
 	/* Set the security state for the initial task. */
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 2b5d6f7..2e1adbb 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -2358,6 +2358,8 @@ static void smack_release_secctx(char *secdata, u32 seclen)
 }
 
 static struct security_operations smack_ops = {
+	.name =				"smack",
+
 	.ptrace = 			smack_ptrace,
 	.capget = 			cap_capget,
 	.capset_check = 		cap_capset_check,
@@ -2485,6 +2487,14 @@ static struct security_operations smack_ops = {
  */
 static __init int smack_init(void)
 {
+	if (!security_module_enable(&smack_ops)) {
+		printk(KERN_INFO "Smack:  Security registration was not allowed.\n");
+		printk(KERN_INFO "Smack:  Another security module was chosen.\n");
+		printk(KERN_INFO "Smack:  Use security=%s to force choosing "
+		       "Smack on boot.\n", smack_ops.name);
+		return 0;
+	}
+
 	printk(KERN_INFO "Smack:  Initializing.\n");
 
 	/*

---
"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 67%]

* Re: [PATCH -v2 -mm] LSM: Add security= boot parameter
  @ 2008-03-02  7:55 99%       ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2008-03-02  7:55 UTC (permalink / raw)
  To: Casey Schaufler
  Cc: Adrian Bunk, Chris Wright, Stephen Smalley, James Morris,
	Eric Paris, Alexey Dobriyan, LKML, LSM-ML, Anrew Morton

On Sat, Mar 01, 2008 at 07:41:04PM -0800, Casey Schaufler wrote:
> 
> --- "Ahmed S. Darwish" <darwish.07@gmail.com> wrote:
> >
...
> > 
> >  
> >  static struct security_operations selinux_ops = {
> > +	.name =				"selinux",
> > +
> >  	.ptrace =			selinux_ptrace,
> >  	.capget =			selinux_capget,
> >  	.capset_check =			selinux_capset_check,
> > @@ -5420,7 +5422,8 @@ static __init int selinux_init(void)
> >  {
> >  	struct task_security_struct *tsec;
> >  
> > -	if (!selinux_enabled) {
> > +	if (!selinux_enabled || !security_module_enable(&selinux_ops)) {
> > +		selinux_enabled = 0;
> >  		printk(KERN_INFO "SELinux:  Disabled at boot.\n");
> 
> How about "SELinux: Not enabled because LSM %s is already enabled.\n"
> 

Looks better. I'll resend the patch once I know the answer of the SMP
point I asked about in the same thread.

Regards,

-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 99%]

* Re: [PATCH -v2 -mm] LSM: Add security= boot parameter
  2008-03-01 23:27 70%   ` [PATCH -v2 -mm] LSM: Add security= " Ahmed S. Darwish
  @ 2008-03-02  7:49 99%     ` Ahmed S. Darwish
  2008-03-02 10:59 67%       ` [PATCH -v3 " Ahmed S. Darwish
  1 sibling, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2008-03-02  7:49 UTC (permalink / raw)
  To: Casey Schaufler
  Cc: Adrian Bunk, Chris Wright, Stephen Smalley, James Morris,
	Eric Paris, Alexey Dobriyan, LKML, LSM-ML, Anrew Morton

On Sun, Mar 02, 2008 at 01:27:08AM +0200, Ahmed S. Darwish wrote:
> Hi!,
> 
... 
> LSM modules must check now if they are allowed to register
> by calling security_module_enable(ops) first. Modify SELinux 
> and SMACK to do so.
> 
...
>  
> +/* Boot-time LSM user choice */
> +static char chosen_lsm[SECURITY_NAME_MAX + 1];
> +static atomic_t security_ops_registered = ATOMIC_INIT(0);
>  
...
> +int security_module_enable(struct security_operations *ops)
> +{
> +	if (!ops || !ops->name)
> +		return 0;
> +
> +	if (!*chosen_lsm && !atomic_read(&security_ops_registered))
> +		return 1;
> +
...
> @@ -90,6 +134,7 @@ int register_security(struct security_operations *ops)
>  		return -EAGAIN;
>  
>  	security_ops = ops;
> +	atomic_inc(&security_ops_registered);
>  

I'm worried about an implementation detail here. Must the LSM
init calls sequence:
asmlinkage void __init start_kernel(void)
{
	preempt_disable();
	...
	security_init();
	...

int __init security_init(void)
{
	...
	do_security_initcalls();
}
static void __init do_security_initcalls(void)
{
	initcall_t *call;
	call = __security_initcall_start;
	while (call < __security_initcall_end) {
		(*call) ();
		call++;
	}
}
be SMP safe ?

In other words, can the two LSMs 'security_initcall()'s 
(i.e. smack_init() and selinux_init()) be executed concurrently ?

If so, this patch won't be safe.
I'll send a modified one once I know the answer.

Thanks everybody,

-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 99%]

* [PATCH -v2 -mm] LSM: Add security= boot parameter
  @ 2008-03-01 23:27 70%   ` Ahmed S. Darwish
    2008-03-02  7:49 99%     ` Ahmed S. Darwish
  0 siblings, 2 replies; 200+ results
From: Ahmed S. Darwish @ 2008-03-01 23:27 UTC (permalink / raw)
  To: Casey Schaufler
  Cc: Adrian Bunk, Chris Wright, Stephen Smalley, James Morris,
	Eric Paris, Alexey Dobriyan, LKML, LSM-ML, Anrew Morton

Hi!,

Add the security= boot parameter. This is done to avoid LSM 
registration clashes in case of more than one bult-in module.

User can choose a security module to enable at boot. If no 
security= boot parameter is specified, only the first LSM 
asking for registration will be loaded. An invalid security 
module name will be treated as if no module has been chosen.

LSM modules must check now if they are allowed to register
by calling security_module_enable(ops) first. Modify SELinux 
and SMACK to do so.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

I'll send a similar patch for 2.6.25 if no more concerns for
the patch exist. 

Adrian, Casey, Does this one have any more issues ?

 Documentation/kernel-parameters.txt |    6 ++++
 include/linux/security.h            |   12 +++++++++
 security/dummy.c                    |    3 +-
 security/security.c                 |   47 +++++++++++++++++++++++++++++++++++-
 security/selinux/hooks.c            |    5 +++
 security/smack/smack_lsm.c          |    7 +++++

 6 files changed, 77 insertions(+), 3 deletions(-)

diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index c64dfd7..85044e8 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -374,6 +374,12 @@ and is between 256 and 4096 characters. It is defined in the file
 			possible to determine what the correct size should be.
 			This option provides an override for these situations.
 
+	security=	[SECURITY] Choose a security module to enable at boot. 
+			If this boot parameter is not specified, only the first 
+			security module asking for security registration will be
+			loaded. An invalid security module name will be treated
+			as if no module has been chosen.
+
 	capability.disable=
 			[SECURITY] Disable capabilities.  This would normally
 			be used only if an alternative security model is to be
diff --git a/include/linux/security.h b/include/linux/security.h
index a33fd03..416afcf 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -42,6 +42,9 @@
 
 extern unsigned securebits;
 
+/* Maximum number of letters for an LSM name string */
+#define SECURITY_NAME_MAX	10
+
 struct ctl_table;
 
 /*
@@ -117,6 +120,12 @@ struct request_sock;
 /**
  * struct security_operations - main security structure
  *
+ * Security module identifier.
+ *
+ * @name:
+ *	A string that acts as  unique identifeir for the LSM with max number 
+ *	of characters = SECURITY_NAME_MAX.
+ *
  * Security hooks for program execution operations.
  *
  * @bprm_alloc_security:
@@ -1218,6 +1227,8 @@ struct request_sock;
  * This is the main security structure.
  */
 struct security_operations {
+	char name[SECURITY_NAME_MAX + 1];
+
 	int (*ptrace) (struct task_struct * parent, struct task_struct * child);
 	int (*capget) (struct task_struct * target,
 		       kernel_cap_t * effective,
@@ -1477,6 +1488,7 @@ struct security_operations {
 
 /* prototypes */
 extern int security_init	(void);
+extern int security_module_enable(struct security_operations *ops);
 extern int register_security	(struct security_operations *ops);
 extern int mod_reg_security	(const char *name, struct security_operations *ops);
 extern struct dentry *securityfs_create_file(const char *name, mode_t mode,
diff --git a/security/dummy.c b/security/dummy.c
index 6a0056b..7cb999c 100644
--- a/security/dummy.c
+++ b/security/dummy.c
@@ -986,7 +986,7 @@ static int dummy_key_getsecurity(struct key *key, char **_buffer)
 
 #endif /* CONFIG_KEYS */
 
-struct security_operations dummy_security_ops;
+struct security_operations dummy_security_ops = { "dummy" };
 
 #define set_to_dummy_if_null(ops, function)				\
 	do {								\
@@ -999,6 +999,7 @@ struct security_operations dummy_security_ops;
 
 void security_fixup_ops (struct security_operations *ops)
 {
+	BUG_ON(!ops->name);
 	set_to_dummy_if_null(ops, ptrace);
 	set_to_dummy_if_null(ops, capget);
 	set_to_dummy_if_null(ops, capset_check);
diff --git a/security/security.c b/security/security.c
index 3e75b90..261d2e4 100644
--- a/security/security.c
+++ b/security/security.c
@@ -17,6 +17,9 @@
 #include <linux/kernel.h>
 #include <linux/security.h>
 
+/* Boot-time LSM user choice */
+static char chosen_lsm[SECURITY_NAME_MAX + 1];
+static atomic_t security_ops_registered = ATOMIC_INIT(0);
 
 /* things that live in dummy.c */
 extern struct security_operations dummy_security_ops;
@@ -67,13 +70,54 @@ int __init security_init(void)
 	return 0;
 }
 
+/* Save user chosen LSM */
+static int __init choose_lsm(char *str)
+{
+	if (strlen(str) > SECURITY_NAME_MAX) {
+		printk(KERN_INFO "Security: LSM name length extends possible"
+		       "limit.\n");
+		printk(KERN_INFO "Security: Ignoring passed security= "
+		       "parameter.\n");
+		return 0;
+	}
+
+	strncpy(chosen_lsm, str, SECURITY_NAME_MAX);
+	return 1;
+}
+__setup("security=", choose_lsm);
+
+/**
+ * security_module_enable - Load given security module on boot ?
+ * @ops: a pointer to the struct security_operations that is to be checked.
+ *
+ * Return true if:
+ *	-The passed LSM is the one chosen by user at boot time,
+ *	-or user didsn't specify a specific LSM and we're the first to ask
+ *	 for registeration permissoin.
+ * Otherwise, return false.
+ */
+int security_module_enable(struct security_operations *ops)
+{
+	if (!ops || !ops->name)
+		return 0;
+
+	if (!*chosen_lsm && !atomic_read(&security_ops_registered))
+		return 1;
+
+	if (!strncmp(ops->name, chosen_lsm, SECURITY_NAME_MAX))
+		return 1;
+	
+	return 0;
+}
+
 /**
  * register_security - registers a security framework with the kernel
  * @ops: a pointer to the struct security_options that is to be registered
  *
  * This function is to allow a security module to register itself with the
  * kernel security subsystem.  Some rudimentary checking is done on the @ops
- * value passed to this function.
+ * value passed to this function. You'll need to check first if your LSM
+ * is allowed to register by calling security_module_enable(@ops).
  *
  * If there is already a security module registered with the kernel,
  * an error will be returned.  Otherwise 0 is returned on success.
@@ -90,6 +134,7 @@ int register_security(struct security_operations *ops)
 		return -EAGAIN;
 
 	security_ops = ops;
+	atomic_inc(&security_ops_registered);
 
 	return 0;
 }
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index f42ebfc..fe30d2b 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -5233,6 +5233,8 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
 #endif
 
 static struct security_operations selinux_ops = {
+	.name =				"selinux",
+
 	.ptrace =			selinux_ptrace,
 	.capget =			selinux_capget,
 	.capset_check =			selinux_capset_check,
@@ -5420,7 +5422,8 @@ static __init int selinux_init(void)
 {
 	struct task_security_struct *tsec;
 
-	if (!selinux_enabled) {
+	if (!selinux_enabled || !security_module_enable(&selinux_ops)) {
+		selinux_enabled = 0;
 		printk(KERN_INFO "SELinux:  Disabled at boot.\n");
 		return 0;
 	}
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 2b5d6f7..3fc8c6e 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -2358,6 +2358,8 @@ static void smack_release_secctx(char *secdata, u32 seclen)
 }
 
 static struct security_operations smack_ops = {
+	.name =				"smack",
+
 	.ptrace = 			smack_ptrace,
 	.capget = 			cap_capget,
 	.capset_check = 		cap_capset_check,
@@ -2485,6 +2487,11 @@ static struct security_operations smack_ops = {
  */
 static __init int smack_init(void)
 {
+	if (!security_module_enable(&smack_ops)) {
+		printk(KERN_INFO "Smack: Disabled at boot.\n");
+		return 0;
+	}
+
 	printk(KERN_INFO "Smack:  Initializing.\n");
 
 	/*

-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 70%]

* [PATCH 9/9] Audit: Final renamings and cleanup
  2008-03-01 19:47 95% [PATCH-v2 -mm 0/9] LSM-neutral Audit (SELinux audit separation) Ahmed S. Darwish
                   ` (7 preceding siblings ...)
  2008-03-01 20:03 57% ` [PATCH 8/9] SELinux: use new audit hooks, remove redundant exports Ahmed S. Darwish
@ 2008-03-01 20:05 71% ` Ahmed S. Darwish
  8 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2008-03-01 20:05 UTC (permalink / raw)
  To: Chris Wright, Stephen Smalley, James Morris, Eric Paris,
	Casey Schaufler, David Woodhouse, Paul Moore, Andrew Morton
  Cc: LKML, Audit-ML, LSM-ML

Rename the se_str and se_rule audit fields elements to
lsm_str and lsm_rule to avoid confusion.

Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

 include/linux/audit.h |    4 ++--
 kernel/auditfilter.c  |   40 ++++++++++++++++++++--------------------
 kernel/auditsc.c      |   12 ++++++------
 3 files changed, 28 insertions(+), 28 deletions(-)

Woo, hooo .. That was fun ;)

diff --git a/include/linux/audit.h b/include/linux/audit.h
index 3367c80..a35678e 100644
--- a/include/linux/audit.h
+++ b/include/linux/audit.h
@@ -377,8 +377,8 @@ struct audit_field {
 	u32				type;
 	u32				val;
 	u32				op;
-	char				*se_str;
-	void				*se_rule;
+	char				*lsm_str;
+	void				*lsm_rule;
 };
 
 #define AUDITSC_INVALID 0
diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c
index 7c69cb5..28fef6b 100644
--- a/kernel/auditfilter.c
+++ b/kernel/auditfilter.c
@@ -139,8 +139,8 @@ static inline void audit_free_rule(struct audit_entry *e)
 	if (e->rule.fields)
 		for (i = 0; i < e->rule.field_count; i++) {
 			struct audit_field *f = &e->rule.fields[i];
-			kfree(f->se_str);
-			security_audit_rule_free(f->se_rule);
+			kfree(f->lsm_str);
+			security_audit_rule_free(f->lsm_rule);
 		}
 	kfree(e->rule.fields);
 	kfree(e->rule.filterkey);
@@ -554,8 +554,8 @@ static struct audit_entry *audit_data_to_entry(struct audit_rule_data *data,
 		f->op = data->fieldflags[i] & AUDIT_OPERATORS;
 		f->type = data->fields[i];
 		f->val = data->values[i];
-		f->se_str = NULL;
-		f->se_rule = NULL;
+		f->lsm_str = NULL;
+		f->lsm_rule = NULL;
 		switch(f->type) {
 		case AUDIT_PID:
 		case AUDIT_UID:
@@ -598,7 +598,7 @@ static struct audit_entry *audit_data_to_entry(struct audit_rule_data *data,
 			entry->rule.buflen += f->val;
 
 			err = security_audit_rule_init(f->type, f->op, str,
-						       (void **)&f->se_rule);
+						       (void **)&f->lsm_rule);
 			/* Keep currently invalid fields around in case they
 			 * become valid after a policy reload. */
 			if (err == -EINVAL) {
@@ -610,7 +610,7 @@ static struct audit_entry *audit_data_to_entry(struct audit_rule_data *data,
 				kfree(str);
 				goto exit_free;
 			} else
-				f->se_str = str;
+				f->lsm_str = str;
 			break;
 		case AUDIT_WATCH:
 			str = audit_unpack_string(&bufp, &remain, f->val);
@@ -754,7 +754,7 @@ static struct audit_rule_data *audit_krule_to_data(struct audit_krule *krule)
 		case AUDIT_OBJ_LEV_LOW:
 		case AUDIT_OBJ_LEV_HIGH:
 			data->buflen += data->values[i] =
-				audit_pack_string(&bufp, f->se_str);
+				audit_pack_string(&bufp, f->lsm_str);
 			break;
 		case AUDIT_WATCH:
 			data->buflen += data->values[i] =
@@ -806,7 +806,7 @@ static int audit_compare_rule(struct audit_krule *a, struct audit_krule *b)
 		case AUDIT_OBJ_TYPE:
 		case AUDIT_OBJ_LEV_LOW:
 		case AUDIT_OBJ_LEV_HIGH:
-			if (strcmp(a->fields[i].se_str, b->fields[i].se_str))
+			if (strcmp(a->fields[i].lsm_str, b->fields[i].lsm_str))
 				return 1;
 			break;
 		case AUDIT_WATCH:
@@ -862,28 +862,28 @@ out:
 	return new;
 }
 
-/* Duplicate LSM field information.  The se_rule is opaque, so must be
+/* Duplicate LSM field information.  The lsm_rule is opaque, so must be
  * re-initialized. */
 static inline int audit_dupe_lsm_field(struct audit_field *df,
 					   struct audit_field *sf)
 {
 	int ret = 0;
-	char *se_str;
+	char *lsm_str;
 
-	/* our own copy of se_str */
-	se_str = kstrdup(sf->se_str, GFP_KERNEL);
-	if (unlikely(!se_str))
+	/* our own copy of lsm_str */
+	lsm_str = kstrdup(sf->lsm_str, GFP_KERNEL);
+	if (unlikely(!lsm_str))
 		return -ENOMEM;
-	df->se_str = se_str;
+	df->lsm_str = lsm_str;
 
-	/* our own (refreshed) copy of se_rule */
-	ret = security_audit_rule_init(df->type, df->op, df->se_str,
-				       (void **)&df->se_rule);
+	/* our own (refreshed) copy of lsm_rule */
+	ret = security_audit_rule_init(df->type, df->op, df->lsm_str,
+				       (void **)&df->lsm_rule);
 	/* Keep currently invalid fields around in case they
 	 * become valid after a policy reload. */
 	if (ret == -EINVAL) {
 		printk(KERN_WARNING "audit rule for LSM \'%s\' is "
-		       "invalid\n", df->se_str);
+		       "invalid\n", df->lsm_str);
 		ret = 0;
 	}
 
@@ -930,7 +930,7 @@ static struct audit_entry *audit_dupe_rule(struct audit_krule *old,
 	new->tree = old->tree;
 	memcpy(new->fields, old->fields, sizeof(struct audit_field) * fcount);
 
-	/* deep copy this information, updating the se_rule fields, because
+	/* deep copy this information, updating the lsm_rule fields, because
 	 * the originals will all be freed when the old rule is freed. */
 	for (i = 0; i < fcount; i++) {
 		switch (new->fields[i].type) {
@@ -1762,7 +1762,7 @@ unlock_and_return:
 	return result;
 }
 
-/* This function will re-initialize the se_rule field of all applicable rules.
+/* This function will re-initialize the lsm_rule field of all applicable rules.
  * It will traverse the filter lists serarching for rules that contain LSM
  * specific filter fields.  When such a rule is found, it is copied, the
  * LSM field is re-initialized, and the old rule is replaced with the
diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index 8afd349..6ac71bb 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -527,14 +527,14 @@ static int audit_filter_rules(struct task_struct *tsk,
 			   match for now to avoid losing information that
 			   may be wanted.   An error message will also be
 			   logged upon error */
-			if (f->se_rule) {
+			if (f->lsm_rule) {
 				if (need_sid) {
 					security_task_getsecid(tsk, &sid);
 					need_sid = 0;
 				}
 				result = security_audit_rule_match(sid, f->type,
 				                                  f->op,
-				                                  f->se_rule,
+				                                  f->lsm_rule,
 				                                  ctx);
 			}
 			break;
@@ -545,18 +545,18 @@ static int audit_filter_rules(struct task_struct *tsk,
 		case AUDIT_OBJ_LEV_HIGH:
 			/* The above note for AUDIT_SUBJ_USER...AUDIT_SUBJ_CLR
 			   also applies here */
-			if (f->se_rule) {
+			if (f->lsm_rule) {
 				/* Find files that match */
 				if (name) {
 					result = security_audit_rule_match(
 					           name->osid, f->type, f->op,
-					           f->se_rule, ctx);
+					           f->lsm_rule, ctx);
 				} else if (ctx) {
 					for (j = 0; j < ctx->name_count; j++) {
 						if (security_audit_rule_match(
 						      ctx->names[j].osid,
 						      f->type, f->op,
-						      f->se_rule, ctx)) {
+						      f->lsm_rule, ctx)) {
 							++result;
 							break;
 						}
@@ -569,7 +569,7 @@ static int audit_filter_rules(struct task_struct *tsk,
 					     aux = aux->next) {
 						if (aux->type == AUDIT_IPC) {
 							struct audit_aux_data_ipcctl *axi = (void *)aux;
-							if (security_audit_rule_match(axi->osid, f->type, f->op, f->se_rule, ctx)) {
+							if (security_audit_rule_match(axi->osid, f->type, f->op, f->lsm_rule, ctx)) {
 								++result;
 								break;
 							}

-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 71%]

* [PATCH 8/9] SELinux: use new audit hooks, remove redundant exports
  2008-03-01 19:47 95% [PATCH-v2 -mm 0/9] LSM-neutral Audit (SELinux audit separation) Ahmed S. Darwish
                   ` (6 preceding siblings ...)
  2008-03-01 20:01 63% ` [PATCH 7/9] Audit: internally use the new LSM audit hooks Ahmed S. Darwish
@ 2008-03-01 20:03 57% ` Ahmed S. Darwish
  2008-03-01 20:05 71% ` [PATCH 9/9] Audit: Final renamings and cleanup Ahmed S. Darwish
  8 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2008-03-01 20:03 UTC (permalink / raw)
  To: Chris Wright, Stephen Smalley, James Morris, Eric Paris,
	Casey Schaufler, David Woodhouse, Paul Moore, Andrew Morton
  Cc: LKML, Audit-ML, LSM-ML

Setup the new Audit LSM hooks for SELinux.
Remove the now redundant exported SELinux Audit interface.

Audit: Export 'audit_krule' and 'audit_field' to the public 
since their internals are needed by the implementation of the
new LSM hook 'audit_rule_known'.

Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

 include/linux/audit.h            |   29 +++++++++++++++
 include/linux/selinux.h          |   72 ---------------------------------------
 kernel/audit.h                   |   25 -------------
 security/selinux/hooks.c         |    8 ++++
 security/selinux/include/audit.h |   65 +++++++++++++++++++++++++++++++++++
 security/selinux/ss/services.c   |   44 +++++++++++++++++------
 6 files changed, 135 insertions(+), 108 deletions(-)

diff --git a/include/linux/selinux.h b/include/linux/selinux.h
index 24b0af1..20f965d 100644
--- a/include/linux/selinux.h
+++ b/include/linux/selinux.h
@@ -21,54 +21,6 @@ struct kern_ipc_perm;
 #ifdef CONFIG_SECURITY_SELINUX
 
 /**
- *	selinux_audit_rule_init - alloc/init an selinux audit rule structure.
- *	@field: the field this rule refers to
- *	@op: the operater the rule uses
- *	@rulestr: the text "target" of the rule
- *	@rule: pointer to the new rule structure returned via this
- *
- *	Returns 0 if successful, -errno if not.  On success, the rule structure
- *	will be allocated internally.  The caller must free this structure with
- *	selinux_audit_rule_free() after use.
- */
-int selinux_audit_rule_init(u32 field, u32 op, char *rulestr,
-                            struct selinux_audit_rule **rule);
-
-/**
- *	selinux_audit_rule_free - free an selinux audit rule structure.
- *	@rule: pointer to the audit rule to be freed
- *
- *	This will free all memory associated with the given rule.
- *	If @rule is NULL, no operation is performed.
- */
-void selinux_audit_rule_free(struct selinux_audit_rule *rule);
-
-/**
- *	selinux_audit_rule_match - determine if a context ID matches a rule.
- *	@sid: the context ID to check
- *	@field: the field this rule refers to
- *	@op: the operater the rule uses
- *	@rule: pointer to the audit rule to check against
- *	@actx: the audit context (can be NULL) associated with the check
- *
- *	Returns 1 if the context id matches the rule, 0 if it does not, and
- *	-errno on failure.
- */
-int selinux_audit_rule_match(u32 sid, u32 field, u32 op,
-                             struct selinux_audit_rule *rule,
-                             struct audit_context *actx);
-
-/**
- *	selinux_audit_set_callback - set the callback for policy reloads.
- *	@callback: the function to call when the policy is reloaded
- *
- *	This sets the function callback function that will update the rules
- *	upon policy reloads.  This callback should rebuild all existing rules
- *	using selinux_audit_rule_init().
- */
-void selinux_audit_set_callback(int (*callback)(void));
-
-/**
  *     selinux_string_to_sid - map a security context string to a security ID
  *     @str: the security context string to be mapped
  *     @sid: ID value returned via this.
@@ -111,30 +63,6 @@ void selinux_secmark_refcount_inc(void);
 void selinux_secmark_refcount_dec(void);
 #else
 
-static inline int selinux_audit_rule_init(u32 field, u32 op,
-                                          char *rulestr,
-                                          struct selinux_audit_rule **rule)
-{
-	return -EOPNOTSUPP;
-}
-
-static inline void selinux_audit_rule_free(struct selinux_audit_rule *rule)
-{
-	return;
-}
-
-static inline int selinux_audit_rule_match(u32 sid, u32 field, u32 op,
-                                           struct selinux_audit_rule *rule,
-                                           struct audit_context *actx)
-{
-	return 0;
-}
-
-static inline void selinux_audit_set_callback(int (*callback)(void))
-{
-	return;
-}
-
 static inline int selinux_string_to_sid(const char *str, u32 *sid)
 {
        *sid = 0;
diff --git a/security/selinux/include/audit.h b/security/selinux/include/audit.h
new file mode 100644
index 0000000..6c8b9ef
--- /dev/null
+++ b/security/selinux/include/audit.h
@@ -0,0 +1,65 @@
+/*
+ * SELinux support for the Audit LSM hooks
+ *
+ * Most of below header was moved from include/linux/selinux.h which 
+ * is released under below copyrights:
+ *
+ * Author: James Morris <jmorris@redhat.com>
+ *
+ * Copyright (C) 2005 Red Hat, Inc., James Morris <jmorris@redhat.com>
+ * Copyright (C) 2006 Trusted Computer Solutions, Inc. <dgoeddel@trustedcs.com>
+ * Copyright (C) 2006 IBM Corporation, Timothy R. Chavez <tinytim@us.ibm.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * as published by the Free Software Foundation.
+ */
+
+#ifndef _SELINUX_AUDIT_H
+#define _SELINUX_AUDIT_H
+
+/**
+ *	selinux_audit_rule_init - alloc/init an selinux audit rule structure.
+ *	@field: the field this rule refers to
+ *	@op: the operater the rule uses
+ *	@rulestr: the text "target" of the rule
+ *	@rule: pointer to the new rule structure returned via this
+ *
+ *	Returns 0 if successful, -errno if not.  On success, the rule structure
+ *	will be allocated internally.  The caller must free this structure with
+ *	selinux_audit_rule_free() after use.
+ */
+int selinux_audit_rule_init(u32 field, u32 op, char *rulestr, void **rule);
+
+/**
+ *	selinux_audit_rule_free - free an selinux audit rule structure.
+ *	@rule: pointer to the audit rule to be freed
+ *
+ *	This will free all memory associated with the given rule.
+ *	If @rule is NULL, no operation is performed.
+ */
+void selinux_audit_rule_free(void *rule);
+
+/**
+ *	selinux_audit_rule_match - determine if a context ID matches a rule.
+ *	@sid: the context ID to check
+ *	@field: the field this rule refers to
+ *	@op: the operater the rule uses
+ *	@rule: pointer to the audit rule to check against
+ *	@actx: the audit context (can be NULL) associated with the check
+ *
+ *	Returns 1 if the context id matches the rule, 0 if it does not, and
+ *	-errno on failure.
+ */
+int selinux_audit_rule_match(u32 sid, u32 field, u32 op, void *rule,
+                             struct audit_context *actx);
+
+/**
+ *	selinux_audit_rule_known - check to see if rule contains selinux fields.
+ *	@rule: rule to be checked
+ *	Returns 1 if there are selinux fields specified in the rule, 0 otherwise.
+ */
+int selinux_audit_rule_known(struct audit_krule *krule);
+
+#endif /* _SELINUX_AUDIT_H */
+
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 06597d7..bef1834 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -82,6 +82,7 @@
 #include "netnode.h"
 #include "xfrm.h"
 #include "netlabel.h"
+#include "audit.h"
 
 #define XATTR_SELINUX_SUFFIX "selinux"
 #define XATTR_NAME_SELINUX XATTR_SECURITY_PREFIX XATTR_SELINUX_SUFFIX
@@ -5429,6 +5430,13 @@ static struct security_operations selinux_ops = {
 	.key_permission =		selinux_key_permission,
 	.key_getsecurity =		selinux_key_getsecurity,
 #endif
+
+#ifdef CONFIG_AUDIT
+	.audit_rule_init =		selinux_audit_rule_init,
+	.audit_rule_known =		selinux_audit_rule_known,
+	.audit_rule_match =		selinux_audit_rule_match,
+	.audit_rule_free =		selinux_audit_rule_free,
+#endif
 };
 
 static __init int selinux_init(void)
diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
index f374186..7094623 100644
--- a/security/selinux/ss/services.c
+++ b/security/selinux/ss/services.c
@@ -56,6 +56,7 @@
 #include "netlabel.h"
 #include "xfrm.h"
 #include "ebitmap.h"
+#include "audit.h"
 
 extern void selnl_notify_policyload(u32 seqno);
 unsigned int policydb_loaded_version;
@@ -2271,21 +2272,23 @@ struct selinux_audit_rule {
 	struct context au_ctxt;
 };
 
-void selinux_audit_rule_free(struct selinux_audit_rule *rule)
+void selinux_audit_rule_free(void *vrule)
 {
+	struct selinux_audit_rule *rule = vrule;
+
 	if (rule) {
 		context_destroy(&rule->au_ctxt);
 		kfree(rule);
 	}
 }
 
-int selinux_audit_rule_init(u32 field, u32 op, char *rulestr,
-                            struct selinux_audit_rule **rule)
+int selinux_audit_rule_init(u32 field, u32 op, char *rulestr, void **vrule)
 {
 	struct selinux_audit_rule *tmprule;
 	struct role_datum *roledatum;
 	struct type_datum *typedatum;
 	struct user_datum *userdatum;
+	struct selinux_audit_rule **rule = (struct selinux_audit_rule **)vrule;
 	int rc = 0;
 
 	*rule = NULL;
@@ -2372,12 +2375,37 @@ int selinux_audit_rule_init(u32 field, u32 op, char *rulestr,
 	return rc;
 }
 
-int selinux_audit_rule_match(u32 sid, u32 field, u32 op,
-                             struct selinux_audit_rule *rule,
+/* Check to see if the rule contains any selinux fields */
+int selinux_audit_rule_known(struct audit_krule *rule)
+{
+	int i;
+
+	for (i = 0; i < rule->field_count; i++) {
+		struct audit_field *f = &rule->fields[i];
+		switch (f->type) {
+		case AUDIT_SUBJ_USER:
+		case AUDIT_SUBJ_ROLE:
+		case AUDIT_SUBJ_TYPE:
+		case AUDIT_SUBJ_SEN:
+		case AUDIT_SUBJ_CLR:
+		case AUDIT_OBJ_USER:
+		case AUDIT_OBJ_ROLE:
+		case AUDIT_OBJ_TYPE:
+		case AUDIT_OBJ_LEV_LOW:
+		case AUDIT_OBJ_LEV_HIGH:
+			return 1;
+		}
+	}
+
+	return 0;
+}
+
+int selinux_audit_rule_match(u32 sid, u32 field, u32 op, void *vrule,
                              struct audit_context *actx)
 {
 	struct context *ctxt;
 	struct mls_level *level;
+	struct selinux_audit_rule *rule = vrule;
 	int match = 0;
 
 	if (!rule) {
@@ -2484,7 +2512,7 @@ out:
 	return match;
 }
 
-static int (*aurule_callback)(void) = NULL;
+static int (*aurule_callback)(void) = audit_update_lsm_rules;
 
 static int aurule_avc_callback(u32 event, u32 ssid, u32 tsid,
                                u16 class, u32 perms, u32 *retained)
@@ -2509,11 +2537,6 @@ static int __init aurule_init(void)
 }
 __initcall(aurule_init);
 
-void selinux_audit_set_callback(int (*callback)(void))
-{
-	aurule_callback = callback;
-}
-
 #ifdef CONFIG_NETLABEL
 /**
  * security_netlbl_cache_add - Add an entry to the NetLabel cache
diff --git a/kernel/audit.h b/kernel/audit.h
index 2554bd5..3cfc54e 100644
--- a/kernel/audit.h
+++ b/kernel/audit.h
@@ -65,34 +65,9 @@ struct audit_watch {
 	struct list_head	rules;	/* associated rules */
 };
 
-struct audit_field {
-	u32				type;
-	u32				val;
-	u32				op;
-	char				*se_str;
-	struct selinux_audit_rule	*se_rule;
-};
-
 struct audit_tree;
 struct audit_chunk;
 
-struct audit_krule {
-	int			vers_ops;
-	u32			flags;
-	u32			listnr;
-	u32			action;
-	u32			mask[AUDIT_BITMASK_SIZE];
-	u32			buflen; /* for data alloc on list rules */
-	u32			field_count;
-	char			*filterkey; /* ties events to rules */
-	struct audit_field	*fields;
-	struct audit_field	*arch_f; /* quick access to arch field */
-	struct audit_field	*inode_f; /* quick access to an inode field */
-	struct audit_watch	*watch;	/* associated watch */
-	struct audit_tree	*tree;	/* associated watched tree */
-	struct list_head	rlist;	/* entry in audit_{watch,tree}.rules list */
-};
-
 struct audit_entry {
 	struct list_head	list;
 	struct rcu_head		rcu;
diff --git a/include/linux/audit.h b/include/linux/audit.h
index 2af9ec0..3367c80 100644
--- a/include/linux/audit.h
+++ b/include/linux/audit.h
@@ -353,6 +353,33 @@ struct netlink_skb_parms;
 struct linux_binprm;
 struct mq_attr;
 struct mqstat;
+struct audit_watch;
+struct audit_tree;
+
+struct audit_krule {
+	int			vers_ops;
+	u32			flags;
+	u32			listnr;
+	u32			action;
+	u32			mask[AUDIT_BITMASK_SIZE];
+	u32			buflen; /* for data alloc on list rules */
+	u32			field_count;
+	char			*filterkey; /* ties events to rules */
+	struct audit_field	*fields;
+	struct audit_field	*arch_f; /* quick access to arch field */
+	struct audit_field	*inode_f; /* quick access to an inode field */
+	struct audit_watch	*watch;	/* associated watch */
+	struct audit_tree	*tree;	/* associated watched tree */
+	struct list_head	rlist;	/* entry in audit_{watch,tree}.rules list */
+};
+
+struct audit_field {
+	u32				type;
+	u32				val;
+	u32				op;
+	char				*se_str;
+	void				*se_rule;
+};
 
 #define AUDITSC_INVALID 0
 #define AUDITSC_SUCCESS 1
@@ -536,6 +563,8 @@ extern void		    audit_log_d_path(struct audit_buffer *ab,
 					     const char *prefix,
 					     struct path *path);
 extern void		    audit_log_lost(const char *message);
+extern int		    audit_update_lsm_rules(void);
+		    
 				/* Private API (for audit.c only) */
 extern int audit_filter_user(struct netlink_skb_parms *cb, int type);
 extern int audit_filter_type(int type);

-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 57%]

* [PATCH 7/9] Audit: internally use the new LSM audit hooks
  2008-03-01 19:47 95% [PATCH-v2 -mm 0/9] LSM-neutral Audit (SELinux audit separation) Ahmed S. Darwish
                   ` (5 preceding siblings ...)
  2008-03-01 20:00 75% ` [PATCH 6/9] LSM/Audit: Introduce generic Audit LSM hooks Ahmed S. Darwish
@ 2008-03-01 20:01 63% ` Ahmed S. Darwish
    2008-03-01 20:03 57% ` [PATCH 8/9] SELinux: use new audit hooks, remove redundant exports Ahmed S. Darwish
  2008-03-01 20:05 71% ` [PATCH 9/9] Audit: Final renamings and cleanup Ahmed S. Darwish
  8 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2008-03-01 20:01 UTC (permalink / raw)
  To: Chris Wright, Stephen Smalley, James Morris, Eric Paris,
	Casey Schaufler, David Woodhouse, Paul Moore, Andrew Morton
  Cc: LKML, Audit-ML, LSM-ML

Convert Audit to use the new LSM Audit hooks instead of
the exported SELinux interface.

Basically, use:
security_audit_rule_init
secuirty_audit_rule_free
security_audit_rule_known
security_audit_rule_match

instad of (respectively) :
selinux_audit_rule_init
selinux_audit_rule_free
audit_rule_has_selinux
selinux_audit_rule_match

Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

 audit.c       |    7 ------
 auditfilter.c |   61 ++++++++++++++++------------------------------------------
 auditsc.c     |    9 +++-----
 3 files changed, 22 insertions(+), 55 deletions(-)

Andrew, please atomically merge patch #7 and patch #8. Although
a system with patch7 and without patch8 will be compiled fine,
the SELinux Audit hooks are not set up yet. This means below
audit hooks will point to the dummy hooks instead of SELinux
ones even if SELinux is enabled.

I could not setup the SELinux hooks first cause they have
the same name of the old exported SELinux interface with a 
difference of one parameter.

Thanks!

diff --git a/kernel/audit.c b/kernel/audit.c
index d79f866..40c3507 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -21,7 +21,7 @@
  *
  * Written by Rickard E. (Rik) Faith <faith@redhat.com>
  *
- * Goals: 1) Integrate fully with SELinux.
+ * Goals: 1) Integrate fully with Security Modules.
  *	  2) Minimal run-time overhead:
  *	     a) Minimal when syscall auditing is disabled (audit_enable=0).
  *	     b) Small when syscall auditing is enabled and no audit record
@@ -55,7 +55,6 @@
 #include <net/netlink.h>
 #include <linux/skbuff.h>
 #include <linux/netlink.h>
-#include <linux/selinux.h>
 #include <linux/inotify.h>
 #include <linux/freezer.h>
 #include <linux/tty.h>
@@ -874,10 +873,6 @@ static int __init audit_init(void)
 	audit_enabled = audit_default;
 	audit_ever_enabled |= !!audit_default;
 
-	/* Register the callback with selinux.  This callback will be invoked
-	 * when a new policy is loaded. */
-	selinux_audit_set_callback(&selinux_audit_rule_update);
-
 	audit_log(NULL, GFP_KERNEL, AUDIT_KERNEL, "initialized");
 
 #ifdef CONFIG_AUDITSYSCALL
diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c
index 35e58a1..7c69cb5 100644
--- a/kernel/auditfilter.c
+++ b/kernel/auditfilter.c
@@ -29,7 +29,6 @@
 #include <linux/sched.h>
 #include <linux/inotify.h>
 #include <linux/security.h>
-#include <linux/selinux.h>
 #include "audit.h"
 
 /*
@@ -39,7 +38,7 @@
  * 		Synchronizes writes and blocking reads of audit's filterlist
  * 		data.  Rcu is used to traverse the filterlist and access
  * 		contents of structs audit_entry, audit_watch and opaque
- * 		selinux rules during filtering.  If modified, these structures
+ * 		LSM rules during filtering.  If modified, these structures
  * 		must be copied and replace their counterparts in the filterlist.
  * 		An audit_parent struct is not accessed during filtering, so may
  * 		be written directly provided audit_filter_mutex is held.
@@ -141,7 +140,7 @@ static inline void audit_free_rule(struct audit_entry *e)
 		for (i = 0; i < e->rule.field_count; i++) {
 			struct audit_field *f = &e->rule.fields[i];
 			kfree(f->se_str);
-			selinux_audit_rule_free(f->se_rule);
+			security_audit_rule_free(f->se_rule);
 		}
 	kfree(e->rule.fields);
 	kfree(e->rule.filterkey);
@@ -598,12 +597,12 @@ static struct audit_entry *audit_data_to_entry(struct audit_rule_data *data,
 				goto exit_free;
 			entry->rule.buflen += f->val;
 
-			err = selinux_audit_rule_init(f->type, f->op, str,
-						      &f->se_rule);
+			err = security_audit_rule_init(f->type, f->op, str,
+						       (void **)&f->se_rule);
 			/* Keep currently invalid fields around in case they
 			 * become valid after a policy reload. */
 			if (err == -EINVAL) {
-				printk(KERN_WARNING "audit rule for selinux "
+				printk(KERN_WARNING "audit rule for LSM "
 				       "\'%s\' is invalid\n",  str);
 				err = 0;
 			}
@@ -863,9 +862,9 @@ out:
 	return new;
 }
 
-/* Duplicate selinux field information.  The se_rule is opaque, so must be
+/* Duplicate LSM field information.  The se_rule is opaque, so must be
  * re-initialized. */
-static inline int audit_dupe_selinux_field(struct audit_field *df,
+static inline int audit_dupe_lsm_field(struct audit_field *df,
 					   struct audit_field *sf)
 {
 	int ret = 0;
@@ -878,12 +877,12 @@ static inline int audit_dupe_selinux_field(struct audit_field *df,
 	df->se_str = se_str;
 
 	/* our own (refreshed) copy of se_rule */
-	ret = selinux_audit_rule_init(df->type, df->op, df->se_str,
-				      &df->se_rule);
+	ret = security_audit_rule_init(df->type, df->op, df->se_str,
+				       (void **)&df->se_rule);
 	/* Keep currently invalid fields around in case they
 	 * become valid after a policy reload. */
 	if (ret == -EINVAL) {
-		printk(KERN_WARNING "audit rule for selinux \'%s\' is "
+		printk(KERN_WARNING "audit rule for LSM \'%s\' is "
 		       "invalid\n", df->se_str);
 		ret = 0;
 	}
@@ -892,7 +891,7 @@ static inline int audit_dupe_selinux_field(struct audit_field *df,
 }
 
 /* Duplicate an audit rule.  This will be a deep copy with the exception
- * of the watch - that pointer is carried over.  The selinux specific fields
+ * of the watch - that pointer is carried over.  The LSM specific fields
  * will be updated in the copy.  The point is to be able to replace the old
  * rule with the new rule in the filterlist, then free the old rule.
  * The rlist element is undefined; list manipulations are handled apart from
@@ -945,7 +944,7 @@ static struct audit_entry *audit_dupe_rule(struct audit_krule *old,
 		case AUDIT_OBJ_TYPE:
 		case AUDIT_OBJ_LEV_LOW:
 		case AUDIT_OBJ_LEV_HIGH:
-			err = audit_dupe_selinux_field(&new->fields[i],
+			err = audit_dupe_lsm_field(&new->fields[i],
 						       &old->fields[i]);
 			break;
 		case AUDIT_FILTERKEY:
@@ -1763,38 +1762,12 @@ unlock_and_return:
 	return result;
 }
 
-/* Check to see if the rule contains any selinux fields.  Returns 1 if there
-   are selinux fields specified in the rule, 0 otherwise. */
-static inline int audit_rule_has_selinux(struct audit_krule *rule)
-{
-	int i;
-
-	for (i = 0; i < rule->field_count; i++) {
-		struct audit_field *f = &rule->fields[i];
-		switch (f->type) {
-		case AUDIT_SUBJ_USER:
-		case AUDIT_SUBJ_ROLE:
-		case AUDIT_SUBJ_TYPE:
-		case AUDIT_SUBJ_SEN:
-		case AUDIT_SUBJ_CLR:
-		case AUDIT_OBJ_USER:
-		case AUDIT_OBJ_ROLE:
-		case AUDIT_OBJ_TYPE:
-		case AUDIT_OBJ_LEV_LOW:
-		case AUDIT_OBJ_LEV_HIGH:
-			return 1;
-		}
-	}
-
-	return 0;
-}
-
 /* This function will re-initialize the se_rule field of all applicable rules.
- * It will traverse the filter lists serarching for rules that contain selinux
+ * It will traverse the filter lists serarching for rules that contain LSM
  * specific filter fields.  When such a rule is found, it is copied, the
- * selinux field is re-initialized, and the old rule is replaced with the
+ * LSM field is re-initialized, and the old rule is replaced with the
  * updated rule. */
-int selinux_audit_rule_update(void)
+int audit_update_lsm_rules(void)
 {
 	struct audit_entry *entry, *n, *nentry;
 	struct audit_watch *watch;
@@ -1806,7 +1779,7 @@ int selinux_audit_rule_update(void)
 
 	for (i = 0; i < AUDIT_NR_FILTERS; i++) {
 		list_for_each_entry_safe(entry, n, &audit_filter_list[i], list) {
-			if (!audit_rule_has_selinux(&entry->rule))
+			if (!security_audit_rule_known(&entry->rule))
 				continue;
 
 			watch = entry->rule.watch;
@@ -1817,7 +1790,7 @@ int selinux_audit_rule_update(void)
 				 * return value */
 				if (!err)
 					err = PTR_ERR(nentry);
-				audit_panic("error updating selinux filters");
+				audit_panic("error updating LSM filters");
 				if (watch)
 					list_del(&entry->rule.rlist);
 				list_del_rcu(&entry->list);
diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index a9fc9dd..8afd349 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -61,7 +61,6 @@
 #include <linux/security.h>
 #include <linux/list.h>
 #include <linux/tty.h>
-#include <linux/selinux.h>
 #include <linux/binfmts.h>
 #include <linux/highmem.h>
 #include <linux/syscalls.h>
@@ -533,7 +532,7 @@ static int audit_filter_rules(struct task_struct *tsk,
 					security_task_getsecid(tsk, &sid);
 					need_sid = 0;
 				}
-				result = selinux_audit_rule_match(sid, f->type,
+				result = security_audit_rule_match(sid, f->type,
 				                                  f->op,
 				                                  f->se_rule,
 				                                  ctx);
@@ -549,12 +548,12 @@ static int audit_filter_rules(struct task_struct *tsk,
 			if (f->se_rule) {
 				/* Find files that match */
 				if (name) {
-					result = selinux_audit_rule_match(
+					result = security_audit_rule_match(
 					           name->osid, f->type, f->op,
 					           f->se_rule, ctx);
 				} else if (ctx) {
 					for (j = 0; j < ctx->name_count; j++) {
-						if (selinux_audit_rule_match(
+						if (security_audit_rule_match(
 						      ctx->names[j].osid,
 						      f->type, f->op,
 						      f->se_rule, ctx)) {
@@ -570,7 +569,7 @@ static int audit_filter_rules(struct task_struct *tsk,
 					     aux = aux->next) {
 						if (aux->type == AUDIT_IPC) {
 							struct audit_aux_data_ipcctl *axi = (void *)aux;
-							if (selinux_audit_rule_match(axi->osid, f->type, f->op, f->se_rule, ctx)) {
+							if (security_audit_rule_match(axi->osid, f->type, f->op, f->se_rule, ctx)) {
 								++result;
 								break;
 							}

-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 63%]

* [PATCH 6/9] LSM/Audit: Introduce generic Audit LSM hooks
  2008-03-01 19:47 95% [PATCH-v2 -mm 0/9] LSM-neutral Audit (SELinux audit separation) Ahmed S. Darwish
                   ` (4 preceding siblings ...)
  2008-03-01 19:58 81% ` [PATCH 5/9] SELinux: remove redundant exports Ahmed S. Darwish
@ 2008-03-01 20:00 75% ` Ahmed S. Darwish
  2008-03-01 20:01 63% ` [PATCH 7/9] Audit: internally use the new LSM audit hooks Ahmed S. Darwish
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2008-03-01 20:00 UTC (permalink / raw)
  To: Chris Wright, Stephen Smalley, James Morris, Eric Paris,
	Casey Schaufler, David Woodhouse, Paul Moore, Andrew Morton
  Cc: LKML, Audit-ML, LSM-ML

Introduce a generic Audit interface for security modules
by adding the following new LSM hooks:

audit_rule_init(field, op, rulestr, lsmrule)
audit_rule_known(krule)
audit_rule_match(secid, field, op, rule, actx)
audit_rule_free(rule)

Those hooks are only available if CONFIG_AUDIT is enabled.

Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

 include/linux/security.h |   72 +++++++++++++++++++++++++++++++++++++++++++++++
 security/dummy.c         |   31 +++++++++++++++++++-
 security/security.c      |   25 ++++++++++++++++
 3 files changed, 127 insertions(+), 1 deletion(-)

diff --git a/include/linux/security.h b/include/linux/security.h
index b5d1ad7..eb663e5 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -43,6 +43,7 @@
 extern unsigned securebits;
 
 struct ctl_table;
+struct audit_krule;
 
 /*
  * These functions are in security/capability.c and are used
@@ -1227,6 +1228,37 @@ struct request_sock;
  *	@secdata contains the security context.
  *	@seclen contains the length of the security context.
  *
+ * Security hooks for Audit
+ *
+ * @audit_rule_init:
+ *	Allocate and initialize an LSM audit rule structure.
+ *	@field contains the required Audit action. Fields flags are defined in include/linux/audit.h
+ *	@op contains the operator the rule uses.
+ *	@rulestr contains the context where the rule will be applied to.
+ *	@lsmrule contains a pointer to receive the result.
+ *	Return 0 if @lsmrule has been successfully set,
+ *	-EINVAL in case of an invalid rule.
+ *
+ * @audit_rule_known:
+ *	Specifies whether given @rule contains any fields related to current LSM.
+ *	@rule contains the audit rule of interest.
+ *	Return 1 in case of relation found, 0 otherwise.
+ *
+ * @audit_rule_match:
+ *	Determine if given @secid matches a rule previously approved
+ *	by @audit_rule_known.
+ *	@secid contains the security id in question.
+ *	@field contains the field which relates to current LSM.
+ *	@op contains the operator that will be used for matching.
+ *	@rule points to the audit rule that will be checked against.
+ *	@actx points to the audit context associated with the check.
+ *	Return 1 if secid matches the rule, 0 if it does not, -ERRNO on failure.
+ *
+ * @audit_rule_free:
+ *	Deallocate the LSM audit rule structure previously allocated by
+ *	audit_rule_init.
+ *	@rule contains the allocated rule
+ *
  * This is the main security structure.
  */
 struct security_operations {
@@ -1487,6 +1519,13 @@ struct security_operations {
 	int (*key_getsecurity)(struct key *key, char **_buffer);
 #endif	/* CONFIG_KEYS */
 
+#ifdef CONFIG_AUDIT
+	int (*audit_rule_init)(u32 field, u32 op, char *rulestr, void **lsmrule);
+	int (*audit_rule_known)(struct audit_krule *krule);
+	int (*audit_rule_match)(u32 secid, u32 field, u32 op, void *lsmrule,
+				struct audit_context *actx);
+	void (*audit_rule_free)(void *lsmrule);
+#endif /* CONFIG_AUDIT */
 };
 
 /* prototypes */
@@ -2670,5 +2709,38 @@ static inline int security_key_getsecurity(struct key *key, char **_buffer)
 #endif
 #endif /* CONFIG_KEYS */
 
+#ifdef CONFIG_AUDIT
+#ifdef CONFIG_SECURITY
+int security_audit_rule_init(u32 field, u32 op, char *rulestr, void **lsmrule);
+int security_audit_rule_known(struct audit_krule *krule);
+int security_audit_rule_match(u32 secid, u32 field, u32 op, void *lsmrule,
+			      struct audit_context *actx);
+void security_audit_rule_free(void *lsmrule);
+
+#else
+
+static inline int security_audit_rule_init(u32 field, u32 op, char *rulestr,
+					   void **lsmrule)
+{
+	return 0;
+}
+
+static inline int security_audit_rule_known(struct audit_krule *krule)
+{
+	return 0;
+}
+
+static inline int security_audit_rule_match(u32 secid, u32 field, u32 op,
+				   void *lsmrule, struct audit_context *actx)
+{
+	return 0;
+}
+
+static inline void security_audit_rule_free(void *lsmrule)
+{ }
+
+#endif /* CONFIG_SECURITY */
+#endif /* CONFIG_AUDIT */
+
 #endif /* ! __LINUX_SECURITY_H */
 
diff --git a/security/dummy.c b/security/dummy.c
index b4967f4..241ab20 100644
--- a/security/dummy.c
+++ b/security/dummy.c
@@ -998,6 +998,30 @@ static int dummy_key_getsecurity(struct key *key, char **_buffer)
 
 #endif /* CONFIG_KEYS */
 
+#ifdef CONFIG_AUDIT
+static inline int dummy_audit_rule_init(u32 field, u32 op, char *rulestr,
+					void **lsmrule)
+{
+	return 0;
+}
+
+static inline int dummy_audit_rule_known(struct audit_krule *krule)
+{
+	return 0;
+}
+
+static inline int dummy_audit_rule_match(u32 secid, u32 field, u32 op,
+					 void *lsmrule,
+					 struct audit_context *actx)
+{
+	return 0;
+}
+
+static inline void dummy_audit_rule_free(void *lsmrule)
+{ }
+
+#endif /* CONFIG_AUDIT */
+
 struct security_operations dummy_security_ops;
 
 #define set_to_dummy_if_null(ops, function)				\
@@ -1187,6 +1211,11 @@ void security_fixup_ops (struct security_operations *ops)
 	set_to_dummy_if_null(ops, key_permission);
 	set_to_dummy_if_null(ops, key_getsecurity);
 #endif	/* CONFIG_KEYS */
-
+#ifdef CONFIG_AUDIT
+	set_to_dummy_if_null(ops, audit_rule_init);
+	set_to_dummy_if_null(ops, audit_rule_known);
+	set_to_dummy_if_null(ops, audit_rule_match);
+	set_to_dummy_if_null(ops, audit_rule_free);
+#endif
 }
 
diff --git a/security/security.c b/security/security.c
index 1748329..1bf2ee4 100644
--- a/security/security.c
+++ b/security/security.c
@@ -1118,3 +1118,28 @@ int security_key_getsecurity(struct key *key, char **_buffer)
 }
 
 #endif	/* CONFIG_KEYS */
+
+#ifdef CONFIG_AUDIT
+
+int security_audit_rule_init(u32 field, u32 op, char *rulestr, void **lsmrule)
+{
+	return security_ops->audit_rule_init(field, op, rulestr, lsmrule);
+}
+
+int security_audit_rule_known(struct audit_krule *krule)
+{
+	return security_ops->audit_rule_known(krule);
+}
+
+void security_audit_rule_free(void *lsmrule)
+{
+	security_ops->audit_rule_free(lsmrule);
+}
+
+int security_audit_rule_match(u32 secid, u32 field, u32 op, void *lsmrule,
+			      struct audit_context *actx)
+{
+	return security_ops->audit_rule_match(secid, field, op, lsmrule, actx);
+}
+
+#endif /* CONFIG_AUDIT */

-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 75%]

* [PATCH 5/9] SELinux: remove redundant exports
  2008-03-01 19:47 95% [PATCH-v2 -mm 0/9] LSM-neutral Audit (SELinux audit separation) Ahmed S. Darwish
                   ` (3 preceding siblings ...)
  2008-03-01 19:56 98% ` [PATCH 4/9] Netlink: Use generic LSM hook Ahmed S. Darwish
@ 2008-03-01 19:58 81% ` Ahmed S. Darwish
  2008-03-01 20:00 75% ` [PATCH 6/9] LSM/Audit: Introduce generic Audit LSM hooks Ahmed S. Darwish
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2008-03-01 19:58 UTC (permalink / raw)
  To: Chris Wright, Stephen Smalley, James Morris, Eric Paris,
	Casey Schaufler, David Woodhouse, Paul Moore, Andrew Morton
  Cc: LKML, Audit-ML, LSM-ML

Remove the following exported SELinux interfaces:
selinux_get_inode_sid(inode, sid)
selinux_get_ipc_sid(ipcp, sid) 
selinux_get_task_sid(tsk, sid)
selinux_sid_to_string(sid, ctx, len)

They can be substitued with the following generic equivalents 
respectively:
new LSM hook, inode_getsecid(inode, secid)
new LSM hook, ipc_getsecid*(ipcp, secid)
LSM hook, task_getsecid(tsk, secid)
LSM hook, sid_to_secctx(sid, ctx, len)

Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

 include/linux/selinux.h    |   62 ---------------------------------------------
 security/selinux/exports.c |   42 ------------------------------
 2 files changed, 104 deletions(-)

diff --git a/include/linux/selinux.h b/include/linux/selinux.h
index 8c2cc4c..24b0af1 100644
--- a/include/linux/selinux.h
+++ b/include/linux/selinux.h
@@ -16,7 +16,6 @@
 
 struct selinux_audit_rule;
 struct audit_context;
-struct inode;
 struct kern_ipc_perm;
 
 #ifdef CONFIG_SECURITY_SELINUX
@@ -70,45 +69,6 @@ int selinux_audit_rule_match(u32 sid, u32 field, u32 op,
 void selinux_audit_set_callback(int (*callback)(void));
 
 /**
- *     selinux_sid_to_string - map a security context ID to a string
- *     @sid: security context ID to be converted.
- *     @ctx: address of context string to be returned
- *     @ctxlen: length of returned context string.
- *
- *     Returns 0 if successful, -errno if not.  On success, the context
- *     string will be allocated internally, and the caller must call
- *     kfree() on it after use.
- */
-int selinux_sid_to_string(u32 sid, char **ctx, u32 *ctxlen);
-
-/**
- *     selinux_get_inode_sid - get the inode's security context ID
- *     @inode: inode structure to get the sid from.
- *     @sid: pointer to security context ID to be filled in.
- *
- *     Returns nothing
- */
-void selinux_get_inode_sid(const struct inode *inode, u32 *sid);
-
-/**
- *     selinux_get_ipc_sid - get the ipc security context ID
- *     @ipcp: ipc structure to get the sid from.
- *     @sid: pointer to security context ID to be filled in.
- *
- *     Returns nothing
- */
-void selinux_get_ipc_sid(const struct kern_ipc_perm *ipcp, u32 *sid);
-
-/**
- *     selinux_get_task_sid - return the SID of task
- *     @tsk: the task whose SID will be returned
- *     @sid: pointer to security context ID to be filled in.
- *
- *     Returns nothing
- */
-void selinux_get_task_sid(struct task_struct *tsk, u32 *sid);
-
-/**
  *     selinux_string_to_sid - map a security context string to a security ID
  *     @str: the security context string to be mapped
  *     @sid: ID value returned via this.
@@ -175,28 +135,6 @@ static inline void selinux_audit_set_callback(int (*callback)(void))
 	return;
 }
 
-static inline int selinux_sid_to_string(u32 sid, char **ctx, u32 *ctxlen)
-{
-       *ctx = NULL;
-       *ctxlen = 0;
-       return 0;
-}
-
-static inline void selinux_get_inode_sid(const struct inode *inode, u32 *sid)
-{
-	*sid = 0;
-}
-
-static inline void selinux_get_ipc_sid(const struct kern_ipc_perm *ipcp, u32 *sid)
-{
-	*sid = 0;
-}
-
-static inline void selinux_get_task_sid(struct task_struct *tsk, u32 *sid)
-{
-	*sid = 0;
-}
-
 static inline int selinux_string_to_sid(const char *str, u32 *sid)
 {
        *sid = 0;
diff --git a/security/selinux/exports.c b/security/selinux/exports.c
index 87d2bb3..64af2d3 100644
--- a/security/selinux/exports.c
+++ b/security/selinux/exports.c
@@ -25,48 +25,6 @@
 /* SECMARK reference count */
 extern atomic_t selinux_secmark_refcount;
 
-int selinux_sid_to_string(u32 sid, char **ctx, u32 *ctxlen)
-{
-	if (selinux_enabled)
-		return security_sid_to_context(sid, ctx, ctxlen);
-	else {
-		*ctx = NULL;
-		*ctxlen = 0;
-	}
-
-	return 0;
-}
-
-void selinux_get_inode_sid(const struct inode *inode, u32 *sid)
-{
-	if (selinux_enabled) {
-		struct inode_security_struct *isec = inode->i_security;
-		*sid = isec->sid;
-		return;
-	}
-	*sid = 0;
-}
-
-void selinux_get_ipc_sid(const struct kern_ipc_perm *ipcp, u32 *sid)
-{
-	if (selinux_enabled) {
-		struct ipc_security_struct *isec = ipcp->security;
-		*sid = isec->sid;
-		return;
-	}
-	*sid = 0;
-}
-
-void selinux_get_task_sid(struct task_struct *tsk, u32 *sid)
-{
-	if (selinux_enabled) {
-		struct task_security_struct *tsec = tsk->security;
-		*sid = tsec->sid;
-		return;
-	}
-	*sid = 0;
-}
-
 int selinux_string_to_sid(char *str, u32 *sid)
 {
 	if (selinux_enabled)

-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 81%]

* [PATCH 4/9] Netlink: Use generic LSM hook
  2008-03-01 19:47 95% [PATCH-v2 -mm 0/9] LSM-neutral Audit (SELinux audit separation) Ahmed S. Darwish
                   ` (2 preceding siblings ...)
  2008-03-01 19:54 67% ` [PATCH 3/9] Audit: use new LSM hooks instead of SELinux exports Ahmed S. Darwish
@ 2008-03-01 19:56 98% ` Ahmed S. Darwish
  2008-03-01 19:58 81% ` [PATCH 5/9] SELinux: remove redundant exports Ahmed S. Darwish
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2008-03-01 19:56 UTC (permalink / raw)
  To: Chris Wright, Stephen Smalley, James Morris, Eric Paris,
	Casey Schaufler, David Woodhouse, Paul Moore, Andrew Morton
  Cc: LKML, Audit-ML, LSM-ML

Don't use SELinux exported selinux_get_task_sid symbol. 
Use the generic LSM equivalent instead.

Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 1ab0da2..61fd277 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -54,7 +54,6 @@
 #include <linux/mm.h>
 #include <linux/types.h>
 #include <linux/audit.h>
-#include <linux/selinux.h>
 #include <linux/mutex.h>
 
 #include <net/net_namespace.h>
@@ -1239,7 +1238,7 @@ static int netlink_sendmsg(struct kiocb *kiocb, struct socket *sock,
 	NETLINK_CB(skb).pid	= nlk->pid;
 	NETLINK_CB(skb).dst_group = dst_group;
 	NETLINK_CB(skb).loginuid = audit_get_loginuid(current);
-	selinux_get_task_sid(current, &(NETLINK_CB(skb).sid));
+	security_task_getsecid(current, &(NETLINK_CB(skb).sid));
 	memcpy(NETLINK_CREDS(skb), &siocb->scm->creds, sizeof(struct ucred));
 
 	/* What can I do? Netlink is asynchronous, so that

-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 98%]

* [PATCH 3/9] Audit: use new LSM hooks instead of SELinux exports
  2008-03-01 19:47 95% [PATCH-v2 -mm 0/9] LSM-neutral Audit (SELinux audit separation) Ahmed S. Darwish
  2008-03-01 19:51 70% ` [PATCH 1/9] LSM: Introduce inode_getsecid and ipc_getsecid hooks Ahmed S. Darwish
  2008-03-01 19:52 93% ` [PATCH 2/9] SELinux: setup new inode/ipc getsecid hooks Ahmed S. Darwish
@ 2008-03-01 19:54 67% ` Ahmed S. Darwish
  2008-03-01 19:56 98% ` [PATCH 4/9] Netlink: Use generic LSM hook Ahmed S. Darwish
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2008-03-01 19:54 UTC (permalink / raw)
  To: Chris Wright, Stephen Smalley, James Morris, Eric Paris,
	Casey Schaufler, David Woodhouse, Paul Moore, Andrew Morton
  Cc: LKML, Audit-ML, LSM-ML

Stop using the following exported SELinux interfaces:
selinux_get_inode_sid(inode, sid)
selinux_get_ipc_sid(ipcp, sid) 
selinux_get_task_sid(tsk, sid)
selinux_sid_to_string(sid, ctx, len)
kfree(ctx)

and use following generic LSM equivalents respectively:
security_inode_getsecid(inode, secid)
security_ipc_getsecid*(ipcp, secid)
security_task_getsecid(tsk, secid)
security_sid_to_secctx(sid, ctx, len)
security_release_secctx(ctx, len)

Call security_release_secctx only if security_secid_to_secctx
succeeded.

Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

 audit.c       |   17 +++++++++--------
 auditfilter.c |    8 +++++---
 auditsc.c     |   55 +++++++++++++++++++++++++++++--------------------------
 3 files changed, 43 insertions(+), 37 deletions(-)

diff --git a/kernel/audit.c b/kernel/audit.c
index 8316a88..d79f866 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -259,13 +259,13 @@ static int audit_log_config_change(char *function_name, int new, int old,
 		char *ctx = NULL;
 		u32 len;
 
-		rc = selinux_sid_to_string(sid, &ctx, &len);
+		rc = security_secid_to_secctx(sid, &ctx, &len);
 		if (rc) {
 			audit_log_format(ab, " sid=%u", sid);
 			allow_changes = 0; /* Something weird, deny request */
 		} else {
 			audit_log_format(ab, " subj=%s", ctx);
-			kfree(ctx);
+			security_release_secctx(ctx, len);
 		}
 	}
 	audit_log_format(ab, " res=%d", allow_changes);
@@ -543,12 +543,13 @@ static int audit_log_common_recv_msg(struct audit_buffer **ab, u16 msg_type,
 	audit_log_format(*ab, "user pid=%d uid=%u auid=%u",
 			 pid, uid, auid);
 	if (sid) {
-		rc = selinux_sid_to_string(sid, &ctx, &len);
+		rc = security_secid_to_secctx(sid, &ctx, &len);
 		if (rc)
 			audit_log_format(*ab, " ssid=%u", sid);
-		else
+		else {
 			audit_log_format(*ab, " subj=%s", ctx);
-		kfree(ctx);
+			security_release_secctx(ctx, len);
+		}
 	}
 
 	return rc;
@@ -750,18 +751,18 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
 		break;
 	}
 	case AUDIT_SIGNAL_INFO:
-		err = selinux_sid_to_string(audit_sig_sid, &ctx, &len);
+		err = security_secid_to_secctx(audit_sig_sid, &ctx, &len);
 		if (err)
 			return err;
 		sig_data = kmalloc(sizeof(*sig_data) + len, GFP_KERNEL);
 		if (!sig_data) {
-			kfree(ctx);
+			security_release_secctx(ctx, len);
 			return -ENOMEM;
 		}
 		sig_data->uid = audit_sig_uid;
 		sig_data->pid = audit_sig_pid;
 		memcpy(sig_data->ctx, ctx, len);
-		kfree(ctx);
+		security_release_secctx(ctx, len);
 		audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_SIGNAL_INFO,
 				0, 0, sig_data, sizeof(*sig_data) + len);
 		kfree(sig_data);
diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c
index 2f2914b..35e58a1 100644
--- a/kernel/auditfilter.c
+++ b/kernel/auditfilter.c
@@ -28,6 +28,7 @@
 #include <linux/netlink.h>
 #include <linux/sched.h>
 #include <linux/inotify.h>
+#include <linux/security.h>
 #include <linux/selinux.h>
 #include "audit.h"
 
@@ -1515,11 +1516,12 @@ static void audit_log_rule_change(uid_t loginuid, u32 sid, char *action,
 	if (sid) {
 		char *ctx = NULL;
 		u32 len;
-		if (selinux_sid_to_string(sid, &ctx, &len))
+		if (security_secid_to_secctx(sid, &ctx, &len))
 			audit_log_format(ab, " ssid=%u", sid);
-		else
+		else {
 			audit_log_format(ab, " subj=%s", ctx);
-		kfree(ctx);
+			security_release_secctx(ctx, len);
+		}
 	}
 	audit_log_format(ab, " op=%s rule key=", action);
 	if (rule->filterkey)
diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index d07fc4a..a9fc9dd 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -530,7 +530,7 @@ static int audit_filter_rules(struct task_struct *tsk,
 			   logged upon error */
 			if (f->se_rule) {
 				if (need_sid) {
-					selinux_get_task_sid(tsk, &sid);
+					security_task_getsecid(tsk, &sid);
 					need_sid = 0;
 				}
 				result = selinux_audit_rule_match(sid, f->type,
@@ -885,11 +885,11 @@ void audit_log_task_context(struct audit_buffer *ab)
 	int error;
 	u32 sid;
 
-	selinux_get_task_sid(current, &sid);
+	security_task_getsecid(current, &sid);
 	if (!sid)
 		return;
 
-	error = selinux_sid_to_string(sid, &ctx, &len);
+	error = security_secid_to_secctx(sid, &ctx, &len);
 	if (error) {
 		if (error != -EINVAL)
 			goto error_path;
@@ -897,7 +897,7 @@ void audit_log_task_context(struct audit_buffer *ab)
 	}
 
 	audit_log_format(ab, " subj=%s", ctx);
-	kfree(ctx);
+	security_release_secctx(ctx, len);
 	return;
 
 error_path:
@@ -941,7 +941,7 @@ static int audit_log_pid_context(struct audit_context *context, pid_t pid,
 				 u32 sid, char *comm)
 {
 	struct audit_buffer *ab;
-	char *s = NULL;
+	char *ctx = NULL;
 	u32 len;
 	int rc = 0;
 
@@ -951,15 +951,16 @@ static int audit_log_pid_context(struct audit_context *context, pid_t pid,
 
 	audit_log_format(ab, "opid=%d oauid=%d ouid=%d oses=%d", pid, auid,
 			 uid, sessionid);
-	if (selinux_sid_to_string(sid, &s, &len)) {
+	if (security_secid_to_secctx(sid, &ctx, &len)) {
 		audit_log_format(ab, " obj=(none)");
 		rc = 1;
-	} else
-		audit_log_format(ab, " obj=%s", s);
+	} else {
+		audit_log_format(ab, " obj=%s", ctx);
+		security_release_secctx(ctx, len);
+	}
 	audit_log_format(ab, " ocomm=");
 	audit_log_untrustedstring(ab, comm);
 	audit_log_end(ab);
-	kfree(s);
 
 	return rc;
 }
@@ -1268,14 +1269,15 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *ts
 			if (axi->osid != 0) {
 				char *ctx = NULL;
 				u32 len;
-				if (selinux_sid_to_string(
+				if (security_secid_to_secctx(
 						axi->osid, &ctx, &len)) {
 					audit_log_format(ab, " osid=%u",
 							axi->osid);
 					call_panic = 1;
-				} else
+				} else {
 					audit_log_format(ab, " obj=%s", ctx);
-				kfree(ctx);
+					security_release_secctx(ctx, len);
+				}
 			}
 			break; }
 
@@ -1389,13 +1391,14 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *ts
 		if (n->osid != 0) {
 			char *ctx = NULL;
 			u32 len;
-			if (selinux_sid_to_string(
+			if (security_secid_to_secctx(
 				n->osid, &ctx, &len)) {
 				audit_log_format(ab, " osid=%u", n->osid);
 				call_panic = 2;
-			} else
+			} else {
 				audit_log_format(ab, " obj=%s", ctx);
-			kfree(ctx);
+				security_release_secctx(ctx, len);
+			}
 		}
 
 		audit_log_end(ab);
@@ -1772,7 +1775,7 @@ static void audit_copy_inode(struct audit_names *name, const struct inode *inode
 	name->uid   = inode->i_uid;
 	name->gid   = inode->i_gid;
 	name->rdev  = inode->i_rdev;
-	selinux_get_inode_sid(inode, &name->osid);
+	security_inode_getsecid(inode, &name->osid);
 }
 
 /**
@@ -2187,8 +2190,7 @@ int __audit_ipc_obj(struct kern_ipc_perm *ipcp)
 	ax->uid = ipcp->uid;
 	ax->gid = ipcp->gid;
 	ax->mode = ipcp->mode;
-	selinux_get_ipc_sid(ipcp, &ax->osid);
-
+	security_ipc_getsecid(ipcp, &ax->osid);
 	ax->d.type = AUDIT_IPC;
 	ax->d.next = context->aux;
 	context->aux = (void *)ax;
@@ -2340,7 +2342,7 @@ void __audit_ptrace(struct task_struct *t)
 	context->target_auid = audit_get_loginuid(t);
 	context->target_uid = t->uid;
 	context->target_sessionid = audit_get_sessionid(t);
-	selinux_get_task_sid(t, &context->target_sid);
+	security_task_getsecid(t, &context->target_sid);
 	memcpy(context->target_comm, t->comm, TASK_COMM_LEN);
 }
 
@@ -2368,7 +2370,7 @@ int __audit_signal_info(int sig, struct task_struct *t)
 				audit_sig_uid = tsk->loginuid;
 			else
 				audit_sig_uid = tsk->uid;
-			selinux_get_task_sid(tsk, &audit_sig_sid);
+			security_task_getsecid(tsk, &audit_sig_sid);
 		}
 		if (!audit_signals || audit_dummy_context())
 			return 0;
@@ -2381,7 +2383,7 @@ int __audit_signal_info(int sig, struct task_struct *t)
 		ctx->target_auid = audit_get_loginuid(t);
 		ctx->target_uid = t->uid;
 		ctx->target_sessionid = audit_get_sessionid(t);
-		selinux_get_task_sid(t, &ctx->target_sid);
+		security_task_getsecid(t, &ctx->target_sid);
 		memcpy(ctx->target_comm, t->comm, TASK_COMM_LEN);
 		return 0;
 	}
@@ -2402,7 +2404,7 @@ int __audit_signal_info(int sig, struct task_struct *t)
 	axp->target_auid[axp->pid_count] = audit_get_loginuid(t);
 	axp->target_uid[axp->pid_count] = t->uid;
 	axp->target_sessionid[axp->pid_count] = audit_get_sessionid(t);
-	selinux_get_task_sid(t, &axp->target_sid[axp->pid_count]);
+	security_task_getsecid(t, &axp->target_sid[axp->pid_count]);
 	memcpy(axp->target_comm[axp->pid_count], t->comm, TASK_COMM_LEN);
 	axp->pid_count++;
 
@@ -2432,16 +2434,17 @@ void audit_core_dumps(long signr)
 	ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_ANOM_ABEND);
 	audit_log_format(ab, "auid=%u uid=%u gid=%u ses=%u",
 			auid, current->uid, current->gid, sessionid);
-	selinux_get_task_sid(current, &sid);
+	security_task_getsecid(current, &sid);
 	if (sid) {
 		char *ctx = NULL;
 		u32 len;
 
-		if (selinux_sid_to_string(sid, &ctx, &len))
+		if (security_secid_to_secctx(sid, &ctx, &len))
 			audit_log_format(ab, " ssid=%u", sid);
-		else
+		else {
 			audit_log_format(ab, " subj=%s", ctx);
-		kfree(ctx);
+			security_release_secctx(ctx, len);
+		}
 	}
 	audit_log_format(ab, " pid=%d comm=", current->pid);
 	audit_log_untrustedstring(ab, current->comm);

-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 67%]

* [PATCH 2/9] SELinux: setup new inode/ipc getsecid hooks
  2008-03-01 19:47 95% [PATCH-v2 -mm 0/9] LSM-neutral Audit (SELinux audit separation) Ahmed S. Darwish
  2008-03-01 19:51 70% ` [PATCH 1/9] LSM: Introduce inode_getsecid and ipc_getsecid hooks Ahmed S. Darwish
@ 2008-03-01 19:52 93% ` Ahmed S. Darwish
  2008-03-01 19:54 67% ` [PATCH 3/9] Audit: use new LSM hooks instead of SELinux exports Ahmed S. Darwish
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2008-03-01 19:52 UTC (permalink / raw)
  To: Chris Wright, Stephen Smalley, James Morris, Eric Paris,
	Casey Schaufler, David Woodhouse, Paul Moore, Andrew Morton
  Cc: LKML, Audit-ML, LSM-ML

Setup the new inode_getsecid and ipc_getsecid() LSM hooks
for SELinux.

Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

 hooks.c |   19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index f42ebfc..06597d7 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -2724,6 +2724,12 @@ static int selinux_inode_killpriv(struct dentry *dentry)
 	return secondary_ops->inode_killpriv(dentry);
 }
 
+static void selinux_inode_getsecid(const struct inode *inode, u32 *secid)
+{
+	struct inode_security_struct *isec = inode->i_security;
+	*secid = isec->sid;
+}
+
 /* file security operations */
 
 static int selinux_revalidate_file_permission(struct file *file, int mask)
@@ -3120,7 +3126,8 @@ static int selinux_task_getsid(struct task_struct *p)
 
 static void selinux_task_getsecid(struct task_struct *p, u32 *secid)
 {
-	selinux_get_task_sid(p, secid);
+	struct task_security_struct *tsec = p->security;
+	*secid = tsec->sid;
 }
 
 static int selinux_task_setgroups(struct group_info *group_info)
@@ -4090,7 +4097,7 @@ static int selinux_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *
 		goto out;
 
 	if (sock && family == PF_UNIX)
-		selinux_get_inode_sid(SOCK_INODE(sock), &peer_secid);
+		selinux_inode_getsecid(SOCK_INODE(sock), &peer_secid);
 	else if (skb)
 		selinux_skb_peerlbl_sid(skb, family, &peer_secid);
 
@@ -4970,6 +4977,12 @@ static int selinux_ipc_permission(struct kern_ipc_perm *ipcp, short flag)
 	return ipc_has_perm(ipcp, av);
 }
 
+static void selinux_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
+{
+	struct ipc_security_struct *isec = ipcp->security;
+	*secid = isec->sid;
+}
+
 /* module stacking operations */
 static int selinux_register_security (const char *name, struct security_operations *ops)
 {
@@ -5292,6 +5305,7 @@ static struct security_operations selinux_ops = {
 	.inode_listsecurity =           selinux_inode_listsecurity,
 	.inode_need_killpriv =		selinux_inode_need_killpriv,
 	.inode_killpriv =		selinux_inode_killpriv,
+	.inode_getsecid =               selinux_inode_getsecid,
 
 	.file_permission =		selinux_file_permission,
 	.file_alloc_security =		selinux_file_alloc_security,
@@ -5332,6 +5346,7 @@ static struct security_operations selinux_ops = {
 	.task_to_inode =                selinux_task_to_inode,
 
 	.ipc_permission =		selinux_ipc_permission,
+	.ipc_getsecid =                 selinux_ipc_getsecid,
 
 	.msg_msg_alloc_security =	selinux_msg_msg_alloc_security,
 	.msg_msg_free_security =	selinux_msg_msg_free_security,

-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 93%]

* [PATCH 1/9] LSM: Introduce inode_getsecid and ipc_getsecid hooks
  2008-03-01 19:47 95% [PATCH-v2 -mm 0/9] LSM-neutral Audit (SELinux audit separation) Ahmed S. Darwish
@ 2008-03-01 19:51 70% ` Ahmed S. Darwish
  2008-03-01 19:52 93% ` [PATCH 2/9] SELinux: setup new inode/ipc getsecid hooks Ahmed S. Darwish
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2008-03-01 19:51 UTC (permalink / raw)
  To: Chris Wright, Stephen Smalley, James Morris, Eric Paris,
	Casey Schaufler, David Woodhouse, Paul Moore, Andrew Morton
  Cc: LKML, Audit-ML, LSM-ML

Introduce inode_getsecid(inode, secid) and ipc_getsecid(ipcp, secid)
LSM hooks. These hooks will be used instead of similar exported 
SELinux interfaces.

Let {inode,ipc,task}_getsecid hooks set the secid to 0 by default 
if CONFIG_SECURITY is not defined or if the hook is set to 
NULL (dummy). This is done to notify the caller that no valid 
secid exists.

Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

 include/linux/security.h |   30 +++++++++++++++++++++++++++++-
 security/dummy.c         |   16 +++++++++++++++-
 security/security.c      |   10 ++++++++++
 3 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/include/linux/security.h b/include/linux/security.h
index a33fd03..205a053 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -449,6 +449,11 @@ struct request_sock;
  *	@dentry is the dentry being changed.
  *	Return 0 on success.  If error is returned, then the operation
  *	causing setuid bit removal is failed.
+ * @inode_getsecid:
+ *	Get the secid associated with the node.
+ *	@inode contains a pointer to the inode.
+ *	@secid contains a pointer to the location where result will be saved.
+ *	In case of failure, @secid will be set to zero.
  *
  * Security hooks for file operations
  *
@@ -617,6 +622,8 @@ struct request_sock;
  * @task_getsecid:
  *	Retrieve the security identifier of the process @p.
  *	@p contains the task_struct for the process and place is into @secid.
+ *	In case of failure, @secid will be set to zero.
+ *
  * @task_setgroups:
  *	Check permission before setting the supplementary group set of the
  *	current process.
@@ -989,6 +996,11 @@ struct request_sock;
  *	@ipcp contains the kernel IPC permission structure
  *	@flag contains the desired (requested) permission set
  *	Return 0 if permission is granted.
+ * @ipc_getsecid:
+ *	Get the secid associated with the ipc object.
+ *	@ipcp contains the kernel IPC permission structure.
+ *	@secid contains a pointer to the location where result will be saved.
+ *	In case of failure, @secid will be set to zero.
  *
  * Security hooks for individual messages held in System V IPC message queues
  * @msg_msg_alloc_security:
@@ -1310,6 +1322,7 @@ struct security_operations {
 	int (*inode_getsecurity)(const struct inode *inode, const char *name, void **buffer, bool alloc);
   	int (*inode_setsecurity)(struct inode *inode, const char *name, const void *value, size_t size, int flags);
   	int (*inode_listsecurity)(struct inode *inode, char *buffer, size_t buffer_size);
+	void (*inode_getsecid)(const struct inode *inode, u32 *secid);
 
 	int (*file_permission) (struct file * file, int mask);
 	int (*file_alloc_security) (struct file * file);
@@ -1362,6 +1375,7 @@ struct security_operations {
 	void (*task_to_inode)(struct task_struct *p, struct inode *inode);
 
 	int (*ipc_permission) (struct kern_ipc_perm * ipcp, short flag);
+	void (*ipc_getsecid) (struct kern_ipc_perm *ipcp, u32 *secid);
 
 	int (*msg_msg_alloc_security) (struct msg_msg * msg);
 	void (*msg_msg_free_security) (struct msg_msg * msg);
@@ -1571,6 +1585,7 @@ int security_inode_killpriv(struct dentry *dentry);
 int security_inode_getsecurity(const struct inode *inode, const char *name, void **buffer, bool alloc);
 int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags);
 int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size);
+void security_inode_getsecid(const struct inode *inode, u32 *secid);
 int security_file_permission(struct file *file, int mask);
 int security_file_alloc(struct file *file);
 void security_file_free(struct file *file);
@@ -1615,6 +1630,7 @@ int security_task_prctl(int option, unsigned long arg2, unsigned long arg3,
 void security_task_reparent_to_init(struct task_struct *p);
 void security_task_to_inode(struct task_struct *p, struct inode *inode);
 int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag);
+void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid);
 int security_msg_msg_alloc(struct msg_msg *msg);
 void security_msg_msg_free(struct msg_msg *msg);
 int security_msg_queue_alloc(struct msg_queue *msq);
@@ -1985,6 +2001,11 @@ static inline int security_inode_listsecurity(struct inode *inode, char *buffer,
 	return 0;
 }
 
+static inline void security_inode_getsecid(const struct inode *inode, u32 *secid)
+{
+	*secid = 0;
+}
+
 static inline int security_file_permission (struct file *file, int mask)
 {
 	return 0;
@@ -2100,7 +2121,9 @@ static inline int security_task_getsid (struct task_struct *p)
 }
 
 static inline void security_task_getsecid (struct task_struct *p, u32 *secid)
-{ }
+{
+	*secid = 0;
+}
 
 static inline int security_task_setgroups (struct group_info *group_info)
 {
@@ -2179,6 +2202,11 @@ static inline int security_ipc_permission (struct kern_ipc_perm *ipcp,
 	return 0;
 }
 
+static inline void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
+{
+	*secid = 0;
+}
+
 static inline int security_msg_msg_alloc (struct msg_msg * msg)
 {
 	return 0;
diff --git a/security/dummy.c b/security/dummy.c
index 6a0056b..f5e5f95 100644
--- a/security/dummy.c
+++ b/security/dummy.c
@@ -422,6 +422,11 @@ static int dummy_inode_listsecurity(struct inode *inode, char *buffer, size_t bu
 	return 0;
 }
 
+static void dummy_inode_getsecid(const struct inode *inode, u32 *secid)
+{
+	*secid = 0;
+}
+
 static int dummy_file_permission (struct file *file, int mask)
 {
 	return 0;
@@ -540,7 +545,9 @@ static int dummy_task_getsid (struct task_struct *p)
 }
 
 static void dummy_task_getsecid (struct task_struct *p, u32 *secid)
-{ }
+{
+	*secid = 0;
+}
 
 static int dummy_task_setgroups (struct group_info *group_info)
 {
@@ -614,6 +621,11 @@ static int dummy_ipc_permission (struct kern_ipc_perm *ipcp, short flag)
 	return 0;
 }
 
+static void dummy_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
+{
+	*secid = 0;
+}
+
 static int dummy_msg_msg_alloc_security (struct msg_msg *msg)
 {
 	return 0;
@@ -1062,6 +1074,7 @@ void security_fixup_ops (struct security_operations *ops)
 	set_to_dummy_if_null(ops, inode_getsecurity);
 	set_to_dummy_if_null(ops, inode_setsecurity);
 	set_to_dummy_if_null(ops, inode_listsecurity);
+	set_to_dummy_if_null(ops, inode_getsecid);
 	set_to_dummy_if_null(ops, file_permission);
 	set_to_dummy_if_null(ops, file_alloc_security);
 	set_to_dummy_if_null(ops, file_free_security);
@@ -1098,6 +1111,7 @@ void security_fixup_ops (struct security_operations *ops)
 	set_to_dummy_if_null(ops, task_reparent_to_init);
  	set_to_dummy_if_null(ops, task_to_inode);
 	set_to_dummy_if_null(ops, ipc_permission);
+	set_to_dummy_if_null(ops, ipc_getsecid);
 	set_to_dummy_if_null(ops, msg_msg_alloc_security);
 	set_to_dummy_if_null(ops, msg_msg_free_security);
 	set_to_dummy_if_null(ops, msg_queue_alloc_security);
diff --git a/security/security.c b/security/security.c
index 3e75b90..1748329 100644
--- a/security/security.c
+++ b/security/security.c
@@ -516,6 +516,11 @@ int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer
 	return security_ops->inode_listsecurity(inode, buffer, buffer_size);
 }
 
+void security_inode_getsecid(const struct inode *inode, u32 *secid)
+{
+	security_ops->inode_getsecid(inode, secid);
+}
+
 int security_file_permission(struct file *file, int mask)
 {
 	return security_ops->file_permission(file, mask);
@@ -705,6 +710,11 @@ int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag)
 	return security_ops->ipc_permission(ipcp, flag);
 }
 
+void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
+{
+	security_ops->ipc_getsecid(ipcp, secid);
+}
+
 int security_msg_msg_alloc(struct msg_msg *msg)
 {
 	return security_ops->msg_msg_alloc_security(msg);


-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 70%]

* [PATCH-v2 -mm 0/9] LSM-neutral Audit (SELinux audit separation)
@ 2008-03-01 19:47 95% Ahmed S. Darwish
  2008-03-01 19:51 70% ` [PATCH 1/9] LSM: Introduce inode_getsecid and ipc_getsecid hooks Ahmed S. Darwish
                   ` (8 more replies)
  0 siblings, 9 replies; 200+ results
From: Ahmed S. Darwish @ 2008-03-01 19:47 UTC (permalink / raw)
  To: Chris Wright, Stephen Smalley, James Morris, Eric Paris,
	Casey Schaufler, David Woodhouse, Paul Moore, Andrew Morton
  Cc: LKML, Audit-ML, LSM-ML

Hi everybody,

A series of 9 patches to let Audit be LSM netural. This is done 
for proper future audit<->SMACK integration which will also be
useful for any future LSM.

Basically, patches add below new LSM hooks:

1- secid extraction:
inode_getsecid(inode, secid)
ipc_getsecid(ipcp, secid)

2- LSM-specific Audit rules manipulation:
audit_rule_init(field, op, rulestr, lsmrule)
audit_rule_known(krule)
audit_rule_match(secid, field, op, rule, actx)
audit_rule_free(rule)

and remove ,now redundant, equivalent SELinux exported interfaces.

Initial work and idea by: Casey Schaufler <casey@schaufler-ca.com>
Thanks to Paul Moore <paul.moore@hp.com> for his deep review of first
version.

 include/linux/audit.h            |   29 ++++++++
 include/linux/security.h         |  102 +++++++++++++++++++++++++++++
 include/linux/selinux.h          |  134 ---------------------------------------
 kernel/audit.c                   |   24 ++----
 kernel/audit.h                   |   25 -------
 kernel/auditfilter.c             |   99 ++++++++++------------------
 kernel/auditsc.c                 |   74 +++++++++++----------
 net/netlink/af_netlink.c         |    3 +-
 security/dummy.c                 |   47 +++++++++++++
 security/security.c              |   35 ++++++++++
 security/selinux/exports.c       |   42 ------------
 security/selinux/hooks.c         |   27 +++++++
 security/selinux/include/audit.h |   65 ++++++++++++++++++
 security/selinux/ss/services.c   |   45 +++++++++----
 14 files changed, 420 insertions(+), 331 deletions(-)

Regards,

-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 95%]

* [RFC PATCH -mm] LSM: Add lsm= boot parameter
@ 2008-03-01 19:07 77% Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2008-03-01 19:07 UTC (permalink / raw)
  To: Chris Wright, Stephen Smalley, James Morris, Eric Paris,
	Casey Schaufler, Alexey Dobriyan
  Cc: LKML, LSM-ML

Hi everybody,

This is a first try of adding lsm= boot parameter. 

Current situation is:
1- Ignore wrong input, with a small warning to users.
2- If user didn't specify a specific module, none will be loaded

Basically, the patch adds a @name attribute to each LSM. It
also adds a security_module_chosen(op) method where each
LSM _must_ pass before calling register_security().

Thanks,

 Documentation/kernel-parameters.txt |    4 ++++
 include/linux/security.h            |   10 ++++++++++
 security/dummy.c                    |    3 ++-
 security/security.c                 |   35 +++++++++++++++++++++++++++++++++++
 security/selinux/hooks.c            |    5 ++++-
 security/smack/smack_lsm.c          |    7 +++++++
 6 files changed, 62 insertions(+), 2 deletions(-)

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index c64dfd7..dde04c8 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -374,6 +374,10 @@ and is between 256 and 4096 characters. It is defined in the file
 			possible to determine what the correct size should be.
 			This option provides an override for these situations.
 
+	lsm=		[SECURITY] Choose an LSM to enable at boot. If this boot
+			parameter is not specified, no security module will be 
+			loaded.
+
 	capability.disable=
 			[SECURITY] Disable capabilities.  This would normally
 			be used only if an alternative security model is to be
diff --git a/include/linux/security.h b/include/linux/security.h
index eb663e5..4f695c0 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -42,6 +42,9 @@
 
 extern unsigned securebits;
 
+/* Maximum number of letters for an LSM name string */
+#define SECURITY_NAME_MAX	10
+
 struct ctl_table;
 struct audit_krule;
 
@@ -118,6 +121,10 @@ struct request_sock;
 /**
  * struct security_operations - main security structure
  *
+ * Security module identifier.
+ *
+ * @name: LSM name
+ *
  * Security hooks for program execution operations.
  *
  * @bprm_alloc_security:
@@ -1262,6 +1269,8 @@ struct request_sock;
  * This is the main security structure.
  */
 struct security_operations {
+	char name[SECURITY_NAME_MAX + 1];
+
 	int (*ptrace) (struct task_struct * parent, struct task_struct * child);
 	int (*capget) (struct task_struct * target,
 		       kernel_cap_t * effective,
@@ -1530,6 +1539,7 @@ struct security_operations {
 
 /* prototypes */
 extern int security_init	(void);
+extern int security_module_chosen(struct security_operations *ops);
 extern int register_security	(struct security_operations *ops);
 extern int mod_reg_security	(const char *name, struct security_operations *ops);
 extern struct dentry *securityfs_create_file(const char *name, mode_t mode,
diff --git a/security/dummy.c b/security/dummy.c
index 241ab20..ed11f97 100644
--- a/security/dummy.c
+++ b/security/dummy.c
@@ -1022,7 +1022,7 @@ static inline void dummy_audit_rule_free(void *lsmrule)
 
 #endif /* CONFIG_AUDIT */
 
-struct security_operations dummy_security_ops;
+struct security_operations dummy_security_ops = { "dummy" };
 
 #define set_to_dummy_if_null(ops, function)				\
 	do {								\
@@ -1035,6 +1035,7 @@ struct security_operations dummy_security_ops;
 
 void security_fixup_ops (struct security_operations *ops)
 {
+	BUG_ON(!ops->name);
 	set_to_dummy_if_null(ops, ptrace);
 	set_to_dummy_if_null(ops, capget);
 	set_to_dummy_if_null(ops, capset_check);
diff --git a/security/security.c b/security/security.c
index 1bf2ee4..7a84b4e 100644
--- a/security/security.c
+++ b/security/security.c
@@ -17,6 +17,8 @@
 #include <linux/kernel.h>
 #include <linux/security.h>
 
+/* Boot time LSM user choice */
+char chosen_lsm[SECURITY_NAME_MAX + 1];
 
 /* things that live in dummy.c */
 extern struct security_operations dummy_security_ops;
@@ -67,6 +69,39 @@ int __init security_init(void)
 	return 0;
 }
 
+/* Save user chosen LSM */
+static int __init choose_lsm(char *str)
+{
+	if (strlen(str) > SECURITY_NAME_MAX) {
+		printk(KERN_INFO "Security: LSM name length extends possible "
+		       "limit.\n");
+		printk(KERN_INFO "Security: Ignoring passed lsm= parameter.\n");
+		return 0;
+	}
+
+	strncpy(chosen_lsm, str, SECURITY_NAME_MAX);
+	return 1;
+}
+__setup("lsm=", choose_lsm);
+
+/**
+ * security_module_chosen - Load given security module on boot ?
+ * @ops: a pointer to the struct security_operations that is to be checked.
+ *
+ * Return true if the passed LSM is the one chosen by user at
+ * boot time, otherwise return false.
+ */
+int security_module_chosen(struct security_operations *ops)
+{
+	if (!ops || !ops->name)
+		return 0;
+
+	if (strncmp(ops->name, chosen_lsm, SECURITY_NAME_MAX))
+		return 0;
+	
+	return 1;
+}
+
 /**
  * register_security - registers a security framework with the kernel
  * @ops: a pointer to the struct security_options that is to be registered
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index bef1834..d4926b0 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -5247,6 +5247,8 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
 #endif
 
 static struct security_operations selinux_ops = {
+	.name =				"selinux",
+
 	.ptrace =			selinux_ptrace,
 	.capget =			selinux_capget,
 	.capset_check =			selinux_capset_check,
@@ -5443,7 +5445,8 @@ static __init int selinux_init(void)
 {
 	struct task_security_struct *tsec;
 
-	if (!selinux_enabled) {
+	if (!selinux_enabled || !security_module_chosen(&selinux_ops)) {
+		selinux_enabled = 0;
 		printk(KERN_INFO "SELinux:  Disabled at boot.\n");
 		return 0;
 	}
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 2b5d6f7..4348257 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -2358,6 +2358,8 @@ static void smack_release_secctx(char *secdata, u32 seclen)
 }
 
 static struct security_operations smack_ops = {
+	.name =				"smack",
+
 	.ptrace = 			smack_ptrace,
 	.capget = 			cap_capget,
 	.capset_check = 		cap_capset_check,
@@ -2485,6 +2487,11 @@ static struct security_operations smack_ops = {
  */
 static __init int smack_init(void)
 {
+	if (!security_module_chosen(&smack_ops)) {
+		printk(KERN_INFO "Smack: Disabled at boot.\n");
+		return 0;
+	}
+
 	printk(KERN_INFO "Smack:  Initializing.\n");
 
 	/*

-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 77%]

* Re: [BUG + PATCH/Bugfix] x86/lguest: fix pgdir pmd index calculation
  2008-02-25  0:18 97%     ` Ahmed S. Darwish
@ 2008-02-29  0:32 89%       ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2008-02-29  0:32 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Rusty Russell,
	LKML, lguest, akpm, Jeremy Fitzhardinge

Hi Ingo/x86-folks,

On Mon, Feb 25, 2008 at 02:18:16AM +0200, Ahmed S. Darwish wrote:
...
> 
> This thread's main bug no longer appears. There's a new bug though,
> but it looks nicer than the original ugly bug!. 
> 
> The new bug does *not* appear in mainline with the same patch. It's
> a panic, but this time on the _guest_ side (which is the same host's
> kernel).
>
> [    0.023996] CPU: Intel(R) Pentium(R) M processor 1500MHz stepping 05
> [    0.023996] Kernel panic - not syncing: Kernel compiled for Pentium+, requires TSC feature!
> [    0.023996] Pid: 0, comm: swapper Not tainted 2.6.25-rc2-00815-g3db3a05 #64
> 

The bug appeared in mainline due to the latest x86 merge. The commit
that caused the bug is not faulty though:

commit 12c247a6719987aad65f83158d2bb3e73c75c1f5
    x86: fix boot failure on 486 due to TSC breakage

    1. arch/x86/kernel/tsc_32.c:tsc_init() sees !cpu_has_tsc,
       so bails and calls setup_clear_cpu_cap(X86_FEATURE_TSC).
    2. include/asm-x86/cpufeature.h:setup_clear_cpu_cap(bit) clears
       the bit in boot_cpu_data and sets it in cleared_cpu_caps
    3. arch/x86/kernel/cpu/common.c:identify_cpu() XORs all caps
       in with cleared_cpu_caps
       HOWEVER, at this point c->x86_capability correctly has TSC
       Off, cleared_cpu_caps has TSC On, so the XOR incorrectly
       sets TSC to On in c->x86_capability, with disastrous results.

diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index f86a3c4..a38aafa 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -504,7 +504,7 @@ void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
 
 	/* Clear all flags overriden by options */
 	for (i = 0; i < NCAPINTS; i++)
-		c->x86_capability[i] ^= cleared_cpu_caps[i];
+		c->x86_capability[i] &= ~cleared_cpu_caps[i];
 

Now the commit fixed everything, and x86_capability shows the right
thing (TSC = off). 

On the lguest _guest_ side, 'cpu_has_tsc' is _always_ false (due to 
lguest using his own clocksource ?), thus a guest with a pentium+ 
cpu always panics with:

#ifdef CONFIG_X86_TSC
	if (!cpu_has_tsc)
		panic("Kernel compiled for Pentium+, requires TSC feature!");
#endif


In older kernels (2.6.23), the problem was also hidden using 'tsc_disable':

tsc.c:
	if (!cpu_has_tsc || tsc_disable)
		tsc_disable = 1;

bug.c:
#ifdef CONFIG_X86_TSC
	if (!cpu_has_tsc && !tsc_disable)
		panic("Kernel compiled for Pentium+, requires TSC feature!");
#endif


I've tried solving the problem with several tweaks including something like:

	/* If we're running on a pentium+, fake an enabled TSC to bypass
	 * kernel checks for processor bugs (see x86/cpu/bugs.c) */
	if (boot_cpu_data.x86 >= 5)
		setup_force_cpu_cap(X86_FEATURE_TSC);

with no luck at all. 

Any idea how to solve this problem in a right/mergeable way ?

Thank you,

-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 89%]

* Re: [PATCH -mm 3/4] Audit: start not to use SELinux exported symbols
  @ 2008-02-27 17:11 98%     ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2008-02-27 17:11 UTC (permalink / raw)
  To: Paul Moore
  Cc: Chris Wright, Stephen Smalley, James Morris, Eric Paris,
	Casey Schaufler, David Woodhouse, linux-security-module, LKML,
	akpm

Hi!,

On Wed, Feb 27, 2008 at 11:00:57AM -0500, Paul Moore wrote:
> On Tuesday 26 February 2008 6:28:08 pm Ahmed S. Darwish wrote:
...
> >
> > Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
> > Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
> 
> In the future, such patches should probably also be CC'd to the audit 
> list.
> 

No problem.

> > ---
> >
> >  include/linux/security.h |    5 ++++-
> >  kernel/audit.c           |   14 +++++++-------
> >  kernel/auditfilter.c     |    5 +++--
> >  kernel/auditsc.c         |   37
> > ++++++++++++++++++------------------- security/dummy.c         |    4
> > +++-
> >  6 files changed, 36 insertions(+), 32 deletions(-)
> >
> > diff --git a/include/linux/security.h b/include/linux/security.h
> > index a7fb136..35c98f0 100644
> > --- a/include/linux/security.h
> > +++ b/include/linux/security.h
> > @@ -621,6 +621,7 @@ struct request_sock;
> >   * @task_getsecid:
> >   *	Retrieve the security identifier of the process @p.
> >   *	@p contains the task_struct for the process and place is into
> > @secid.
> > + *      In case of failure, @secid will be set to zero
> 
> This is a nit, but you used spaces between the "*" and "In case ..." 
> where the rest of the files uses tabs.  When in doubt, try and stick 
> with whatever formatting the rest of the source file uses.
> 

I'll find a way to teach emacs how to print a tab ;). Will do.

> > diff --git a/kernel/audit.c b/kernel/audit.c
> > index 8316a88..2bd4124 100644
> > --- a/kernel/audit.c
> > +++ b/kernel/audit.c
> > @@ -259,13 +259,13 @@ static int audit_log_config_change(char
> > *function_name, int new, int old, char *ctx = NULL;
> >  		u32 len;
> >
> > -		rc = selinux_sid_to_string(sid, &ctx, &len);
> > +		rc = security_secid_to_secctx(sid, &ctx, &len);
> >  		if (rc) {
> >  			audit_log_format(ab, " sid=%u", sid);
> >  			allow_changes = 0; /* Something weird, deny request */
> >  		} else {
> >  			audit_log_format(ab, " subj=%s", ctx);
> > -			kfree(ctx);
> > +			security_release_secctx(ctx, len);
> >  		}
> >  	}
> >  	audit_log_format(ab, " res=%d", allow_changes);
> > @@ -543,12 +543,12 @@ static int audit_log_common_recv_msg(struct
> > audit_buffer **ab, u16 msg_type, audit_log_format(*ab, "user pid=%d
> > uid=%u auid=%u",
> >  			 pid, uid, auid);
> >  	if (sid) {
> > -		rc = selinux_sid_to_string(sid, &ctx, &len);
> > +		rc = security_secid_to_secctx(sid, &ctx, &len);
> >  		if (rc)
> >  			audit_log_format(*ab, " ssid=%u", sid);
> >  		else
> >  			audit_log_format(*ab, " subj=%s", ctx);
> > -		kfree(ctx);
> > +		security_release_secctx(ctx, len);
> >  	}
> >
> >  	return rc;
> 
> This next part isn't your fault, but you're touching the code so I'm 
> going to point it out and suggest you fix it while you are at it :)
> 
> If you look at how kfree()/security_release_secctx() is called in the 
> above two functions you notice how it is inconsistent: it is only 
> called on success in the first case, but called regardless in the 
> second.  Make this consistent, preferably using the approach taken in 
> the first case (only call it on success).
> 

My pleasure. You'll find them consistent in the next send.

[Same release_ctx() consistency point]
...

> 
> > @@ -951,7 +951,7 @@ static int audit_log_pid_context(struct
> > audit_context *context, pid_t pid,
> >
> >  	audit_log_format(ab, "opid=%d oauid=%d ouid=%d oses=%d", pid, auid,
> >  			 uid, sessionid);
> > -	if (selinux_sid_to_string(sid, &s, &len)) {
> > +	if (security_secid_to_secctx(sid, &s, &len)) {
> >  		audit_log_format(ab, " obj=(none)");
> >  		rc = 1;
> >  	} else
> 
> You forgot to convert the matching kfree() call to a 
> security_release_secctx() call.  Also it might be nice to change the 
> context variable name from "s" to "ctx", but some ornery folks might 
> whine about that ...
> 

Nice spot, will do. 's' will be changed too, context is already
used as 'ctx' in the whole file anyway.

[...]
> 
> Only call the release routine on success.
> 
[...]
> 
> Here too.
> 
[...]
> 
> One last time.
> 

Thanks a lot for such a deep review :). I'll modify spotted problems
as suggested, reorder the patch in a non compilation-breaking order, 
and keep you informed.

Modified patches will be sent with the new ones that will complete 
the separation not to add too much noise in LKML.

Warm regards

-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 98%]

* Re: [PATCH -mm 1/4] LSM: Introduce inode_getsecid and ipc_getsecid hooks
  @ 2008-02-27 16:45 99%     ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2008-02-27 16:45 UTC (permalink / raw)
  To: Paul Moore
  Cc: Chris Wright, Stephen Smalley, James Morris, Eric Paris,
	Casey Schaufler, David Woodhouse, linux-security-module, LKML,
	akpm

Hi Paul,

On Wed, Feb 27, 2008 at 11:04:57AM -0500, Paul Moore wrote:
> On Tuesday 26 February 2008 6:24:11 pm Ahmed S. Darwish wrote:
> > Introduce inode_getsecid(inode, secid) and ipc_getsecid(ipcp, secid)
> > LSM hooks.
> >
> > This hooks will be used instead of similar exported SELinux
> > interfaces.
> >
> > Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
> > Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
> > ---
> >
> >  include/linux/security.h |   18 ++++++++++++++++++
> >  security/dummy.c         |   12 ++++++++++++
> >  security/security.c      |   12 ++++++++++++
> >  3 files changed, 42 insertions(+)
> >
...
> ...
> 
> > +static inline void security_ipc_getsecid(struct kern_ipc_perm *ipcp,
> > u32 *secid)
> > +{ } 
> 
> Should these both do a  "*secid = 0;"?
> 

Yes, this will also lead to consistency in the interface espcially 
after changing task_getsecid to do the same (in patch #3).

> > diff --git a/security/dummy.c b/security/dummy.c
> > index 6a0056b..c2f4c52 100644
> > --- a/security/dummy.c
> > +++ b/security/dummy.c
> > @@ -422,6 +422,11 @@ static int dummy_inode_listsecurity(struct inode
> > *inode, char *buffer, size_t bu return 0;
> >  }
> >
> > +static void dummy_inode_getsecid(const struct inode *inode, u32
> > *secid)
> > +{ 
> > +	return;
> > +}
> 
> ...
> 
> > +static void dummy_ipc_getsecid(struct kern_ipc_perm *ipcp, u32
> > *secid)
> > +{ 
> > +	return;
> > +}
> 
> Same question.
> 

Both will be changed to *secid = 0 in the comming send. Thanks!

-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 99%]

* [PATCH -mm 4/4] Netlink: Use LSM interface instead of SELinux one
  2008-02-26 23:22 94% [PATCH -mm 0/4] LSM interfaced Audit (SELinux audit separation) Ahmed S. Darwish
                   ` (2 preceding siblings ...)
  2008-02-26 23:28 65% ` [PATCH -mm 3/4] Audit: start not to use SELinux " Ahmed S. Darwish
@ 2008-02-26 23:31 99% ` Ahmed S. Darwish
  3 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2008-02-26 23:31 UTC (permalink / raw)
  To: Chris Wright, Stephen Smalley, James Morris, Eric Paris,
	Casey Schaufler, David Woodhouse
  Cc: linux-security-module, LKML, akpm

Don't use SELinux exported selinux_get_task_sid symbol. 
Use the generic LSM equivalent instead.

Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 1ab0da2..61fd277 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -54,7 +54,6 @@
 #include <linux/mm.h>
 #include <linux/types.h>
 #include <linux/audit.h>
-#include <linux/selinux.h>
 #include <linux/mutex.h>
 
 #include <net/net_namespace.h>
@@ -1239,7 +1238,7 @@ static int netlink_sendmsg(struct kiocb *kiocb, struct socket *sock,
 	NETLINK_CB(skb).pid	= nlk->pid;
 	NETLINK_CB(skb).dst_group = dst_group;
 	NETLINK_CB(skb).loginuid = audit_get_loginuid(current);
-	selinux_get_task_sid(current, &(NETLINK_CB(skb).sid));
+	security_task_getsecid(current, &(NETLINK_CB(skb).sid));
 	memcpy(NETLINK_CREDS(skb), &siocb->scm->creds, sizeof(struct ucred));
 
 	/* What can I do? Netlink is asynchronous, so that

-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 99%]

* [PATCH -mm 3/4] Audit: start not to use SELinux exported symbols
  2008-02-26 23:22 94% [PATCH -mm 0/4] LSM interfaced Audit (SELinux audit separation) Ahmed S. Darwish
  2008-02-26 23:24 75% ` [PATCH -mm 1/4] LSM: Introduce inode_getsecid and ipc_getsecid hooks Ahmed S. Darwish
  2008-02-26 23:25 74% ` [PATCH -mm 2/4] SELinux: Remove various exported symbols Ahmed S. Darwish
@ 2008-02-26 23:28 65% ` Ahmed S. Darwish
    2008-02-26 23:31 99% ` [PATCH -mm 4/4] Netlink: Use LSM interface instead of SELinux one Ahmed S. Darwish
  3 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2008-02-26 23:28 UTC (permalink / raw)
  To: Chris Wright, Stephen Smalley, James Morris, Eric Paris,
	Casey Schaufler, David Woodhouse
  Cc: linux-security-module, LKML, akpm

Remove the following exported SELinux interfaces:
selinux_get_inode_sid(inode, sid)
selinux_get_ipc_sid(ipcp, sid) 
selinux_get_task_sid(tsk, sid)
selinux_sid_to_string(sid, ctx, len)

and substitue them with following generic LSM equivalents 
respectively:
security_inode_getsecid(inode, secid)
security_ipc_getsecid*(ipcp, secid)
security_task_getsecid(tsk, secid)
security_sid_to_secctx(sid, ctx, len)

Let the security_task_getsecid(tsk, secid) LSM hook set
the secid to 0 by default if CONFIG_SECURITY is not defined 
or if the hook is set to NULL (dummy). This is done to
notify the caller that no valid secid exists.

Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

 include/linux/security.h |    5 ++++-
 kernel/audit.c           |   14 +++++++-------
 kernel/auditfilter.c     |    5 +++--
 kernel/auditsc.c         |   37 ++++++++++++++++++-------------------
 security/dummy.c         |    4 +++-
 6 files changed, 36 insertions(+), 32 deletions(-)

diff --git a/include/linux/security.h b/include/linux/security.h
index a7fb136..35c98f0 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -621,6 +621,7 @@ struct request_sock;
  * @task_getsecid:
  *	Retrieve the security identifier of the process @p.
  *	@p contains the task_struct for the process and place is into @secid.
+ *      In case of failure, @secid will be set to zero
  * @task_setgroups:
  *	Check permission before setting the supplementary group set of the
  *	current process.
@@ -2115,7 +2116,9 @@ static inline int security_task_getsid (struct task_struct *p)
 }
 
 static inline void security_task_getsecid (struct task_struct *p, u32 *secid)
-{ }
+{ 
+	*secid = 0;
+}
 
 static inline int security_task_setgroups (struct group_info *group_info)
 {
diff --git a/security/dummy.c b/security/dummy.c
index c2f4c52..56b007e 100644
--- a/security/dummy.c
+++ b/security/dummy.c
@@ -545,7 +545,9 @@ static int dummy_task_getsid (struct task_struct *p)
 }
 
 static void dummy_task_getsecid (struct task_struct *p, u32 *secid)
-{ }
+{
+	*secid = 0;
+}
 
 static int dummy_task_setgroups (struct group_info *group_info)
 {
diff --git a/kernel/audit.c b/kernel/audit.c
index 8316a88..2bd4124 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -259,13 +259,13 @@ static int audit_log_config_change(char *function_name, int new, int old,
 		char *ctx = NULL;
 		u32 len;
 
-		rc = selinux_sid_to_string(sid, &ctx, &len);
+		rc = security_secid_to_secctx(sid, &ctx, &len);
 		if (rc) {
 			audit_log_format(ab, " sid=%u", sid);
 			allow_changes = 0; /* Something weird, deny request */
 		} else {
 			audit_log_format(ab, " subj=%s", ctx);
-			kfree(ctx);
+			security_release_secctx(ctx, len);
 		}
 	}
 	audit_log_format(ab, " res=%d", allow_changes);
@@ -543,12 +543,12 @@ static int audit_log_common_recv_msg(struct audit_buffer **ab, u16 msg_type,
 	audit_log_format(*ab, "user pid=%d uid=%u auid=%u",
 			 pid, uid, auid);
 	if (sid) {
-		rc = selinux_sid_to_string(sid, &ctx, &len);
+		rc = security_secid_to_secctx(sid, &ctx, &len);
 		if (rc)
 			audit_log_format(*ab, " ssid=%u", sid);
 		else
 			audit_log_format(*ab, " subj=%s", ctx);
-		kfree(ctx);
+		security_release_secctx(ctx, len);
 	}
 
 	return rc;
@@ -750,18 +750,18 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
 		break;
 	}
 	case AUDIT_SIGNAL_INFO:
-		err = selinux_sid_to_string(audit_sig_sid, &ctx, &len);
+		err = security_secid_to_secctx(audit_sig_sid, &ctx, &len);
 		if (err)
 			return err;
 		sig_data = kmalloc(sizeof(*sig_data) + len, GFP_KERNEL);
 		if (!sig_data) {
-			kfree(ctx);
+			security_release_secctx(ctx, len);
 			return -ENOMEM;
 		}
 		sig_data->uid = audit_sig_uid;
 		sig_data->pid = audit_sig_pid;
 		memcpy(sig_data->ctx, ctx, len);
-		kfree(ctx);
+		security_release_secctx(ctx, len);
 		audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_SIGNAL_INFO,
 				0, 0, sig_data, sizeof(*sig_data) + len);
 		kfree(sig_data);
diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c
index 2f2914b..894e3bd 100644
--- a/kernel/auditfilter.c
+++ b/kernel/auditfilter.c
@@ -28,6 +28,7 @@
 #include <linux/netlink.h>
 #include <linux/sched.h>
 #include <linux/inotify.h>
+#include <linux/security.h>
 #include <linux/selinux.h>
 #include "audit.h"
 
@@ -1515,11 +1516,11 @@ static void audit_log_rule_change(uid_t loginuid, u32 sid, char *action,
 	if (sid) {
 		char *ctx = NULL;
 		u32 len;
-		if (selinux_sid_to_string(sid, &ctx, &len))
+		if (security_secid_to_secctx(sid, &ctx, &len))
 			audit_log_format(ab, " ssid=%u", sid);
 		else
 			audit_log_format(ab, " subj=%s", ctx);
-		kfree(ctx);
+		security_release_secctx(ctx, len);
 	}
 	audit_log_format(ab, " op=%s rule key=", action);
 	if (rule->filterkey)
diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index d07fc4a..631c044 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -530,7 +530,7 @@ static int audit_filter_rules(struct task_struct *tsk,
 			   logged upon error */
 			if (f->se_rule) {
 				if (need_sid) {
-					selinux_get_task_sid(tsk, &sid);
+					security_task_getsecid(tsk, &sid);
 					need_sid = 0;
 				}
 				result = selinux_audit_rule_match(sid, f->type,
@@ -885,11 +885,11 @@ void audit_log_task_context(struct audit_buffer *ab)
 	int error;
 	u32 sid;
 
-	selinux_get_task_sid(current, &sid);
+	security_task_getsecid(current, &sid);
 	if (!sid)
 		return;
 
-	error = selinux_sid_to_string(sid, &ctx, &len);
+	error = security_secid_to_secctx(sid, &ctx, &len);
 	if (error) {
 		if (error != -EINVAL)
 			goto error_path;
@@ -897,7 +897,7 @@ void audit_log_task_context(struct audit_buffer *ab)
 	}
 
 	audit_log_format(ab, " subj=%s", ctx);
-	kfree(ctx);
+	security_release_secctx(ctx, len);
 	return;
 
 error_path:
@@ -951,7 +951,7 @@ static int audit_log_pid_context(struct audit_context *context, pid_t pid,
 
 	audit_log_format(ab, "opid=%d oauid=%d ouid=%d oses=%d", pid, auid,
 			 uid, sessionid);
-	if (selinux_sid_to_string(sid, &s, &len)) {
+	if (security_secid_to_secctx(sid, &s, &len)) {
 		audit_log_format(ab, " obj=(none)");
 		rc = 1;
 	} else
@@ -1268,14 +1268,14 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *ts
 			if (axi->osid != 0) {
 				char *ctx = NULL;
 				u32 len;
-				if (selinux_sid_to_string(
+				if (security_secid_to_secctx(
 						axi->osid, &ctx, &len)) {
 					audit_log_format(ab, " osid=%u",
 							axi->osid);
 					call_panic = 1;
 				} else
 					audit_log_format(ab, " obj=%s", ctx);
-				kfree(ctx);
+				security_release_secctx(ctx, len);
 			}
 			break; }
 
@@ -1389,13 +1389,13 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *ts
 		if (n->osid != 0) {
 			char *ctx = NULL;
 			u32 len;
-			if (selinux_sid_to_string(
+			if (security_secid_to_secctx(
 				n->osid, &ctx, &len)) {
 				audit_log_format(ab, " osid=%u", n->osid);
 				call_panic = 2;
 			} else
 				audit_log_format(ab, " obj=%s", ctx);
-			kfree(ctx);
+			security_release_secctx(ctx, len);
 		}
 
 		audit_log_end(ab);
@@ -1772,7 +1772,7 @@ static void audit_copy_inode(struct audit_names *name, const struct inode *inode
 	name->uid   = inode->i_uid;
 	name->gid   = inode->i_gid;
 	name->rdev  = inode->i_rdev;
-	selinux_get_inode_sid(inode, &name->osid);
+	security_inode_getsecid(inode, &name->osid);
 }
 
 /**
@@ -2187,8 +2187,7 @@ int __audit_ipc_obj(struct kern_ipc_perm *ipcp)
 	ax->uid = ipcp->uid;
 	ax->gid = ipcp->gid;
 	ax->mode = ipcp->mode;
-	selinux_get_ipc_sid(ipcp, &ax->osid);
-
+	security_ipc_getsecid(ipcp, &ax->osid);
 	ax->d.type = AUDIT_IPC;
 	ax->d.next = context->aux;
 	context->aux = (void *)ax;
@@ -2340,7 +2339,7 @@ void __audit_ptrace(struct task_struct *t)
 	context->target_auid = audit_get_loginuid(t);
 	context->target_uid = t->uid;
 	context->target_sessionid = audit_get_sessionid(t);
-	selinux_get_task_sid(t, &context->target_sid);
+	security_task_getsecid(t, &context->target_sid);
 	memcpy(context->target_comm, t->comm, TASK_COMM_LEN);
 }
 
@@ -2368,7 +2367,7 @@ int __audit_signal_info(int sig, struct task_struct *t)
 				audit_sig_uid = tsk->loginuid;
 			else
 				audit_sig_uid = tsk->uid;
-			selinux_get_task_sid(tsk, &audit_sig_sid);
+			security_task_getsecid(tsk, &audit_sig_sid);
 		}
 		if (!audit_signals || audit_dummy_context())
 			return 0;
@@ -2381,7 +2380,7 @@ int __audit_signal_info(int sig, struct task_struct *t)
 		ctx->target_auid = audit_get_loginuid(t);
 		ctx->target_uid = t->uid;
 		ctx->target_sessionid = audit_get_sessionid(t);
-		selinux_get_task_sid(t, &ctx->target_sid);
+		security_task_getsecid(t, &ctx->target_sid);
 		memcpy(ctx->target_comm, t->comm, TASK_COMM_LEN);
 		return 0;
 	}
@@ -2402,7 +2401,7 @@ int __audit_signal_info(int sig, struct task_struct *t)
 	axp->target_auid[axp->pid_count] = audit_get_loginuid(t);
 	axp->target_uid[axp->pid_count] = t->uid;
 	axp->target_sessionid[axp->pid_count] = audit_get_sessionid(t);
-	selinux_get_task_sid(t, &axp->target_sid[axp->pid_count]);
+	security_task_getsecid(t, &axp->target_sid[axp->pid_count]);
 	memcpy(axp->target_comm[axp->pid_count], t->comm, TASK_COMM_LEN);
 	axp->pid_count++;
 
@@ -2432,16 +2431,16 @@ void audit_core_dumps(long signr)
 	ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_ANOM_ABEND);
 	audit_log_format(ab, "auid=%u uid=%u gid=%u ses=%u",
 			auid, current->uid, current->gid, sessionid);
-	selinux_get_task_sid(current, &sid);
+	security_task_getsecid(current, &sid);
 	if (sid) {
 		char *ctx = NULL;
 		u32 len;
 
-		if (selinux_sid_to_string(sid, &ctx, &len))
+		if (security_secid_to_secctx(sid, &ctx, &len))
 			audit_log_format(ab, " ssid=%u", sid);
 		else
 			audit_log_format(ab, " subj=%s", ctx);
-		kfree(ctx);
+		security_release_secctx(ctx, len);
 	}
 	audit_log_format(ab, " pid=%d comm=", current->pid);
 	audit_log_untrustedstring(ab, current->comm);


-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 65%]

* [PATCH -mm 2/4] SELinux: Remove various exported symbols
  2008-02-26 23:22 94% [PATCH -mm 0/4] LSM interfaced Audit (SELinux audit separation) Ahmed S. Darwish
  2008-02-26 23:24 75% ` [PATCH -mm 1/4] LSM: Introduce inode_getsecid and ipc_getsecid hooks Ahmed S. Darwish
@ 2008-02-26 23:25 74% ` Ahmed S. Darwish
  2008-02-26 23:28 65% ` [PATCH -mm 3/4] Audit: start not to use SELinux " Ahmed S. Darwish
  2008-02-26 23:31 99% ` [PATCH -mm 4/4] Netlink: Use LSM interface instead of SELinux one Ahmed S. Darwish
  3 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2008-02-26 23:25 UTC (permalink / raw)
  To: Chris Wright, Stephen Smalley, James Morris, Eric Paris,
	Casey Schaufler, David Woodhouse
  Cc: linux-security-module, LKML, akpm

Remove the following exported SELinux interfaces:
selinux_get_inode_sid(inode, sid)
selinux_get_ipc_sid(ipcp, sid) 
selinux_get_task_sid(tsk, sid)
selinux_sid_to_string(sid, ctx, len)

and substitue them with following equivalents respectively:
new LSM hook, inode_getsecid(inode, secid)
new LSM hook, ipc_getsecid*(ipcp, secid)
LSM hook, task_getsecid(tsk, secid)
LSM hook, sid_to_secctx(sid, ctx, len)

This is done to remove SELinux dependency from some
of the kernel subsystems (audit).

Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

 include/linux/selinux.h    |   62 ---------------------------------------------
 security/selinux/exports.c |   42 ------------------------------
 security/selinux/hooks.c   |   19 ++++++++++++-
 3 files changed, 17 insertions(+), 106 deletions(-)

diff --git a/include/linux/selinux.h b/include/linux/selinux.h
index 8c2cc4c..24b0af1 100644
--- a/include/linux/selinux.h
+++ b/include/linux/selinux.h
@@ -16,7 +16,6 @@
 
 struct selinux_audit_rule;
 struct audit_context;
-struct inode;
 struct kern_ipc_perm;
 
 #ifdef CONFIG_SECURITY_SELINUX
@@ -70,45 +69,6 @@ int selinux_audit_rule_match(u32 sid, u32 field, u32 op,
 void selinux_audit_set_callback(int (*callback)(void));
 
 /**
- *     selinux_sid_to_string - map a security context ID to a string
- *     @sid: security context ID to be converted.
- *     @ctx: address of context string to be returned
- *     @ctxlen: length of returned context string.
- *
- *     Returns 0 if successful, -errno if not.  On success, the context
- *     string will be allocated internally, and the caller must call
- *     kfree() on it after use.
- */
-int selinux_sid_to_string(u32 sid, char **ctx, u32 *ctxlen);
-
-/**
- *     selinux_get_inode_sid - get the inode's security context ID
- *     @inode: inode structure to get the sid from.
- *     @sid: pointer to security context ID to be filled in.
- *
- *     Returns nothing
- */
-void selinux_get_inode_sid(const struct inode *inode, u32 *sid);
-
-/**
- *     selinux_get_ipc_sid - get the ipc security context ID
- *     @ipcp: ipc structure to get the sid from.
- *     @sid: pointer to security context ID to be filled in.
- *
- *     Returns nothing
- */
-void selinux_get_ipc_sid(const struct kern_ipc_perm *ipcp, u32 *sid);
-
-/**
- *     selinux_get_task_sid - return the SID of task
- *     @tsk: the task whose SID will be returned
- *     @sid: pointer to security context ID to be filled in.
- *
- *     Returns nothing
- */
-void selinux_get_task_sid(struct task_struct *tsk, u32 *sid);
-
-/**
  *     selinux_string_to_sid - map a security context string to a security ID
  *     @str: the security context string to be mapped
  *     @sid: ID value returned via this.
@@ -175,28 +135,6 @@ static inline void selinux_audit_set_callback(int (*callback)(void))
 	return;
 }
 
-static inline int selinux_sid_to_string(u32 sid, char **ctx, u32 *ctxlen)
-{
-       *ctx = NULL;
-       *ctxlen = 0;
-       return 0;
-}
-
-static inline void selinux_get_inode_sid(const struct inode *inode, u32 *sid)
-{
-	*sid = 0;
-}
-
-static inline void selinux_get_ipc_sid(const struct kern_ipc_perm *ipcp, u32 *sid)
-{
-	*sid = 0;
-}
-
-static inline void selinux_get_task_sid(struct task_struct *tsk, u32 *sid)
-{
-	*sid = 0;
-}
-
 static inline int selinux_string_to_sid(const char *str, u32 *sid)
 {
        *sid = 0;
diff --git a/security/selinux/exports.c b/security/selinux/exports.c
index 87d2bb3..64af2d3 100644
--- a/security/selinux/exports.c
+++ b/security/selinux/exports.c
@@ -25,48 +25,6 @@
 /* SECMARK reference count */
 extern atomic_t selinux_secmark_refcount;
 
-int selinux_sid_to_string(u32 sid, char **ctx, u32 *ctxlen)
-{
-	if (selinux_enabled)
-		return security_sid_to_context(sid, ctx, ctxlen);
-	else {
-		*ctx = NULL;
-		*ctxlen = 0;
-	}
-
-	return 0;
-}
-
-void selinux_get_inode_sid(const struct inode *inode, u32 *sid)
-{
-	if (selinux_enabled) {
-		struct inode_security_struct *isec = inode->i_security;
-		*sid = isec->sid;
-		return;
-	}
-	*sid = 0;
-}
-
-void selinux_get_ipc_sid(const struct kern_ipc_perm *ipcp, u32 *sid)
-{
-	if (selinux_enabled) {
-		struct ipc_security_struct *isec = ipcp->security;
-		*sid = isec->sid;
-		return;
-	}
-	*sid = 0;
-}
-
-void selinux_get_task_sid(struct task_struct *tsk, u32 *sid)
-{
-	if (selinux_enabled) {
-		struct task_security_struct *tsec = tsk->security;
-		*sid = tsec->sid;
-		return;
-	}
-	*sid = 0;
-}
-
 int selinux_string_to_sid(char *str, u32 *sid)
 {
 	if (selinux_enabled)
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index f42ebfc..62a0f26 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -2724,6 +2724,12 @@ static int selinux_inode_killpriv(struct dentry *dentry)
 	return secondary_ops->inode_killpriv(dentry);
 }
 
+static void selinux_inode_getsecid(const struct inode *inode, u32 *secid)
+{
+	struct inode_security_struct *isec = inode->i_security;
+	*secid = isec->sid;
+}
+
 /* file security operations */
 
 static int selinux_revalidate_file_permission(struct file *file, int mask)
@@ -3120,7 +3126,8 @@ static int selinux_task_getsid(struct task_struct *p)
 
 static void selinux_task_getsecid(struct task_struct *p, u32 *secid)
 {
-	selinux_get_task_sid(p, secid);
+	struct task_security_struct *tsec = p->security;
+	*secid = tsec->sid;
 }
 
 static int selinux_task_setgroups(struct group_info *group_info)
@@ -4090,7 +4097,7 @@ static int selinux_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *
 		goto out;
 
 	if (sock && family == PF_UNIX)
-		selinux_get_inode_sid(SOCK_INODE(sock), &peer_secid);
+		selinux_inode_getsecid(SOCK_INODE(sock), &peer_secid);
 	else if (skb)
 		selinux_skb_peerlbl_sid(skb, family, &peer_secid);
 
@@ -4970,6 +4977,12 @@ static int selinux_ipc_permission(struct kern_ipc_perm *ipcp, short flag)
 	return ipc_has_perm(ipcp, av);
 }
 
+static void selinux_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
+{
+	struct ipc_security_struct *isec = ipcp->security;
+	*secid = isec->sid;
+}
+
 /* module stacking operations */
 static int selinux_register_security (const char *name, struct security_operations *ops)
 {
@@ -5292,6 +5305,7 @@ static struct security_operations selinux_ops = {
 	.inode_listsecurity =           selinux_inode_listsecurity,
 	.inode_need_killpriv =		selinux_inode_need_killpriv,
 	.inode_killpriv =		selinux_inode_killpriv,
+	.inode_getsecid =               selinux_inode_getsecid,
 
 	.file_permission =		selinux_file_permission,
 	.file_alloc_security =		selinux_file_alloc_security,
@@ -5332,6 +5346,7 @@ static struct security_operations selinux_ops = {
 	.task_to_inode =                selinux_task_to_inode,
 
 	.ipc_permission =		selinux_ipc_permission,
+	.ipc_getsecid =                 selinux_ipc_getsecid,
 
 	.msg_msg_alloc_security =	selinux_msg_msg_alloc_security,
 	.msg_msg_free_security =	selinux_msg_msg_free_security,

-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 74%]

* [PATCH -mm 1/4] LSM: Introduce inode_getsecid and ipc_getsecid hooks
  2008-02-26 23:22 94% [PATCH -mm 0/4] LSM interfaced Audit (SELinux audit separation) Ahmed S. Darwish
@ 2008-02-26 23:24 75% ` Ahmed S. Darwish
    2008-02-26 23:25 74% ` [PATCH -mm 2/4] SELinux: Remove various exported symbols Ahmed S. Darwish
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2008-02-26 23:24 UTC (permalink / raw)
  To: Chris Wright, Stephen Smalley, James Morris, Eric Paris,
	Casey Schaufler, David Woodhouse
  Cc: linux-security-module, LKML, akpm

Introduce inode_getsecid(inode, secid) and ipc_getsecid(ipcp, secid)
LSM hooks.

This hooks will be used instead of similar exported SELinux 
interfaces.

Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

 include/linux/security.h |   18 ++++++++++++++++++
 security/dummy.c         |   12 ++++++++++++
 security/security.c      |   12 ++++++++++++
 3 files changed, 42 insertions(+)

diff --git a/include/linux/security.h b/include/linux/security.h
index a33fd03..a7fb136 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -449,6 +449,10 @@ struct request_sock;
  *	@dentry is the dentry being changed.
  *	Return 0 on success.  If error is returned, then the operation
  *	causing setuid bit removal is failed.
+ * @inode_getsecid:
+ *      Get the secid associated with the node
+ *      @inode contains a pointer to the inode
+ *      @secid contains a pointer to the location to store the result
  *
  * Security hooks for file operations
  *
@@ -989,6 +993,10 @@ struct request_sock;
  *	@ipcp contains the kernel IPC permission structure
  *	@flag contains the desired (requested) permission set
  *	Return 0 if permission is granted.
+ * @ipc_getsecid:
+ *      Get the secid associated with the ipc object
+ *      @ipcp contains the kernel IPC permission structure
+ *      @secid contains a pointer to the location where result will be saved
  *
  * Security hooks for individual messages held in System V IPC message queues
  * @msg_msg_alloc_security:
@@ -1310,6 +1318,7 @@ struct security_operations {
 	int (*inode_getsecurity)(const struct inode *inode, const char *name, void **buffer, bool alloc);
   	int (*inode_setsecurity)(struct inode *inode, const char *name, const void *value, size_t size, int flags);
   	int (*inode_listsecurity)(struct inode *inode, char *buffer, size_t buffer_size);
+	void (*inode_getsecid)(const struct inode *inode, u32 *secid);
 
 	int (*file_permission) (struct file * file, int mask);
 	int (*file_alloc_security) (struct file * file);
@@ -1362,6 +1371,7 @@ struct security_operations {
 	void (*task_to_inode)(struct task_struct *p, struct inode *inode);
 
 	int (*ipc_permission) (struct kern_ipc_perm * ipcp, short flag);
+	void (*ipc_getsecid) (struct kern_ipc_perm *ipcp, u32 *secid);
 
 	int (*msg_msg_alloc_security) (struct msg_msg * msg);
 	void (*msg_msg_free_security) (struct msg_msg * msg);
@@ -1571,6 +1581,7 @@ int security_inode_killpriv(struct dentry *dentry);
 int security_inode_getsecurity(const struct inode *inode, const char *name, void **buffer, bool alloc);
 int security_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags);
 int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size);
+void security_inode_getsecid(const struct inode *inode, u32 *secid);
 int security_file_permission(struct file *file, int mask);
 int security_file_alloc(struct file *file);
 void security_file_free(struct file *file);
@@ -1615,6 +1626,7 @@ int security_task_prctl(int option, unsigned long arg2, unsigned long arg3,
 void security_task_reparent_to_init(struct task_struct *p);
 void security_task_to_inode(struct task_struct *p, struct inode *inode);
 int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag);
+void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid);
 int security_msg_msg_alloc(struct msg_msg *msg);
 void security_msg_msg_free(struct msg_msg *msg);
 int security_msg_queue_alloc(struct msg_queue *msq);
@@ -1985,6 +1997,9 @@ static inline int security_inode_listsecurity(struct inode *inode, char *buffer,
 	return 0;
 }
 
+static inline void security_inode_getsecid(const struct inode *inode, u32 *secid)
+{ }
+
 static inline int security_file_permission (struct file *file, int mask)
 {
 	return 0;
@@ -2179,6 +2194,9 @@ static inline int security_ipc_permission (struct kern_ipc_perm *ipcp,
 	return 0;
 }
 
+static inline void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
+{ }
+
 static inline int security_msg_msg_alloc (struct msg_msg * msg)
 {
 	return 0;
diff --git a/security/dummy.c b/security/dummy.c
index 6a0056b..c2f4c52 100644
--- a/security/dummy.c
+++ b/security/dummy.c
@@ -422,6 +422,11 @@ static int dummy_inode_listsecurity(struct inode *inode, char *buffer, size_t bu
 	return 0;
 }
 
+static void dummy_inode_getsecid(const struct inode *inode, u32 *secid)
+{
+	return;
+}
+
 static int dummy_file_permission (struct file *file, int mask)
 {
 	return 0;
@@ -614,6 +619,11 @@ static int dummy_ipc_permission (struct kern_ipc_perm *ipcp, short flag)
 	return 0;
 }
 
+static void dummy_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
+{
+	return;
+}
+
 static int dummy_msg_msg_alloc_security (struct msg_msg *msg)
 {
 	return 0;
@@ -1062,6 +1072,7 @@ void security_fixup_ops (struct security_operations *ops)
 	set_to_dummy_if_null(ops, inode_getsecurity);
 	set_to_dummy_if_null(ops, inode_setsecurity);
 	set_to_dummy_if_null(ops, inode_listsecurity);
+	set_to_dummy_if_null(ops, inode_getsecid);
 	set_to_dummy_if_null(ops, file_permission);
 	set_to_dummy_if_null(ops, file_alloc_security);
 	set_to_dummy_if_null(ops, file_free_security);
@@ -1098,6 +1109,7 @@ void security_fixup_ops (struct security_operations *ops)
 	set_to_dummy_if_null(ops, task_reparent_to_init);
  	set_to_dummy_if_null(ops, task_to_inode);
 	set_to_dummy_if_null(ops, ipc_permission);
+	set_to_dummy_if_null(ops, ipc_getsecid);
 	set_to_dummy_if_null(ops, msg_msg_alloc_security);
 	set_to_dummy_if_null(ops, msg_msg_free_security);
 	set_to_dummy_if_null(ops, msg_queue_alloc_security);
diff --git a/security/security.c b/security/security.c
index 3e75b90..fcf2be3 100644
--- a/security/security.c
+++ b/security/security.c
@@ -516,6 +516,12 @@ int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer
 	return security_ops->inode_listsecurity(inode, buffer, buffer_size);
 }
 
+void security_inode_getsecid(const struct inode *inode, u32 *secid)
+{
+	security_ops->inode_getsecid(inode, secid);
+}
+EXPORT_SYMBOL(security_inode_getsecid);
+
 int security_file_permission(struct file *file, int mask)
 {
 	return security_ops->file_permission(file, mask);
@@ -705,6 +711,12 @@ int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag)
 	return security_ops->ipc_permission(ipcp, flag);
 }
 
+void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
+{
+	security_ops->ipc_getsecid(ipcp, secid);
+}
+EXPORT_SYMBOL(security_ipc_getsecid);
+
 int security_msg_msg_alloc(struct msg_msg *msg)
 {
 	return security_ops->msg_msg_alloc_security(msg);

-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 75%]

* [PATCH -mm 0/4] LSM interfaced Audit (SELinux audit separation)
@ 2008-02-26 23:22 94% Ahmed S. Darwish
  2008-02-26 23:24 75% ` [PATCH -mm 1/4] LSM: Introduce inode_getsecid and ipc_getsecid hooks Ahmed S. Darwish
                   ` (3 more replies)
  0 siblings, 4 replies; 200+ results
From: Ahmed S. Darwish @ 2008-02-26 23:22 UTC (permalink / raw)
  To: Chris Wright, Stephen Smalley, James Morris, Eric Paris,
	Casey Schaufler, David Woodhouse
  Cc: linux-security-module, LKML, akpm

Hi everybody,

This is a beginning of work (started and suggested by Casey Schaufler)
to let Audit be LSM neutral. This is done for proper audit<->SMACK 
integration which will also be useful for any future LSM.

What follows is four patches to remove the following exported 
SElinux interfaces:
selinux_get_inode_sid(inode, sid)
selinux_get_ipc_sid(ipcp, sid) 
selinux_get_task_sid(tsk, sid)
selinux_sid_to_string(sid, ctx, len)

and substitue them respectively with:
new LSM hook, inode_getsecid(inode, secid)
new LSM hook, ipc_getsecid*(ipcp, secid)
LSM hook, task_getsecid(tsk, secid)
LSM hook, sid_to_secctx(sid, ctx, len)

The work isn't complete yet, and those four patches are sent for
an early review. A new LSM interfaces/hooks will be created to
substitute the SELinux exported audit interfaces, thus completing
the separation.

It's worthy to note that those changes can be merged in
their current state. The tree is fully grepped to make sure
that no subsystem ,except the patched ones, will be affected
by this SELinux API breakage.

Diffstat:

 include/linux/security.h   |   23 +++++++++++++++-
 include/linux/selinux.h    |   62 ---------------------------------------------
 kernel/audit.c             |   14 +++++-----
 kernel/auditfilter.c       |    5 ++-
 kernel/auditsc.c           |   37 +++++++++++++-------------
 net/netlink/af_netlink.c   |    3 --
 security/dummy.c           |   16 ++++++++++-
 security/security.c        |   12 ++++++++
 security/selinux/exports.c |   42 ------------------------------
 security/selinux/hooks.c   |   19 ++++++++++++-
 10 files changed, 95 insertions(+), 138 deletions(-)

Thanks in advance for your reviews and comments.

-- 
Ahmed S. Darwish
Blog: http://darwish-07.blogspot.com
Homepage: http://darwish.07.googlepages.com


^ permalink raw reply	[relevance 94%]

* Re: 2.6.25-rc3: Reported regressions from 2.6.24
  @ 2008-02-25 18:24 99% ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2008-02-25 18:24 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: LKML, Andrew Morton, Linus Torvalds, Adrian Bunk, Ingo Molnar

On Mon, Feb 25, 2008 at 02:41:40AM +0100, Rafael J. Wysocki wrote:
> This message contains a list of some regressions from 2.6.24 reported since
> 2.6.25-rc1 was released, for which there are no fixes in the mainline I know
> of.  If any of them have been fixed already, please let me know.
> 
> If you know of any other unresolved regressions from 2.6.24, please let me know
> either and I'll add them to the list.  Also, please let me know if any of the
> entries below are invalid.
> 

There's an lguest Oops reported here:

http://lkml.org/lkml/2008/2/24/136

and a patch in the same report. It's not yet approved by Rusty, but
Ingo thinks it's fine.

Regards,

-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 99%]

* Re: [BUG + PATCH/Bugfix] x86/lguest: fix pgdir pmd index calculation
  2008-02-24 16:26 99%   ` Ahmed S. Darwish
@ 2008-02-25  0:18 97%     ` Ahmed S. Darwish
  2008-02-29  0:32 89%       ` Ahmed S. Darwish
  0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2008-02-25  0:18 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Rusty Russell,
	LKML, lguest, akpm, Jeremy Fitzhardinge

On Sun, Feb 24, 2008 at 06:26:53PM +0200, Ahmed S. Darwish wrote:
> On Sun, Feb 24, 2008 at 05:18:14PM +0100, Ingo Molnar wrote:
> 
> > I've picked up your patch into x86.git#testing (until Rusty picks it 
> > up), you can track it the following way:
> > 
> >     http://people.redhat.com/mingo/x86.git/README
> > 
> > it has other lguest fixes as well - could you double-check that 
> > x86.git#testing works fine for you as-is? (i've just updated the git 
> > tree so it includes your fix as well)
> > 
> 
> Ofcourse. I'll send you the results by GMT night.
> 

This thread's main bug no longer appears. There's a new bug though,
but it looks nicer than the original ugly bug!. 

The new bug does *not* appear in mainline with the same patch. It's
a panic, but this time on the _guest_ side (which is the same host's
kernel).

[    0.023996] CPU: Intel(R) Pentium(R) M processor 1500MHz stepping 05
[    0.023996] Kernel panic - not syncing: Kernel compiled for Pentium+, requires TSC feature!
[    0.023996] Pid: 0, comm: swapper Not tainted 2.6.25-rc2-00815-g3db3a05 #64
[    0.024996]  [<c011bbc7>] panic+0x47/0x120
[    0.024996]  [<c0101b30>] lguest_power_off+0x0/0x20
[    0.024996]  [<c02a88c5>] check_bugs+0x155/0x170
[    0.024996]  [<c02a2b1f>] start_kernel+0x22f/0x2d0
[    0.024996]  [<c02a2390>] unknown_bootoption+0x0/0x1f0
[    0.024996]  [<c0101450>] lguest_restart+0x0/0x20
[    0.024996]  [<c0101450>] lguest_restart+0x0/0x20
[    0.024996]  [<c02a5e22>] lguest_init+0x282/0x290
[    0.024996]  =======================

I'll track it further in my first free time slot.

It seems lguest is very sensitive to x86 tree changes. Could it be 
included in a sort of automatic guest-boot testing, please ?

Thank you,

-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 97%]

* Re: [BUG + PATCH/Bugfix] x86/lguest: fix pgdir pmd index calculation
  @ 2008-02-24 16:26 99%   ` Ahmed S. Darwish
  2008-02-25  0:18 97%     ` Ahmed S. Darwish
  0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2008-02-24 16:26 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Rusty Russell,
	LKML, lguest, akpm, Jeremy Fitzhardinge

On Sun, Feb 24, 2008 at 05:18:14PM +0100, Ingo Molnar wrote:
> 
> * Ahmed S. Darwish <darwish.07@gmail.com> wrote:
> 
> > I am not sure why the division over four existed in the first place. 
> > It seems bogus, maybe the Xen patch just made the problem appear ?
> 
> i think so - nice detective work and nice fix!
> 

Thanks!. Your turn-around time is super, which is so nice too ;).

> I've picked up your patch into x86.git#testing (until Rusty picks it 
> up), you can track it the following way:
> 
>     http://people.redhat.com/mingo/x86.git/README
> 
> it has other lguest fixes as well - could you double-check that 
> x86.git#testing works fine for you as-is? (i've just updated the git 
> tree so it includes your fix as well)
> 

Ofcourse. I'll send you the results by GMT night.

Regards,

-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 99%]

* [BUG + PATCH/Bugfix] x86/lguest: fix pgdir pmd index calculation
@ 2008-02-24 15:55 78% Ahmed S. Darwish
      0 siblings, 2 replies; 200+ results
From: Ahmed S. Darwish @ 2008-02-24 15:55 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Rusty Russell
  Cc: LKML, lguest, akpm

Hi all,

Beginning from commits close to v2.6.25-rc2, running lguest always oopses
the host kernel. Oops is at [1].

Bisection led to the following commit:

commit 37cc8d7f963ba2deec29c9b68716944516a3244f

    x86/early_ioremap: don't assume we're using swapper_pg_dir
    
    At the early stages of boot, before the kernel pagetable has been
    fully initialized, a Xen kernel will still be running off the
    Xen-provided pagetables rather than swapper_pg_dir[].  Therefore,
    readback cr3 to determine the base of the pagetable rather than
    assuming swapper_pg_dir[].
    
 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
 {
-	pgd_t *pgd = &swapper_pg_dir[pgd_index(addr)];
+	/* Don't assume we're using swapper_pg_dir at this point */
+	pgd_t *base = __va(read_cr3());
+	pgd_t *pgd = &base[pgd_index(addr)];
 	pud_t *pud = pud_offset(pgd, addr);
 	pmd_t *pmd = pmd_offset(pud, addr);
 
Trying to analyze the problem, it seems on the guest side of lguest, 
%cr3 has a different value from &swapper_pg-dir (which
is AFAIK fine on a pravirt guest): 

Putting some debugging messages in early_ioremap_pmd:

/* Appears 3 times */
[    0.000000] ***************************
[    0.000000] __va(%cr3) = c0000000, &swapper_pg_dir = c02cc000
[    0.000000] ***************************

After 8 hours of debugging and staring on lguest code, I noticed something
strange in paravirt_ops->set_pmd hypercall invocation:

static void lguest_set_pmd(pmd_t *pmdp, pmd_t pmdval)
{
	*pmdp = pmdval;	
	lazy_hcall(LHCALL_SET_PMD, __pa(pmdp)&PAGE_MASK,
		   (__pa(pmdp)&(PAGE_SIZE-1))/4, 0);
}

The first hcall parameter is global pgdir which looks fine. The second
parameter is the pmd index in the pgdir which is suspectful.

AFAIK, calculating the index of pmd does not need a divisoin over four. 
Removing the division made lguest work fine again . Patch is at [2].

I am not sure why the division over four existed in the first place. It
seems bogus, maybe the Xen patch just made the problem appear ?

[2]: The patch:

[PATCH] lguest: fix pgdir pmd index cacluation

Remove an error in index calculation which leads to removing
a not existing shadow page table (leading to a Null dereference).

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
index 5afdde4..6636750 100644
--- a/arch/x86/lguest/boot.c
+++ b/arch/x86/lguest/boot.c
@@ -489,7 +489,7 @@ static void lguest_set_pmd(pmd_t *pmdp, pmd_t pmdval)
 {
 	*pmdp = pmdval;
 	lazy_hcall(LHCALL_SET_PMD, __pa(pmdp)&PAGE_MASK,
-		   (__pa(pmdp)&(PAGE_SIZE-1))/4, 0);
+		   (__pa(pmdp)&(PAGE_SIZE-1)), 0);
 }
 
 /* There are a couple of legacy places where the kernel sets a PTE, but we


[1]: The oops:

[    9.936880] BUG: unable to handle kernel NULL pointer dereference at 00000ff8
[    9.938015] IP: [<c0204ef6>] release_pgd+0x6/0x60
[    9.938379] *pde = 00000000 
[    9.938618] Oops: 0000 [#1] 
[    9.938680] Modules linked in:
[    9.938680] 
[    9.938680] Pid: 173, comm: lguest Not tainted (2.6.25-rc2-dirty #59)
[    9.938680] EIP: 0060:[<c0204ef6>] EFLAGS: 00000202 CPU: 0
[    9.938680] EIP is at release_pgd+0x6/0x60
[    9.938680] EAX: c7cfe000 EBX: c7d06fb8 ECX: 00000000 EDX: 00000ff8
[    9.938680] ESI: c7cfe004 EDI: 00000ff8 EBP: 00000000 ESP: c7cebe5c
[    9.938680]  DS: 007b ES: 007b FS: 0000 GS: 0033 SS: 0058
[    9.938680] Process lguest (pid: 173, ti=c7cea000 task=c7c94ac0 task.ti=c7cea000)
[    9.938680] Stack: c7d06fb8 c7cfe004 c7cfe004 00000000 c0204a61 00000000 00000246 00000246 
[    9.938680]        c7cbd528 c10ed500 b5d65000 00000002 c02110f4 076a8067 c0151ccc c7cc8668 
[    9.938680]        01d65000 c7cbd528 00000007 c7cc8668 00000000 b5d65000 c01531b8 00000246 
[    9.938680] Call Trace:
[    9.938680]  [<c0204a61>] do_hcall+0x1a1/0x230
[    9.938680]  [<c02110f4>] _spin_unlock+0x14/0x20
[    9.938680]  [<c0151ccc>] follow_page+0x9c/0x190
[    9.938680]  [<c01531b8>] get_user_pages+0x108/0x2c0
[    9.938680]  [<c01bd9af>] copy_to_user+0x3f/0x70
[    9.938680]  [<c0206ae0>] read+0x0/0xb8
[    9.938680]  [<c0204ba9>] do_hypercalls+0xb9/0x2a0
[    9.938680]  [<c0207b5a>] lguest_arch_run_guest+0xfa/0x1d0
[    9.938680]  [<c0204651>] run_guest+0xc1/0x110
[    9.938680]  [<c0206ae0>] read+0x0/0xb8
[    9.938680]  [<c02045bb>] run_guest+0x2b/0x110
[    9.938680]  [<c01655df>] vfs_read+0x8f/0xc0
[    9.938680]  [<c0165ab6>] sys_pread64+0x76/0x80
[    9.938680]  [<c0103864>] sysenter_past_esp+0x6d/0xc5
[    9.938680]  =======================
[    9.938680] Code: 75 03 5b c3 90 89 d8 e8 39 dc f0 ff 90 8b 1d d8 44 4f c0 c1 e8 0c c1 e0 05 01 d8 5b e9 24 81 f4 ff 8d 74 26 00 55 57 89 d7 56 53 <8b> 02 e8 f3 db f0 ff 90 a8 01 74 3f 8b 07 e8 e7 db f0 ff 90 25 
[    9.938680] EIP: [<c0204ef6>] release_pgd+0x6/0x60 SS:ESP 0058:c7cebe5c
[    9.939759] ---[ end trace 0cda9e589a597173 ]---

Regards,

-- 

"Better to light a candle, than curse the darkness"

Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 78%]

* Re: [PATCH] Tasklets: Avoid duplicating __tasklet_{,hi_}schedule() code
  @ 2008-02-20 19:39 99%           ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2008-02-20 19:39 UTC (permalink / raw)
  To: Dmitry Adamushko; +Cc: Ingo Molnar, LKML, Andrew Morton

On Wed, Feb 20, 2008 at 03:20:52PM +0100, Dmitry Adamushko wrote:
> On 20/02/2008, Ahmed S. Darwish <darwish.07@gmail.com> wrote:
> > On Wed, Feb 20, 2008 at 11:41:13AM +0100, Ingo Molnar wrote:
> > >
> > > * Ahmed S. Darwish <darwish.07@gmail.com> wrote:
> > >
> > > > > > -               local_irq_disable();
> > > > > > -               t->next = __get_cpu_var(tasklet_vec).list;
> > > > > > -               __get_cpu_var(tasklet_vec).list = t;
> > > > > > -               __raise_softirq_irqoff(TASKLET_SOFTIRQ);
> > > > > > -               local_irq_enable();
> > > > > > +               /* We were not lucky enough to run, reschedule. */
> > > > > > +               __tasklet_schedule(t);
> > > > >
> > > > > i think there's a subtle difference that you missed: this one does
> > > > > __raise_softirq_irqoff(), while __tasklet_schedule() does a
> > > > > raise_softirq_irqoff(). (note the lack of undescores)
> > > > >
> > > > > the reason is to avoid infinitely self-activating tasklets.
> > > >
> > > > Indeed, thanks a lot for the explanation. (maybe it's time to check
> > > > for new eyeglasses ;)).
> > >
> > > nah, it's rather subtle and the code looked good to me at first but i
> > > remembered that there was some small detail here to watch out for.
> > >
> > > i really dont like tasklets due to their many, arbitrary scheduling
> > > limitations, we should really use the "turn tasklets into kthreads"
> > > patch i posted last year.
> > >
> >
> > While we are at it, there's a small question that is bothering me
> > for a while (and I'm really thankful for help).
> >
> > I keep reading that softirqs (and naturally, tasklets) got executed
> > in interrupt context at the return from hardirq code path.
> >
> > Checking entry_32.S, I find no mentioning of softirqs on the return
> > path (beginning from ret_from_intr: to restore_all: )
> >
> > The only invocation I'm able to find is from local_bh_enable() and
> > from ksoftirqd/n threads (by calling do_softirq()). AFAIK, both
> > invocations occur in a _nont-interrupt_ context (exception context).
> >
> > So, where does the interrupt-context tasklets invocation really
> > occur ?
> 
> Look at irq_exit() in softirq.c.
> 
> The common sequence is ... -> do_IRQ() --> irq_exit() --> invoke_softirq()
> 
> 

Great, this was the last missing block in my understanding of softirqs :).
Thank you.

[btw, your MUA broke the CC list]

-- 
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 99%]

* Re: [PATCH] Tasklets: Avoid duplicating __tasklet_{,hi_}schedule() code
  @ 2008-02-20 13:37 99%       ` Ahmed S. Darwish
    0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2008-02-20 13:37 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Andrew Morton, Ingo Molnar, LKML

On Wed, Feb 20, 2008 at 11:41:13AM +0100, Ingo Molnar wrote:
> 
> * Ahmed S. Darwish <darwish.07@gmail.com> wrote:
> 
> > > > -		local_irq_disable();
> > > > -		t->next = __get_cpu_var(tasklet_vec).list;
> > > > -		__get_cpu_var(tasklet_vec).list = t;
> > > > -		__raise_softirq_irqoff(TASKLET_SOFTIRQ);
> > > > -		local_irq_enable();
> > > > +		/* We were not lucky enough to run, reschedule. */
> > > > +		__tasklet_schedule(t);
> > > 
> > > i think there's a subtle difference that you missed: this one does 
> > > __raise_softirq_irqoff(), while __tasklet_schedule() does a 
> > > raise_softirq_irqoff(). (note the lack of undescores)
> > > 
> > > the reason is to avoid infinitely self-activating tasklets.
> > 
> > Indeed, thanks a lot for the explanation. (maybe it's time to check 
> > for new eyeglasses ;)).
> 
> nah, it's rather subtle and the code looked good to me at first but i 
> remembered that there was some small detail here to watch out for.
> 
> i really dont like tasklets due to their many, arbitrary scheduling 
> limitations, we should really use the "turn tasklets into kthreads" 
> patch i posted last year.
> 

While we are at it, there's a small question that is bothering me
for a while (and I'm really thankful for help). 

I keep reading that softirqs (and naturally, tasklets) got executed 
in interrupt context at the return from hardirq code path.

Checking entry_32.S, I find no mentioning of softirqs on the return
path (beginning from ret_from_intr: to restore_all: )

The only invocation I'm able to find is from local_bh_enable() and
from ksoftirqd/n threads (by calling do_softirq()). AFAIK, both 
invocations occur in a _nont-interrupt_ context (exception context).

So, where does the interrupt-context tasklets invocation really 
occur ?

Thanks

-- 
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 99%]

* Re: [PATCH] Tasklets: Avoid duplicating __tasklet_{,hi_}schedule() code
  @ 2008-02-19 16:27 99%   ` Ahmed S. Darwish
    0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2008-02-19 16:27 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: Andrew Morton, Ingo Molnar, LKML

On Tue, Feb 19, 2008 at 04:52:52PM +0100, Ingo Molnar wrote:
> 
> * Ahmed S. Darwish <darwish.07@gmail.com> wrote:
> 
> > -		local_irq_disable();
> > -		t->next = __get_cpu_var(tasklet_vec).list;
> > -		__get_cpu_var(tasklet_vec).list = t;
> > -		__raise_softirq_irqoff(TASKLET_SOFTIRQ);
> > -		local_irq_enable();
> > +		/* We were not lucky enough to run, reschedule. */
> > +		__tasklet_schedule(t);
> 
> i think there's a subtle difference that you missed: this one does 
> __raise_softirq_irqoff(), while __tasklet_schedule() does a 
> raise_softirq_irqoff(). (note the lack of undescores)
> 
> the reason is to avoid infinitely self-activating tasklets.
> 

Indeed, thanks a lot for the explanation. (maybe it's time to check
for new eyeglasses ;)).

Regards

-- 
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 99%]

* [PATCH] Tasklets: Avoid duplicating __tasklet_{,hi_}schedule() code
@ 2008-02-19 15:37 99% Ahmed S. Darwish
    0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2008-02-19 15:37 UTC (permalink / raw)
  To: Andrew Morton, Ingo Molnar; +Cc: LKML

Hi all,

Avoid duplicating __tasklet_schedule() and __tasklet_hi_schedule()
code in tasklet_action() and tasklet_hi_action() respectively.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

This also saves a few bytes of image space:

   text	   data	    bss	    dec	    hex	filename
   3632	     12	    324	   3968	    f80	softirq.o.before
   3552	     12	    324	   3888	    f30	softirq.o.after

diff --git a/kernel/softirq.c b/kernel/softirq.c
index 5b3aea5..3068dc3 100644
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -414,11 +414,8 @@ static void tasklet_action(struct softirq_action *a)
 			tasklet_unlock(t);
 		}
 
-		local_irq_disable();
-		t->next = __get_cpu_var(tasklet_vec).list;
-		__get_cpu_var(tasklet_vec).list = t;
-		__raise_softirq_irqoff(TASKLET_SOFTIRQ);
-		local_irq_enable();
+		/* We were not lucky enough to run, reschedule. */
+		__tasklet_schedule(t);
 	}
 }
 
@@ -447,11 +444,8 @@ static void tasklet_hi_action(struct softirq_action *a)
 			tasklet_unlock(t);
 		}
 
-		local_irq_disable();
-		t->next = __get_cpu_var(tasklet_hi_vec).list;
-		__get_cpu_var(tasklet_hi_vec).list = t;
-		__raise_softirq_irqoff(HI_SOFTIRQ);
-		local_irq_enable();
+		/* We were not lucky enough to run, reschedule. */
+		__tasklet_hi_schedule(t);
 	}
 }
 

Regards,

-- 
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 99%]

* [PATCH x86] i8259A_32: Remove redundant irq_desc[NR_IRQ] initialization
@ 2008-02-17 22:59 98% Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2008-02-17 22:59 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin; +Cc: LKML

Hi all,

Remove redundant irq_desc[NR_IRQS] element initialization in 
init_ISA_irqs(). irq_desc[NR_IRQS] is already statically 
initialized with the same values in kernel/irq/handle.c .

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

 i8259_32.c |   26 ++++++--------------------
 1 file changed, 6 insertions(+), 20 deletions(-)

Tested only on a UP machine with an i8259A PIC.

diff --git a/arch/x86/kernel/i8259_32.c b/arch/x86/kernel/i8259_32.c
index 2d25b77..0fea87d 100644
--- a/arch/x86/kernel/i8259_32.c
+++ b/arch/x86/kernel/i8259_32.c
@@ -26,8 +26,6 @@
  * present in the majority of PC/AT boxes.
  * plus some generic x86 specific things if generic specifics makes
  * any sense at all.
- * this file should become arch/i386/kernel/irq.c when the old irq.c
- * moves to arch independent land
  */
 
 static int i8259A_auto_eoi;
@@ -362,24 +360,12 @@ void __init init_ISA_irqs (void)
 #endif
 	init_8259A(0);
 
-	for (i = 0; i < NR_IRQS; i++) {
-		irq_desc[i].status = IRQ_DISABLED;
-		irq_desc[i].action = NULL;
-		irq_desc[i].depth = 1;
-
-		if (i < 16) {
-			/*
-			 * 16 old-style INTA-cycle interrupts:
-			 */
-			set_irq_chip_and_handler_name(i, &i8259A_chip,
-						      handle_level_irq, "XT");
-		} else {
-			/*
-			 * 'high' PCI IRQs filled in on demand
-			 */
-			irq_desc[i].chip = &no_irq_chip;
-		}
-	}
+	/*
+	 * 16 old-style INTA-cycle interrupts:
+	 */
+	for (i = 0; i < 16; i++)
+		set_irq_chip_and_handler_name(i, &i8259A_chip,
+					      handle_level_irq, "XT");
 }
 
 /* Overridden in paravirt.c */

Regards,

-- 
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 98%]

* Re: Linux i386 clone(): %ebx 'frobbing' ?
  @ 2008-02-15 23:54 99%       ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2008-02-15 23:54 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: libc-alpha, libc-alpha, linux-kernel

On Sat, Feb 16, 2008 at 12:28:11AM +0100, Andreas Schwab wrote:
> "Ahmed S. Darwish" <darwish.07@gmail.com> writes:
> 
> > Hi Andreas,
> >
> > On Fri, Feb 15, 2008, Andreas Schwab wrote:
> >> "Ahmed S. Darwish" <darwish.07@gmail.com> writes:
> >> 
> >> > I don't understand how the `fn' argument reached the child thread
> >> > in the %ebx register. It's said in the comment that `fn' will be
> >> > popped to child 'in the ebx frobbing below'. But what does that mean ?
> >> 
> >> See "popl %ebx" after "int $0x80".
> >> 
> >
> > I hope I'm not misreading something obvious, but I can't find
> > the code where FUNC(%esp) is stored in %ebx before %ebx value
> > got pushed in the stack (and restored in above 'popl' statement).
> 
> It is stored in the new stack for the child, as explained in the
> comment.  The parent has a different stack.
> 

Ooh great, I got it. Sorry, my mind didn't connect the dots though 
I read the comment several times. Thanks a lot for bearing with me :).

Regards,

-- 
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 99%]

* Re: Linux i386 clone(): %ebx 'frobbing' ?
  @ 2008-02-15 23:07 99%   ` Ahmed S. Darwish
    0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2008-02-15 23:07 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: libc-alpha, libc-alpha, linux-kernel

Hi Andreas,

On Fri, Feb 15, 2008, Andreas Schwab wrote:
> "Ahmed S. Darwish" <darwish.07@gmail.com> writes:
> 
> > I don't understand how the `fn' argument reached the child thread
> > in the %ebx register. It's said in the comment that `fn' will be
> > popped to child 'in the ebx frobbing below'. But what does that mean ?
> 
> See "popl %ebx" after "int $0x80".
> 

I hope I'm not misreading something obvious, but I can't find
the code where FUNC(%esp) is stored in %ebx before %ebx value
got pushed in the stack (and restored in above 'popl' statement).

Thanks a lot for help.

-- 
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 99%]

* Linux i386 clone(): %ebx 'frobbing' ?
@ 2008-02-15 18:42 98% Ahmed S. Darwish
    0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2008-02-15 18:42 UTC (permalink / raw)
  To: libc-alpha, libc-alpha; +Cc: linux-kernel

Hi all,

In the clone(int (*fn)(void *arg), void *child_stack, ..., void *arg, ...)
Glibc library function defind in sysdeps/unix/sysv/linux/i386/:

`fn' is saved in 8(child_stack), and `arg' is stored in 12(child_stack):

	movl	STACK(%esp),%ecx
	movl	ARG(%esp),%eax		/* no negative argument counts */
	movl	%eax,12(%ecx)		<---

	/* Save the function pointer as the zeroth argument.
	   It will be popped off in the child in the ebx frobbing below.  */
	movl	FUNC(%esp),%eax
	movl	%eax,8(%ecx)		<---

But after the exectuion of `sys_clone' system call, `fn' is 
called in the child thread by the statement 'call *%ebx' as follows:

	int	$0x80
	[...]

	test	%eax,%eax
	jz	L(thread_start)

/* Parent */
L(pseudo_end):
	ret

/* Child */
L(thread_start):
	/* Note: %esi is zero.  */
	movl	%esi,%ebp	/* terminate the stack frame */
	call	*%ebx

I don't understand how the `fn' argument reached the child thread
in the %ebx register. It's said in the comment that `fn' will be
popped to child 'in the ebx frobbing below'. But what does that mean ?

Thanks in advance

-- 
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 98%]

* [PATCH BUGFIX 25-rc1] Smack: Don't fail against Nulled sk sockets
@ 2008-02-13  1:25 96% Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2008-02-13  1:25 UTC (permalink / raw)
  To: Andrew Morton, Linus Torvalds; +Cc: Casey Schaufler, Joerg Platte, LKML, Netdev

Hi!,

Appropriately handle sockets with sk = NULL. This is usually the socket
case when starting kernel nfsd.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
Acked-by: Casey Schaufler <casey@schuafler-ca.com>
Tested-by: Joerg Platte <jplatte@naasa.net>
--

diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 1c11e42..eb04278 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -701,7 +701,7 @@ static int smack_inode_getsecurity(const struct inode *inode,
 		return -EOPNOTSUPP;
 
 	sock = SOCKET_I(ip);
-	if (sock == NULL)
+	if (sock == NULL || sock->sk == NULL)
 		return -EOPNOTSUPP;
 
 	ssp = sock->sk->sk_security;
@@ -1280,10 +1280,12 @@ static void smack_to_secattr(char *smack, struct netlbl_lsm_secattr *nlsp)
  */
 static int smack_netlabel(struct sock *sk)
 {
-	struct socket_smack *ssp = sk->sk_security;
+	struct socket_smack *ssp;
 	struct netlbl_lsm_secattr secattr;
 	int rc = 0;
 
+	BUG_ON(sk == NULL);
+	ssp = sk->sk_security;
 	netlbl_secattr_init(&secattr);
 	smack_to_secattr(ssp->smk_out, &secattr);
 	if (secattr.flags != NETLBL_SECATTR_NONE)
@@ -1331,7 +1333,7 @@ static int smack_inode_setsecurity(struct inode *inode, const char *name,
 		return -EOPNOTSUPP;
 
 	sock = SOCKET_I(inode);
-	if (sock == NULL)
+	if (sock == NULL || sock->sk == NULL)
 		return -EOPNOTSUPP;
 
 	ssp = sock->sk->sk_security;
@@ -1362,7 +1364,7 @@ static int smack_inode_setsecurity(struct inode *inode, const char *name,
 static int smack_socket_post_create(struct socket *sock, int family,
 				    int type, int protocol, int kern)
 {
-	if (family != PF_INET)
+	if (family != PF_INET || sock->sk == NULL)
 		return 0;
 	/*
 	 * Set the outbound netlbl.


Warm regards

-- 
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com


^ permalink raw reply	[relevance 96%]

* [PATCH - BUGFIX] Smack: Check for 'struct socket' with NULL sk
  @ 2008-02-11 23:23 96% ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2008-02-11 23:23 UTC (permalink / raw)
  To: Joerg Platte; +Cc: linux-kernel, casey

On Mon, Feb 11, 2008 at 07:26:02PM +0100, Joerg Platte wrote:
> Hi,
> 
> when booting linux 2.6.25-rc1 I get the following error:
> 
> BUG: unable to handle kernel NULL pointer dereference at 00000138
> IP: [<c01aa59e>] smack_netlabel+0x13/0xc8
> *pde = 00000000
> Oops: 0000 [#1] PREEMPT
> Modules linked in: nfsd 
[...]
> Call Trace:
>  [<c01aacf8>] ? new_inode_smack+0x39/0x3f
>  [<c01aad52>] ? smack_inode_alloc_security+0x16/0x27
>  [<c01a7510>] ? security_inode_alloc+0x19/0x1b
>  [<c01aa665>] ? smack_socket_post_create+0x12/0x18
>  [<c01a7a06>] ? security_socket_post_create+0x16/0x1b
>  [<c02116ce>] ? sock_create_lite+0x44/0x64
>  [<c0211712>] ? kernel_accept+0x24/0x5f

Hi Joerg,

There's a small problem with smack and NFS. A similar report was also
sent here: http://lkml.org/lkml/2007/10/27/85

Could you please check below patch ? I think it should fix your problem.

I've also added similar checks in inode_{get/set}security(). Cheating
from SELinux post_create_socket(), it does the same. Casey, Thoughts ?

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 1c11e42..eb04278 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -701,7 +701,7 @@ static int smack_inode_getsecurity(const struct inode *inode,
 		return -EOPNOTSUPP;
 
 	sock = SOCKET_I(ip);
-	if (sock == NULL)
+	if (sock == NULL || sock->sk == NULL)
 		return -EOPNOTSUPP;
 
 	ssp = sock->sk->sk_security;
@@ -1280,10 +1280,12 @@ static void smack_to_secattr(char *smack, struct netlbl_lsm_secattr *nlsp)
  */
 static int smack_netlabel(struct sock *sk)
 {
-	struct socket_smack *ssp = sk->sk_security;
+	struct socket_smack *ssp;
 	struct netlbl_lsm_secattr secattr;
 	int rc = 0;
 
+	BUG_ON(sk == NULL);
+	ssp = sk->sk_security;
 	netlbl_secattr_init(&secattr);
 	smack_to_secattr(ssp->smk_out, &secattr);
 	if (secattr.flags != NETLBL_SECATTR_NONE)
@@ -1331,7 +1333,7 @@ static int smack_inode_setsecurity(struct inode *inode, const char *name,
 		return -EOPNOTSUPP;
 
 	sock = SOCKET_I(inode);
-	if (sock == NULL)
+	if (sock == NULL || sock->sk == NULL)
 		return -EOPNOTSUPP;
 
 	ssp = sock->sk->sk_security;
@@ -1362,7 +1364,7 @@ static int smack_inode_setsecurity(struct inode *inode, const char *name,
 static int smack_socket_post_create(struct socket *sock, int family,
 				    int type, int protocol, int kern)
 {
-	if (family != PF_INET)
+	if (family != PF_INET || sock->sk == NULL)
 		return 0;
 	/*
 	 * Set the outbound netlbl.

^ permalink raw reply	[relevance 96%]

* [PATCH] lguest: Accept guest _PAGE_PWT page table entries
  @ 2008-02-07  0:51 99%   ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2008-02-07  0:51 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Rusty Russel, Suresh Siddha, Thomas Gleixner, lguest, linux-kernel

On Thu, Feb 07, 2008 at 12:59:23AM +0100, Ingo Molnar wrote:
> 
> * Ahmed S. Darwish <darwish.07@gmail.com> wrote:
> 
> > Hi all,
> > 
> > Beginning from commit 4138cc3418f5, ioremap_nocache() sets the _PAGE_PWT
> > flag. 
> > 
> > Lguest doesn't accept a guest pte with a _PWT flag and reports a "bad 
> > page table entry" in that case.
> > 
> > I've removed check from lguest code and everything worked fine. Is 
> > this safe from the Lguest side ?
> 
> yes, should be safe. Could you send a patch so that others can apply it 
> too?
> 

Ofcourse :) :

Accept guest _PAGE_PWT page table entries, otherwise lguest will
always fail with a "bad page table entry" message.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
index 74b4cf2..952160b 100644
--- a/drivers/lguest/page_tables.c
+++ b/drivers/lguest/page_tables.c
@@ -178,8 +178,8 @@ static void release_pte(pte_t pte)
 
 static void check_gpte(struct lg_cpu *cpu, pte_t gpte)
 {
-	if ((pte_flags(gpte) & (_PAGE_PWT|_PAGE_PSE))
-	    || pte_pfn(gpte) >= cpu->lg->pfn_limit)
+	if ((pte_flags(gpte) & _PAGE_PSE) || 
+	    pte_pfn(gpte) >= cpu->lg->pfn_limit)
 		kill_guest(cpu, "bad page table entry");
 }
 

Regards,

--
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [Lguest/x86]: Clash with ioremap_nocache() + _PAGE_PWT
@ 2008-02-06 23:21 98% Ahmed S. Darwish
    0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2008-02-06 23:21 UTC (permalink / raw)
  To: Rusty Russel, Suresh Siddha, Ingo Molnar, Thomas Gleixner
  Cc: lguest, linux-kernel

Hi all,

Beginning from commit 4138cc3418f5, ioremap_nocache() sets the _PAGE_PWT
flag. 

Lguest doesn't accept a guest pte with a _PWT flag and reports a
"bad page table entry" in that case. 

I've removed check from lguest code and everything worked fine. 
Is this safe from the Lguest side ?

Mentioned commit [*]:

commit 4138cc3418f5eaa7524ff8e927102863f1ba0ea5
Author: Siddha, Suresh B <suresh.b.siddha@intel.com>
Date:   Wed Jan 30 13:33:43 2008 +0100

    x86: set strong uncacheable where UC is really desired
    
    Also use _PAGE_PWT for all the mappings which need uncache mapping.
    Instead of existing PAT2 which is UC- (and can be overwritten by MTRRs),
    we now use PAT3 which is strong uncacheable.
    
    This makes it consistent with pgprot_noncached()

diff --git a/arch/x86/mm/ioremap_32.c b/arch/x86/mm/ioremap_32.c
index 0b27831..ef0f6a4 100644
--- a/arch/x86/mm/ioremap_32.c
+++ b/arch/x86/mm/ioremap_32.c
@@ -119,7 +119,7 @@ EXPORT_SYMBOL(__ioremap);
 void __iomem *ioremap_nocache (unsigned long phys_addr, unsigned long size)
 {
 	unsigned long last_addr;
-	void __iomem *p = __ioremap(phys_addr, size, _PAGE_PCD);
+	void __iomem *p = __ioremap(phys_addr, size, _PAGE_PCD | _PAGE_PWT);
 	if (!p) 
 		return p; 

Thanks,

[*]: latest pull calls set_memory_uc() which also sets the _PWT flag.

--
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 98%]

* Re: [PATCH] Smackv10: Smack rules grammar + their stateful parser(2)
  @ 2007-11-11 18:37 99%       ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-11-11 18:37 UTC (permalink / raw)
  To: Pavel Machek
  Cc: Casey Schaufler, akpm, torvalds, linux-security-module,
	linux-kernel, Al Viro

Hi Pavel,

On Nov 11, 2007 2:44 PM, Pavel Machek <pavel@ucw.cz> wrote:
> Hi!
>
> > > A Smack Rule in an "egrep" format is:
> > >
> > > "^[:space:]*Subject[:space:]+Object[:space:]+[rwxaRWXA-]+[:space:]*\n"
>
> Perhaps you should make it space, not 'space or tab', and only allow
> lowercase permissions? That way, parser will be slightly simpler, and
> you'll still have a chance to use 'R' as 'slightly different r'.
>

Thanks for your care about this. It seems not a lot of people have
noticed, but to stop any objections not related to the core smack
code, Casey decided to let the parsing be done in a user-space utility
that sends the rules to the kernel in a predefined strict format.

You can find how the whole story in the smackv11 announcement here:
http://article.gmane.org/gmane.linux.kernel.lsm/4463

Regards,

-- 
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH] Smackv10: Smack rules grammar + their stateful parser(2)
  @ 2007-11-10 19:45 99%       ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-11-10 19:45 UTC (permalink / raw)
  To: Jakob Oestergaard
  Cc: Casey Schaufler, akpm, torvalds, linux-security-module,
	linux-kernel, Al Viro

On Nov 10, 2007 7:05 PM, Jakob Oestergaard <jakob@unthought.net> wrote:
> ...
> > I've double-checked the code for any possible off-by-one/overflow
> > errors.
> ...
>
> Two things caught my eye.
>
> ...
> > +             case bol:
> > +             case subject:
> > +                     if (*label_len >= SMK_MAXLEN)
> > +                             goto out;
> > +                     subjectstr[(*label_len)++] = data[i];
>
> Why is the '>' necessary?  Could it happen that you had incremented past the
> point of equality?
>
> If that could not happen, then in my oppinion '>=' is very misleading when '=='
> is really what is needed.
>

Indeed, you're absolutely right.

> ...
> > +             case object:
> > +                     if (*prevstate == blank) {
> > +                             subjectstr[*label_len] = '\0';
> > +                             *label_len = 0;
> > +                     }
>
> I wonder why it is valid to uncritically use the already incremented label_len
> here, without checking its value (like is done above).
>
> It seems strangely asymmetrical. I'm not saying it's wrong, because there may
> be a subtle reason as to why it's not, but if that's the case then I think that
> subtle reason should be documented with a comment.
>

Maximum value label_len could reach is "SMK_MAXLEN". The subjectstr
and objectstr arrays are of "SMK_MAXLEN + 1" length. So I think no
danger is here.

Yes, this deserved a comment.

> ...
> > +             case access:
> > +                     if (*prevstate == blank) {
> > +                             objectstr[*label_len] = '\0';
> > +                             *label_len = 0;
> > +                     }
>
> Same applies here.
>
>  / jakob
>

Good spots, thanks a lot for the review.

Regards,

-- 
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH] Smackv10: Smack rules grammar + their stateful parser
  @ 2007-11-06 14:30 99%                       ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-11-06 14:30 UTC (permalink / raw)
  To: Adrian Bunk
  Cc: Kyle Moffett, Casey Schaufler, akpm, torvalds,
	linux-security-module, linux-kernel

On 11/6/07, Adrian Bunk <bunk@kernel.org> wrote:
> On Tue, Nov 06, 2007 at 04:05:13PM +0200, Ahmed S. Darwish wrote:
> >
> > Great, To summarize the discussion. Will there be a problem in
> > accepting ASCII and the UTF-8 ASCII _subset_ _only_ and  return
> > -EINVAL for all other cases/ecnodings ?.
>
> The UTF-8 ASCII subset is the complete ASCII.
>
> > i.e. The fragment I sent in a previous message:
> >
> > /* Filter UTF-8 non-ascii compatible bytes (> 0x7F) */
> > if (!isascii(c)) return -EINVAL;
> > /* Filter unwanted ascii chars */
> > if (!isspace(c) && !isgraph(c)) return -EINVAL;
> >...
>
> As I already said, this should work fine.
>

I thought you were objecting not handling the remaining non-ASCII
UTF-8 bytes. Everything is clear now. A Big thank you to everybody in
this thread for your effort on this :).

Regards,

-- 
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH] Smackv10: Smack rules grammar + their stateful parser
  @ 2007-11-06 14:05 99%                   ` Ahmed S. Darwish
    0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2007-11-06 14:05 UTC (permalink / raw)
  To: Adrian Bunk
  Cc: Kyle Moffett, Casey Schaufler, akpm, torvalds,
	linux-security-module, linux-kernel

On Tue, Nov 06, 2007 at 02:34:46PM +0100, Adrian Bunk wrote:
> On Tue, Nov 06, 2007 at 07:49:26AM -0500, Kyle Moffett wrote:
> > On Nov 06, 2007, at 07:23:36, Ahmed S. Darwish wrote:
> >> On 11/6/07, Adrian Bunk <bunk@kernel.org> wrote:
> >>> On Tue, Nov 06, 2007 at 01:34:05PM +0200, Ahmed S. Darwish wrote:
> >>>> As far as I understand the problem now, isspace() accepts the 0xa0 
> >>>> character which might collide with some of UTF-8 encoded characters 
> >>>> cause the high bit is set.
> >>
> >> I admit I'm not experienced in such encoding stuff, but shouldn't the 
> >> ASCII and the ASCII-compatible UTF-8 encodings be enough for the labels?
> >>
> >>> It would not work if someone would e.g. give you UTF-16 encoded strings, 
> >>> but I don't see this happening in practice.
> >>
> >> Won't this complicate the code too much ?
> >
> > Well the VFS (for example) certainly doesn't support any encodings other 
> > than various extended-ASCII forms (which includes UTF-8).  Something like 
> > UTF-16 has extra null characters in-between every normal character, and as 
> > such would fail completely if passed to the VFS.
> 
> Good point.
> 
> > Personally I think that isspace() accepting character 0xA0 is a bug, as 
> > there are several variants of extended ASCII only one of which has that 
> > character as a space.  Others have it as ?? (accented A), etc.
> 
> But even then Smack would still have a similar problem with isgraph().
> 

Great, To summarize the discussion. Will there be a problem in 
accepting ASCII and the UTF-8 ASCII _subset_ _only_ and  return 
-EINVAL for all other cases/ecnodings ?.

i.e. The fragment I sent in a previous message:

/* Filter UTF-8 non-ascii compatible bytes (> 0x7F) */
if (!isascii(c)) return -EINVAL; 
/* Filter unwanted ascii chars */
if (!isspace(c) && !isgraph(c)) return -EINVAL; 

> > In addition 
> > the "canonical" internal text format of the kernel is UTF-8 as that 
> > encoding can represent any character in any other encoding and it is 
> > backwards-compatible with traditional ASCII.
> > 
> > Cheers,
> > Kyle Moffett-
> 
> cu
> Adrian
> 

--
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH] Smackv10: Smack rules grammar + their stateful parser
  @ 2007-11-06 12:23 99%             ` Ahmed S. Darwish
    0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2007-11-06 12:23 UTC (permalink / raw)
  To: Adrian Bunk
  Cc: Kyle Moffett, Casey Schaufler, akpm, torvalds,
	linux-security-module, linux-kernel

On 11/6/07, Adrian Bunk <bunk@kernel.org> wrote:
> On Tue, Nov 06, 2007 at 01:34:05PM +0200, Ahmed S. Darwish wrote:
> > Hi,
> >
> > On Tue, Nov 06, 2007 at 09:56:51AM +0100, Adrian Bunk wrote:
> > > On Tue, Nov 06, 2007 at 03:26:12AM -0500, Kyle Moffett wrote:
> > > > On Nov 06, 2007, at 01:33:05, Adrian Bunk wrote:
> > > >> Can you limit this to 7bit ASCII and use isascii() somewhere?
> > > >>
> > > >> Otherwise I'd expect funny things to happen when you e.g. use isspace() on
> > > >> the UTF-8 encoded character ??.
> > > >
> > > > Actually, you don't need to.  You tell them it expects UTF-8 encoded
> > > > strings and be done with it.  All US-ASCII characters from 0 through 127
> > > > (IE: high bit clear) are exactly the same in UTF-8, and UTF-8 special
> > > > characters have the high bit set in all bytes.  Therefore you just assume
> > > > that anything with the high bit set is part of a word and you can handle
> > > > basic UTF-8.  (It doesn't work on special UTF-8 space characters like
> > > > nonbreaking space and similar, but handling those is significantly more
> > > > complicated).
> > >
> > > The documentations says:
> > > "Smack labels cannot contain unprintable characters or the "/" (slash)
> > >  character."
> > >
> > > What you propose might contain unprintable characters, and it might even
> > > be invalid UTF-8.
> >
> > As far as I understand the problem now, isspace() accepts the 0xa0
> > character which might collide with some of UTF-8 encoded characters
> > cause the high bit is set.
> >
> > I used "if (!isspace(c) && !isgraph(c)) return -EINVAL;" to test
> > rules' characters validity which seems not enough. I'll add !isascii(c)
> > in the condition and ask Casey to change the documentation to be
> > something like:
> >
> > Smack labels are represented in ASCII characters, they cannot contain
> > unprintable characters or the '/' (slash) character.
> >
> > and in write():
> > if (!isascii(c) return -EINVAL;
> > if (!isspace(c) && !isgraph(c)) return -EINVAL;
> >
> > This satisfy above customized labels rule, right ?
>
> It should work for all charsets you'll usually have to handle.
>

I admit I'm not experienced in such encoding stuff, but shouldn't the
ASCII and the ASCII-compatible UTF-8 encodings be enough for the
labels ?

> It would not work if someone would e.g. give you UTF-16 encoded strings,
> but I don't see this happening in practice.

Won't this complicate the code too much ?

-- 
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH] Smackv10: Smack rules grammar + their stateful parser
  @ 2007-11-06 11:34 99%         ` Ahmed S. Darwish
    0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2007-11-06 11:34 UTC (permalink / raw)
  To: Adrian Bunk
  Cc: Kyle Moffett, Casey Schaufler, akpm, torvalds,
	linux-security-module, linux-kernel

Hi,

On Tue, Nov 06, 2007 at 09:56:51AM +0100, Adrian Bunk wrote:
> On Tue, Nov 06, 2007 at 03:26:12AM -0500, Kyle Moffett wrote:
> > On Nov 06, 2007, at 01:33:05, Adrian Bunk wrote:
> >> Can you limit this to 7bit ASCII and use isascii() somewhere?
> >>
> >> Otherwise I'd expect funny things to happen when you e.g. use isspace() on 
> >> the UTF-8 encoded character ??.
> >
> > Actually, you don't need to.  You tell them it expects UTF-8 encoded 
> > strings and be done with it.  All US-ASCII characters from 0 through 127 
> > (IE: high bit clear) are exactly the same in UTF-8, and UTF-8 special 
> > characters have the high bit set in all bytes.  Therefore you just assume 
> > that anything with the high bit set is part of a word and you can handle 
> > basic UTF-8.  (It doesn't work on special UTF-8 space characters like 
> > nonbreaking space and similar, but handling those is significantly more 
> > complicated).
> 
> The documentations says:
> "Smack labels cannot contain unprintable characters or the "/" (slash) 
>  character."
> 
> What you propose might contain unprintable characters, and it might even 
> be invalid UTF-8.
> 

As far as I understand the problem now, isspace() accepts the 0xa0
character which might collide with some of UTF-8 encoded characters
cause the high bit is set.

I used "if (!isspace(c) && !isgraph(c)) return -EINVAL;" to test 
rules' characters validity which seems not enough. I'll add !isascii(c)
in the condition and ask Casey to change the documentation to be
something like:

Smack labels are represented in ASCII characters, they cannot contain
unprintable characters or the '/' (slash) character.

and in write():
if (!isascii(c) return -EINVAL;
if (!isspace(c) && !isgraph(c)) return -EINVAL;

This satisfy above customized labels rule, right ?

Regards,

--
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH] Smackv10: Smack rules grammar + their stateful parser
  @ 2007-11-05 23:38 99%         ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-11-05 23:38 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Pavel Machek, Casey Schaufler, akpm, linux-security-module,
	linux-kernel, Al Viro

On 11/5/07, Linus Torvalds <torvalds@linux-foundation.org> wrote:
>
>
> On Mon, 5 Nov 2007, Ahmed S. Darwish wrote:
>
> > On Sun, Nov 04, 2007 at 12:28:48PM +0000, Pavel Machek wrote:
> > >
> > > Can we avoid string parsers in the kernel?
> > >
> >
> > Ok, Could someone suggest a better idea please ?.
>
> I personally think string parsers are *much* better than the alternatives
> (which basically boil down to nasty binary interfaces)
>
> > I thought about packing the rules in a structure and sending
> > it over an ioctl() command. Is this applicable ?
>
> That's *MUCH* worse.
>
> Strings are nice. They aren't that complex, and as long as it's not a
> performance-critical area, there are basically no downsides.
>
> Binary structures and ioctl's are *much* worse. They are totally
> undebuggable with generic tools (think "echo" or "strace"), and they are a
> total nightmare to parse across architectures and pointer sizes.
>
> So the rule should be: always use strings if at all possible and relevant.
> If the data is fundamentally binary, it shouldn't be re-coded to ascii (no
> real advantage), but if the data is "stringish", and there aren't big
> performance issues, then keep it as strings.
>

Thanks a lot for such a kind advice. I'll keep that in my mind.

Regards,

-- 
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH] Smackv10: Smack rules grammar + their stateful parser
    2007-11-04 13:23 99%     ` Ahmed S. Darwish
@ 2007-11-05  9:41 99%     ` Ahmed S. Darwish
    1 sibling, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2007-11-05  9:41 UTC (permalink / raw)
  To: Pavel Machek
  Cc: Casey Schaufler, akpm, torvalds, linux-security-module,
	linux-kernel, Al Viro

On Sun, Nov 04, 2007 at 12:28:48PM +0000, Pavel Machek wrote:
> Hi!
> 
> > > Still to come:
> > > 
> > >   - Final cleanup of smack_load_write and smack_cipso_write.
> > 
> > Hi All,
> > 
> > After agreeing with Casey on the "load" input grammar yesterday, here's
> > the final grammar and its parser (which needs more testing):
> > 
> > A Smack Rule in an "egrep" format is:
> > 
> > "^[:space:]*Subject[:space:]+Object[:space:]+[rwxaRWXA-]+[:space:]*\n"
> > 
> > where Subject/Object strings are in the form:
> > 
> > "^[^/[:space:][:cntrl:]]{1,SMK_MAXLEN}$"
> 
> Can we avoid string parsers in the kernel?
> 

Ok, Could someone suggest a better idea please ?. 

I thought about packing the rules in a structure and sending
it over an ioctl() command. Is this applicable ?

> 
> > +static inline int isblank(char c)
> > +{
> > +	return (c == ' ' || c == '\t');
> > +}
> 
> This sounds like enough for 'NAK'.
> 
> 						Pavel,
> 		who still thinks smack rules should be parsed
> 		in userspace and compiled into selinux rules...
> 		
> -- 
> (english) http://www.livejournal.com/~pavelmachek
> (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[relevance 99%]

* [PATCH] Smackv10: Smack rules grammar + their stateful parser(2)
  2007-11-03 16:43 65% ` [PATCH] Smackv10: Smack rules grammar + their stateful parser Ahmed S. Darwish
                     ` (2 preceding siblings ...)
  2007-11-04 20:06 99%   ` Ahmed S. Darwish
@ 2007-11-05  0:56 69%   ` Ahmed S. Darwish
        4 siblings, 2 replies; 200+ results
From: Ahmed S. Darwish @ 2007-11-05  0:56 UTC (permalink / raw)
  To: Casey Schaufler
  Cc: akpm, torvalds, linux-security-module, linux-kernel, Al Viro

On Sat, Nov 03, 2007 at 06:43:06PM +0200, Ahmed S. Darwish wrote:
> On Fri, Nov 02, 2007 at 01:50:55PM -0700, Casey Schaufler wrote:
> > 
> > Still to come:
> > 
> >   - Final cleanup of smack_load_write and smack_cipso_write.
> 
> Hi All,
> 
> After agreeing with Casey on the "load" input grammar yesterday, here's
> the final grammar and its parser (which needs more testing):
> 
> A Smack Rule in an "egrep" format is:
> 
> "^[:space:]*Subject[:space:]+Object[:space:]+[rwxaRWXA-]+[:space:]*\n"
> 
> where Subject/Object strings are in the form:
> 
> "^[^/[:space:][:cntrl:]]{1,SMK_MAXLEN}$"
> 
> Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
> ---
> 

Same parser with adhering Casey's concers about previous one 
and with using the FSM states in a more readable way. 

I've double-checked the code for any possible off-by-one/overflow 
errors. Could someone overcheck this for any possible hidden 
security holes. Al, please :) ?

diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c
index 3572ae5..c9461cb 100644
--- a/security/smack/smackfs.c
+++ b/security/smack/smackfs.c
@@ -25,6 +25,7 @@
 #include <net/netlabel.h>
 #include <net/cipso_ipv4.h>
 #include <linux/seq_file.h>
+#include <linux/ctype.h>
 #include "smack.h"
 
 /*
@@ -67,6 +68,47 @@ struct smk_list_entry *smack_list;
 #define	SEQ_READ_FINISHED	1
 
 /*
+ * Disable concurrent writing open() operations
+ */
+static struct semaphore smack_write_sem;
+
+/*
+ * States for parsing /smack/load rules
+ */
+enum load_state {
+	bol          = 0,            /* At Beginning Of Line */
+	subject      = 1,            /* At a "subject" token */
+	object       = 2,            /* At an "object" token */
+	access       = 3,            /* At an "access" token */
+	newline      = 4,            /* At end Of Line */
+	blank        = 5,            /* At a space or tab */
+};
+
+/*
+ * Represent current parsing state of /smack/load. Struct
+ * also stores data needed between an open-release session's
+ * multiple write() calls
+ */
+static struct smack_load_state {
+	enum load_state state;       /* Current FSM parsing state */
+	enum load_state prevstate;   /* Previous FSM state */
+	enum load_state prevtoken;   /* Handle state = prevstate = blank */
+	struct smack_rule rule;      /* Rule to be loaded */
+	int label_len;               /* Subject/Object labels length so far */
+	char subject[SMK_LABELLEN];  /* Subject label */
+	char object[SMK_LABELLEN];   /* Object label */
+} *load_state;
+
+/*
+ * Rule's tokens separators are spaces and tabs only
+ */
+static inline int isblank(char c)
+{
+	return (c == ' ' || c == '\t');
+}
+
+
+/*
  * Seq_file read operations for /smack/load
  */
 
@@ -131,12 +173,43 @@ static struct seq_operations load_seq_ops = {
  * @inode: inode structure representing file
  * @file: "load" file pointer
  *
- * Connect our load_seq_* operations with /smack/load
- * file_operations
+ * For reading, use load_seq_* seq_file reading operations.
+ * For writing, prepare a load_state struct to parse
+ * incoming rules.
  */
 static int smk_open_load(struct inode *inode, struct file *file)
 {
-	return seq_open(file, &load_seq_ops);
+	if ((file->f_flags & O_ACCMODE) == O_RDONLY)
+		return seq_open(file, &load_seq_ops);
+
+	if (down_interruptible(&smack_write_sem))
+		return -ERESTARTSYS;
+
+	load_state = kzalloc(sizeof(struct smack_load_state), GFP_KERNEL);
+	if (!load_state)
+		return -ENOMEM;
+
+	return 0;
+}
+
+/**
+ * smk_release_load - release() for /smack/load
+ * @inode: inode structure representing file
+ * @file: "load" file pointer
+ *
+ * For a reading session, use the seq_file release
+ * implementation.
+ * Otherwise, we are at the end of a writing session so
+ * clean everything up.
+ */
+static int smk_release_load(struct inode *inode, struct file *file)
+{
+	if ((file->f_flags & O_ACCMODE) == O_RDONLY)
+		return seq_release(inode, file);
+
+	kfree(load_state);
+	up(&smack_write_sem);
+	return 0;
 }
 
 /**
@@ -174,7 +247,6 @@ static void smk_set_access(struct smack_rule *srp)
 	return;
 }
 
-
 /**
  * smk_write_load - write() for /smack/load
  * @filp: file pointer, not actually used
@@ -182,19 +254,26 @@ static void smk_set_access(struct smack_rule *srp)
  * @count: bytes sent
  * @ppos: where to start
  *
- * Returns number of bytes written or error code, as appropriate
+ * Parse smack rules in below extended regex format:
+ * "^[:space:]*Subject[:space:]+Object[:space:]+[rwxaRWXA-]+[:space:]*$"
+ * Where Subject/Object are: "^[^/[:space:][:cntrl:]]{1,SMK_MAXLEN}$"
+ *
+ * Handle defragmented rules over several write calls using the
+ * load_state structure.
  */
 static ssize_t smk_write_load(struct file *file, const char __user *buf,
 			      size_t count, loff_t *ppos)
 {
-	struct smack_rule rule;
-	ssize_t rc = count;
+	struct smack_rule *rule = &load_state->rule;
+	enum load_state *state = &load_state->state;
+	enum load_state *prevstate = &load_state->prevstate;
+	enum load_state *prevtoken = &load_state->prevtoken;
+	int *label_len = &load_state->label_len;
+	char *subjectstr = load_state->subject;
+	char *objectstr = load_state->object;
+	ssize_t rc = -EINVAL;
 	char *data = NULL;
-	char subjectstr[SMK_LABELLEN];
-	char objectstr[SMK_LABELLEN];
-	char modestr[8];
-	char *cp;
-
+	int i;
 
 	if (!capable(CAP_MAC_OVERRIDE))
 		return -EPERM;
@@ -208,7 +287,7 @@ static ssize_t smk_write_load(struct file *file, const char __user *buf,
 	 * 80 characters per line ought to be enough.
 	 */
 	if (count > SMACK_LIST_MAX * 80)
-		return -ENOMEM;
+		return -EFBIG;
 
 	data = kzalloc(count + 1, GFP_KERNEL);
 	if (data == NULL)
@@ -221,30 +300,94 @@ static ssize_t smk_write_load(struct file *file, const char __user *buf,
 
 	data[count] = '\0';
 
-	for (cp = data - 1; cp != NULL; cp = strchr(cp + 1, '\n')) {
-		if (*++cp == '\0')
+	for (i = 0; i < count && data[i]; i++) {
+		if (!isgraph(data[i]) && !isspace(data[i]))
+			goto out;
+
+		if (isblank(data[i])) {
+			*state = blank;
+			/* A token-blank trasition */
+			if (*prevstate != blank)
+				*prevtoken = *prevstate;
+		} else {
+			if (data[i] == '\n')
+				*state = newline;
+			/* A blank-token transition */
+			else if (*prevstate == blank)
+				*state = *prevtoken + 1;
+			else
+				*state = *prevstate;
+		}
+
+		switch (*state) {
+		case bol:
+		case subject:
+			if (*label_len >= SMK_MAXLEN)
+				goto out;
+			subjectstr[(*label_len)++] = data[i];
+			*prevstate = subject;
 			break;
-		if (sscanf(cp, "%23s %23s %7s\n", subjectstr, objectstr,
-			   modestr) != 3)
+
+		case object:
+			if (*prevstate == blank) {
+				subjectstr[*label_len] = '\0';
+				*label_len = 0;
+			}
+
+			if (*label_len >= SMK_MAXLEN)
+				goto out;
+			objectstr[(*label_len)++] = data[i];
+			*prevstate = object;
+			break;
+
+		case access:
+			if (*prevstate == blank) {
+				objectstr[*label_len] = '\0';
+				*label_len = 0;
+			}
+
+			if (data[i] == 'R' || data[i] == 'r')
+				rule->smk_access |= MAY_READ;
+			else if (data[i] == 'W' || data[i] == 'w')
+				rule->smk_access |= MAY_WRITE;
+			else if (data[i] == 'X' || data[i] == 'x')
+				rule->smk_access |= MAY_EXEC;
+			else if (data[i] == 'A' || data[i] == 'a')
+				rule->smk_access |= MAY_APPEND;
+			else if (data[i] == '-')
+				/* No-Op, '-' is a placeholder */;
+			else
+				goto out;
+
+			*prevstate = *prevtoken = access;
 			break;
-		rule.smk_subject = smk_import(subjectstr, 0);
-		if (rule.smk_subject == NULL)
+
+		case newline:
+			if (*prevtoken != access || data[i] != '\n')
+				goto out;
+
+			rule->smk_subject = smk_import(subjectstr, 0);
+			if (rule->smk_subject == NULL)
+				goto out;
+
+			rule->smk_object = smk_import(objectstr, 0);
+			if (rule->smk_object == NULL)
+				goto out;
+
+			smk_set_access(rule);
+
+			/* Reset everything, a new rule will come */
+			memset(load_state, 0, sizeof(*load_state));
 			break;
-		rule.smk_object = smk_import(objectstr, 0);
-		if (rule.smk_object == NULL)
+
+		case blank:
+			*prevstate = blank;
 			break;
-		rule.smk_access = 0;
-		if (strpbrk(modestr, "rR") != NULL)
-			rule.smk_access |= MAY_READ;
-		if (strpbrk(modestr, "wW") != NULL)
-			rule.smk_access |= MAY_WRITE;
-		if (strpbrk(modestr, "xX") != NULL)
-			rule.smk_access |= MAY_EXEC;
-		if (strpbrk(modestr, "aA") != NULL)
-			rule.smk_access |= MAY_APPEND;
-		smk_set_access(&rule);
+		}
 	}
 
+	rc = count;
+out:
 	kfree(data);
 	return rc;
 }
@@ -254,7 +397,7 @@ static const struct file_operations smk_load_ops = {
 	.read		= seq_read,
 	.llseek         = seq_lseek,
 	.write		= smk_write_load,
-	.release        = seq_release
+	.release        = smk_release_load,
 };
 
 /**
@@ -924,6 +1067,7 @@ static int __init init_smk_fs(void)
 		}
 	}
 
+	sema_init(&smack_write_sem, 1);
 	smk_cipso_doi();
 
 	return err;

--
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 69%]

* Re: [PATCH] Smackv10: Smack rules grammar + their stateful parser
  2007-11-03 16:43 65% ` [PATCH] Smackv10: Smack rules grammar + their stateful parser Ahmed S. Darwish
    @ 2007-11-04 20:06 99%   ` Ahmed S. Darwish
  2007-11-05  0:56 69%   ` [PATCH] Smackv10: Smack rules grammar + their stateful parser(2) Ahmed S. Darwish
    4 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-11-04 20:06 UTC (permalink / raw)
  To: Casey Schaufler; +Cc: akpm, torvalds, linux-security-module, linux-kernel

On 11/3/07, Ahmed S. Darwish <darwish.07@gmail.com> wrote:
>  static int smk_open_load(struct inode *inode, struct file *file)
>  {
> -       return seq_open(file, &load_seq_ops);
> +       if ((file->f_flags & O_ACCMODE) == O_RDONLY)
> +               return seq_open(file, &load_seq_ops);
> +
> +       if (down_interruptible(&smack_write_sem))
> +               return -ERESTARTSYS;
> +
> +       load_state = kzalloc(sizeof(struct smack_load_state), GFP_KERNEL);
> +       if (!load_state)
> +               return -ENOMEM;
> +
> +       return 0;
> +}

Is it right to do the kzalloc with the semaphore being held? Will the
lock be held forever If kzalloc failed and -ENOMEM was returned ?

Thanks,

-- 
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH] Smackv10: Smack rules grammar + their stateful parser
  @ 2007-11-04 13:23 99%     ` Ahmed S. Darwish
  2007-11-05  9:41 99%     ` Ahmed S. Darwish
  1 sibling, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-11-04 13:23 UTC (permalink / raw)
  To: Pavel Machek
  Cc: Casey Schaufler, akpm, torvalds, linux-security-module, linux-kernel

On 11/4/07, Pavel Machek <pavel@ucw.cz> wrote:
> Hi!
>
> > > Still to come:
> > >
> > >   - Final cleanup of smack_load_write and smack_cipso_write.
> >
> > Hi All,
> >
> > After agreeing with Casey on the "load" input grammar yesterday, here's
> > the final grammar and its parser (which needs more testing):
> >
> > A Smack Rule in an "egrep" format is:
> >
> > "^[:space:]*Subject[:space:]+Object[:space:]+[rwxaRWXA-]+[:space:]*\n"
> >
> > where Subject/Object strings are in the form:
> >
> > "^[^/[:space:][:cntrl:]]{1,SMK_MAXLEN}$"
>
> Can we avoid string parsers in the kernel?
>

I've suggested that at first, but (hoping not to misquote Al) Al viro
said that the parsing is simple enough and no need exists for a
user-space utility.

>
> > +static inline int isblank(char c)
> > +{
> > +     return (c == ' ' || c == '\t');
> > +}
>
> This sounds like enough for 'NAK'.
>

Would you please show the reason for the NAK so I can modify the code ?

Thank you,

>                                                 Pavel,
>                 who still thinks smack rules should be parsed
>                 in userspace and compiled into selinux rules...
>

-- 
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH] Smackv10: Smack rules grammar + their stateful parser
  @ 2007-11-03 22:12 99%     ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-11-03 22:12 UTC (permalink / raw)
  To: Kyle Moffett
  Cc: Casey Schaufler, akpm, torvalds, linux-security-module, linux-kernel

On 11/3/07, Kyle Moffett <mrmacman_g4@mac.com> wrote:
> On Nov 03, 2007, at 12:43:06, Ahmed S. Darwish wrote:
> > Bashv3 builtin "echo" behaves very strangely to -EINVAL. It sends
> > all the buffers that causes -EINVAL again in subsequent echo
> > invocations.
> >
> > i.e.
> > echo "Invalid Rule" > /smack/load  # -EINVAL returned
> > echo "Valid Rule" > /smack/load
> >
> > In seconod iteration, echo sends the first invalid buffer again
> > then sends the new one. This causes a "Invalid Rule\nValid Rule"
> > buffer sent to write().
> >
> > IMHO, this is a bug in builtin echo. The external /bin/echo doesn't
> > cause such strange behaviour.
>
> Actually, what causes problems here is something between a bug and a
> feature in libc's buffering.  Basically the -EINVAL error causes libc
> to leave its data in the file-output buffer despite the file being
> closed and reopened. Since a standalone echo just exits that buffer
> is discarded, but for the bash builtin it hangs around in the buffer
> for a while and ends up getting prepended to the following echo
> statement.  There's actually multiple ways to make this fail; this is
> just the simplest.
>

Thanks a lot for such a useful info. Is there a way from my side  to
make subsequent echo invocations not affected by previous failed ones
?

Regards,

-- 
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH] Smackv10: Smack rules grammar + their stateful parser
  @ 2007-11-03 16:43 65% ` Ahmed S. Darwish
                       ` (4 more replies)
  0 siblings, 5 replies; 200+ results
From: Ahmed S. Darwish @ 2007-11-03 16:43 UTC (permalink / raw)
  To: Casey Schaufler; +Cc: akpm, torvalds, linux-security-module, linux-kernel

On Fri, Nov 02, 2007 at 01:50:55PM -0700, Casey Schaufler wrote:
> 
> Still to come:
> 
>   - Final cleanup of smack_load_write and smack_cipso_write.

Hi All,

After agreeing with Casey on the "load" input grammar yesterday, here's
the final grammar and its parser (which needs more testing):

A Smack Rule in an "egrep" format is:

"^[:space:]*Subject[:space:]+Object[:space:]+[rwxaRWXA-]+[:space:]*\n"

where Subject/Object strings are in the form:

"^[^/[:space:][:cntrl:]]{1,SMK_MAXLEN}$"

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

Bashv3 builtin "echo" behaves very strangely to -EINVAL. It sends all
the buffers that causes -EINVAL again in subsequent echo invocations.

i.e.
echo "Invalid Rule" > /smack/load  # -EINVAL returned
echo "Valid Rule" > /smack/load

In seconod iteration, echo sends the first invalid buffer again 
then sends the new one. This causes a 
"Invalid Rule\nValid Rule" buffer sent to write().

IMHO, this is a bug in builtin echo. The external /bin/echo doesn't 
cause such strange behaviour.

diff --git a/security/smack/smack.h b/security/smack/smack.h
index e0b7d26..8dcdb79 100644
--- a/security/smack/smack.h
+++ b/security/smack/smack.h
@@ -219,4 +219,16 @@ static inline char *smk_of_inode(const struct inode *isp)
 	return sip->smk_inode;
 }
 
+static inline int isblank(char c)
+{
+	return (c == ' ' || c == '\t');
+}
+
+#define swap(x, y, type)      \
+do {			      \
+	type tmp = x;	      \
+	x = y;		      \
+	y = tmp;	      \
+} while (0);		      \
+
 #endif  /* _SECURITY_SMACK_H */
diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c
index 3572ae5..0b1b530 100644
--- a/security/smack/smackfs.c
+++ b/security/smack/smackfs.c
@@ -25,6 +25,7 @@
 #include <net/netlabel.h>
 #include <net/cipso_ipv4.h>
 #include <linux/seq_file.h>
+#include <linux/ctype.h>
 #include "smack.h"
 
 /*
@@ -67,6 +68,39 @@ struct smk_list_entry *smack_list;
 #define	SEQ_READ_FINISHED	1
 
 /*
+ * Disable concurrent writing open() operations
+ */
+static struct semaphore smack_write_sem;
+
+/*
+ * States for parsing /smack/load rules
+ */
+enum load_state {
+	bol          = 0,            /* At Beginning Of Line */
+	subject      = 1,            /* At a "subject" token */
+	object       = 2,            /* At an "object" token */
+	access       = 3,            /* At an "access" token */
+	newline      = 4,            /* At end Of Line */
+	blank        = 5,            /* At a space or tab */
+};
+
+/*
+ * Represent current parsing state of /smack/load. Struct
+ * also stores data needed between an open-release session's
+ * multiple write() calls
+ */
+static struct smack_load_state {
+	enum load_state state;       /* Current FSM parsing state */
+	enum load_state prevstate;   /* Previous FSM state */
+	struct smack_rule rule;      /* Rule to be loaded */
+	int label_len;               /* Subject/Object labels length so far */
+	char subject[SMK_LABELLEN];  /* Subject label */
+	char object[SMK_LABELLEN];   /* Object label */
+	int access;                  /* Bool, parsed an "access" token ? */
+} *load_state;
+
+
+/*
  * Seq_file read operations for /smack/load
  */
 
@@ -131,12 +165,43 @@ static struct seq_operations load_seq_ops = {
  * @inode: inode structure representing file
  * @file: "load" file pointer
  *
- * Connect our load_seq_* operations with /smack/load
- * file_operations
+ * For reading, use load_seq_* seq_file reading operations.
+ * For writing, prepare a load_state struct to parse
+ * incoming rules.
  */
 static int smk_open_load(struct inode *inode, struct file *file)
 {
-	return seq_open(file, &load_seq_ops);
+	if ((file->f_flags & O_ACCMODE) == O_RDONLY)
+		return seq_open(file, &load_seq_ops);
+
+	if (down_interruptible(&smack_write_sem))
+		return -ERESTARTSYS;
+
+	load_state = kzalloc(sizeof(struct smack_load_state), GFP_KERNEL);
+	if (!load_state)
+		return -ENOMEM;
+
+	return 0;
+}
+
+/**
+ * smk_release_load - release() for /smack/load
+ * @inode: inode structure representing file
+ * @file: "load" file pointer
+ *
+ * For a reading session, use the seq_file release
+ * implementation.
+ * Otherwise, we are at the end of a writing session so
+ * clean everything up.
+ */
+static int smk_release_load(struct inode *inode, struct file *file)
+{
+	if ((file->f_flags & O_ACCMODE) == O_RDONLY)
+		return seq_release(inode, file);
+
+	kfree(load_state);
+	up(&smack_write_sem);
+	return 0;
 }
 
 /**
@@ -174,7 +239,6 @@ static void smk_set_access(struct smack_rule *srp)
 	return;
 }
 
-
 /**
  * smk_write_load - write() for /smack/load
  * @filp: file pointer, not actually used
@@ -182,19 +246,26 @@ static void smk_set_access(struct smack_rule *srp)
  * @count: bytes sent
  * @ppos: where to start
  *
- * Returns number of bytes written or error code, as appropriate
+ * Parse smack rules in below extended regex format:
+ * "^[:space:]*Subject[:space:]+Object[:space:]+[rwxaRWXA-]+[:space:]*\n"
+ * Where Subject/Object are: "^[^/[:space:][:cntrl:]]{1,SMK_MAXLEN}$"
+ *
+ * Handle defragmented rules over several write calls using a Finite
+ * State Machine that saves its state in the load_state structure.
  */
 static ssize_t smk_write_load(struct file *file, const char __user *buf,
 			      size_t count, loff_t *ppos)
 {
-	struct smack_rule rule;
-	ssize_t rc = count;
+	struct smack_rule *rule = &load_state->rule;
+	enum load_state *state = &load_state->state;
+	enum load_state *prevstate = &load_state->prevstate;
+	int *label_len = &load_state->label_len;
+	char *subjectstr = load_state->subject;
+	char *objectstr = load_state->object;
+	int *accesstok = &load_state->access;
+	ssize_t rc = -EINVAL;
 	char *data = NULL;
-	char subjectstr[SMK_LABELLEN];
-	char objectstr[SMK_LABELLEN];
-	char modestr[8];
-	char *cp;
-
+	int i;
 
 	if (!capable(CAP_MAC_OVERRIDE))
 		return -EPERM;
@@ -208,7 +279,7 @@ static ssize_t smk_write_load(struct file *file, const char __user *buf,
 	 * 80 characters per line ought to be enough.
 	 */
 	if (count > SMACK_LIST_MAX * 80)
-		return -ENOMEM;
+		return -EFBIG;
 
 	data = kzalloc(count + 1, GFP_KERNEL);
 	if (data == NULL)
@@ -221,30 +292,93 @@ static ssize_t smk_write_load(struct file *file, const char __user *buf,
 
 	data[count] = '\0';
 
-	for (cp = data - 1; cp != NULL; cp = strchr(cp + 1, '\n')) {
-		if (*++cp == '\0')
+	for (i = 0; i < count && data[i]; i++) {
+		if (!isgraph(data[i]) && !isspace(data[i]))
+			goto out;
+
+		/* If a char-blank transition occurred */
+		if (isblank(data[i]) && *state != blank)
+			*prevstate = *state;
+		/* If a blank-char transition occurred */
+		if (!isblank(data[i]) && *state == blank) {
+			swap(*state, *prevstate, typeof(*state));
+			++(*state);
+		}
+
+		if (isblank(data[i]))
+			*state = blank;
+
+		if (data[i] == '\n')
+			*state = newline;
+
+		switch (*state) {
+		case bol:
+		case subject:
+			if (*label_len >= SMK_MAXLEN)
+				goto out;
+			subjectstr[(*label_len)++] = data[i];
+			*state = subject;
+			break;
+
+		case object:
+			if (*prevstate == blank) {
+				subjectstr[*label_len] = '\0';
+				*label_len = 0;
+				*prevstate = *state = object;
+			}
+
+			if (*label_len >= SMK_MAXLEN)
+				goto out;
+			objectstr[(*label_len)++] = data[i];
 			break;
-		if (sscanf(cp, "%23s %23s %7s\n", subjectstr, objectstr,
-			   modestr) != 3)
+
+		case access:
+			if (*prevstate == blank) {
+				objectstr[*label_len] = '\0';
+				*label_len = 0;
+				*prevstate = *state = access;
+			}
+
+			if (data[i] == 'r' || data[i] == 'R')
+				rule->smk_access |= MAY_READ;
+			else if (data[i] == 'w' || data[i] == 'W')
+				rule->smk_access |= MAY_WRITE;
+			else if (data[i] == 'x' || data[i] == 'X')
+				rule->smk_access |= MAY_EXEC;
+			else if (data[i] == 'a' || data[i] == 'A')
+				rule->smk_access |= MAY_APPEND;
+			else if (data[i] == '-')
+				/* No-Op, '-' is a placeholder */;
+			else
+				goto out;
+			*accesstok = 1;
 			break;
-		rule.smk_subject = smk_import(subjectstr, 0);
-		if (rule.smk_subject == NULL)
+
+		case newline:
+			if (*accesstok == 0)
+				goto out;
+
+			rule->smk_subject = smk_import(subjectstr, 0);
+			if (rule->smk_subject == NULL)
+				goto out;
+
+			rule->smk_object = smk_import(objectstr, 0);
+			if (rule->smk_object == NULL)
+				goto out;
+
+			smk_set_access(rule);
+
+			/* Reset everything, a new rule will come */
+			memset(load_state, 0, sizeof(*load_state));
 			break;
-		rule.smk_object = smk_import(objectstr, 0);
-		if (rule.smk_object == NULL)
+
+		case blank:
 			break;
-		rule.smk_access = 0;
-		if (strpbrk(modestr, "rR") != NULL)
-			rule.smk_access |= MAY_READ;
-		if (strpbrk(modestr, "wW") != NULL)
-			rule.smk_access |= MAY_WRITE;
-		if (strpbrk(modestr, "xX") != NULL)
-			rule.smk_access |= MAY_EXEC;
-		if (strpbrk(modestr, "aA") != NULL)
-			rule.smk_access |= MAY_APPEND;
-		smk_set_access(&rule);
+		}
 	}
 
+	rc = count;
+out:
 	kfree(data);
 	return rc;
 }
@@ -254,7 +388,7 @@ static const struct file_operations smk_load_ops = {
 	.read		= seq_read,
 	.llseek         = seq_lseek,
 	.write		= smk_write_load,
-	.release        = seq_release
+	.release        = smk_release_load,
 };
 
 /**
@@ -924,6 +1058,7 @@ static int __init init_smk_fs(void)
 		}
 	}
 
+	sema_init(&smack_write_sem, 1);
 	smk_cipso_doi();
 
 	return err;

--
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 65%]

* Re: [PATCH] Smackv9: Use a stateful parser for parsing Smack rules
  @ 2007-11-02 18:50 99%     ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-11-02 18:50 UTC (permalink / raw)
  To: Jan Engelhardt
  Cc: casey, akpm, torvalds, linux-security-module, linux-kernel, viro

On 11/1/07, Jan Engelhardt <jengelh@computergmbh.de> wrote:
>
> On Nov 1 2007 17:54, Ahmed S. Darwish wrote:
> >+
> >+static inline int isblank(char c)
> >+{
> >+      return (c == ' ' || c == '\t');
> >+}
>
> Use isspace().
>

isspace accepts newlines and carriage-returns too which is not
accepted between elements of a one rule.

> >+      for (i = 0; i < count && data[i]; i ++)
> >...
> >+                      subjectstr[(*label_len) ++] = data[i];
>
> i++ w/o space
>

Notes Taken. Thanks for the review.

Regards,

Darwish

^ permalink raw reply	[relevance 99%]

* [PATCH] Smackv9: Use a stateful parser for parsing Smack rules
  @ 2007-11-01 15:54 74% ` Ahmed S. Darwish
    0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2007-11-01 15:54 UTC (permalink / raw)
  To: casey; +Cc: akpm, torvalds, linux-security-module, linux-kernel, viro

Hi Casey/Al/all,

A patch that utilizes Al Viro's concerns on previous smack parser
and solves pevious parser bugs discovered by Ahmed Darwish. By now,
no problem will occur if given smack rules are fragmented over
multiple write() calls.

CC: Al Viro <viro@ftp.linux.org.uk>
Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

A similar patch for parsing CIPSO rules will be sent soon.

diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c
index 88b3f7b..9b56281 100644
--- a/security/smack/smackfs.c
+++ b/security/smack/smackfs.c
@@ -67,6 +67,39 @@ static int smack_cipso_count;
 struct smk_list_entry *smack_list;
 
 /*
+ * Disable concurrent writing open() operations
+ */
+static struct semaphore smack_write_sem;
+
+/*
+ * States for parsing /smack/load rules
+ */
+enum load_state {
+	subject      = 0,
+	object       = 1,
+	access       = 2,
+	eol          = 3,
+};
+
+/*
+ * Represent current parsing state of /smack/load. Struct
+ * also stores data needed between an open-release session's
+ * multiple write() calls
+ */
+static struct smack_load_state {
+	enum load_state state;
+	struct  smack_rule rule;
+	int     label_len;
+	char    subject[SMK_LABELLEN];
+	char    object[SMK_LABELLEN];
+} *load_state;
+
+static inline int isblank(char c)
+{
+	return (c == ' ' || c == '\t');
+}
+
+/*
  * Seq_file read operations for /smack/load
  */
 
@@ -127,12 +160,43 @@ static struct seq_operations load_seq_ops = {
  * @inode: inode structure representing file
  * @file: "load" file pointer
  *
- * Connect our load_seq_* operations with /smack/load
- * file_operations
+ * For reading, use load_seq_* seq_file reading operations.
+ * For writing, prepare a load_state struct to parse
+ * incoming rules.
  */
 static int smk_open_load(struct inode *inode, struct file *file)
 {
-	return seq_open(file, &load_seq_ops);
+	if ((file->f_flags & O_ACCMODE) == O_RDONLY)
+		return seq_open(file, &load_seq_ops);
+
+	if (down_interruptible(&smack_write_sem))
+		return -ERESTARTSYS;
+
+	load_state = kzalloc(sizeof(struct smack_load_state), GFP_KERNEL);
+	if (!load_state)
+		return -ENOMEM;
+
+	return 0;
+}
+
+/**
+ * smk_release_load - release() for /smack/load
+ * @inode: inode structure representing file
+ * @file: "load" file pointer
+ *
+ * For a reading session, use the seq_file release
+ * implementation.
+ * Otherwise, we are at the end of a writing session so
+ * clean everything up.
+ */
+static int smk_release_load(struct inode *inode, struct file *file)
+{
+	if ((file->f_flags & O_ACCMODE) == O_RDONLY)
+		return seq_release(inode, file);
+
+	kfree(load_state);
+	up(&smack_write_sem);
+	return 0;
 }
 
 /**
@@ -171,7 +235,6 @@ static void smk_set_access(struct smack_rule *srp)
 	return;
 }
 
-
 /**
  * smk_write_load - write() for /smack/load
  * @filp: file pointer, not actually used
@@ -179,19 +242,20 @@ static void smk_set_access(struct smack_rule *srp)
  * @count: bytes sent
  * @ppos: where to start
  *
- * Returns number of bytes written or error code, as appropriate
+ * Parse smack rules of format "subject object accesss". Handle
+ * defragmented rules over several write calls using the
+ * load_state structure.
  */
 static ssize_t smk_write_load(struct file *file, const char __user *buf,
 			      size_t count, loff_t *ppos)
 {
-	struct smack_rule rule;
-	ssize_t rc = count;
+	struct smack_rule *rule = &load_state->rule;
+	int *label_len = &load_state->label_len;
+	char *subjectstr = load_state->subject;
+	char *objectstr = load_state->object;
+	ssize_t rc = -EINVAL;
 	char *data = NULL;
-	char subjectstr[SMK_LABELLEN];
-	char objectstr[SMK_LABELLEN];
-	char modestr[8];
-	char *cp;
-
+	int i;
 
 	if (!capable(CAP_MAC_OVERRIDE))
 		return -EPERM;
@@ -205,7 +269,7 @@ static ssize_t smk_write_load(struct file *file, const char __user *buf,
 	 * 80 characters per line ought to be enough.
 	 */
 	if (count > SMACK_LIST_MAX * 80)
-		return -ENOMEM;
+		return -EFBIG;
 
 	data = kzalloc(count + 1, GFP_KERNEL);
 	if (data == NULL)
@@ -218,30 +282,74 @@ static ssize_t smk_write_load(struct file *file, const char __user *buf,
 
 	*(data + count) = '\0';
 
-	for (cp = data - 1; cp != NULL; cp = strchr(cp + 1, '\n')) {
-		if (*++cp == '\0')
+	for (i = 0; i < count && data[i]; i ++)
+		switch (load_state->state) {
+		case subject:
+			if (isblank(data[i])) {
+				load_state->state = object;
+				subjectstr[*label_len] = '\0';
+				*label_len = 0;
+				break;
+			}
+			if (*label_len >= SMK_MAXLEN)
+				goto out;
+			subjectstr[(*label_len) ++] = data[i];
 			break;
-		if (sscanf(cp, "%23s %23s %7s\n", subjectstr, objectstr,
-			   modestr) != 3)
+
+		case object:
+			if (isblank(data[i])) {
+				load_state->state = access;
+				objectstr[*label_len] = '\0';
+				*label_len = 0;
+				break;
+			}
+
+			if (*label_len >= SMK_MAXLEN)
+				goto out;
+			objectstr[(*label_len) ++] = data[i];
 			break;
-		rule.smk_subject = smk_import(subjectstr, 0);
-		if (rule.smk_subject == NULL)
+
+		case access:
+			if (isblank(data[i]) || data[i] == '\n') {
+				load_state->state = eol;
+				/* Let "eol" take control from current char */
+				--i;
+				break;
+			}
+
+			if (data[i] == 'r')
+				rule->smk_access |= MAY_READ;
+			else if (data[i] == 'w')
+				rule->smk_access |= MAY_WRITE;
+			else if (data[i] == 'x')
+				rule->smk_access |= MAY_EXEC;
+			else if (data[i] == 'a')
+				rule->smk_access |= MAY_APPEND;
+			else
+				goto out;
 			break;
-		rule.smk_object = smk_import(objectstr, 0);
-		if (rule.smk_object == NULL)
+
+		case eol:
+			if (isblank(data[i]))
+				break;
+
+			load_state->state = subject;
+			*label_len = 0;
+
+			rule->smk_subject = smk_import(subjectstr, 0);
+			if (rule->smk_subject == NULL)
+				goto out;
+
+			rule->smk_object = smk_import(objectstr, 0);
+			if (rule->smk_object == NULL)
+				goto out;
+
+			smk_set_access(rule);
 			break;
-		rule.smk_access = 0;
-		if (strpbrk(modestr, "rR") != NULL)
-			rule.smk_access |= MAY_READ;
-		if (strpbrk(modestr, "wW") != NULL)
-			rule.smk_access |= MAY_WRITE;
-		if (strpbrk(modestr, "xX") != NULL)
-			rule.smk_access |= MAY_EXEC;
-		if (strpbrk(modestr, "aA") != NULL)
-			rule.smk_access |= MAY_APPEND;
-		smk_set_access(&rule);
-	}
+		}
 
+	rc = count;
+out:
 	kfree(data);
 	return rc;
 }
@@ -251,7 +359,7 @@ static const struct file_operations smk_load_ops = {
 	.read		= seq_read,
 	.llseek         = seq_lseek,
 	.write		= smk_write_load,
-	.release        = seq_release
+	.release        = smk_release_load,
 };
 
 /**
@@ -921,6 +1029,7 @@ static int __init init_smk_fs(void)
 		}
 	}
 
+	sema_init(&smack_write_sem, 1);
 	smk_cipso_doi();
 
 	return err;

--
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 74%]

* Re: [PATCH 2/2] Version 9 (2.6.24-rc1) Smack: Simplified Mandatory Access Control Kernel
  @ 2007-10-28 12:46 99%     ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-10-28 12:46 UTC (permalink / raw)
  To: Al Viro; +Cc: casey, akpm, torvalds, linux-security-module, linux-kernel

On 10/28/07, Al Viro <viro@ftp.linux.org.uk> wrote:
> On Sat, Oct 27, 2007 at 11:01:12AM +0200, Ahmed S. Darwish wrote:
> > The problem here (As discussed in private mails) is that the for loop
> > assumes that the beginning of given user-space buffer is the beginning
> > of a rule. This leads to situations where the rule becomes "ecret 20",
> > or "cret 20" instead of "Secret 20". Big input buffers/files leads
> > smack to recieve a rule like "Secret 20" in fragmented chunks like:
> >
> > write("<lots of rules before ours>\nSec", ..)
> > write("r", 1, ..)
> > write("et 20\n<remaing rules after ours>", ..)
> >
> > Parsing a rule in such tough conditions in _kernel space_ is very
> > hard. I began to feel that it will be much easier if we do the parsing
> > in a userspace utility and let smack accept only small buffers (80 char).
>
> For crying out louf, all it takes is a finite state machine...  BTW, folks,
> your parser *and* input language suck.  Really.  Silently allowing noise
> is Dumb(tm).
>

Ehem .., I really thought about the FSM thing but I thought it won't
be possible with concurrent writes (forgetting that several related
writes is done in one open(),release() session and we can lock writes
in open()).

<Getting back to coding>

-- 
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH 2/2] Version 9 (2.6.24-rc1) Smack: Simplified Mandatory Access Control Kernel
    2007-10-27  3:00 85% ` Ahmed S. Darwish
@ 2007-10-27  9:01 96% ` Ahmed S. Darwish
    1 sibling, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2007-10-27  9:01 UTC (permalink / raw)
  To: casey; +Cc: akpm, torvalds, linux-security-module, linux-kernel

> +/**
> + * smk_write_cipso - write() for /smack/cipso
> + * @filp: file pointer, not actually used
> + * @buf: where to get the data from
> + * @count: bytes sent
> + * @ppos: where to start
> + *
> + * Returns number of bytes written or error code, as appropriate
> + */
> +static ssize_t smk_write_cipso(struct file *file, const char __user *buf,
> +			       size_t count, loff_t *ppos)
> +{

[...]

> +
> +	/*
> +	 * Only allow one writer at a time. Writes should be
> +	 * quite rare and small in any case.
> +	 */
> +	mutex_lock(&smack_cipso_lock);
> +
> +	*(data + count) = '\0';
> +
> +	for (eolp = strchr(data, '\n'), linep = data;
> +		eolp != NULL && rc >= 0;
> +		linep = eolp + 1, eolp = strchr(linep, '\n')) {
> +

The problem here (As discussed in private mails) is that the for loop 
assumes that the beginning of given user-space buffer is the beginning
of a rule. This leads to situations where the rule becomes "ecret 20",
or "cret 20" instead of "Secret 20". Big input buffers/files leads 
smack to recieve a rule like "Secret 20" in fragmented chunks like:

write("<lots of rules before ours>\nSec", ..)
write("r", 1, ..)
write("et 20\n<remaing rules after ours>", ..)

Parsing a rule in such tough conditions in _kernel space_ is very
hard. I began to feel that it will be much easier if we do the parsing 
in a userspace utility and let smack accept only small buffers (80 char). 

i.e. A user space utility that takes a big input file like
exit 10/3,7,4
exit 10/3,7,4
exit 10/3,7,4
<100 times>

And transform it to 100 small write() calls. By this way we can return
-EINVAL if write()'s count field > 80, or if input contains no \n or
more than one.

Any Ideas ?. 

Casey, I can begin modifying cipso_write() and writing this small 
user-space utility now if you agree on this.

Regards,

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 96%]

* Re: [PATCH 2/2] Version 9 (2.6.24-rc1) Smack: Simplified Mandatory Access Control Kernel
  @ 2007-10-27  3:00 85% ` Ahmed S. Darwish
  2007-10-27  9:01 96% ` Ahmed S. Darwish
  1 sibling, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-10-27  3:00 UTC (permalink / raw)
  To: casey; +Cc: akpm, torvalds, linux-security-module, linux-kernel

Hi Casey,

Casey <casey@schaufler-ca.com> wrote:
>
> This version is again aimed at addressing Al Viro's issues in
> smackfs. Ahmed Darwish has again contributed in the repair of the
> locking issues there. The move to 2.6.24 was also an important
> release incentive.
>

My patches mentiond above is not applied in this version. The same 
lock issues remain. Did you forget applying them ? In that case, 
here're the same patches again (on ver8):

==> 1:
cipso_seq_show should not be passed smack labels with no cipso
mapping. Omit non-cipso mapped labels in cipso_seq_start and 
BUG in case cipso_seq_show was passed a non-cipso label.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.coM>
---

smackv8-omit-noncipso-in-seq-start.patch

diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c
index 55ba2dc..b061cd0 100644
--- a/security/smack/smackfs.c
+++ b/security/smack/smackfs.c
@@ -297,14 +297,22 @@ void smk_cipso_doi(void)
 
 /*
  * Seq_file read operations for /smack/cipso
+ *
+ * Omit labels with no associated cipso values from being
+ * displayed in seq_show()
  */
 
 static void *cipso_seq_start(struct seq_file *s, loff_t *pos)
 {
+	struct smack_known *skp = smack_known;
+
 	if (*pos >= smack_cipso_count)
 		return NULL;
 
-	return smack_known;
+	while (skp && !skp->smk_cipso)
+		skp = skp->smk_next;
+
+	return skp;
 }
 
 static void *cipso_seq_next(struct seq_file *s, void *v, loff_t *pos)
@@ -313,9 +321,6 @@ static void *cipso_seq_next(struct seq_file *s, void *v, loff_t *pos)
 
 	(*pos)++;
 
-	/*
-	 * Omit labels with no associated cipso value
-	 */
 	while (skp && !skp->smk_cipso)
 		skp = skp->smk_next;
 
@@ -336,12 +341,11 @@ static int cipso_seq_show(struct seq_file *s, void *v)
 	int i;
 	unsigned char m;
 
-	if (scp == NULL)
-		return 0;
+	BUG_ON(!scp);
+	cbp = scp->smk_catset;
 
 	seq_printf(s, "%s %3d", (char *)&skp->smk_known, scp->smk_level);
 
-	cbp = scp->smk_catset;
 	for (i = 0; i < SMK_LABELLEN; i++)
 		for (m = 0x80; m != 0; m >>= 1) {
 			if (m & cbp[i]) {

==> 2:

Avoid racy use of smack_{list,cipso}_count in traversing lists.
Simple smack_list and smack_known lockless list traversal is all 
what's needed.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

smackv8-lockless-read.patch

diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c
index b061cd0..e343827 100644
--- a/security/smack/smackfs.c
+++ b/security/smack/smackfs.c
@@ -63,16 +63,17 @@ int smack_cipso_direct = SMACK_CIPSO_DIRECT_DEFAULT;
 
 static int smk_cipso_doi_value = SMACK_CIPSO_DOI_DEFAULT;
 static int smack_list_count;
-static int smack_cipso_count;
 struct smk_list_entry *smack_list;
 
+#define SEQ_READ_FINISHED	1
+
 /*
  * Seq_file read operations for /smack/load
  */
 
 static void *load_seq_start(struct seq_file *s, loff_t *pos)
 {
-	if (*pos >= smack_list_count)
+	if (*pos == SEQ_READ_FINISHED)
 		return NULL;
 
 	return smack_list;
@@ -80,8 +81,12 @@ static void *load_seq_start(struct seq_file *s, loff_t *pos)
 
 static void *load_seq_next(struct seq_file *s, void *v, loff_t *pos)
 {
-	(*pos)++;
-	return ((struct smk_list_entry *) v)->smk_next;
+	struct smk_list_entry *skp = ((struct smk_list_entry *) v)->smk_next;
+
+	if (!skp)
+		*pos = SEQ_READ_FINISHED;
+
+	return skp;
 }
 
 static int load_seq_show(struct seq_file *s, void *v)
@@ -306,7 +311,7 @@ static void *cipso_seq_start(struct seq_file *s, loff_t *pos)
 {
 	struct smack_known *skp = smack_known;
 
-	if (*pos >= smack_cipso_count)
+	if (*pos == SEQ_READ_FINISHED)
 		return NULL;
 
 	while (skp && !skp->smk_cipso)
@@ -319,11 +324,12 @@ static void *cipso_seq_next(struct seq_file *s, void *v, loff_t *pos)
 {
 	struct smack_known *skp = ((struct smack_known *) v)->smk_next;
 
-	(*pos)++;
-
 	while (skp && !skp->smk_cipso)
 		skp = skp->smk_next;
 
+	if (!skp)
+		*pos = SEQ_READ_FINISHED;
+
 	return skp;
 }
 
@@ -488,7 +494,6 @@ static ssize_t smk_write_cipso(struct file *file, const char __user *buf,
 				rc = -ENOMEM;
 				break;
 			}
-			++smack_cipso_count;
 		} else
 			scp = NULL;
 

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 85%]

* Rule parsing from a virtual FS write() syscall
@ 2007-10-24 11:00 99% Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-10-24 11:00 UTC (permalink / raw)
  To: linux-kernel; +Cc: casey, viro

Hi all,

In SMACK, some rules are written to a virtual fs file named 
"cipso".

Rule format is

label level[/cat[,cat]]

Under high I/O load we don't recieve the whole rule in one shot.
This means that sometimes the write() operation begins from the 
middle of the rule. Under some conditions, the first rule _letter_
was only recieved while others were recieved in remaining write() 
calls.

Current SMACK versions don't assume fragmented input like above
cases. This means that sometimes bogus rules that does not 
represent users' intent got created.

What is the best way to parse a rule in such hard coditions?

Regards,

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH] Smackv8: Safe lockless {cipso,load} read operation
  2007-10-21  1:40 96% ` [PATCH] Smackv8: Omit non-cipso labels in cipso_seq_start Ahmed S. Darwish
@ 2007-10-21  2:25 93%   ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-10-21  2:25 UTC (permalink / raw)
  To: Casey Schaufler, Al Viro
  Cc: torvalds, akpm, linux-security-module, linux-kernel

Hi,

Utilizing Al's concers about using smack_cipso_count without locking,
here's a patch that remove smack_cipso_count and uses simple list 
traversing in read() without any counting mechanism.

CC: Al Viro <viro@ftp.linux.org.uk>
Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>

---

Please apply over omit-non-cipso-lables-in-cipso-seq-start.patch
Using smack_{list,cipso}_count in the read context was useless
anyway cause we were just traversing the list.

diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c
index b061cd0..c38d0d0 100644
--- a/security/smack/smackfs.c
+++ b/security/smack/smackfs.c
@@ -63,16 +63,17 @@ int smack_cipso_direct = SMACK_CIPSO_DIRECT_DEFAULT;
 
 static int smk_cipso_doi_value = SMACK_CIPSO_DOI_DEFAULT;
 static int smack_list_count;
-static int smack_cipso_count;
 struct smk_list_entry *smack_list;
 
+#define SEQ_READ_FINISHED	1
+
 /*
  * Seq_file read operations for /smack/load
  */
 
 static void *load_seq_start(struct seq_file *s, loff_t *pos)
 {
-	if (*pos >= smack_list_count)
+	if (*pos == SEQ_READ_FINISHED)
 		return NULL;
 
 	return smack_list;
@@ -80,8 +81,13 @@ static void *load_seq_start(struct seq_file *s, loff_t *pos)
 
 static void *load_seq_next(struct seq_file *s, void *v, loff_t *pos)
 {
-	(*pos)++;
-	return ((struct smk_list_entry *) v)->smk_next;
+	struct smk_list_entry *skp = ((struct smk_list_entry *) v)->smk_next;
+
+	if (skp)
+		return skp;
+
+	*pos = SEQ_READ_FINISHED;
+	return NULL;
 }
 
 static int load_seq_show(struct seq_file *s, void *v)
@@ -306,7 +312,7 @@ static void *cipso_seq_start(struct seq_file *s, loff_t *pos)
 {
 	struct smack_known *skp = smack_known;
 
-	if (*pos >= smack_cipso_count)
+	if (*pos == SEQ_READ_FINISHED)
 		return NULL;
 
 	while (skp && !skp->smk_cipso)
@@ -319,12 +325,14 @@ static void *cipso_seq_next(struct seq_file *s, void *v, loff_t *pos)
 {
 	struct smack_known *skp = ((struct smack_known *) v)->smk_next;
 
-	(*pos)++;
-
 	while (skp && !skp->smk_cipso)
 		skp = skp->smk_next;
 
-	return skp;
+	if (skp)
+		return skp;
+
+	*pos = SEQ_READ_FINISHED;
+	return NULL;
 }
 
 /*
@@ -488,7 +496,6 @@ static ssize_t smk_write_cipso(struct file *file, const char __user *buf,
 				rc = -ENOMEM;
 				break;
 			}
-			++smack_cipso_count;
 		} else
 			scp = NULL;
 

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 93%]

* [PATCH] Smackv8: Omit non-cipso labels in cipso_seq_start
    @ 2007-10-21  1:40 96% ` Ahmed S. Darwish
  2007-10-21  2:25 93%   ` [PATCH] Smackv8: Safe lockless {cipso,load} read operation Ahmed S. Darwish
  1 sibling, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2007-10-21  1:40 UTC (permalink / raw)
  To: Casey Schaufler; +Cc: torvalds, akpm, linux-security-module, linux-kernel

Hi!,

[Casey, sending patches in public to get an early review]

Omit non-cipso labels in cipso_seq_start().

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
stopping seq_show() if smk_cipso = NULL only fixes the bug 
symptom. We'll issue a BUG() in that case cause it signals a
serious misbehavior in the list entries.

diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c
index 55ba2dc..b061cd0 100644
--- a/security/smack/smackfs.c
+++ b/security/smack/smackfs.c
@@ -297,14 +297,22 @@ void smk_cipso_doi(void)
 
 /*
  * Seq_file read operations for /smack/cipso
+ *
+ * Omit labels with no associated cipso values from being
+ * displayed in seq_show()
  */
 
 static void *cipso_seq_start(struct seq_file *s, loff_t *pos)
 {
+	struct smack_known *skp = smack_known;
+
 	if (*pos >= smack_cipso_count)
 		return NULL;
 
-	return smack_known;
+	while (skp && !skp->smk_cipso)
+		skp = skp->smk_next;
+
+	return skp;
 }
 
 static void *cipso_seq_next(struct seq_file *s, void *v, loff_t *pos)
@@ -313,9 +321,6 @@ static void *cipso_seq_next(struct seq_file *s, void *v, loff_t *pos)
 
 	(*pos)++;
 
-	/*
-	 * Omit labels with no associated cipso value
-	 */
 	while (skp && !skp->smk_cipso)
 		skp = skp->smk_next;
 
@@ -336,12 +341,11 @@ static int cipso_seq_show(struct seq_file *s, void *v)
 	int i;
 	unsigned char m;
 
-	if (scp == NULL)
-		return 0;
+	BUG_ON(!scp);
+	cbp = scp->smk_catset;
 
 	seq_printf(s, "%s %3d", (char *)&skp->smk_known, scp->smk_level);
 
-	cbp = scp->smk_catset;
 	for (i = 0; i < SMK_LABELLEN; i++)
 		for (m = 0x80; m != 0; m >>= 1) {
 			if (m & cbp[i]) {


-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 96%]

* Re: [PATCH] Version 8 (2.6.23) Smack: Simplified Mandatory Access Control Kernel
  @ 2007-10-19 12:39 99%     ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-10-19 12:39 UTC (permalink / raw)
  To: Al Viro
  Cc: Casey Schaufler, torvalds, akpm, linux-security-module, linux-kernel

On 10/18/07, Al Viro <viro@ftp.linux.org.uk> wrote:
> On Thu, Oct 18, 2007 at 05:57:05AM +0100, Al Viro wrote:
> > On Tue, Oct 16, 2007 at 09:17:40PM -0700, Casey Schaufler wrote:
>
> > Think what happens if CPU1 adds to list and CPU2 sees write to smk_known
> > *before* it sees write to ->smk_next.  We see a single-element list and
> > we'll be lucky if that single entry won't be FUBAR.
>
> While we are at it, what protects smack_cipso_count?
> -

My fault. I sent to Casey a one-liner patch to make "smack_cipso_count++"
be protected by the smk_cipsolock spinlock.

We don't need a lock in the reading side since we don't do a write operation
depending on that read, right ?.

-- 
Ahmed S. Darwish
Homepage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH try #3] Input/Joystick Driver: add support AD7142 joystick driver
  @ 2007-10-16 16:40 99%       ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-10-16 16:40 UTC (permalink / raw)
  To: Bryan Wu
  Cc: Dmitry Torokhov, bryan.wu, Andrey Panin, Roel Kluin, linux-input,
	linux-joystick, linux-kernel, akpm, Jean Delvare

On Tue, Oct 16, 2007 at 02:08:04PM +0800, Bryan Wu wrote:
> On 10/16/07, Ahmed S. Darwish <darwish.07@gmail.com> wrote:
> > On Mon, Oct 15, 2007 at 11:48:17AM -0400, Dmitry Torokhov wrote:
> > > Hi Bryan,
> > >
> > > On 10/15/07, Bryan Wu <bryan.wu@analog.com> wrote:
> > > > +
> > > > +static int ad7142_thread(void *nothing)
> > > > +{
> > > > +       do {
> > > > +               wait_for_completion(&ad7142_completion);
> > > > +               ad7142_decode();
> > > > +               enable_irq(CONFIG_BFIN_JOYSTICK_IRQ_PFX);
> > > > +       } while (!kthread_should_stop());
> > > > +
> > >
> > > No, this is not going to work well:
> > > - you at least need to reinitialize the completion before enabling
> > > IRQ, otherwise you will spin in a very tight loop
> > > - if noone would touch the joystick ad7142_clsoe would() block
> > > infinitely because noone would signal the completion and
> > > ad7142_thread() would never stop.
> > >
> > > Completion is just not a good abstraction here... Please use work
> > > abstraction and possibly a separate workqueue.
> > >
> >
> > Bryan, I'm very interested in the technical advantage of using a completion
> > here.
> >
> You are welcome, I'd like to discuss these things here.
> 
> > In my _not-experienced_ opinion, I remember completions was created mainly for
> > "create_task, wait till task got finished, go on" case. Why using it in a
> > different context while workqueues was created for a similar situation to
> > ad7142 one (non-irq context bottom-half) ?
> 
> I like completion because it is simple to use and understand. Your
> understanding is right. But there is no limit for using different
> context with completion. completion is a wrapper of waitqueue+done
> flag. For some drivers, in process context call
> wait_for_completetion(), then schedule out and in irq handler call
> complete(). This is very simple and helpful for driver design (For
> example, you call dma function to transfer data, then you schedule out
> and then DMA IRQ handler will call complete() to wakeup you).
> 

Thank you for such a useful information.

> But in this driver, a) can not call ad7142_decode() in IRQ handler,
> because it will sleep in IRQ context by calling some i2c API, b) in
> original design, creating a new kthread and using some waitqueue API
> is the same way as using workqueue, c) cannot use completion as Dmitry
> said.
> 
> I am going to use workqueue here.
> 
> Any idea?
> 

I have no better thoughts than the ones provided by Dmitry actually.

> Thanks
> -Bryan Wu

Regards :),

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH try #3] Input/Joystick Driver: add support AD7142 joystick driver
  @ 2007-10-15 18:27 99%   ` Ahmed S. Darwish
    0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2007-10-15 18:27 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: bryan.wu, Andrey Panin, Roel Kluin, linux-input, linux-joystick,
	linux-kernel, akpm, Jean Delvare

On Mon, Oct 15, 2007 at 11:48:17AM -0400, Dmitry Torokhov wrote:
> Hi Bryan,
> 
> On 10/15/07, Bryan Wu <bryan.wu@analog.com> wrote:
> > +
> > +static int ad7142_thread(void *nothing)
> > +{
> > +       do {
> > +               wait_for_completion(&ad7142_completion);
> > +               ad7142_decode();
> > +               enable_irq(CONFIG_BFIN_JOYSTICK_IRQ_PFX);
> > +       } while (!kthread_should_stop());
> > +
> 
> No, this is not going to work well:
> - you at least need to reinitialize the completion before enabling
> IRQ, otherwise you will spin in a very tight loop
> - if noone would touch the joystick ad7142_clsoe would() block
> infinitely because noone would signal the completion and
> ad7142_thread() would never stop.
> 
> Completion is just not a good abstraction here... Please use work
> abstraction and possibly a separate workqueue.
> 

Bryan, I'm very interested in the technical advantage of using a completion
here.

In my _not-experienced_ opinion, I remember completions was created mainly for
"create_task, wait till task got finished, go on" case. Why using it in a
different context while workqueues was created for a similar situation to
ad7142 one (non-irq context bottom-half) ?

Regards,

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH] Version 7 (2.6.23) Smack: Simplified Mandatory Access Control Kernel
  @ 2007-10-14 23:13 90% ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-10-14 23:13 UTC (permalink / raw)
  To: Casey Schaufler; +Cc: torvalds, akpm, linux-security-module, linux-kernel

Hi Casey,

On Sun, Oct 14, 2007 at 10:15:42AM -0700, Casey Schaufler wrote:
> 
> +
> +CIPSO Configuration
> +
> +It is normally unnecessary to specify the CIPSO configuration. The default
> +values used by the system handle all internal cases. Smack will compose CIPSO
> +label values to match the Smack labels being used without administrative
> +intervention. 
>

I have two issues with CIPSO and Smack:

1-

Using default configuration (system startup script + smacfs fstab line), system
can't access any service outside the Lan. "ICMP parameter problem message" always
appear from the first Wan router (traceroute + tcpdump at [1]).

Services inside the LAN can be accessed normally. System can connect to a Lan
Windows share. It also connects to the gateway HTTP server easily.

After some tweaking, I discovered that using CIPSOv6 solves all above problems:
$ echo -n "NLBL_CIPSOv6" > /smack/nltype

Is this a normal behaviour ?

2-

> 4. Any access requested on an object labeled "*" is permitted.
[...]
> +Unlabeled packets that come into the system will be given the
> +ambient label.

Default conf let the ambient attribute = _ which works fine. Setting ambient = *
stops all external (non lo) network traffic. Did I miss another use of "ambient"
or this is a normal behaviour ?.

> +Administration
> +
> +Smack supports some mount options:
> +
> +	smackfsdef=label: specifies the label to give files that lack
> +	the Smack label extended attribute.
> +

Although using smackfsdef=* as a mount option, all my system files have the floor
attribute. Most of the /dev files have the * attribute though.


[1]

traceroute to google.com (64.233.187.99), 30 hops max, 40 byte packets
 1  host-196.218.207.17.tedata.net (196.218.207.17)  1.976 ms  1.850 ms  2.127 ms
 2  DOKKI-R03C-GZ-EG (163.121.170.78)  27.429 ms  28.091 ms  23.336 ms

Here's the tcpdump for accessing google.com:

22:51:26.008883 IP host-196.218.207.18.tedata.net.54011 > host-196.218.207.17.tedata.net.domain:  11001+ A? google.com. (28)
22:51:26.011066 IP host-196.218.207.18.tedata.net.45317 > host-196.218.207.17.tedata.net.domain:  44913+[|domain]
22:51:26.052154 IP host-196.218.207.17.tedata.net.domain > host-196.218.207.18.tedata.net.54011:  11001 3/0/0 A py-in-f99.google.com,[|domain]
22:51:26.052700 IP host-196.218.207.18.tedata.net.57180 > py-in-f99.google.com.www: S 282373541:282373541(0) win 5840 <mss 1460,sackOK,timestamp 741383 0,nop,wscale 5>
22:51:26.090608 IP host-196.218.207.17.tedata.net.domain > host-196.218.207.18.tedata.net.45317:  44913 1/0/0 (89)
22:51:26.091473 IP host-196.218.207.18.tedata.net.34417 > host-196.218.207.17.tedata.net.domain:  49202+[|domain]
--> 22:51:26.105443 IP DOKKI-R03C-GZ-EG > host-196.218.207.18.tedata.net: ICMP parameter problem - octet 20, length 48

Best Regards,

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 90%]

* Re: 2.6.23-git2 buid failure
  @ 2007-10-14 11:18 99% ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-10-14 11:18 UTC (permalink / raw)
  To: Kamalesh Babulal; +Cc: LKML

On Sat, Oct 13, 2007 at 12:45:47PM +0530, Kamalesh Babulal wrote:
> Hi,
> 
> The 2.6.23-git2 build fails with build error 
> 
>   CC [M]  drivers/mmc/core/core.o
>   CC [M]  drivers/mmc/core/sysfs.o
>   CC [M]  drivers/mmc/core/bus.o
>   CC [M]  drivers/mmc/core/host.o
> drivers/mmc/core/host.c: In function ‘mmc_remove_host’:
> drivers/mmc/core/host.c:146: error: implicit declaration of function ‘led_trigger_unregister’
> drivers/mmc/core/host.c:146: error: ‘struct mmc_host’ has no member named ‘led’
> make[3]: *** [drivers/mmc/core/host.o] Error 1
> make[2]: *** [drivers/mmc/core] Error 2
> make[1]: *** [drivers/mmc] Error 2
> make: *** [drivers] Error 2
> 

You can fix it using this patch: http://lkml.org/lkml/2007/10/12/380
Or the patch titled: mmc-fix-compile-without-led-triggers.patch

Regards,

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH try #2] Input/Joystick Driver: add support AD7142 joystick driver
  @ 2007-10-12 19:21 99%     ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-10-12 19:21 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: Bryan Wu, linux-input, linux-joystick, linux-kernel, akpm

On Fri, Oct 12, 2007 at 01:29:31PM -0400, Dmitry Torokhov wrote:
> Hi Ahmed,
> 

Hi :),

> On 10/12/07, Ahmed S. Darwish <darwish.07@gmail.com> wrote:
> > On Fri, Oct 12, 2007 at 03:38:47PM +0800, Bryan Wu wrote:
> > >
> > > Signed-off-by: Bryan Wu <bryan.wu@analog.com>
> > > ---
> >
> > Hi Bryan,
> >
> > Why creating module's own kthread to call ad7142_decode and process keycodes
> > instead of using a tasklet ?
> >
> 
> Yo can't access i2c from a tasklet context.
> 
> > Isn't disabling device interrupts from the begining of the ISR "ad7142_interrupt"
> > till the kthread "ad7142_thread" got waked-up and scheduled a long time,
> > espicially if there's a high load on the userspace side ?
> >
> 
> It is OK - you disable a specific interrupt line preventing it from
> raising any more IRQs until current one is serviced. 

Won't this affect system responsiveness if the IRQ line was shared ?

>
> This is different from disabling interrupts on CPU.
> 

mm, Why disabling interrupts in general. Doesn't IRQ hanlers of the same kind got
executed in a serialized fashion even on SMPs ?. If so, why not just wakeup our
custom-thread or use workqueues and let them do their business ?

It's the first time for me to read others' patches carefully and kindly ask about
some explanations. I hope I'm not bothering people with my misunderstandings!
(till I get more experienced).


Thanks,

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH try #2] Input/Joystick Driver: add support AD7142 joystick driver
  @ 2007-10-12 16:41 99% ` Ahmed S. Darwish
    0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2007-10-12 16:41 UTC (permalink / raw)
  To: Bryan Wu; +Cc: dmitry.torokhov, linux-input, linux-joystick, linux-kernel, akpm

On Fri, Oct 12, 2007 at 03:38:47PM +0800, Bryan Wu wrote:
>
> Signed-off-by: Bryan Wu <bryan.wu@analog.com>
> ---

Hi Bryan,

Why creating module's own kthread to call ad7142_decode and process keycodes 
instead of using a tasklet ?

Isn't disabling device interrupts from the begining of the ISR "ad7142_interrupt"
till the kthread "ad7142_thread" got waked-up and scheduled a long time,
espicially if there's a high load on the userspace side ?

Minor issues below.

> +
> +/* R    ADC stage 0 - 11 result (uncompensated) actually located in SRAM */
> +#define ADCRESULT_S0		0x0B
> +#define ADCRESULT_S1		0x0C
> +#define ADCRESULT_S2		0x0D
> +#define ADCRESULT_S3		0x0E
> +#define ADCRESULT_S4		0x0F
> +#define ADCRESULT_S5		0x10
> +#define ADCRESULT_S6		0x11
> +#define ADCRESULT_S7		0x12
> +#define ADCRESULT_S8		0x13
> +#define ADCRESULT_S9		0x14
> +#define ADCRESULT_S10		0x15
> +#define ADCRESULT_S11		0x16
> +

Keeping last two lines aligned with their above counterparts ?

> +static int
> +ad7142_probe(struct i2c_adapter *adap, int addr, int kind)
> +{
> +	struct i2c_client *client;
> +	int rc;
> +
> +	client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
> +	if (!client)
> +		return -ENOMEM;
> +	memset(client, 0, sizeof(struct i2c_client));

kzalloc.

Regards,

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH] NTFS error messages: replace static char pointers by static char arrays
  @ 2007-10-09 22:03 99%     ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-10-09 22:03 UTC (permalink / raw)
  To: Philipp Matthias Hahn; +Cc: Kernel Mailing List

On Tue, Oct 09, 2007 at 08:33:59PM +0200, Philipp Matthias Hahn wrote:
> Hello!
> 
> On Tue, Oct 09, 2007 at 02:40:35PM +0200, Ahmed S. Darwish wrote:
> > On Tue, Oct 09, 2007 at 01:55:42AM +0400, Dmitri Vorobiev wrote:
> > > The patch below contains a small code clean-up for the NTFS driver: all
> > > static char pointers to error message strings have been replaced by 
> > > static char arrays.
> 
>       char *       a = "a"; // pointer and content can be changed

Only the pointer can be changed here. AFAIK "a" is a const string.

> const char *       b = "b"; // the thing pointed to is const

The "const" here is redundant (just useful for forcing the compiler to
prevent us from shooting our feet). The "b" string is already constant.

>       char * const c = "c"; // the pointer is const
> const char * const d = "d"; // pointer and content can't be changed
> 
> void foo(void) {
>         *a = 'A';

This will segfault.

>         a++;
>         *b = 'B'; // error: assignment of read-only location
>         b++;
>         *c = 'C';

Last line will segfault too.

>         c++;      // error: increment  of read-only variable 'c'
>         *d = 'D'; // error: assignment of read-only location
>         d++;      // error: increment  of read-only variable 'd'
> }
> 

Please continue below.

> > Isn't the only difference between char *c = "msg" and char c[] = "msg" is 
> > that the first is a non-const pointer to a const char array while the second 
> > is a modifiable char array ?
> 
> $ cat [ab].c
> const char *a = "a";
> const char b[] = "b";
> $ gcc -c [ab].c
> $ size [ab].o
>    text    data     bss     dec     hex filename
>       2       4       0       6       6 a.o
>       2       0       0       2       2 b.o
> 
> 'a' has two entries: one for the named read-writeable pointer, and one for the
>     anonymous read-only string, the pointer points to.
> 'b' has a single entry: just the named read-only string.
> 

Got the point, Thanks!.

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH] Stop docproc segfaulting when SRCTREE isn't set.
  @ 2007-10-09 17:51 99%         ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-10-09 17:51 UTC (permalink / raw)
  To: Randy Dunlap; +Cc: Rob Landley, akpm, linux-kernel, rdunlap

On Tue, Oct 09, 2007 at 10:24:03AM -0700, Randy Dunlap wrote:
> Ahmed S. Darwish wrote:
> >On Tue, Oct 09, 2007 at 08:55:00AM -0700, Randy Dunlap wrote:
> >>On Tue, 9 Oct 2007 15:03:15 +0200 Ahmed S. Darwish wrote:
> >>
> >>>Hi Rob,
> >>>
> >>>On Tue, Oct 09, 2007 at 01:25:18AM -0500, Rob Landley wrote:
> >>>[...]
> >>>> 	FILE * infile;
> >>>>+
> >>>>+	srctree = getenv("SRCTREE");
> >>>>+	if (!srctree) srctree = getcwd(NULL,0);
> >>>> 	if (argc != 3) {
> >>>> 		usage();
> >>>> 		exit(1);
> >>>$ man getcwd
> >>>
> >>> char *getcwd(char *buf, size_t size);
> >>>      
> >>> As an extension to the POSIX.1 standard, Linux (libc4, libc5, glibc) 
> >>> getcwd() allocates the buffer dynamically using malloc() if buf is NULL 
> >>> on call.
> >>>
> >>>Shouldn't "srctree" be free()ed in case getenv("SRCTREE") failed ?
> >>What is there to free() at that point?  If getenv() fails (i.e.,
> >>the env. variable is not found), it returns NULL.
> >>or do I need another cup of coffee?
> >>
> >
> >I meant if getenv() failed, "srctree = getcwd(NULL, 0)" will let 
> >"srctree" point to a _ malloc()ed _ buffer representing PWD. 
> >As said in the manpage, this buffer needs to be free()ed after usage.
> >Right or I'm the one who needs that cup of coffee :) ?
> 
> so it needs to be freed at program termination, is that what you are
> saying?  That will happen automatically (along with any open files being
> closed, etc.).
> 

I didn't know that leaked mem will be automatically freed at program 
termination. A new info, Thanks!.

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH] Stop docproc segfaulting when SRCTREE isn't set.
  @ 2007-10-09 17:19 99%     ` Ahmed S. Darwish
    0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2007-10-09 17:19 UTC (permalink / raw)
  To: Randy Dunlap; +Cc: Rob Landley, akpm, linux-kernel, rdunlap

On Tue, Oct 09, 2007 at 08:55:00AM -0700, Randy Dunlap wrote:
> On Tue, 9 Oct 2007 15:03:15 +0200 Ahmed S. Darwish wrote:
> 
> > Hi Rob,
> > 
> > On Tue, Oct 09, 2007 at 01:25:18AM -0500, Rob Landley wrote:
> > [...]
> > >  	FILE * infile;
> > > +
> > > +	srctree = getenv("SRCTREE");
> > > +	if (!srctree) srctree = getcwd(NULL,0);
> > >  	if (argc != 3) {
> > >  		usage();
> > >  		exit(1);
> > 
> > $ man getcwd
> > 
> >  char *getcwd(char *buf, size_t size);
> >       
> >  As an extension to the POSIX.1 standard, Linux (libc4, libc5, glibc) getcwd() 
> >  allocates the buffer dynamically using malloc() if buf is NULL on call.
> > 
> > Shouldn't "srctree" be free()ed in case getenv("SRCTREE") failed ?
> 
> What is there to free() at that point?  If getenv() fails (i.e.,
> the env. variable is not found), it returns NULL.
> or do I need another cup of coffee?
>

I meant if getenv() failed, "srctree = getcwd(NULL, 0)" will let 
"srctree" point to a _ malloc()ed _ buffer representing PWD. 
As said in the manpage, this buffer needs to be free()ed after usage.
Right or I'm the one who needs that cup of coffee :) ?

Regards,

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH -mm] fix wrong /proc/cpuinfo output
  @ 2007-10-09 13:32 99% ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-10-09 13:32 UTC (permalink / raw)
  To: Akinobu Mita, linux-kernel, Mike Travis, Andrew Morton

On Tue, Oct 09, 2007 at 07:43:21PM +0900, Akinobu Mita wrote:
> This patch fixes the problem introduced by:
> http://kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.23-rc8/2.6.23-rc8-mm2/broken-out/x86-convert-cpuinfo_x86-array-to-a-per_cpu-array.patch
> 

Link is dead, same patch in lkml.org:

http://lkml.org/lkml/2007/9/24/394

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH] Stop docproc segfaulting when SRCTREE isn't set.
  @ 2007-10-09 13:03 99% ` Ahmed S. Darwish
    0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2007-10-09 13:03 UTC (permalink / raw)
  To: Rob Landley; +Cc: akpm, linux-kernel, rdunlap

Hi Rob,

On Tue, Oct 09, 2007 at 01:25:18AM -0500, Rob Landley wrote:
[...]
>  	FILE * infile;
> +
> +	srctree = getenv("SRCTREE");
> +	if (!srctree) srctree = getcwd(NULL,0);
>  	if (argc != 3) {
>  		usage();
>  		exit(1);

$ man getcwd

 char *getcwd(char *buf, size_t size);
      
 As an extension to the POSIX.1 standard, Linux (libc4, libc5, glibc) getcwd() 
 allocates the buffer dynamically using malloc() if buf is NULL on call.

Shouldn't "srctree" be free()ed in case getenv("SRCTREE") failed ?

Regards,

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH] NTFS error messages: replace static char pointers by static char arrays
  @ 2007-10-09 12:40 99% ` Ahmed S. Darwish
    0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2007-10-09 12:40 UTC (permalink / raw)
  To: Dmitri Vorobiev; +Cc: aia21, linux-ntfs-dev, linux-kernel

On Tue, Oct 09, 2007 at 01:55:42AM +0400, Dmitri Vorobiev wrote:
> Hi,
> 
> The patch below contains a small code clean-up for the NTFS driver: all
> static char pointers to error message strings have been replaced by 
> static char arrays.
> 

Hi Dmitri,

Isn't the only difference between char *c = "msg" and char c[] = "msg" is 
that the first is a non-const pointer to a const char array while the second 
is a modifiable char array ?

If so, what's the point of the patch ?

Thanks,

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: PROBLEM: kernel 2.6.22.9-cfs-v22 compile warnings
  @ 2007-10-08 18:11 99% ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-10-08 18:11 UTC (permalink / raw)
  To: Konstantin Oshovskij; +Cc: linux-kernel

Hi Konstantin,

On Mon, Oct 08, 2007 at 03:34:24PM +0300, Konstantin Oshovskij wrote:
>
> Hello,
> i have encountered 2.6.22.9 compile warnings. This is the first time i
> decided to report them. I had various compile warnings with earlier
> kernel versions, its just i didnt had courage to report them :)  I'm
> using instructions from REPORTING-BUGS file as template so please bear
> with me :)
> 

The "may be used uninitialized" errors are false positives from GCC. Mostly
this happens from code paths like: 

int x, y; 
set_method(&x); 
y = x;

> fs/xfs/xfs_bmap.c: In function 'xfs_bmap_rtalloc':
> fs/xfs/xfs_bmap.c:2650: warning: 'rtx' is used uninitialized in this
> function
> 

Hidden by uninitialized_var() macro in latest pull. This macro silence
the gcc by using the trick: #define uninitialized_var(x) x = x

> function
> ipc/msg.c:390: warning: 'setbuf.mode' may be used uninitialized in
> this function
>   CC      ipc/sem.o
> ipc/sem.c: In function 'sys_semctl':
> ipc/sem.c:861: warning: 'setbuf.uid' may be used uninitialized in this
> function
> ipc/sem.c:861: warning: 'setbuf.gid' may be used uninitialized in this
> function
> ipc/sem.c:861: warning: 'setbuf.mode' may be used uninitialized in
> this function
> 

Already hidden now by the uninitialized_var() macro.

> drivers/pci/search.c: In function 'pci_find_slot':
> drivers/pci/search.c:99: warning: 'pci_find_device' is deprecated
> (declared at include/linux/pci.h:477)

pci_find_slot is using pci_find_device on purpose here (equivalent to the
safe pci_get_slot method).

> drivers/pci/search.c: At top level:
> drivers/pci/search.c:434: warning: 'pci_find_device' is deprecated
> (declared at drivers/pci/search.c:241)
> drivers/pci/search.c:434: warning: 'pci_find_device' is deprecated
> (declared at drivers/pci/search.c:241)
> 

False positives from function definition and from the innocent EXPORT_SYMBOL
macro (It makes the method available to kernel modules).

Regards,

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [Oops] on 2.6.23-rc9 sysRq Show Tasks (t)
  @ 2007-10-07 19:39 99%   ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-10-07 19:39 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: linux-kernel

On Sun, Oct 07, 2007 at 01:12:38AM +0400, Alexey Dobriyan wrote:
> On Sat, Oct 06, 2007 at 10:14:06PM +0200, Ahmed S. Darwish wrote:
> > Pressing sysRq+T always produce an Oops for every running system task (94 
> > Oopses, that's a record ;)).
> 
> uh-oh. For every sleeping task, I think.
> 
> > The bug is 100% reproducable. Should I begin bisecting/investigating the 
> > issue or it's a known problem ?
> 
> Start with some old kernel, like mmm.. 2.6.0. The fact that same behaviour
> was present there may make you think about faulty assumptions you've
> made.
> 

Yeah I understood my mistake (not an Oops, a normal behaviour). 
Thanks for your advice :).

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [Oops] on 2.6.23-rc9 sysRq Show Tasks (t)
  2007-10-06 20:14 70% [Oops] on 2.6.23-rc9 sysRq Show Tasks (t) Ahmed S. Darwish
@ 2007-10-06 20:52 99% ` Ahmed S. Darwish
    1 sibling, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-10-06 20:52 UTC (permalink / raw)
  To: linux-kernel

On Sat, Oct 06, 2007 at 10:14:05PM +0200, ahmed wrote:
> Hi all,
> 
> Pressing sysRq+T always produce an Oops for every running system task (94 
> Oopses, that's a record ;)).
> The bug is 100% reproducable. Should I begin bisecting/investigating the 
> issue or it's a known problem ?
>

Shame, This is not an Oops at all. Really sorry.

/me wondering about my look now posting a normal message as an Ooops a day 
before the stable release :(.

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [Oops] on 2.6.23-rc9 sysRq Show Tasks (t)
@ 2007-10-06 20:14 70% Ahmed S. Darwish
  2007-10-06 20:52 99% ` Ahmed S. Darwish
    0 siblings, 2 replies; 200+ results
From: Ahmed S. Darwish @ 2007-10-06 20:14 UTC (permalink / raw)
  To: linux-kernel

Hi all,

Pressing sysRq+T always produce an Oops for every running system task (94 
Oopses, that's a record ;)).
The bug is 100% reproducable. Should I begin bisecting/investigating the 
issue or it's a known problem ?

$ ver_linux
Linux darwish-laptop 2.6.23-rc9 #23 Sat Oct 6 21:48:45 EET 2007 i686 GNU/Linux
 
Gnu C                  4.0.3
Gnu make               3.81beta4
binutils               2.16.91
util-linux             2.12r
mount                  2.12r
module-init-tools      3.2.2
e2fsprogs              1.38
Linux C Library        3.6
Dynamic linker (ldd)   2.3.6
Procps                 3.2.6
Net-tools              1.60
Console-tools          0.2.3
Sh-utils               5.93
udev                   079

[  226.309874] SysRq : Show State
[  226.309948]   task                PC stack   pid father
[  226.310105] init          S c1465b64     0     1      0
[  226.310195]        c1465b54 00000082 00000286 c1465b64 c04255c0 c03c3ec0 00000000 00000286 
[  226.310414]        c1465b64 fffd689a 0000000b 00000000 c02e8fda c1537040 00000292 c0425ab4 
[  226.310664]        c0425ab4 fffd689a c0123cd0 c14634f0 c04255c0 00000800 c1465f9c c0176bf5 
[  226.310914] Call Trace:
[  226.310995]  [<c02e8fda>] schedule_timeout+0x4a/0xc0
[  226.311075]  [<c0123cd0>] process_timeout+0x0/0x10
[  226.311148]  [<c0176bf5>] do_select+0x375/0x4b0
[  226.311231]  [<c01760e0>] __pollwait+0x0/0x100
[  226.311302]  [<c0117a50>] default_wake_function+0x0/0x10
[  226.311379]  [<c0138bad>] __lock_acquire+0x74d/0x1130
[  226.311452]  [<c01c0278>] do_get_write_access+0x2c8/0x570
[  226.311538]  [<c0164a39>] poison_obj+0x29/0x60
[  226.311613]  [<c0139997>] mark_held_locks+0x67/0x80
[  226.311684]  [<c01663dd>] kmem_cache_free+0xad/0xf0
[  226.311755]  [<c0139b64>] trace_hardirqs_on+0x104/0x170
[  226.311832]  [<c0138bad>] __lock_acquire+0x74d/0x1130
[  226.311903]  [<c0138bad>] __lock_acquire+0x74d/0x1130
[  226.311981]  [<c0138bad>] __lock_acquire+0x74d/0x1130
[  226.312052]  [<c01aefb6>] ext3_ordered_commit_write+0xa6/0xe0
[  226.312137]  [<c0138bad>] __lock_acquire+0x74d/0x1130
[  226.312207]  [<c02eb074>] _spin_unlock+0x14/0x20
[  226.312278]  [<c017c0d7>] __d_lookup+0x107/0x110
[  226.312352]  [<c01dbc95>] _atomic_dec_and_lock+0x15/0x40
[  226.312428]  [<c02eb074>] _spin_unlock+0x14/0x20
[  226.312498]  [<c01dbcaa>] _atomic_dec_and_lock+0x2a/0x40
[  226.312570]  [<c017ae71>] dput+0x51/0x120
[  226.312638]  [<c0172b0e>] __link_path_walk+0xc4e/0xca0
[  226.312718]  [<c0176ef6>] core_sys_select+0x1c6/0x320
[  226.312796]  [<c0164a39>] poison_obj+0x29/0x60
[  226.312868]  [<c01653c0>] cache_free_debugcheck+0xb0/0x1e0
[  226.312949]  [<c01e215f>] copy_to_user+0x3f/0x70
[  226.313020]  [<c016d1ff>] cp_new_stat64+0xef/0x110
[  226.313110]  [<c01773b1>] sys_select+0x51/0x1c0
[  226.313179]  [<c0139b64>] trace_hardirqs_on+0x104/0x170
[  226.313255]  [<c0104026>] sysenter_past_esp+0x5f/0x99
[  226.313336]  =======================
[  226.313380] kthreadd      S 00000000     0     2      0
[  226.313468]        c1467fd0 00000082 00000002 00000000 c012dee2 00000246 c03a4ee0 00000584 
[  226.313686]        c03a4efc 00000584 ded73c48 00000000 c012df3c c012de40 00000000 00000000 
[  226.313936]        c0104c23 00000000 00000000 00000000 00000000 00000000 00000000 
[  226.314163] Call Trace:
[  226.314237]  [<c012dee2>] kthreadd+0xa2/0x110
[  226.314311]  [<c012df3c>] kthreadd+0xfc/0x110
[  226.314379]  [<c012de40>] kthreadd+0x0/0x110
[  226.314447]  [<c0104c23>] kernel_thread_helper+0x7/0x14
[  226.314521]  =======================
[  226.314564] ksoftirqd/0   S c0139b64     0     3      2
[  226.314652]        c146bfcc 00000082 00000000 c0139b64 00000001 c012038f c01205b6 00000246 
[  226.314869]        00000000 fffffffc c0120640 00000000 c0120688 c012de34 c012ddc0 00000000 
[  226.315118]        00000000 c0104c23 c1465f04 00000000 00000000 00000000 00000000 00000000 
[  226.315367] Call Trace:
[  226.315441]  [<c0139b64>] trace_hardirqs_on+0x104/0x170
[  226.315512]  [<c012038f>] _local_bh_enable+0x4f/0xf0
[  226.315584]  [<c01205b6>] __do_softirq+0x76/0xb0
[  226.315654]  [<c0120640>] ksoftirqd+0x0/0x90
[  226.315721]  [<c0120688>] ksoftirqd+0x48/0x90
[  226.315788]  [<c012de34>] kthread+0x74/0x80
[  226.315855]  [<c012ddc0>] kthread+0x0/0x80
[  226.315923]  [<c0104c23>] kernel_thread_helper+0x7/0x14
[  226.315997]  =======================
[  226.316039] watchdog/0    S 00000073     0     4      2
[  226.316127]        c146ffc8 00000096 00000001 00000073 ffffffff 308b09e3 00000d34 00000000 
[  226.316345]        00000000 fffffffc c0147c60 00000000 c0147c97 00000063 c012de34 c012ddc0 
[  226.316595]        00000000 00000000 c0104c23 c1465f08 00000000 00000000 00000000 00000000 
[  226.316844] Call Trace:
[  226.316922]  [<c0147c60>] watchdog+0x0/0x50
[  226.316992]  [<c0147c97>] watchdog+0x37/0x50
[  226.317061]  [<c012de34>] kthread+0x74/0x80
[  226.317128]  [<c012ddc0>] kthread+0x0/0x80
[  226.317196]  [<c0104c23>] kernel_thread_helper+0x7/0x14
[  226.317270]  =======================
[  226.317312] events/0      R running      0     5      2
[  226.317400] khelper       S 00000002     0     6      2
[  226.317488]        c1473fac 00000086 c0139b64 00000002 00000046 df789444 00000286 df789444 
[  226.317706]        df789444 df789420 c012ae00 00000000 c012aed5 00000000 c146c070 c012e030 
[  226.317956]        df789460 df789460 df789420 fffffffc c012ae00 c012de34 c012ddc0 00000000 
[  226.318205] Call Trace:
[  226.318278]  [<c0139b64>] trace_hardirqs_on+0x104/0x170
[  226.318353]  [<c012ae00>] worker_thread+0x0/0x100
[  226.318422]  [<c012aed5>] worker_thread+0xd5/0x100
[  226.318491]  [<c012e030>] autoremove_wake_function+0x0/0x50
[  226.318566]  [<c012ae00>] worker_thread+0x0/0x100
[  226.318633]  [<c012de34>] kthread+0x74/0x80
[  226.318701]  [<c012ddc0>] kthread+0x0/0x80
[  226.318769]  [<c0104c23>] kernel_thread_helper+0x7/0x14
[  226.318843]  =======================
[  226.318885] kblockd/0     S 00000002     0    35      2
[  226.318973]        df751fac 00000086 c0139b64 00000002 00000046 c03c3ec0 00000286 df706e5c 
[  226.319191]        df706e5c df706e38 c012ae00 00000000 c012aed5 00000000 df748a90 c012e030 
[  226.319440]        df706e78 df706e78 df706e38 fffffffc c012ae00 c012de34 c012ddc0 00000000 
[  226.319690] Call Trace:
[  226.319764]  [<c0139b64>] trace_hardirqs_on+0x104/0x170
[  226.319840]  [<c012ae00>] worker_thread+0x0/0x100
[  226.319909]  [<c012aed5>] worker_thread+0xd5/0x100
[  226.319978]  [<c012e030>] autoremove_wake_function+0x0/0x50
[  226.320051]  [<c012ae00>] worker_thread+0x0/0x100
[  226.320120]  [<c012de34>] kthread+0x74/0x80
[  226.320187]  [<c012ddc0>] kthread+0x0/0x80
[  226.320255]  [<c0104c23>] kernel_thread_helper+0x7/0x14
[  226.320329]  =======================
[  226.320372] kacpid        S 00000002     0    38      2
[  226.320459]        df759fac 00000086 c0139b64 00000002 00000046 df706a34 00000286 df706a34 
[  226.320677]        df706a34 df706a10 c012ae00 00000000 c012aed5 00000000 df754ad0 c012e030 
[  226.320927]        df706a50 df706a50 df706a10 fffffffc c012ae00 c012de34 c012ddc0 00000000 
[  226.321177] Call Trace:
[  226.321251]  [<c0139b64>] trace_hardirqs_on+0x104/0x170
[  226.321326]  [<c012ae00>] worker_thread+0x0/0x100
[  226.321395]  [<c012aed5>] worker_thread+0xd5/0x100
[  226.321465]  [<c012e030>] autoremove_wake_function+0x0/0x50
[  226.321538]  [<c012ae00>] worker_thread+0x0/0x100
[  226.321606]  [<c012de34>] kthread+0x74/0x80
[  226.321673]  [<c012ddc0>] kthread+0x0/0x80
[  226.321741]  [<c0104c23>] kernel_thread_helper+0x7/0x14
[  226.321814]  =======================
[  226.321857] kacpi_notify  S 00000002     0    39      2
[  226.321945]        df75bfac 00000086 c0139b64 00000002 00000046 df70e99c 00000286 df70e99c 
[  226.322162]        df70e99c df70e978 c012ae00 00000000 c012aed5 00000000 df754070 c012e030 
[  226.322412]        df70e9b8 df70e9b8 df70e978 fffffffc c012ae00 c012de34 c012ddc0 00000000 
[  226.322662] Call Trace:
[  226.322735]  [<c0139b64>] trace_hardirqs_on+0x104/0x170
[  226.322810]  [<c012ae00>] worker_thread+0x0/0x100
[  226.322879]  [<c012aed5>] worker_thread+0xd5/0x100
[  226.322948]  [<c012e030>] autoremove_wake_function+0x0/0x50
[  226.323022]  [<c012ae00>] worker_thread+0x0/0x100
[  226.323090]  [<c012de34>] kthread+0x74/0x80
[  226.323157]  [<c012ddc0>] kthread+0x0/0x80
[  226.323226]  [<c0104c23>] kernel_thread_helper+0x7/0x14
[  226.324145]  =======================
[  226.324188] kseriod       S 00000002     0   159      2
[  226.324276]        c14bdf98 00000092 c0139b64 00000002 00000046 c03b8f80 00000286 c03b8f80 
[  226.324493]        00000000 00000000 00000000 00000000 c0269674 c02eb320 00000002 c02e87ff 
[  226.324742]        00000000 00000000 df720070 c012e030 c03b8f9c c03b8f9c 00000000 fffffffc 
[  226.324992] Call Trace:
[  226.325065]  [<c0139b64>] trace_hardirqs_on+0x104/0x170
[  226.325142]  [<c0269674>] serio_thread+0x204/0x330
[  226.325213]  [<c02eb320>] _spin_unlock_irq+0x20/0x30
[  226.325285]  [<c02e87ff>] schedule+0x1af/0x340
[  226.325355]  [<c012e030>] autoremove_wake_function+0x0/0x50
[  226.325430]  [<c0269470>] serio_thread+0x0/0x330
[  226.325500]  [<c012de34>] kthread+0x74/0x80
[  226.325567]  [<c012ddc0>] kthread+0x0/0x80
[  226.325635]  [<c0104c23>] kernel_thread_helper+0x7/0x14
[  226.325709]  =======================
[  226.325751] rt-test-0     S 00000046     0   184      2
[  226.325839]        c14e9fc8 00000096 c011cfe8 00000046 df71857c fffffffc df71857c fffffffc 
[  226.326056]        c0621f00 fffffffc c013e250 00000000 c013e2c8 c0621f00 c012de34 c012ddc0 
[  226.326306]        00000000 00000000 c0104c23 c1465efc 00000000 00000000 00000000 00000000 
[  226.326555] Call Trace:
[  226.326629]  [<c011cfe8>] allow_signal+0x28/0x80
[  226.326703]  [<c013e250>] test_func+0x0/0xb0
[  226.326773]  [<c013e2c8>] test_func+0x78/0xb0
[  226.326842]  [<c012de34>] kthread+0x74/0x80
[  226.326909]  [<c012ddc0>] kthread+0x0/0x80
[  226.326978]  [<c0104c23>] kernel_thread_helper+0x7/0x14
[  226.327051]  =======================
[  226.327094] rt-test-1     S 00000046     0   186      2
[  226.327182]        c14effc8 00000096 c011cfe8 00000046 c14edb3c fffffffc c14edb3c fffffffc 
[  226.327400]        c0621f90 fffffffc c013e250 00000000 c013e2c8 c0621f90 c012de34 c012ddc0 
[  226.327649]        00000000 00000000 c0104c23 c1465efc 00000000 00000000 00000000 00000000 
[  226.327899] Call Trace:
[  226.327972]  [<c011cfe8>] allow_signal+0x28/0x80
[  226.328046]  [<c013e250>] test_func+0x0/0xb0
[  226.328115]  [<c013e2c8>] test_func+0x78/0xb0
[  226.328184]  [<c012de34>] kthread+0x74/0x80
[  226.328252]  [<c012ddc0>] kthread+0x0/0x80
[  226.328319]  [<c0104c23>] kernel_thread_helper+0x7/0x14
[  226.328392]  =======================
[  226.328435] rt-test-2     S 00000046     0   188      2
[  226.328522]        c14f3fc8 00000096 c011cfe8 00000046 c14ed5dc fffffffc c14ed5dc fffffffc 
[  226.328740]        c0622020 fffffffc c013e250 00000000 c013e2c8 c0622020 c012de34 c012ddc0 
[  226.328990]        00000000 00000000 c0104c23 c1465efc 00000000 00000000 00000000 00000000 
[  226.329239] Call Trace:
[  226.329312]  [<c011cfe8>] allow_signal+0x28/0x80
[  226.329385]  [<c013e250>] test_func+0x0/0xb0
[  226.329453]  [<c013e2c8>] test_func+0x78/0xb0
[  226.329522]  [<c012de34>] kthread+0x74/0x80
[  226.329589]  [<c012ddc0>] kthread+0x0/0x80
[  226.329657]  [<c0104c23>] kernel_thread_helper+0x7/0x14
[  226.329730]  =======================
[  226.329772] rt-test-3     S 00000046     0   190      2
[  226.329860]        c14f7fc8 00000096 c011cfe8 00000046 c14ed07c fffffffc c14ed07c fffffffc 
[  226.330078]        c06220b0 fffffffc c013e250 00000000 c013e2c8 c06220b0 c012de34 c012ddc0 
[  226.330347]        00000000 00000000 c0104c23 c1465efc 00000000 00000000 00000000 00000000 
[  226.330597] Call Trace:
[  226.330670]  [<c011cfe8>] allow_signal+0x28/0x80
[  226.330744]  [<c013e250>] test_func+0x0/0xb0
[  226.330813]  [<c013e2c8>] test_func+0x78/0xb0
[  226.330882]  [<c012de34>] kthread+0x74/0x80
[  226.330949]  [<c012ddc0>] kthread+0x0/0x80
[  226.331017]  [<c0104c23>] kernel_thread_helper+0x7/0x14
[  226.331090]  =======================

And So on for every task.

Thanks,

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 70%]

* [PATCH RFC 2/2] IRQ: Modularize the setup_irq code (2)
  2007-10-05  5:30 83% [PATCH RFC 1/2] IRQ: Modularize the setup_irq code (1) Ahmed S. Darwish
@ 2007-10-05  5:36 88% ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-10-05  5:36 UTC (permalink / raw)
  To: tglx; +Cc: linux-kernel, akpm

Introduce irq_desc_match_fist_irqaction() to support setup_irq() 
code modularity.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

Any ideas for a better method name ?

 manage.c |   89 ++++++++++++++++++++++++++++++++++++---------------------------
 1 file changed, 51 insertions(+), 38 deletions(-)

diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 6a0d778..4e96d56 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -293,6 +293,55 @@ int can_add_irqaction_on_allocated_irq(unsigned int irq, struct irqaction *new)
 }
 
 /*
+ * Configure the passed irq descriptor to satisfy our first newly
+ * added irqaction needs
+ * must be called with the irq_desc[irq]->lock held
+ */
+void irq_desc_match_fist_irqaction(unsigned int irq, struct irqaction *new)
+{
+	struct irq_desc *desc = irq_desc + irq;
+
+	/* We must be the first and the only irqaction */
+	BUG_ON(desc->action != new || new->next);
+
+	irq_chip_set_defaults(desc->chip);
+
+#if defined(CONFIG_IRQ_PER_CPU)
+	if (new->flags & IRQF_PERCPU)
+		desc->status |= IRQ_PER_CPU;
+#endif
+
+	/* Setup the type (level, edge polarity) if configured: */
+	if (new->flags & IRQF_TRIGGER_MASK) {
+		if (desc->chip && desc->chip->set_type)
+			desc->chip->set_type(irq,
+					     new->flags & IRQF_TRIGGER_MASK);
+		else
+			/*
+			 * IRQF_TRIGGER_* but the PIC does not support
+			 * multiple flow-types?
+			 */
+			printk(KERN_WARNING "No IRQF_TRIGGER set_type "
+			       "function for IRQ %d (%s)\n", irq,
+			       desc->chip ? desc->chip->name : "unknown");
+	} else
+		compat_irq_chip_set_default_handler(desc);
+
+	desc->status &= ~(IRQ_AUTODETECT | IRQ_WAITING | IRQ_INPROGRESS);
+
+	if (!(desc->status & IRQ_NOAUTOEN)) {
+		desc->depth = 0;
+		desc->status &= ~IRQ_DISABLED;
+		if (desc->chip->startup)
+			desc->chip->startup(irq);
+		else
+			desc->chip->enable(irq);
+	} else
+		/* Undo nested disables: */
+		desc->depth = 1;
+}
+
+/*
  * Internal function to register an irqaction - typically used to
  * allocate special interrupts that are part of the architecture.
  */
@@ -352,45 +401,9 @@ int setup_irq(unsigned int irq, struct irqaction *new)
 	if (new->flags & IRQF_NOBALANCING)
 		desc->status |= IRQ_NO_BALANCING;
 
-	if (!shared) {
-		irq_chip_set_defaults(desc->chip);
+	if (!shared)
+		irq_desc_match_fist_irqaction(irq, new);
 
-#if defined(CONFIG_IRQ_PER_CPU)
-		if (new->flags & IRQF_PERCPU)
-			desc->status |= IRQ_PER_CPU;
-#endif
-
-		/* Setup the type (level, edge polarity) if configured: */
-		if (new->flags & IRQF_TRIGGER_MASK) {
-			if (desc->chip && desc->chip->set_type)
-				desc->chip->set_type(irq,
-						new->flags & IRQF_TRIGGER_MASK);
-			else
-				/*
-				 * IRQF_TRIGGER_* but the PIC does not support
-				 * multiple flow-types?
-				 */
-				printk(KERN_WARNING "No IRQF_TRIGGER set_type "
-				       "function for IRQ %d (%s)\n", irq,
-				       desc->chip ? desc->chip->name :
-				       "unknown");
-		} else
-			compat_irq_chip_set_default_handler(desc);
-
-		desc->status &= ~(IRQ_AUTODETECT | IRQ_WAITING |
-				  IRQ_INPROGRESS);
-
-		if (!(desc->status & IRQ_NOAUTOEN)) {
-			desc->depth = 0;
-			desc->status &= ~IRQ_DISABLED;
-			if (desc->chip->startup)
-				desc->chip->startup(irq);
-			else
-				desc->chip->enable(irq);
-		} else
-			/* Undo nested disables: */
-			desc->depth = 1;
-	}
 	/* Reset broken irq detection when installing new handler */
 	desc->irq_count = 0;
 	desc->irqs_unhandled = 0;

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 88%]

* [PATCH RFC 1/2] IRQ: Modularize the setup_irq code (1)
@ 2007-10-05  5:30 83% Ahmed S. Darwish
  2007-10-05  5:36 88% ` [PATCH RFC 2/2] IRQ: Modularize the setup_irq code (2) Ahmed S. Darwish
  0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2007-10-05  5:30 UTC (permalink / raw)
  To: tglx; +Cc: linux-kernel, akpm

Hi Thomas/lkml,

setup_irq() code contains a big chunk of 130 code lines that 
can be divided to several smaller methods. These 2 patches introduce 
those small functions to aid toward setup_irq() code modularity. 
No major code logic changes exist.

Patches can be applied cleanly over v2.6.23-rc9.

Thanks,

==> (Description for Logs)

Introduce can_add_irqaction_on_allocated_irq and warn_about_irqaction_mismatch
methods to support setup_irq() code modularity.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

 manage.c |   92 +++++++++++++++++++++++++++++++++++++--------------------------
 1 file changed, 55 insertions(+), 37 deletions(-)

diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 7230d91..6a0d778 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -248,6 +248,50 @@ void compat_irq_chip_set_default_handler(struct irq_desc *desc)
 		desc->handle_irq = NULL;
 }
 
+static inline void warn_about_irqaction_mismatch(unsigned int irq,
+						 struct irqaction *new)
+{
+#ifdef CONFIG_DEBUG_SHIRQ
+	const char *name = irq_desc[irq].action->name;
+	/* If device doesn't expect the mismatch */
+	if (!(new->flags & IRQF_PROBE_SHARED)) {
+		printk(KERN_ERR "IRQ handler type mismatch for IRQ %d\n", irq);
+		if (name)
+			printk(KERN_ERR "current handler: %s\n", name);
+		dump_stack();
+	}
+#endif
+}
+
+/*
+ * Test if an irqaction can be added to the passed allocated IRQ line
+ * Must be called with the irq_desc[irq]->lock held.
+ */
+int can_add_irqaction_on_allocated_irq(unsigned int irq, struct irqaction *new)
+{
+	struct irqaction *old = irq_desc[irq].action;
+
+	BUG_ON(!old);
+	/*
+	 * Can't share interrupts unless both agree to and are
+	 * the same type (level, edge, polarity). So both flag
+	 * fields must have IRQF_SHARED set and the bits which
+	 * set the trigger type must match.
+	 */
+	if (!((old->flags & new->flags) & IRQF_SHARED) ||
+	    ((old->flags ^ new->flags) & IRQF_TRIGGER_MASK))
+		return 0;
+
+#if defined(CONFIG_IRQ_PER_CPU)
+	/* All handlers must agree on per-cpuness */
+	if ((old->flags & IRQF_PERCPU) !=
+	    (new->flags & IRQF_PERCPU))
+		return 0;
+#endif
+
+	return 1;
+}
+
 /*
  * Internal function to register an irqaction - typically used to
  * allocate special interrupts that are part of the architecture.
@@ -256,7 +300,6 @@ int setup_irq(unsigned int irq, struct irqaction *new)
 {
 	struct irq_desc *desc = irq_desc + irq;
 	struct irqaction *old, **p;
-	const char *old_name = NULL;
 	unsigned long flags;
 	int shared = 0;
 
@@ -289,31 +332,18 @@ int setup_irq(unsigned int irq, struct irqaction *new)
 	p = &desc->action;
 	old = *p;
 	if (old) {
-		/*
-		 * Can't share interrupts unless both agree to and are
-		 * the same type (level, edge, polarity). So both flag
-		 * fields must have IRQF_SHARED set and the bits which
-		 * set the trigger type must match.
-		 */
-		if (!((old->flags & new->flags) & IRQF_SHARED) ||
-		    ((old->flags ^ new->flags) & IRQF_TRIGGER_MASK)) {
-			old_name = old->name;
-			goto mismatch;
-		}
-
-#if defined(CONFIG_IRQ_PER_CPU)
-		/* All handlers must agree on per-cpuness */
-		if ((old->flags & IRQF_PERCPU) !=
-		    (new->flags & IRQF_PERCPU))
-			goto mismatch;
-#endif
-
-		/* add new interrupt at end of irq queue */
-		do {
-			p = &old->next;
-			old = *p;
-		} while (old);
 		shared = 1;
+		if (can_add_irqaction_on_allocated_irq(irq, new)) {
+			/* add new interrupt at end of irq queue */
+			do {
+				p = &old->next;
+				old = *p;
+			} while (old);
+		} else {
+			warn_about_irqaction_mismatch(irq, new);
+			spin_unlock_irqrestore(&desc->lock, flags);
+			return -EBUSY;
+		}
 	}
 
 	*p = new;
@@ -372,18 +402,6 @@ int setup_irq(unsigned int irq, struct irqaction *new)
 	register_handler_proc(irq, new);
 
 	return 0;
-
-mismatch:
-#ifdef CONFIG_DEBUG_SHIRQ
-	if (!(new->flags & IRQF_PROBE_SHARED)) {
-		printk(KERN_ERR "IRQ handler type mismatch for IRQ %d\n", irq);
-		if (old_name)
-			printk(KERN_ERR "current handler: %s\n", old_name);
-		dump_stack();
-	}
-#endif
-	spin_unlock_irqrestore(&desc->lock, flags);
-	return -EBUSY;
 }
 
 /**


-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 83%]

* [PATCH 3/3] NCR53C8XX: Remove deprecated IRQ flags (SA_*)
  2007-09-26 22:33 98% [PATCH 1/3] Completely remove deprecated IRQ flags (SA_*) Ahmed S. Darwish
  2007-09-26 22:35 99% ` [PATCH 2/3] MIPS: Remove " Ahmed S. Darwish
@ 2007-09-26 22:36 81% ` Ahmed S. Darwish
  1 sibling, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-09-26 22:36 UTC (permalink / raw)
  To: linux-kernel; +Cc: akpm, matthew, linux-scsi

Hi Matthew,

A patch to stop using deprecated IRQ flags in ncr53c8xx documentaion. The new
IRQF_* macros are used instead.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

diff --git a/Documentation/scsi/ChangeLog.ncr53c8xx b/Documentation/scsi/ChangeLog.ncr53c8xx
index 7d03e9d..a9f721a 100644
--- a/Documentation/scsi/ChangeLog.ncr53c8xx
+++ b/Documentation/scsi/ChangeLog.ncr53c8xx
@@ -195,9 +195,9 @@ Sun Feb  14:00 1999 Gerard Roudier (groudier@club-internet.fr)
 	  Pointed out by Leonard Zubkoff.
 	- Allow to tune request_irq() flags from the boot command line using 
 	  ncr53c8xx=irqm:??, as follows:
-	  a) If bit 0x10 is set in irqm, SA_SHIRQ flag is not used.
-	  b) If bit 0x20 is set in irqm, SA_INTERRUPT flag is not used.
-	  By default the driver uses both SA_SHIRQ and SA_INTERRUPT.
+	  a) If bit 0x10 is set in irqm, IRQF_SHARED flag is not used.
+	  b) If bit 0x20 is set in irqm, IRQF_DISABLED flag is not used.
+	  By default the driver uses both IRQF_SHARED and IRQF_DISABLED.
 	  Option 'ncr53c8xx=irqm:0x20' may be used when an IRQ is shared by 
 	  a 53C8XX adapter and a network board.
 	- Tiny mispelling fixed (ABORT instead of ABRT). Was fortunately 
diff --git a/Documentation/scsi/ncr53c8xx.txt b/Documentation/scsi/ncr53c8xx.txt
index 39d409a..a65cea9 100644
--- a/Documentation/scsi/ncr53c8xx.txt
+++ b/Documentation/scsi/ncr53c8xx.txt
@@ -785,8 +785,8 @@ port address 0x1400.
         irqm:0     always open drain
         irqm:1     same as initial settings (assumed BIOS settings)
         irqm:2     always totem pole
-        irqm:0x10  driver will not use SA_SHIRQ flag when requesting irq
-        irqm:0x20  driver will not use SA_INTERRUPT flag when requesting irq
+        irqm:0x10  driver will not use IRQF_SHARED flag when requesting irq
+        irqm:0x20  driver will not use IRQF_DISABLED flag when requesting irq
 
     (Bits 0x10 and 0x20 can be combined with hardware irq mode option)
 
@@ -1236,15 +1236,15 @@ when the SCSI DATA IN phase is reentered after a phase mismatch.
 When an IRQ is shared by devices that are handled by different drivers, it 
 may happen that one driver complains about the request of the IRQ having 
 failed. Inder Linux-2.0, this may be due to one driver having requested the 
-IRQ using the SA_INTERRUPT flag but some other having requested the same IRQ 
+IRQ using the IRQF_DISABLED flag but some other having requested the same IRQ 
 without this flag. Under both Linux-2.0 and linux-2.2, this may be caused by 
-one driver not having requested the IRQ with the SA_SHIRQ flag.
+one driver not having requested the IRQ with the IRQF_SHARED flag.
 
 By default, the ncr53c8xx and sym53c8xx drivers request IRQs with both the 
-SA_INTERRUPT and the SA_SHIRQ flag under Linux-2.0 and with only the SA_SHIRQ 
+IRQF_DISABLED and the IRQF_SHARED flag under Linux-2.0 and with only the IRQF_SHARED 
 flag under Linux-2.2.
 
-Under Linux-2.0, you can disable use of SA_INTERRUPT flag from the boot 
+Under Linux-2.0, you can disable use of IRQF_DISABLED flag from the boot 
 command line by using the following option:
 
      ncr53c8xx=irqm:0x20   (for the generic ncr53c8xx driver)
@@ -1252,7 +1252,7 @@ command line by using the following option:
 
 If this does not fix the problem, then you may want to check how all other 
 drivers are requesting the IRQ and report the problem. Note that if at least 
-a single driver does not request the IRQ with the SA_SHIRQ flag (share IRQ), 
+a single driver does not request the IRQ with the IRQF_SHARED flag (share IRQ), 
 then the request of the IRQ obviously will not succeed for all the drivers.
 
 15. SCSI problem troubleshooting

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 81%]

* [PATCH 2/3] MIPS: Remove deprecated IRQ flags (SA_*)
  2007-09-26 22:33 98% [PATCH 1/3] Completely remove deprecated IRQ flags (SA_*) Ahmed S. Darwish
@ 2007-09-26 22:35 99% ` Ahmed S. Darwish
  2007-09-26 22:36 81% ` [PATCH 3/3] NCR53C8XX: " Ahmed S. Darwish
  1 sibling, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-09-26 22:35 UTC (permalink / raw)
  To: linux-kernel; +Cc: akpm, ralf

Hi Ralf,

A patch to stop using deprecated IRQ flags. The new IRQF_* macros are used
instead.


Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

diff --git a/arch/mips/pci/ops-pmcmsp.c b/arch/mips/pci/ops-pmcmsp.c
index 09fa007..a86a189 100644
--- a/arch/mips/pci/ops-pmcmsp.c
+++ b/arch/mips/pci/ops-pmcmsp.c
@@ -404,7 +404,7 @@ int msp_pcibios_config_access(unsigned char access_type,
 	if (pciirqflag == 0) {
 		request_irq(MSP_INT_PCI,/* Hardcoded internal MSP7120 wiring */
 				bpci_interrupt,
-				SA_SHIRQ | SA_INTERRUPT,
+				IRQF_SHARED | IRQF_DISABLED,
 				"PMC MSP PCI Host",
 				preg);
 		pciirqflag = ~0;
diff --git a/arch/mips/pmc-sierra/msp71xx/msp_hwbutton.c b/arch/mips/pmc-sierra/msp71xx/msp_hwbutton.c
index 6fa8572..ab96a2d 100644
--- a/arch/mips/pmc-sierra/msp71xx/msp_hwbutton.c
+++ b/arch/mips/pmc-sierra/msp71xx/msp_hwbutton.c
@@ -163,7 +163,7 @@ static int msp_hwbutton_register(struct hwbutton_interrupt *hirq)
 		CIC_EXT_SET_ACTIVE_HI(cic_ext, hirq->eirq);
 	*CIC_EXT_CFG_REG = cic_ext;
 
-	return request_irq(hirq->irq, hwbutton_handler, SA_INTERRUPT,
+	return request_irq(hirq->irq, hwbutton_handler, IRQF_DISABLED,
 				hirq->name, (void *)hirq);
 }
 

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 1/3] Completely remove deprecated IRQ flags (SA_*)
@ 2007-09-26 22:33 98% Ahmed S. Darwish
  2007-09-26 22:35 99% ` [PATCH 2/3] MIPS: Remove " Ahmed S. Darwish
  2007-09-26 22:36 81% ` [PATCH 3/3] NCR53C8XX: " Ahmed S. Darwish
  0 siblings, 2 replies; 200+ results
From: Ahmed S. Darwish @ 2007-09-26 22:33 UTC (permalink / raw)
  To: linux-kernel; +Cc: akpm

Hi all,

Only very little files use the deprecated SA_* IRQ flags in latest pull. This
minimal patch series removes such macros from the tree and transfrom old code
to the new IRQF_* flags.

Andrew, I've grepped the whole tree to make sure that no more files than the
patched ones use such deprecated macros. I hope this series won't introduce 
build errors.

Patches can be applied cleanly on v2.6.23-rc8.

==>

Get rid of the deprecated SA_* IRQ flags.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
index 5523f19..00bdebb 100644
--- a/include/linux/interrupt.h
+++ b/include/linux/interrupt.h
@@ -55,28 +55,6 @@
 #define IRQF_NOBALANCING	0x00000800
 #define IRQF_IRQPOLL		0x00001000
 
-/*
- * Migration helpers. Scheduled for removal in 9/2007
- * Do not use for new code !
- */
-static inline
-unsigned long __deprecated deprecated_irq_flag(unsigned long flag)
-{
-	return flag;
-}
-
-#define SA_INTERRUPT		deprecated_irq_flag(IRQF_DISABLED)
-#define SA_SAMPLE_RANDOM	deprecated_irq_flag(IRQF_SAMPLE_RANDOM)
-#define SA_SHIRQ		deprecated_irq_flag(IRQF_SHARED)
-#define SA_PROBEIRQ		deprecated_irq_flag(IRQF_PROBE_SHARED)
-#define SA_PERCPU		deprecated_irq_flag(IRQF_PERCPU)
-
-#define SA_TRIGGER_LOW		deprecated_irq_flag(IRQF_TRIGGER_LOW)
-#define SA_TRIGGER_HIGH		deprecated_irq_flag(IRQF_TRIGGER_HIGH)
-#define SA_TRIGGER_FALLING	deprecated_irq_flag(IRQF_TRIGGER_FALLING)
-#define SA_TRIGGER_RISING	deprecated_irq_flag(IRQF_TRIGGER_RISING)
-#define SA_TRIGGER_MASK		deprecated_irq_flag(IRQF_TRIGGER_MASK)
-
 typedef irqreturn_t (*irq_handler_t)(int, void *);
 
 struct irqaction {


Regards,

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 98%]

* i386: Fix null interrupt handler (ignore_int) message ?
@ 2007-09-24 22:08 99% Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-09-24 22:08 UTC (permalink / raw)
  To: linux-kernel; +Cc: hpa

Hi all,

I'm getting little confused by some ignore_int (null interrupt handler) code in
head.S. Code notifies the user about the unknown raised interrupt by below
string:

int_msg:
	.asciz "Unknown interrupt or fault at EIP %p %p %p\n"

and prints it using below code path:

ignore_int:
	pushl %eax; pushl %ecx; pushl %edx; pushl %es; pushl %ds
	[...]
	pushl 16(%esp); pushl 24(%esp); 
	pushl 32(%esp); pushl 40(%esp); 
	pushl $int_msg
	[...]
	call printk

** But here's the state of stack before calling printk:

     ???            <-- 40(%esp)             
     ???            <-- 36(%esp)
     --> (Automatically pushed by the processor)
     %eflags        <-- 32(%esp)
     %cs	    <-- 28(%esp)
     %eip	    <-- 24(%esp)
     error-code     <-- 20(%esp)
     --> (Pushed by first lines of ignore_int)
     %eax	    <-- 16(%esp)
     %ecx	    <--	12(%esp)
     %edx	    <-- 8(%esp)
     %es	    <-- 4(%esp)
     %ds	    <-- %esp      

Does 40(%esp) hold a meaningfule value here ?. Also why passing 4 arguments after
the string to prinkt while the string only has 3 conversion specifications (i.e.,
3 * %p) ?.

Best regards,

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: PROBLEM: System Freeze on Particular workload with kernel 2.6.22.6
  @ 2007-09-20 15:24 99%         ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-09-20 15:24 UTC (permalink / raw)
  To: Jarek Poplawski
  Cc: Low Yucheng, Oleg Verych, linux-kernel, linux-mm, Andrew Morton

On Thu, Sep 20, 2007 at 12:00:31PM +0200, Jarek Poplawski wrote:
> On 19-09-2007 21:25, Ahmed S. Darwish wrote:
> > Hi Low,
> > 
> > On Wed, Sep 19, 2007 at 12:16:39PM -0400, Low Yucheng wrote:
> >> There are no additional console messages.
> >> Not sure what this is: * no relevant Cc (memory management added)
> > 
> > Relevant CCs means CCing maintainers or subsystem mailing lists related to your
> > bug report. i.e, if it's a networking bug, you need to CC the linux kernel
> > networking mailing list. If it's a kobject bug, you need to CC its maintainer
> > (Greg) and so on.
> 
> So, which one do you recommend here?
> 

I'm not really sure, just wanted to solve Jarek's confusion :).

Regards,

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: PROBLEM: System Freeze on Particular workload with kernel 2.6.22.6
  @ 2007-09-19 19:25 99%     ` Ahmed S. Darwish
    0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2007-09-19 19:25 UTC (permalink / raw)
  To: Low Yucheng; +Cc: Oleg Verych, linux-kernel, linux-mm, Andrew Morton

Hi Low,

On Wed, Sep 19, 2007 at 12:16:39PM -0400, Low Yucheng wrote:
> There are no additional console messages.
> Not sure what this is: * no relevant Cc (memory management added)

Relevant CCs means CCing maintainers or subsystem mailing lists related to your
bug report. i.e, if it's a networking bug, you need to CC the linux kernel
networking mailing list. If it's a kobject bug, you need to CC its maintainer
(Greg) and so on.

Regards,  

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [i386] Questions regarding provisional page tables initialization
  @ 2007-07-02 15:43 99%           ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-07-02 15:43 UTC (permalink / raw)
  To: Brian Gerst; +Cc: Andreas Schwab, Jeremy Fitzhardinge, linux-kernel

On Mon, Jul 02, 2007 at 07:34:20AM -0400, Brian Gerst wrote:
> Ahmed S. Darwish wrote:
> > now back to head.S code:
> >  	leal    0x007(%edi),%ecx	/* Create PDE entry */
> > 
> > Isn't the above line the same condition (bytes, not bits displacement) ?. 
> > Thanks for your patience !.
> 
> The leal instruction (Load Effective Address) is often used as a way to
> add a constant to one register and store the result in another register
> in a single instruction.
> [...]

At last I got it due to all of everybody's very nice explanations :). 
Here's the provisional page tables intialization scenario:

We want to store pg0 pte addresses to high 20bits swapper_pg_dir entries,
we also want the PRESENT,RW,USER flags be set in those entries. This is 
done by  getting the address of each pg0 entry and adding 7 to it (Brian's
note). Since pg0 entires address are page aligned(Andreas, Jeremy notes),
adding 7 will assure that the first 3 bits are set without affecting the
high 20 bits.

Big Thanks!,

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [i386] Questions regarding provisional page tables initialization
  @ 2007-07-02 10:23 99%       ` Ahmed S. Darwish
    0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2007-07-02 10:23 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Jeremy Fitzhardinge, linux-kernel

Hi Andreas,

On Mon, Jul 02, 2007 at 11:18:08AM +0200, Andreas Schwab wrote:
> "Ahmed S. Darwish" <darwish.07@gmail.com> writes:
> 
> > yes, but isn't the displacement here (0x007) a _bytes_ displacement ?. so
> > effectively, %ecx now contains physical address of pg0 + 7bytes. Is it A 
> > meaningful place/address ?.
> 
> It's not pg0 + 7bytes, it is pg0 plus 3 flag bits.  Since a page address
> is always page aligned, the low bits are reused for flags.
> 

I'm sure there's a problem in _my_ understanding, but isn't the displacement
- as specified by AT&T syntax - represented in bytes ?. I've wrote a small
assembly function to be sure:

.data
integer:
	.string "%d\n"

.text
test_func:
	push	%ebp
	mov	%esp, %ebp
	push	0x008(%ebp)   ## 8 bytes displacement (the first arg), right ?
	push	$integer
	call 	printf
	mov	%ebp, %esp
	pop	%ebp
	ret

The above method works fine and prints "5" to stdout by the code:

.global	main
main:
	mov	$5, %eax
	push	%eax
	call	test_func

	movl	$1, %eax
	movl	$0, %ebx
	int	$0x80

now back to head.S code:
 	leal    0x007(%edi),%ecx	/* Create PDE entry */

Isn't the above line the same condition (bytes, not bits displacement) ?. 
Thanks for your patience !.

(For other kind replies, don't understand me wrong. I did my homework and
 studied the pte format before asking ;). It's just the bytes/bits issue 
 above that confuses me).

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [i386] Questions regarding provisional page tables initialization
  @ 2007-07-02  1:13 99%   ` Ahmed S. Darwish
    0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2007-07-02  1:13 UTC (permalink / raw)
  To: Jeremy Fitzhardinge; +Cc: linux-kernel

Hi Jeremy,

On Sun, Jul 01, 2007 at 03:19:30PM -0700, Jeremy Fitzhardinge wrote:
> Ahmed S. Darwish wrote:
> >Hi list,
> >
> >AFAIK, in the initializaion phase, kernel builds pages tables with two
> >mappings, identity and PAGE_OFFSET + C mapping. The provisional _global
> >directory_ is contained in swapper_pg_dir variable. while the provisional 
> >_page tables_ are stored starting from pg0, right after _end.
> >
> >There're some stuff that confused me for a full day about the code (head.S)
> >that  accomplishes the above words:
> >
> >	movl $(pg0 - __PAGE_OFFSET), %edi
> >	movl $(swapper_pg_dir - __PAGE_OFFSET), %edx	
> >	movl $0x007, %eax			/* 0x007 = PRESENT+RW+USER */
> >10:
> >	leal $0x007(%edi),%ecx			/* Create PDE entry */
> >
> >What does the address of 7 bytes displacement after %edi - the physical 
> >address
> >of pg0 - represent ?. Why not just putting the address of %edi (the 
> >address of
> >pagetable cell to be mapped by swapper_pg_dir) in %ecx without 
> >displacement?
> >  
> 
> The pte format contains the pfn in the top 20 bits, and flags in the 
> lower 12 bits.  As the comment says "0x007 = PRESENT+RW+USER".
> 

yes, but isn't the displacement here (0x007) a _bytes_ displacement ?. so
effectively, %ecx now contains physical address of pg0 + 7bytes. Is it A 
meaningful place/address ?.

> >        page_pde_offset = (__PAGE_OFFSET >> 20)
> >	movl %ecx,(%edx)			/* Store identity PDE entry 
> >	*/
> >	movl %ecx,page_pde_offset(%edx)		/* Store kernel PDE entry */
> >
> >Why the pde_offset is PAGE_OFFSET >> 20 instead of PAGE_OFFSET >> 22 ?
> >* 22 to right shift the whole page_shift (12) and pgdir_shift (10) bits.
> >  
> 
> As Andreas said, its (PAGE_OFFSET >> 22) << 2.
> 

Great!, Thanks a lot.

> >        [...]
> >	/* Initialize the 1024 _page table_ cells with %eax (0x007) */
> >	movl $1024, %ecx
> >11:
> >	stosl
> >	addl $0x1000,%eax
> >	loop 11b
> >
> >The page table entries beginning from pg0 (pointed by %edi) and following 
> >pages are initialized with  the series 7 + 8 + 8 + ... for each cell. This 
> >series has
> >the property of setting the PRESENT+RW+USER bits in the whole entries to 1 
> >but it
> >sets lots of the entries BASE address to 0 too. Why is this done ?
> >  
> 
> I don't follow you.  Are you overlooking the 'L' on stosl?
> 

Sorry for not making the question clear. my question was that the first entry in
the page table pointed by (%edi) is initialize with %eax = 0x007, a reasonable
value (setting the 3 pte flags). Beginning from entry 2, they got initialized
with a value = "new %eax = old %eax + 8", generating a table of entries
initialized with 7, 15, 31, .. . While this scheme makes the 3 PRESENT, RW 
and USER flags set, it makes alot of "pte"s with equivalent "pfn"s. Here comes 
my wonder, why initializing pg0 that way ?.

Thanks,

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [i386] Questions regarding provisional page tables initialization
@ 2007-07-01 20:38 96% Ahmed S. Darwish
    0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2007-07-01 20:38 UTC (permalink / raw)
  To: linux-kernel

Hi list,

AFAIK, in the initializaion phase, kernel builds pages tables with two
mappings, identity and PAGE_OFFSET + C mapping. The provisional _global
directory_ is contained in swapper_pg_dir variable. while the provisional 
_page tables_ are stored starting from pg0, right after _end.

There're some stuff that confused me for a full day about the code (head.S)
that  accomplishes the above words:

	movl $(pg0 - __PAGE_OFFSET), %edi
	movl $(swapper_pg_dir - __PAGE_OFFSET), %edx	
	movl $0x007, %eax			/* 0x007 = PRESENT+RW+USER */
10:
	leal $0x007(%edi),%ecx			/* Create PDE entry */

What does the address of 7 bytes displacement after %edi - the physical address
of pg0 - represent ?. Why not just putting the address of %edi (the address of
pagetable cell to be mapped by swapper_pg_dir) in %ecx without displacement?

        page_pde_offset = (__PAGE_OFFSET >> 20)
	movl %ecx,(%edx)			/* Store identity PDE entry */
	movl %ecx,page_pde_offset(%edx)		/* Store kernel PDE entry */

Why the pde_offset is PAGE_OFFSET >> 20 instead of PAGE_OFFSET >> 22 ?
* 22 to right shift the whole page_shift (12) and pgdir_shift (10) bits.

        [...]
	/* Initialize the 1024 _page table_ cells with %eax (0x007) */
	movl $1024, %ecx
11:
	stosl
	addl $0x1000,%eax
	loop 11b

The page table entries beginning from pg0 (pointed by %edi) and following pages 
are initialized with  the series 7 + 8 + 8 + ... for each cell. This series has
the property of setting the PRESENT+RW+USER bits in the whole entries to 1 but it
sets lots of the entries BASE address to 0 too. Why is this done ?

Thanks,

-- 
Ahmed S. Darwish
HomePage: http://darwish.07.googlepages.com
Blog: http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 96%]

* Re: Fork Bombing Attack
  @ 2007-05-18 13:19 99%     ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-05-18 13:19 UTC (permalink / raw)
  To: Anand Jahagirdar; +Cc: Valdis.Kletnieks, linux-kernel

On 5/18/07, Anand Jahagirdar <anandjigar@gmail.com> wrote:
> Hello All
>            I tried to execute a program which creates 8152 process.(
> i=0; while( i<14) i++ fork(); )  with ulimit 8200. This program
> created 8152 processes and then stopped and came back to command
> prompt. this proves that my machine do have sufficient resources to
> create 8000 processes.
>
>            I found one more interesting thing on the same machine
> having FC6 distribution and Linux Kernel 2.6.18. i have set "ulimit -u
> 100". after setting this limit i tried to execute fork bombing program
> with guest account. after executing it
>
> expected result:-  guest uesr should not able to fork another single
> process when it reaches to 100 processes count.
>
> actual result :-  kernel allow me to create another processes without
> giving error. due to this i tried to execute same fork bombing program
> on another terminal with guest account and this fork bombing attack
> killed the box completely and machine needed reboot.
>

I think if you want resource limiting per _UID_ (and not per _process_
as you did), you should use PAM module pam_limits.so. You can edit
those limits using the file /etc/security/limits.conf

Regards,
-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: Student Project Ideas
  @ 2007-03-29 20:59 99%   ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-03-29 20:59 UTC (permalink / raw)
  To: Cong WANG; +Cc: Russ Meyerriecks, linux-kernel, Andrew Morton

On Thu, Mar 29, 2007 at 06:32:21PM +0800, Cong WANG wrote:
> 2007/3/29, Russ Meyerriecks <datachomper@gmail.com>:
> >Hi all,
> >  I've been hacking on the Linux kernel all semester for my OS:
> >Internals class. We are given full autonomy in picking our final
> >programming project and I would love for mine to be /useful/ for the
> >Linux kernel and not just a theoretical exorcise. If anybody has any
> >bug fixes or features maybe they never got around to, and would be
> >suitable for this situation, I would love to hear about them.
> >
> 
> First, I think you can read the book named "Kernel Projects for
> Linux". It's a good book although it's outdated.
> 
> Second, in fact, I am also a college student and also want to find a
> suitable and real task in linux kernel for me to work on. KJ doesn't
> help much. ;-p
> 

No, it really helps alot, just be _patient_. For me, I sent a series of dumb
patches at first to use ARRAY_SIZE macro instead of manual computation. Though
the patches were completely braindead, I learnt alot of stuff about how
everything works here. 

Beside sending this KJ patches, I keep reading from Understanding Linux kernel v3
and reading lots of code everyday. Yesterday my first semi-real patch was
accepted in -mm. I'm sure that day by day my patches will be more real and fix
serious issues. 

All of that wouldn't have smoothly happened without the first step, the KJ step ;).

It seems that being a developer in the kernel community is going exactly like how
code goes, _evolution_ not a revolution. You can't be responsible for a good
project directly, just take your way from a janitor to a subsystem maintaner :).
Ofcourse, unless you have an old experience in other OSs (espcifically Unix ones).

Regards,

-- 
Ahmed S. Darwish
http://darwish.07.googlepages.com


^ permalink raw reply	[relevance 99%]

* Re: Student Project Ideas
    @ 2007-03-29 20:44 99% ` Ahmed S. Darwish
  1 sibling, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-03-29 20:44 UTC (permalink / raw)
  To: Russ Meyerriecks; +Cc: linux-kernel

On Thu, Mar 29, 2007 at 05:04:08AM -0500, Russ Meyerriecks wrote:
> Hi all,
>  I've been hacking on the Linux kernel all semester for my OS:
> Internals class. We are given full autonomy in picking our final
> programming project and I would love for mine to be /useful/ for the
> Linux kernel and not just a theoretical exorcise. If anybody has any
> bug fixes or features maybe they never got around to, and would be
> suitable for this situation, I would love to hear about them.
> 

I'm a college student too and I wished a wish like that in the past. After 
watching the development process for a while, I realized that somehow
a college final project won't fit with the linux kernel project.
Everything here is done by _evolution_ not a revolution, you'll even see the 
highest matured programmers in this project send little patches day by day. 

And the problem that you can't meet your PH.D and tell him/her: hey, I have
a patch or two, they simply don't understand that ;).

Second, I think it's very hard to make a considerable project in the kernel
without doing some little patches here and there at first. Google for kernel
newbies and kernel janitors.

Regards,

-- 
Ahmed S. Darwish
http://darwish.07.googlepages.com


^ permalink raw reply	[relevance 99%]

* Re: [PATCH] IRQ: Check for PERCPU flag only when adding first irqaction.
  2007-03-26 19:14 99% [PATCH] IRQ: Check for PERCPU flag only when adding first irqaction Ahmed S. Darwish
@ 2007-03-27  8:54 99% ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-03-27  8:54 UTC (permalink / raw)
  To: linux-kernel

On Mon, Mar 26, 2007 at 09:14:55PM +0200, ahmed wrote:
> Hi,
> 
> An irqaction structure won't be added to the IRQ line irqaction list if they
> don't agree wrt the IRQF_PERCPU flag. Only check and set this flag in IRQ
> descriptor `status' field when the first irqaction is added to the line list.
> 
> 
> Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
> ---
> Patch over 2.6.21-rc5.

Maybe just a better description (with the same patch below):

An irqaction structure won't be added to an IRQ descriptor irqaction list
if it don't agree with other irqactions on the IRQF_PERCPU flag. Don't 
check for this flag to change IRQ descriptor `status' for every irqaction
added to the list, Doing the check only for the first irqaction added is
enough.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 5597c15..ea82a54 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -317,10 +317,7 @@ int setup_irq(unsigned int irq, struct irqaction *new)
 	}
 
 	*p = new;
-#if defined(CONFIG_IRQ_PER_CPU)
-	if (new->flags & IRQF_PERCPU)
-		desc->status |= IRQ_PER_CPU;
-#endif
+
 	/* Exclude IRQ from balancing */
 	if (new->flags & IRQF_NOBALANCING)
 		desc->status |= IRQ_NO_BALANCING;
@@ -328,6 +325,11 @@ int setup_irq(unsigned int irq, struct irqaction *new)
 	if (!shared) {
 		irq_chip_set_defaults(desc->chip);
 
+#if defined(CONFIG_IRQ_PER_CPU)
+		if (new->flags & IRQF_PERCPU)
+			desc->status |= IRQ_PER_CPU;
+#endif
+		
 		/* Setup the type (level, edge polarity) if configured: */
 		if (new->flags & IRQF_TRIGGER_MASK) {
 			if (desc->chip && desc->chip->set_type)


-- 
Ahmed S. Darwish
http://darwish.07.googlepages.com


^ permalink raw reply	[relevance 99%]

* Re: [PATCH] net: tun/tap: fixed hw address handling
  2007-03-26 20:55 99% ` Ahmed S. Darwish
@ 2007-03-26 21:05 99%   ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-03-26 21:05 UTC (permalink / raw)
  To: Brian Braunstein
  Cc: Max Krasnyansky, vtun, akpm, jgarzik, netdev, linux-kernel

On Mon, Mar 26, 2007 at 10:55:11PM +0200, ahmed wrote:
> On Sun, Mar 25, 2007 at 01:29:29AM -0700, Brian Braunstein wrote:
> > --- linux-2.6.20.4-ORIG/drivers/net/tun.c	2007-03-23 
> > 12:52:51.000000000 -0700
> > +++ linux-2.6.20.4/drivers/net/tun.c	2007-03-25 00:44:20.000000000 -0700
> > @@ -18,6 +18,10 @@
> > /*
> >  *  Changes:
> >  *
> > + *  Brian Braunstein <linuxkernel@bristyle.com> 2007/03/23
> > + *    Fixed hw address handling.  Now net_device.dev_addr is kept 
> > consistent
> 
> Your mailer still wrap the long lines mistakenly as it did in the first
> version of the patch.
> 

It seems a bug in my mutt mail reader (not a feature, it displays other 
mails long lines without wrapping), sorry.

-- 
Ahmed S. Darwish
http://darwish.07.googlepages.com


^ permalink raw reply	[relevance 99%]

* Re: [PATCH] net: tun/tap: fixed hw address handling
  @ 2007-03-26 20:55 99% ` Ahmed S. Darwish
  2007-03-26 21:05 99%   ` Ahmed S. Darwish
  0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2007-03-26 20:55 UTC (permalink / raw)
  To: Brian Braunstein
  Cc: Max Krasnyansky, vtun, akpm, jgarzik, netdev, linux-kernel

On Sun, Mar 25, 2007 at 01:29:29AM -0700, Brian Braunstein wrote:
> 
> From: Brian Braunstein <linuxkernel@bristyle.com>
> 

No need for this line. This line is used when you _forward_ another patch
from others. Signed-off-by is enough

> 
> Signed-off-by: Brian Braunstein <linuxkernel@bristyle.com>
> 
> ---
> 
> Kernel Version: 2.6.20.4
> 

It's always better to generate the patch against the latest -rc kernel.

> --- linux-2.6.20.4-ORIG/drivers/net/tun.c	2007-03-23 
> 12:52:51.000000000 -0700
> +++ linux-2.6.20.4/drivers/net/tun.c	2007-03-25 00:44:20.000000000 -0700
> @@ -18,6 +18,10 @@
> /*
>  *  Changes:
>  *
> + *  Brian Braunstein <linuxkernel@bristyle.com> 2007/03/23
> + *    Fixed hw address handling.  Now net_device.dev_addr is kept 
> consistent

Your mailer still wrap the long lines mistakenly as it did in the first
version of the patch.

Regards,

-- 
Ahmed S. Darwish
http://darwish.07.googlepages.com


^ permalink raw reply	[relevance 99%]

* [PATCH] IRQ: Check for PERCPU flag only when adding first irqaction.
@ 2007-03-26 19:14 99% Ahmed S. Darwish
  2007-03-27  8:54 99% ` Ahmed S. Darwish
  0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2007-03-26 19:14 UTC (permalink / raw)
  To: linux-kernel

Hi,

An irqaction structure won't be added to the IRQ line irqaction list if they
don't agree wrt the IRQF_PERCPU flag. Only check and set this flag in IRQ
descriptor `status' field when the first irqaction is added to the line list.


Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

Patch over 2.6.21-rc5.

diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 5597c15..ea82a54 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -317,10 +317,7 @@ int setup_irq(unsigned int irq, struct irqaction *new)
 	}
 
 	*p = new;
-#if defined(CONFIG_IRQ_PER_CPU)
-	if (new->flags & IRQF_PERCPU)
-		desc->status |= IRQ_PER_CPU;
-#endif
+
 	/* Exclude IRQ from balancing */
 	if (new->flags & IRQF_NOBALANCING)
 		desc->status |= IRQ_NO_BALANCING;
@@ -328,6 +325,11 @@ int setup_irq(unsigned int irq, struct irqaction *new)
 	if (!shared) {
 		irq_chip_set_defaults(desc->chip);
 
+#if defined(CONFIG_IRQ_PER_CPU)
+		if (new->flags & IRQF_PERCPU)
+			desc->status |= IRQ_PER_CPU;
+#endif
+		
 		/* Setup the type (level, edge polarity) if configured: */
 		if (new->flags & IRQF_TRIGGER_MASK) {
 			if (desc->chip && desc->chip->set_type)

-- 
Ahmed S. Darwish
http://darwish.07.googlepages.com

^ permalink raw reply	[relevance 99%]

* Re: PATCH: tun/tap driver hw address handling
  @ 2007-03-24 17:04 99%     ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-03-24 17:04 UTC (permalink / raw)
  To: Brian Braunstein; +Cc: Max Krasnyansky, torvalds, linux-kernel, rajesh_mish

Hi Brian,

On Sat, Mar 24, 2007 at 01:56:50AM -0700, Brian Braunstein wrote:
> 
> Linus,
> 
>  According to Documentation/SubmittingPatches "bug fixes" or "obvious" 
> changes
>  should CCed to you, so this is why I have done this.
>

IMHO these days patches got reviewed on LKML, then tested enough on the
unstable -mm tree then it got added to mainline kernel. Subsystem maintaners
can also add patches directly to mainline if they're trivial enough.
 
> Note: This entire email can be found at
> http://bristyle.com/share/patch-tuntap-hw_addr_handling.txt
> 

I think No need for such two lines. everyone uses his favourite LKML archive.

>  Summary:
>    Fix tun/tap driver's handling of hw addresses.  Specifically, ensure 
> that
>    when the tun.dev_addr field is set, the net_device.dev_addr field gets
>    set to the same value.
> 
>  Background:
>    The device hw address is stored in 2 places, in the tun.dev_addr field,
>    and of course the net_device struct's dev_addr field.  It really 
> seems to
>    me that the tun.dev_addr field is redundant, and that anywhere it is 
> used

Editor/mailer wrapping your lines badly ?

> 
> --- linux-2.6.20.4-ORIG/drivers/net/tun.c       2007-03-23 
> 12:52:51.000000000 -0700
> +++ linux-2.6.20.4/drivers/net/tun.c    2007-03-24 01:36:59.000000000 -0700
> @@ -18,6 +18,11 @@

Please reread SubmittingPatches to know the canonical patch format (missing
Signed-off-by and others).

> /*
>  *  Changes:
>  *
> + *  Brian Braunstein <linuxkernel@bristyle.com> 2007/03/23
> + *    Fixed hw address handling.  Now net_device.dev_addr is kept 
> consistent
[Remaing patch]

Patch can't be applied or even read cause your mailer has mistakenly wrapped
its lines.

Regards,

-- 
Ahmed S. Darwish
http://darwish.07.googlepages.com


^ permalink raw reply	[relevance 99%]

* Re: i386: Why putting __USER_DS in kernel threads stack initialization?
  @ 2007-03-21 19:25 99%   ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-03-21 19:25 UTC (permalink / raw)
  To: linux-os (Dick Johnson); +Cc: Linux kernel

On Mon, Mar 19, 2007 at 07:23:25AM -0400, linux-os (Dick Johnson) wrote:
> 
> On Sun, 18 Mar 2007, Ahmed S. Darwish wrote:
> 
> > Hi list,
> >
> > Reading the kernel threads initialization code I see:
> >
> > int kernel_thread(...) {
> >
> > 	struct pt_regs regs;
> > 	memset(&regs, 0, sizeof(regs));
> > 	[...]
> > **	regs.xds = __USER_DS;
> > **	regs.xes = __USER_DS;
> > 	[...]
> > 	/* Ok, create the new process.. */
> > 	return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, \
> > 	       	       0, NULL, NULL);
> >
> > Continuing with the code, the threads stack (beginning from %esp) is
> > initialized with the passed *regs from do_fork:
> >
> > int copy_thread(..., struct task_struct *p, struct pt_regs *regs) {
> >
> > 	struct pt_regs * childregs;
> > 	struct task_struct *tsk;
> > 	childregs = task_pt_regs(p);
> > **	*childregs = *regs;
> > 	[...]
> > ** 	p->thread.esp = (unsigned long) childregs;
> >
> >
> > So the question is what will a _kernel_ thread do with the Usermode Segment
> > address ?
> >
> > Thanks,
> >
> > P.S. I've tried commenting out both lines which led to a non functional init,
> > Also setting them to __USER_DS made init start but stopped issuing the error:
> > `Panic: Segment violation at 0x8049798 - Sleeping for 30 seconds'
> >

Sorry, I meant "setting them to __KERNEL_DS" here.

> 
> You might be confusing two routines. The kernel thread routine sets
> DS and ES to the kernel data segment, __KERNEL_DS, not the user data
> segment. 

And that's what's _not_ happening in the code as I mentioned in original post.

> This is so the kernel thread can access the kernel data. Note
> that this is done by putting the values in the pt_regs structure so
> it doesn't happen 'now', but after the fork.

I've searched the code for such case (setting xds to __KERNEL_DS _After_ 
copy_thread()) with no success. As I understand, the kernel thread 
executes the passed function immediately (when given control by scheduler):

i386/kernel/process::kernel_thread():
**	regs.ebx = (unsigned long) fn;
	regs.edx = (unsigned long) arg;
	regs.xds = __USER_DS;
	regs.xes = __USER_DS;
	regs.xfs = __KERNEL_PDA;
	regs.orig_eax = -1;
**	regs.eip = (unsigned long) kernel_thread_helper;
	do_fork(...)

entry.S::kernel_thread_helper (removing CFI_* pseudo ops):

   ENTRY(kernel_thread_helper)
	pushl $0		
	movl %edx,%eax
	push %edx
**	call *%ebx
	push %eax
	call do_exit
	
Am I interpreting the forking process completely wrong?. I'm just curious why 
the __USER_DS is playing a vital rule in kernel threads regs/stack ?

Thanks alot,

-- 
Ahmed S. Darwish
http://darwish.07.googlepages.com


^ permalink raw reply	[relevance 99%]

* Re: i386: Why putting __USER_DS in kernel threads stack initialization?
  2007-03-18 22:58 99% i386: Why putting __USER_DS in kernel threads stack initialization? Ahmed S. Darwish
@ 2007-03-18 23:15 99% ` Ahmed S. Darwish
    1 sibling, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-03-18 23:15 UTC (permalink / raw)
  To: linux-kernel

On Mon, Mar 19, 2007 at 12:58:31AM +0200, ahmed wrote:
> 
> P.S. I've tried commenting out both lines which led to a non functional init,
> Also setting them to __USER_DS made init start but stopped issuing the error:
> `Panic: Segment violation at 0x8049798 - Sleeping for 30 seconds'
> 

Sorry, I meant setting them to __KERNEL_DS.

Thanks,

-- 
Ahmed S. Darwish
http://darwish.07.googlepages.com


^ permalink raw reply	[relevance 99%]

* i386: Why putting __USER_DS in kernel threads stack initialization?
@ 2007-03-18 22:58 99% Ahmed S. Darwish
  2007-03-18 23:15 99% ` Ahmed S. Darwish
    0 siblings, 2 replies; 200+ results
From: Ahmed S. Darwish @ 2007-03-18 22:58 UTC (permalink / raw)
  To: linux-kernel

Hi list,

Reading the kernel threads initialization code I see:

int kernel_thread(...) {

	struct pt_regs regs;
	memset(&regs, 0, sizeof(regs));
	[...]
**	regs.xds = __USER_DS;
**	regs.xes = __USER_DS;
	[...]
	/* Ok, create the new process.. */
	return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, \
	       	       0, NULL, NULL);

Continuing with the code, the threads stack (beginning from %esp) is
initialized with the passed *regs from do_fork:

int copy_thread(..., struct task_struct *p, struct pt_regs *regs) {

	struct pt_regs * childregs;
	struct task_struct *tsk;
 	childregs = task_pt_regs(p);
**	*childregs = *regs;
	[...]
** 	p->thread.esp = (unsigned long) childregs;


So the question is what will a _kernel_ thread do with the Usermode Segment
address ?

Thanks,

P.S. I've tried commenting out both lines which led to a non functional init,
Also setting them to __USER_DS made init start but stopped issuing the error:
`Panic: Segment violation at 0x8049798 - Sleeping for 30 seconds'

-- 
Ahmed S. Darwish
http://darwish.07.googlepages.com


^ permalink raw reply	[relevance 99%]

* Re: [PATCH 2.6.21-rc4] kernel/exit: Fix a comment and code contradiction
  @ 2007-03-17 15:00 99%   ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-03-17 15:00 UTC (permalink / raw)
  To: hannes-kernel; +Cc: kernel-janitors, linux-kernel, trivial

[Johannes please use replay-to-all to notify all readers]

On 2007-03-17 9:45:36 Johannes Weiner wrote:
> On Sat, Mar 17, 2007 at 08:21:32AM +0200, Ahmed S. Darwish wrote:
> > Comment in release_task() claims that group leader's parent process 
> > is signalled only if it desires so, which is not true.
>
> AFAIS, `if it wants notification' means, it does not ignore its children
> via SIG_IGN als handler for SIGCHLD.
>

AFAIK, exit_signal = -1 means that the parent don't want to be signalled,
like what happenes when using CLONE_THREAD. 

But it's even signalled in that case (after issuing a BUG):
   BUG_ON(leader->exit_signal == -1);
   do_notify_parent(leader, leader->exit_signal);

> do_notify_parent() checks if the parent wants to get informed about the
> child states.
>

Yes it does the check but it notifies the given task_struct anyway:

	BUG_ON(sig == -1);
	[ Continue parent notification normally ]
-- 
Ahmed S. Darwish
http://darwish.07.googlepages.com


^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.21-rc4] kernel/exit: Fix a comment and code contradiction
@ 2007-03-17  6:21 99% Ahmed S. Darwish
    0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2007-03-17  6:21 UTC (permalink / raw)
  To: kernel-janitors, linux-kernel; +Cc: trivial

Hi list,

Comment in release_task() claims that group leader's parent process 
is signalled only if it desires so, which is not true.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

To save your time, here's the contradictory code which don't appear in 
the patch (appears after its last line):

      leader = p->group_leader;
      if (leader != p && thread_group_empty(leader) && leader->exit_state == EXIT_ZOMBIE) {
		BUG_ON(leader->exit_signal == -1);
		do_notify_parent(leader, leader->exit_signal);


diff --git a/kernel/exit.c b/kernel/exit.c
index f132349..4a0a35f 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -152,7 +152,7 @@ repeat:
 	/*
 	 * If we are the last non-leader member of the thread
 	 * group, and the leader is zombie, then notify the
-	 * group leader's parent process. (if it wants notification.)
+	 * group leader's parent process.
 	 */
 	zap_leader = 0;
 	leader = p->group_leader;

-- 
Ahmed S. Darwish
http://darwish.07.googlepages.com


^ permalink raw reply	[relevance 99%]

* Re: [PATCH] drivers/media/video/videocodec.c: check kmalloc() return value.
  @ 2007-03-12 10:45 99% ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-03-12 10:45 UTC (permalink / raw)
  To: Amit Choudhary; +Cc: Linux Kernel

Hi Amit,

On Thu, Mar 08, 2007 at 11:14:01PM -0800, Amit Choudhary wrote:
> Description: Check the return value of kmalloc() in function 
> videocodec_build_table(), in file drivers/media/video/videocodec.c.

No need for `Description:'. This line is automatically put in the logs 
as a patch description if the patch got accepted. 

It's better not to use very large lines. 

Also there's no need to specify the exact function in the log, it's already
displayed in the patch.

> 
> Signed-off-by: Amit Choudhary <amit2030@gmail.com>
> 

As said in Documentation/SubmittingPatches put a "---" line after
Signed-off-by signature.

Thanks,

-- 
Ahmed S. Darwish
http://darwish.07.googlepages.com


^ permalink raw reply	[relevance 99%]

* Video GL rendering worked only between 2.6.20 and 2.6.21-rc1
@ 2007-02-23 18:07 99% Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-23 18:07 UTC (permalink / raw)
  To: linux-kernel

Hi list,

Aiglx/Beryl effects (transparency and other stuff) on windows that display 
video worked magically for the first time in a pull point between 2.6.20 and 
2.6.21-rc1. Unfortunately It doesn't work again now in 2.6.21-rc1 and even in 
2.6.20-mm{1,2}.

I'm not able to find the good commit again :(. Could someone please tell
me the files that is most probably responsible for video GL rendering 
so I can track their changes and find the good commit.

The machine is a Centrino laptop with an i810 card. So I guess those are 
the responsible files:
    
    drivers/char/drm/i810_*.c
    drivers/video/i810/*

Any more probably responsible files? 

Thanks,

-- 
Ahmed S. Darwish
http://darwish.07.googlepages.com


^ permalink raw reply	[relevance 99%]

* Re: [patch 1/2] natsemi: Add support for using MII port with no PHY
  @ 2007-02-14 13:28 99%   ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-14 13:28 UTC (permalink / raw)
  To: Mark Brown; +Cc: Tim Hockin, Jeff Garzik, netdev, linux-kernel

On Wed, Feb 14, 2007 at 10:02:04AM +0000, Mark Brown wrote:

> Signed-Off-By: Mark Brown <broonie@sirena.org.uk>
> 
[...]
> -		if (np->phy_addr_external == PHY_ADDR_NONE) {
> +		/* If we're ignoring the PHY it doesn't matter if we can't
> +		 * find one. */
> +		if (!np->ignore_phy && np->phy_addr_external == PHY_ADDR_NONE) {
[...]
> +	if (!np->ignore_phy) {
> +		/* The link status field is latched: it remains low
> +		 * after a temporary link failure until it's read. We
> +		 * need the current link status, thus read twice.
> +		 */
> +		mdio_read(dev, MII_BMSR);
> +		bmsr = mdio_read(dev, MII_BMSR);
[...]
>  	/*
> +	 * If we're ignoring the PHY then autoneg and the internal
> +	 * transciever are really not going to work so don't let the
> +	 * user select them.
> +	 */
> +	if (np->ignore_phy && (ecmd->autoneg == AUTONEG_ENABLE ||

A trivial comment actually, Is there a point to write multi-line comments 
in two different formats ?

Thanks,

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH 2.6.20] isdn-capi: Use ARRAY_SIZE macro when appropriate
  @ 2007-02-07 19:41 99%         ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-07 19:41 UTC (permalink / raw)
  To: Philippe De Muyter
  Cc: Joe Perches, kkeil, kai.germaschewski, linux-kernel, isdn4linux

On Tue, Feb 06, 2007 at 10:18:14PM +0100, Philippe De Muyter wrote:
> On Tue, Feb 06, 2007 at 10:41:30PM +0200, Ahmed S. Darwish wrote:
> >  
> > -    for (i=nelem-1; i >= 0; i--) {
> > +    for (i = ARRAY_SIZE(procfsentries) - 1; i >= 0; i--) {
> 
> I would write such decrementing loops as :
> 
>        for (i = ARRAY_SIZE(procfsentries); --i >= 0; ) {
> 
> Long time ago, that produced better code.  I did not check recently though.
[...]
> > -    for (i=nelem-1; i >= 0; i--) {
> > +    for (i = ARRAY_SIZE(procfsentries) - 1; i >= 0; i--) {
> 
> Same here

Hi Philippe,

Won't this hurt readability ?. I'm not a gcc guru anyway to have an
opinion on such stuff :).

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH 2.6.20] isdn-capi: Use ARRAY_SIZE macro when appropriate
  @ 2007-02-06 20:41 95%     ` Ahmed S. Darwish
    0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2007-02-06 20:41 UTC (permalink / raw)
  To: Joe Perches; +Cc: kkeil, kai.germaschewski, linux-kernel, isdn4linux

On Tue, Feb 06, 2007 at 09:52:17AM -0800, Joe Perches wrote:
> On Tue, 2007-02-06 at 18:04 +0200, Ahmed S. Darwish wrote:
> > A patch to use ARRAY_SIZE macro already defined in kernel.h
> > Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
[...]
> > -    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
> > +    int nelem = ARRAY_SIZE(procfsentries);
> >      int i;
> >  
> >      for (i=0; i < nelem; i++) {
> 
> For these patches, perhaps you can eliminate the temporary
> variable and change the loop to the more common form of
> 
> 	for (i = 0; i < ARRAY_SIZE(array); i++) {

Thanks, I think it's better too. Here's the modified patch.

A patch to use ARRAY_SIZE macro when appropriate.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index d22c022..87fe89c 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -1456,10 +1456,9 @@ static struct procfsentries {
 
 static void __init proc_init(void)
 {
-    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
     int i;
 
-    for (i=0; i < nelem; i++) {
+    for (i = 0; i < ARRAY_SIZE(procfsentries); i++) {
         struct procfsentries *p = procfsentries + i;
 	p->procent = create_proc_entry(p->name, p->mode, NULL);
 	if (p->procent) p->procent->read_proc = p->read_proc;
@@ -1468,10 +1467,9 @@ static void __init proc_init(void)
 
 static void __exit proc_exit(void)
 {
-    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
     int i;
 
-    for (i=nelem-1; i >= 0; i--) {
+    for (i = ARRAY_SIZE(procfsentries) - 1; i >= 0; i--) {
         struct procfsentries *p = procfsentries + i;
 	if (p->procent) {
 	   remove_proc_entry(p->name, NULL);
diff --git a/drivers/isdn/capi/capidrv.c b/drivers/isdn/capi/capidrv.c
index c4d438c..cff5d1e 100644
--- a/drivers/isdn/capi/capidrv.c
+++ b/drivers/isdn/capi/capidrv.c
@@ -2218,10 +2218,9 @@ static struct procfsentries {
 
 static void __init proc_init(void)
 {
-    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
     int i;
 
-    for (i=0; i < nelem; i++) {
+    for (i = 0; i < ARRAY_SIZE(procfsentries); i++) {
         struct procfsentries *p = procfsentries + i;
 	p->procent = create_proc_entry(p->name, p->mode, NULL);
 	if (p->procent) p->procent->read_proc = p->read_proc;
@@ -2230,10 +2229,9 @@ static void __init proc_init(void)
 
 static void __exit proc_exit(void)
 {
-    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
     int i;
 
-    for (i=nelem-1; i >= 0; i--) {
+    for (i = ARRAY_SIZE(procfsentries) - 1; i >= 0; i--) {
         struct procfsentries *p = procfsentries + i;
 	if (p->procent) {
 	   remove_proc_entry(p->name, NULL);


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 95%]

* [PATCH 2.6.20] drm: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 97% [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
                   ` (14 preceding siblings ...)
  2007-02-06 16:09 99% ` [PATCH 2.6.20] w1: " Ahmed S. Darwish
@ 2007-02-06 16:10 99% ` Ahmed S. Darwish
  15 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-06 16:10 UTC (permalink / raw)
  To: airlied; +Cc: linux-kernel, dri-devel

Hi all,

A patch to use ARRAY_SIZE macro already defined in kernel.h

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
diff --git a/drivers/char/drm/drm_proc.c b/drivers/char/drm/drm_proc.c
index 62d5fe1..8943ad1 100644
--- a/drivers/char/drm/drm_proc.c
+++ b/drivers/char/drm/drm_proc.c
@@ -72,7 +72,7 @@ static struct drm_proc_list {
 #endif
 };
 
-#define DRM_PROC_ENTRIES (sizeof(drm_proc_list)/sizeof(drm_proc_list[0]))
+#define DRM_PROC_ENTRIES ARRAY_SIZE(drm_proc_list)
 
 /**
  * Initialize the DRI proc filesystem for a device.


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.20] w1: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 97% [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
                   ` (13 preceding siblings ...)
  2007-02-06 16:09 99% ` [PATCH 2.6.20] toshiba-acpi: " Ahmed S. Darwish
@ 2007-02-06 16:09 99% ` Ahmed S. Darwish
  2007-02-06 16:10 99% ` [PATCH 2.6.20] drm: " Ahmed S. Darwish
  15 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-06 16:09 UTC (permalink / raw)
  To: johnpol; +Cc: linux-kernel

Hi all,

A patch to use ARRAY_SIZE macro already defined in kernel.h

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
diff --git a/drivers/w1/slaves/w1_therm.c b/drivers/w1/slaves/w1_therm.c
index b022fff..732db47 100644
--- a/drivers/w1/slaves/w1_therm.c
+++ b/drivers/w1/slaves/w1_therm.c
@@ -141,7 +141,7 @@ static inline int w1_convert_temp(u8 rom[9], u8 fid)
 {
 	int i;
 
-	for (i=0; i<sizeof(w1_therm_families)/sizeof(w1_therm_families[0]); ++i)
+	for (i = 0; i < ARRAY_SIZE(w1_therm_families); ++i)
 		if (w1_therm_families[i].f->fid == fid)
 			return w1_therm_families[i].convert(rom);
 
@@ -238,7 +238,7 @@ static int __init w1_therm_init(void)
 {
 	int err, i;
 
-	for (i=0; i<sizeof(w1_therm_families)/sizeof(w1_therm_families[0]); ++i) {
+	for (i = 0; i < ARRAY_SIZE(w1_therm_families); ++i) {
 		err = w1_register_family(w1_therm_families[i].f);
 		if (err)
 			w1_therm_families[i].broken = 1;
@@ -251,7 +251,7 @@ static void __exit w1_therm_fini(void)
 {
 	int i;
 
-	for (i=0; i<sizeof(w1_therm_families)/sizeof(w1_therm_families[0]); ++i)
+	for (i = 0; i < ARRAY_SIZE(w1_therm_families); ++i)
 		if (!w1_therm_families[i].broken)
 			w1_unregister_family(w1_therm_families[i].f);
 }


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.20] toshiba-acpi: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 97% [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
                   ` (12 preceding siblings ...)
  2007-02-06 16:08 99% ` [PATCH 2.6.20] reiserfs: " Ahmed S. Darwish
@ 2007-02-06 16:09 99% ` Ahmed S. Darwish
  2007-02-06 16:09 99% ` [PATCH 2.6.20] w1: " Ahmed S. Darwish
  2007-02-06 16:10 99% ` [PATCH 2.6.20] drm: " Ahmed S. Darwish
  15 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-06 16:09 UTC (permalink / raw)
  To: toshiba_acpi; +Cc: linux-kernel

Hi all,

A patch to use ARRAY_SIZE macro already defined in kernel.h

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
diff --git a/drivers/acpi/toshiba_acpi.c b/drivers/acpi/toshiba_acpi.c
index d9b651f..0208d3a 100644
--- a/drivers/acpi/toshiba_acpi.c
+++ b/drivers/acpi/toshiba_acpi.c
@@ -125,7 +125,7 @@ static int write_acpi_int(const char *methodName, int val)
 	union acpi_object in_objs[1];
 	acpi_status status;
 
-	params.count = sizeof(in_objs) / sizeof(in_objs[0]);
+	params.count = ARRAY_SIZE(in_objs);
 	params.pointer = in_objs;
 	in_objs[0].type = ACPI_TYPE_INTEGER;
 	in_objs[0].integer.value = val;

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.20] reiserfs: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 97% [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
                   ` (11 preceding siblings ...)
  2007-02-06 16:08 99% ` [PATCH 2.6.20] intel-agp: " Ahmed S. Darwish
@ 2007-02-06 16:08 99% ` Ahmed S. Darwish
  2007-02-06 16:09 99% ` [PATCH 2.6.20] toshiba-acpi: " Ahmed S. Darwish
                   ` (2 subsequent siblings)
  15 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-06 16:08 UTC (permalink / raw)
  To: reiserfs-dev; +Cc: linux-kernel, reiserfs-list

Hi all,

A patch to use ARRAY_SIZE macro already defined in kernel.h

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
index fba304e..f85c5cf 100644
--- a/fs/reiserfs/do_balan.c
+++ b/fs/reiserfs/do_balan.c
@@ -19,6 +19,7 @@
 #include <linux/time.h>
 #include <linux/reiserfs_fs.h>
 #include <linux/buffer_head.h>
+#include <linux/kernel.h>
 
 #ifdef CONFIG_REISERFS_CHECK
 
@@ -1756,7 +1757,7 @@ static void store_thrown(struct tree_balance *tb, struct buffer_head *bh)
 	if (buffer_dirty(bh))
 		reiserfs_warning(tb->tb_sb,
 				 "store_thrown deals with dirty buffer");
-	for (i = 0; i < sizeof(tb->thrown) / sizeof(tb->thrown[0]); i++)
+	for (i = 0; i < ARRAY_SIZE(tb->thrown); i++)
 		if (!tb->thrown[i]) {
 			tb->thrown[i] = bh;
 			get_bh(bh);	/* free_thrown puts this */
@@ -1769,7 +1770,7 @@ static void free_thrown(struct tree_balance *tb)
 {
 	int i;
 	b_blocknr_t blocknr;
-	for (i = 0; i < sizeof(tb->thrown) / sizeof(tb->thrown[0]); i++) {
+	for (i = 0; i < ARRAY_SIZE(tb->thrown); i++) {
 		if (tb->thrown[i]) {
 			blocknr = tb->thrown[i]->b_blocknr;
 			if (buffer_dirty(tb->thrown[i]))


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.20] intel-agp: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 97% [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
                   ` (10 preceding siblings ...)
  2007-02-06 16:08 99% ` [PATCH 2.6.20] rcutorture: " Ahmed S. Darwish
@ 2007-02-06 16:08 99% ` Ahmed S. Darwish
  2007-02-06 16:08 99% ` [PATCH 2.6.20] reiserfs: " Ahmed S. Darwish
                   ` (3 subsequent siblings)
  15 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-06 16:08 UTC (permalink / raw)
  To: davej; +Cc: linux-kernel

Hi all,

A patch to use ARRAY_SIZE macro already defined in kernel.h

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
diff --git a/drivers/char/agp/intel-agp.c b/drivers/char/agp/intel-agp.c
index ab0a9c0..7233310 100644
--- a/drivers/char/agp/intel-agp.c
+++ b/drivers/char/agp/intel-agp.c
@@ -5,6 +5,7 @@
 #include <linux/module.h>
 #include <linux/pci.h>
 #include <linux/init.h>
+#include <linux/kernel.h>
 #include <linux/pagemap.h>
 #include <linux/agp_backend.h>
 #include "agp.h"
@@ -803,7 +804,7 @@ static int intel_i915_remove_entries(struct agp_memory *mem,off_t pg_start,
  */
 static int intel_i9xx_fetch_size(void)
 {
-	int num_sizes = sizeof(intel_i830_sizes) / sizeof(*intel_i830_sizes);
+	int num_sizes = ARRAY_SIZE(intel_i830_sizes);
 	int aper_size; /* size in megabytes */
 	int i;
 


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.20] rcutorture: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 97% [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
                   ` (9 preceding siblings ...)
  2007-02-06 16:07 99% ` [PATCH 2.6.20] s390-drivers: " Ahmed S. Darwish
@ 2007-02-06 16:08 99% ` Ahmed S. Darwish
  2007-02-06 16:08 99% ` [PATCH 2.6.20] intel-agp: " Ahmed S. Darwish
                   ` (4 subsequent siblings)
  15 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-06 16:08 UTC (permalink / raw)
  To: josh; +Cc: linux-kernel

Hi all,

A patch to use ARRAY_SIZE macro already defined in kernel.h

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
index 482b11f..97c2277 100644
--- a/kernel/rcutorture.c
+++ b/kernel/rcutorture.c
@@ -899,7 +899,7 @@ rcu_torture_init(void)
 	/* Set up the freelist. */
 
 	INIT_LIST_HEAD(&rcu_torture_freelist);
-	for (i = 0; i < sizeof(rcu_tortures) / sizeof(rcu_tortures[0]); i++) {
+	for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++) {
 		rcu_tortures[i].rtort_mbtest = 0;
 		list_add_tail(&rcu_tortures[i].rtort_free,
 			      &rcu_torture_freelist);


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.20] s390-drivers: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 97% [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
                   ` (8 preceding siblings ...)
  2007-02-06 16:07 99% ` [PATCH 2.6.20] infinband: " Ahmed S. Darwish
@ 2007-02-06 16:07 99% ` Ahmed S. Darwish
  2007-02-06 16:08 99% ` [PATCH 2.6.20] rcutorture: " Ahmed S. Darwish
                   ` (5 subsequent siblings)
  15 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-06 16:07 UTC (permalink / raw)
  To: schwidefsky; +Cc: linux-kernel, linux-390

Hi all,

A patch to use ARRAY_SIZE macro already defined in kernel.h

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
Not compile tested due to (ofcourse ;)) missing hardware.

diff --git a/drivers/s390/cio/device_id.c b/drivers/s390/cio/device_id.c
index f172759..997f468 100644
--- a/drivers/s390/cio/device_id.c
+++ b/drivers/s390/cio/device_id.c
@@ -11,6 +11,7 @@
 
 #include <linux/module.h>
 #include <linux/init.h>
+#include <linux/kernel.h>
 
 #include <asm/ccwdev.h>
 #include <asm/delay.h>
@@ -138,7 +139,7 @@ VM_virtual_device_info (__u16 devno, struct senseid *ps)
 		ps->cu_model = 0x60;
 		return;
 	}
-	for (i = 0; i < sizeof(vm_devices) / sizeof(vm_devices[0]); i++)
+	for (i = 0; i < ARRAY_SIZE(vm_devices); i++)
 		if (diag_data.vrdcvcla == vm_devices[i].vrdcvcla &&
 		    diag_data.vrdcvtyp == vm_devices[i].vrdcvtyp) {
 			ps->cu_type = vm_devices[i].cu_type;


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.20] infinband: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 97% [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
                   ` (7 preceding siblings ...)
  2007-02-06 16:06 99% ` [PATCH 2.6.20] drivers/md.c: " Ahmed S. Darwish
@ 2007-02-06 16:07 99% ` Ahmed S. Darwish
  2007-02-06 16:07 99% ` [PATCH 2.6.20] s390-drivers: " Ahmed S. Darwish
                   ` (6 subsequent siblings)
  15 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-06 16:07 UTC (permalink / raw)
  To: rolandd; +Cc: linux-kernel, openib-general

Hi all,

A patch to use ARRAY_SIZE macro already defined in kernel.h

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
index 63d2a39..7fabb42 100644
--- a/drivers/infiniband/core/device.c
+++ b/drivers/infiniband/core/device.c
@@ -36,6 +36,7 @@
 #include <linux/module.h>
 #include <linux/string.h>
 #include <linux/errno.h>
+#include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/init.h>
 #include <linux/mutex.h>
@@ -93,7 +94,7 @@ static int ib_device_check_mandatory(struct ib_device *device)
 	};
 	int i;
 
-	for (i = 0; i < sizeof mandatory_table / sizeof mandatory_table[0]; ++i) {
+	for (i = 0; i < ARRAY_SIZE(mandatory_table); ++i) {
 		if (!*(void **) ((void *) device + mandatory_table[i].offset)) {
 			printk(KERN_WARNING "Device %s is missing mandatory function %s\n",
 			       device->name, mandatory_table[i].name);

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.20] drivers/md.c: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 97% [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
                   ` (6 preceding siblings ...)
  2007-02-06 16:06 94% ` [PATCH 2.6.20] atm: " Ahmed S. Darwish
@ 2007-02-06 16:06 99% ` Ahmed S. Darwish
  2007-02-06 16:07 99% ` [PATCH 2.6.20] infinband: " Ahmed S. Darwish
                   ` (7 subsequent siblings)
  15 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-06 16:06 UTC (permalink / raw)
  To: mingo; +Cc: linux-kernel, linux-raid

Hi all,

A patch to use ARRAY_SIZE macro already defined in kernel.h

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
diff --git a/drivers/md/md.c b/drivers/md/md.c
index e8807ea..6f6d9e5 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -33,6 +33,7 @@
 */
 
 #include <linux/module.h>
+#include <linux/kernel.h>
 #include <linux/kthread.h>
 #include <linux/linkage.h>
 #include <linux/raid/md.h>
@@ -2635,8 +2636,7 @@ metadata_store(mddev_t *mddev, const char *buf, size_t len)
 	minor = simple_strtoul(buf, &e, 10);
 	if (e==buf || (*e && *e != '\n') )
 		return -EINVAL;
-	if (major >= sizeof(super_types)/sizeof(super_types[0]) ||
-	    super_types[major].name == NULL)
+	if (major >= ARRAY_SIZE(super_types) || super_types[major].name == NULL)
 		return -ENOENT;
 	mddev->major_version = major;
 	mddev->minor_version = minor;
@@ -3973,7 +3973,7 @@ static int set_array_info(mddev_t * mddev, mdu_array_info_t *info)
 	if (info->raid_disks == 0) {
 		/* just setting version number for superblock loading */
 		if (info->major_version < 0 ||
-		    info->major_version >= sizeof(super_types)/sizeof(super_types[0]) ||
+		    info->major_version >= ARRAY_SIZE(super_types) ||
 		    super_types[info->major_version].name == NULL) {
 			/* maybe try to auto-load a module? */
 			printk(KERN_INFO 


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.20] atm: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 97% [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
                   ` (5 preceding siblings ...)
  2007-02-06 16:05 94% ` [PATCH 2.6.20 2/2] " Ahmed S. Darwish
@ 2007-02-06 16:06 94% ` Ahmed S. Darwish
  2007-02-06 16:06 99% ` [PATCH 2.6.20] drivers/md.c: " Ahmed S. Darwish
                   ` (8 subsequent siblings)
  15 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-06 16:06 UTC (permalink / raw)
  To: chas; +Cc: linux-kernel

Hi all,

A patch to use ARRAY_SIZE macro already defined in kernel.h for ATM
drivers.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
diff --git a/drivers/atm/he.c b/drivers/atm/he.c
index db33f6f..8510026 100644
--- a/drivers/atm/he.c
+++ b/drivers/atm/he.c
@@ -3017,7 +3017,7 @@ read_prom_byte(struct he_dev *he_dev, int addr)
 	he_writel(he_dev, val, HOST_CNTL);
        
 	/* Send READ instruction */
-	for (i = 0; i < sizeof(readtab)/sizeof(readtab[0]); i++) {
+	for (i = 0; i < ARRAY_SIZE(readtab); i++) {
 		he_writel(he_dev, val | readtab[i], HOST_CNTL);
 		udelay(EEPROM_DELAY);
 	}
diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
index f407861..b4b8014 100644
--- a/drivers/atm/idt77252.c
+++ b/drivers/atm/idt77252.c
@@ -388,7 +388,7 @@ idt77252_eeprom_read_status(struct idt77252_dev *card)
 
 	gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO);
 
-	for (i = 0; i < sizeof(rdsrtab)/sizeof(rdsrtab[0]); i++) {
+	for (i = 0; i < ARRAY_SIZE(rdsrtab); i++) {
 		idt77252_write_gp(card, gp | rdsrtab[i]);
 		udelay(5);
 	}
@@ -422,7 +422,7 @@ idt77252_eeprom_read_byte(struct idt77252_dev *card, u8 offset)
 
 	gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO);
 
-	for (i = 0; i < sizeof(rdtab)/sizeof(rdtab[0]); i++) {
+	for (i = 0; i < ARRAY_SIZE(rdtab); i++) {
 		idt77252_write_gp(card, gp | rdtab[i]);
 		udelay(5);
 	}
@@ -469,14 +469,14 @@ idt77252_eeprom_write_byte(struct idt77252_dev *card, u8 offset, u8 data)
 
 	gp = idt77252_read_gp(card) & ~(SAR_GP_EESCLK|SAR_GP_EECS|SAR_GP_EEDO);
 
-	for (i = 0; i < sizeof(wrentab)/sizeof(wrentab[0]); i++) {
+	for (i = 0; i < ARRAY_SIZE(wrentab); i++) {
 		idt77252_write_gp(card, gp | wrentab[i]);
 		udelay(5);
 	}
 	idt77252_write_gp(card, gp | SAR_GP_EECS);
 	udelay(5);
 
-	for (i = 0; i < sizeof(wrtab)/sizeof(wrtab[0]); i++) {
+	for (i = 0; i < ARRAY_SIZE(wrtab); i++) {
 		idt77252_write_gp(card, gp | wrtab[i]);
 		udelay(5);
 	}
diff --git a/drivers/atm/nicstarmac.c b/drivers/atm/nicstarmac.c
index 2c5e3ae..480947f 100644
--- a/drivers/atm/nicstarmac.c
+++ b/drivers/atm/nicstarmac.c
@@ -7,6 +7,8 @@
  * Read this ForeRunner's MAC address from eprom/eeprom
  */
 
+#include <linux/kernel.h>
+
 typedef void __iomem *virt_addr_t;
 
 #define CYCLE_DELAY 5
@@ -176,7 +178,7 @@ read_eprom_byte(virt_addr_t base, u_int8_t offset)
    val = NICSTAR_REG_READ( base, NICSTAR_REG_GENERAL_PURPOSE ) & 0xFFFFFFF0;
 
    /* Send READ instruction */
-   for (i=0; i<sizeof readtab/sizeof readtab[0]; i++)
+   for (i=0; i<ARRAY_SIZE(readtab); i++)
    {
 	NICSTAR_REG_WRITE( base, NICSTAR_REG_GENERAL_PURPOSE,
 		(val | readtab[i]) );


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 94%]

* [PATCH 2.6.20 2/2] OSS: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 97% [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
                   ` (4 preceding siblings ...)
  2007-02-06 16:05 96% ` [PATCH 2.6.20 1/2] OSS: " Ahmed S. Darwish
@ 2007-02-06 16:05 94% ` Ahmed S. Darwish
  2007-02-06 16:06 94% ` [PATCH 2.6.20] atm: " Ahmed S. Darwish
                   ` (9 subsequent siblings)
  15 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-06 16:05 UTC (permalink / raw)
  To: linux-kernel

Hi all,

A patch to use ARRAY_SIZE macro already defined in kernel.h

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
I couldn't compile-test this patch with `allyesconfig' or `allmodconfig'.

 au1550_ac97.c   |    4 ++--
 nec_vrc5477.c   |    4 ++--
 swarm_cs4297a.c |    3 ++-
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/sound/oss/au1550_ac97.c b/sound/oss/au1550_ac97.c
index 2197951..a339f0c 100644
--- a/sound/oss/au1550_ac97.c
+++ b/sound/oss/au1550_ac97.c
@@ -1354,11 +1354,11 @@ au1550_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
 		((file->f_mode & FMODE_READ) && s->dma_adc.mapped);
 
 #ifdef DEBUG
-	for (count=0; count<sizeof(ioctl_str)/sizeof(ioctl_str[0]); count++) {
+	for (count = 0; count < ARRAY_SIZE(ioctl_str); count++) {
 		if (ioctl_str[count].cmd == cmd)
 			break;
 	}
-	if (count < sizeof(ioctl_str) / sizeof(ioctl_str[0]))
+	if (count < ARRAY_SIZE(ioctl_str))
 		pr_debug("ioctl %s, arg=0x%lxn", ioctl_str[count].str, arg);
 	else
 		pr_debug("ioctl 0x%x unknown, arg=0x%lx\n", cmd, arg);
diff --git a/sound/oss/nec_vrc5477.c b/sound/oss/nec_vrc5477.c
index da9728e..d459bdb 100644
--- a/sound/oss/nec_vrc5477.c
+++ b/sound/oss/nec_vrc5477.c
@@ -1381,11 +1381,11 @@ static int vrc5477_ac97_ioctl(struct inode *inode, struct file *file,
 	int val, ret;
 
 #ifdef VRC5477_AC97_DEBUG
-	for (count=0; count<sizeof(ioctl_str)/sizeof(ioctl_str[0]); count++) {
+	for (count = 0; count < ARRAY_SIZE(ioctl_str); count++) {
 		if (ioctl_str[count].cmd == cmd)
 			break;
 	}
-	if (count < sizeof(ioctl_str)/sizeof(ioctl_str[0]))
+	if (count < ARRAY_SIZE(ioctl_str))
 		printk(KERN_INFO PFX "ioctl %s\n", ioctl_str[count].str);
 	else
 		printk(KERN_INFO PFX "ioctl unknown, 0x%x\n", cmd);
diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
index 471c274..9f7e5f5 100644
--- a/sound/oss/swarm_cs4297a.c
+++ b/sound/oss/swarm_cs4297a.c
@@ -77,6 +77,7 @@
 #include <linux/poll.h>
 #include <linux/smp_lock.h>
 #include <linux/mutex.h>
+#include <linux/kernel.h>
 
 #include <asm/byteorder.h>
 #include <asm/dma.h>
@@ -2676,7 +2677,7 @@ static int __init cs4297a_init(void)
 #if 0
                 val = SOUND_MASK_LINE;
                 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
-                for (i = 0; i < sizeof(initvol) / sizeof(initvol[0]); i++) {
+                for (i = 0; i < ARRAY_SIZE(initvol); i++) {
                         val = initvol[i].vol;
                         mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
                 }

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 94%]

* [PATCH 2.6.20 1/2] OSS: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 97% [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
                   ` (3 preceding siblings ...)
  2007-02-06 16:04 99% ` [PATCH 2.6.20] isdn-capi: " Ahmed S. Darwish
@ 2007-02-06 16:05 96% ` Ahmed S. Darwish
  2007-02-06 16:05 94% ` [PATCH 2.6.20 2/2] " Ahmed S. Darwish
                   ` (10 subsequent siblings)
  15 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-06 16:05 UTC (permalink / raw)
  To: linux-kernel

Hi all,

A patch to use ARRAY_SIZE macro already defined in kernel.h

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
[PATCH 1/2] compile-tested
[PATCH 2/2] couldn't be compile-tested (orphaned hardware ?)

diff --git a/sound/oss/es1371.c b/sound/oss/es1371.c
index cc282a0..e1fbcca 100644
--- a/sound/oss/es1371.c
+++ b/sound/oss/es1371.c
@@ -131,6 +131,7 @@
 #include <linux/dma-mapping.h>
 #include <linux/mutex.h>
 #include <linux/mm.h>
+#include <linux/kernel.h>
 
 #include <asm/io.h>
 #include <asm/page.h>
@@ -2998,7 +2999,7 @@ static int __devinit es1371_probe(struct pci_dev *pcidev, const struct pci_devic
 	set_fs(KERNEL_DS);
 	val = SOUND_MASK_LINE;
 	mixdev_ioctl(s->codec, SOUND_MIXER_WRITE_RECSRC, (unsigned long)&val);
-	for (i = 0; i < sizeof(initvol)/sizeof(initvol[0]); i++) {
+	for (i = 0; i < ARRAY_SIZE(initvol); i++) {
 		val = initvol[i].vol;
 		mixdev_ioctl(s->codec, initvol[i].mixch, (unsigned long)&val);
 	}
diff --git a/sound/oss/soundcard.c b/sound/oss/soundcard.c
index a89108c..b92c8cd 100644
--- a/sound/oss/soundcard.c
+++ b/sound/oss/soundcard.c
@@ -32,6 +32,7 @@
 #include <linux/ctype.h>
 #include <linux/stddef.h>
 #include <linux/kmod.h>
+#include <linux/kernel.h>
 #include <asm/dma.h>
 #include <asm/io.h>
 #include <linux/wait.h>
@@ -557,7 +558,7 @@ static int __init oss_init(void)
 	/* Protecting the innocent */
 	sound_dmap_flag = (dmabuf > 0 ? 1 : 0);
 
-	for (i = 0; i < sizeof (dev_list) / sizeof *dev_list; i++) {
+	for (i = 0; i < ARRAY_SIZE(dev_list); i++) {
 		device_create(sound_class, NULL,
 			      MKDEV(SOUND_MAJOR, dev_list[i].minor),
 			      "%s", dev_list[i].name);
@@ -581,7 +582,7 @@ static void __exit oss_cleanup(void)
 {
 	int i, j;
 
-	for (i = 0; i < sizeof (dev_list) / sizeof *dev_list; i++) {
+	for (i = 0; i < ARRAY_SIZE(dev_list); i++) {
 		device_destroy(sound_class, MKDEV(SOUND_MAJOR, dev_list[i].minor));
 		if (!dev_list[i].num)
 			continue;

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 96%]

* [PATCH 2.6.20] isdn-capi: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 97% [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
                   ` (2 preceding siblings ...)
  2007-02-06 16:04 64% ` [PATCH 2.6.20] isdn-eicon: " Ahmed S. Darwish
@ 2007-02-06 16:04 99% ` Ahmed S. Darwish
    2007-02-06 16:05 96% ` [PATCH 2.6.20 1/2] OSS: " Ahmed S. Darwish
                   ` (11 subsequent siblings)
  15 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2007-02-06 16:04 UTC (permalink / raw)
  To: kkeil, kai.germaschewski; +Cc: linux-kernel, isdn4linux

Hi all,

A patch to use ARRAY_SIZE macro already defined in kernel.h

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
 capi.c    |    4 ++--
 capidrv.c |    4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index d22c022..3804591 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -1456,7 +1456,7 @@ static struct procfsentries {
 
 static void __init proc_init(void)
 {
-    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
+    int nelem = ARRAY_SIZE(procfsentries);
     int i;
 
     for (i=0; i < nelem; i++) {
@@ -1468,7 +1468,7 @@ static void __init proc_init(void)
 
 static void __exit proc_exit(void)
 {
-    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
+    int nelem = ARRAY_SIZE(procfsentries);
     int i;
 
     for (i=nelem-1; i >= 0; i--) {
diff --git a/drivers/isdn/capi/capidrv.c b/drivers/isdn/capi/capidrv.c
index c4d438c..8cec9c3 100644
--- a/drivers/isdn/capi/capidrv.c
+++ b/drivers/isdn/capi/capidrv.c
@@ -2218,7 +2218,7 @@ static struct procfsentries {
 
 static void __init proc_init(void)
 {
-    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
+    int nelem = ARRAY_SIZE(procfsentries);
     int i;
 
     for (i=0; i < nelem; i++) {
@@ -2230,7 +2230,7 @@ static void __init proc_init(void)
 
 static void __exit proc_exit(void)
 {
-    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
+    int nelem = ARRAY_SIZE(procfsentries);
     int i;
 
     for (i=nelem-1; i >= 0; i--) {

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.20] isdn-eicon: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 97% [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
  2007-02-06 16:03 83% ` [PATCH 2.6.20] DVB: Use ARRAY_SIZE macro when appropriate Ahmed S. Darwish
  2007-02-06 16:03 94% ` [PATCH 2.6.20] KVM: " Ahmed S. Darwish
@ 2007-02-06 16:04 64% ` Ahmed S. Darwish
  2007-02-06 16:04 99% ` [PATCH 2.6.20] isdn-capi: " Ahmed S. Darwish
                   ` (12 subsequent siblings)
  15 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-06 16:04 UTC (permalink / raw)
  To: mac, kkeil; +Cc: linux-kernel, isdn4linux

Hi all,

A patch to use ARRAY_SIZE macro already defined in kernel.h

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
Also remove the macro 
`#define DIM(array)  (sizeof (array)/sizeof ((array)[0]))'
that reimplements ARRAY_SIZE. Encourage new code to use ARRAY_SIZE ;).

 debug.c    |   30 +++++++++++++++---------------
 message.c  |   23 +++++++++++------------
 platform.h |    4 ----
 3 files changed, 26 insertions(+), 31 deletions(-)

diff --git a/drivers/isdn/hardware/eicon/debug.c b/drivers/isdn/hardware/eicon/debug.c
index d835e74..0db9cc6 100644
--- a/drivers/isdn/hardware/eicon/debug.c
+++ b/drivers/isdn/hardware/eicon/debug.c
@@ -287,7 +287,7 @@ void* diva_maint_finit (void) {
   }
   external_dbg_queue = 0;
 
-  for (i = 1; i < (sizeof(clients)/sizeof(clients[0])); i++) {
+  for (i = 1; i < ARRAY_SIZE(clients); i++) {
     if (clients[i].pmem) {
       diva_os_free (0, clients[i].pmem);
     }
@@ -391,7 +391,7 @@ static void DI_register (void *arg) {
 
   diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "register");
 
-  for (id = 1; id < (sizeof(clients)/sizeof(clients[0])); id++) {
+  for (id = 1; id < ARRAY_SIZE(clients); id++) {
     if (clients[id].hDbg == hDbg) {
       /*
         driver already registered
@@ -494,7 +494,7 @@ static void DI_deregister (pDbgHandle hDbg) {
   diva_os_enter_spin_lock (&dbg_adapter_lock, &old_irql1, "read");
   diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "read");
 
-  for (i = 1; i < (sizeof(clients)/sizeof(clients[0])); i++) {
+  for (i = 1; i < ARRAY_SIZE(clients); i++) {
     if (clients[i].hDbg == hDbg) {
       diva_dbg_entry_head_t* pmsg;
       char tmp[256];
@@ -736,7 +736,7 @@ int diva_get_driver_info (dword id, byte* data, int data_length) {
   int to_copy;
 
   if (!data || !id || (data_length < 17) ||
-      (id >= (sizeof(clients)/sizeof(clients[0])))) {
+      (id >= ARRAY_SIZE(clients))) {
     return (-1);
   }
 
@@ -786,7 +786,7 @@ int diva_get_driver_dbg_mask (dword id, byte* data) {
   diva_os_spin_lock_magic_t old_irql;
   int ret = -1;
 
-  if (!data || !id || (id >= (sizeof(clients)/sizeof(clients[0])))) {
+  if (!data || !id || (id >= ARRAY_SIZE(clients))) {
     return (-1);
   }
   diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "driver info");
@@ -809,7 +809,7 @@ int diva_set_driver_dbg_mask (dword id, dword mask) {
   int ret = -1;
   
 
-  if (!id || (id >= (sizeof(clients)/sizeof(clients[0])))) {
+  if (!id || (id >= ARRAY_SIZE(clients))) {
     return (-1);
   }
 
@@ -887,7 +887,7 @@ void diva_mnt_add_xdi_adapter (const DESCRIPTOR* d) {
   diva_os_enter_spin_lock (&dbg_adapter_lock, &old_irql1, "register");
   diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "register");
 
-  for (id = 1; id < (sizeof(clients)/sizeof(clients[0])); id++) {
+  for (id = 1; id < ARRAY_SIZE(clients); id++) {
     if (clients[id].hDbg && (clients[id].request == d->request)) {
       diva_os_leave_spin_lock (&dbg_q_lock, &old_irql, "register");
       diva_os_leave_spin_lock (&dbg_adapter_lock, &old_irql1, "register");
@@ -1037,7 +1037,7 @@ void diva_mnt_remove_xdi_adapter (const DESCRIPTOR* d) {
   diva_os_enter_spin_lock (&dbg_adapter_lock, &old_irql1, "read");
   diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "read");
 
-  for (i = 1; i < (sizeof(clients)/sizeof(clients[0])); i++) {
+  for (i = 1; i < ARRAY_SIZE(clients); i++) {
     if (clients[i].hDbg && (clients[i].request == d->request)) {
       diva_dbg_entry_head_t* pmsg;
       char tmp[256];
@@ -1115,7 +1115,7 @@ void diva_mnt_remove_xdi_adapter (const DESCRIPTOR* d) {
 void* SuperTraceOpenAdapter   (int AdapterNumber) {
   int i;
 
-  for (i = 1; i < (sizeof(clients)/sizeof(clients[0])); i++) {
+  for (i = 1; i < ARRAY_SIZE(clients); i++) {
     if (clients[i].hDbg && clients[i].request && (clients[i].logical == AdapterNumber)) {
       return (&clients[i]);
     }
@@ -1508,7 +1508,7 @@ static void diva_maint_state_change_notify (void* user_context,
 					int ch = TraceFilterChannel;
 					int id = TraceFilterIdent;
 
-					if ((id >= 0) && (ch >= 0) && (id < sizeof(clients)/sizeof(clients[0])) &&
+					if ((id >= 0) && (ch >= 0) && (id < ARRAY_SIZE(clients)) &&
 						(clients[id].Dbg.id == (byte)id) && (clients[id].pIdiLib == hLib)) {
 						if (ch != (int)modem->ChannelNumber) {
 							break;
@@ -1555,7 +1555,7 @@ static void diva_maint_state_change_notify (void* user_context,
 					int ch = TraceFilterChannel;
 					int id = TraceFilterIdent;
 
-					if ((id >= 0) && (ch >= 0) && (id < sizeof(clients)/sizeof(clients[0])) &&
+					if ((id >= 0) && (ch >= 0) && (id < ARRAY_SIZE(clients)) &&
 						(clients[id].Dbg.id == (byte)id) && (clients[id].pIdiLib == hLib)) {
 						if (ch != (int)fax->ChannelNumber) {
 							break;
@@ -1803,7 +1803,7 @@ static void diva_maint_trace_notify (void* user_context,
   /*
     Selective trace
     */
-  if ((id >= 0) && (ch >= 0) && (id < sizeof(clients)/sizeof(clients[0])) &&
+  if ((id >= 0) && (ch >= 0) && (id < ARRAY_SIZE(clients)) &&
       (clients[id].Dbg.id == (byte)id) && (clients[id].pIdiLib == hLib)) {
     const char* p = NULL;
     int ch_value = -1;
@@ -1925,7 +1925,7 @@ int diva_mnt_shutdown_xdi_adapters (void) {
   byte * pmem;
 
 
-  for (i = 1; i < (sizeof(clients)/sizeof(clients[0])); i++) {
+  for (i = 1; i < ARRAY_SIZE(clients); i++) {
     pmem = NULL;
 
     diva_os_enter_spin_lock (&dbg_adapter_lock, &old_irql1, "unload");
@@ -2006,7 +2006,7 @@ int diva_set_trace_filter (int filter_length, const char* filter) {
 
   on = (TraceFilter[0] == 0);
 
-  for (i = 1; i < (sizeof(clients)/sizeof(clients[0])); i++) {
+  for (i = 1; i < ARRAY_SIZE(clients); i++) {
     if (clients[i].hDbg && clients[i].pIdiLib && clients[i].request) {
       client_b_on    = on && ((clients[i].hDbg->dbgMask & DIVA_MGT_DBG_IFC_BCHANNEL) != 0);
       client_atap_on = on && ((clients[i].hDbg->dbgMask & DIVA_MGT_DBG_IFC_AUDIO)    != 0);
@@ -2017,7 +2017,7 @@ int diva_set_trace_filter (int filter_length, const char* filter) {
     }
   }
 
-  for (i = 1; i < (sizeof(clients)/sizeof(clients[0])); i++) {
+  for (i = 1; i < ARRAY_SIZE(clients); i++) {
     if (clients[i].hDbg && clients[i].pIdiLib && clients[i].request && clients[i].request_pending) {
       diva_os_leave_spin_lock (&dbg_q_lock, &old_irql, "write_filter");
       clients[i].request_pending = 0;
diff --git a/drivers/isdn/hardware/eicon/message.c b/drivers/isdn/hardware/eicon/message.c
index f9b00f1..4e29d38 100644
--- a/drivers/isdn/hardware/eicon/message.c
+++ b/drivers/isdn/hardware/eicon/message.c
@@ -6812,7 +6812,7 @@ void nl_ind(PLCI   * plci)
         }
         if (((plci->NL.Ind & 0x0f) == N_DISC) || ((plci->NL.Ind & 0x0f) == N_DISC_ACK))
         {
-          if (((T30_INFO   *)plci->NL.RBuffer->P)->code < sizeof(fax_info) / sizeof(fax_info[0]))
+	  if (((T30_INFO   *)plci->NL.RBuffer->P)->code < ARRAY_SIZE(fax_info))
             info = fax_info[((T30_INFO   *)plci->NL.RBuffer->P)->code];
           else
             info = _FAX_PROTOCOL_ERROR;
@@ -9564,7 +9564,7 @@ static struct
 
 };
 
-#define DTMF_DIGIT_MAP_ENTRIES (sizeof(dtmf_digit_map) / sizeof(dtmf_digit_map[0]))
+#define DTMF_DIGIT_MAP_ENTRIES ARRAY_SIZE(dtmf_digit_map)
 
 
 static void dtmf_enable_receiver (PLCI   *plci, byte enable_mask)
@@ -10069,8 +10069,7 @@ static byte dtmf_request (dword Id, word Number, DIVA_CAPI_ADAPTER   *a, PLCI
           PUT_WORD (&result[1], DTMF_INCORRECT_DIGIT);
           break;
         }
-        if (plci->dtmf_send_requests >=
-          sizeof(plci->dtmf_msg_number_queue) / sizeof(plci->dtmf_msg_number_queue[0]))
+        if (plci->dtmf_send_requests >= ARRAY_SIZE(plci->dtmf_msg_number_queue))
         {
           dbug (1, dprintf ("[%06lx] %s,%d: DTMF request overrun",
             UnMapId (Id), (char   *)(FILE_), __LINE__));
@@ -11018,9 +11017,9 @@ static byte xconnect_write_coefs_process (dword Id, PLCI   *plci, byte Rc)
             li_config_table[i].coef_table[j] ^= xconnect_write_prog[n].mask << 4;
           }
           n++;
-        } while ((n < sizeof(xconnect_write_prog) / sizeof(xconnect_write_prog[0]))
+        } while ((n < ARRAY_SIZE(xconnect_write_prog))
           && ((p - plci->internal_req_buffer) + 16 < INTERNAL_REQ_BUFFER_SIZE));
-        if (n == sizeof(xconnect_write_prog) / sizeof(xconnect_write_prog[0]))
+        if (n == ARRAY_SIZE(xconnect_write_prog))
         {
           do
           {
@@ -11090,7 +11089,7 @@ static byte xconnect_write_coefs_process (dword Id, PLCI   *plci, byte Rc)
             ch_map[j+1] = (byte)(j+1);
           }
         }
-        for (n = 0; n < sizeof(mixer_write_prog_bri) / sizeof(mixer_write_prog_bri[0]); n++)
+        for (n = 0; n < ARRAY_SIZE(mixer_write_prog_bri); n++)
         {
           i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
           j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
@@ -11140,7 +11139,7 @@ static byte xconnect_write_coefs_process (dword Id, PLCI   *plci, byte Rc)
           w |= MIXER_FEATURE_ENABLE_RX_DATA;
         *(p++) = (byte) w;
         *(p++) = (byte)(w >> 8);
-        for (n = 0; n < sizeof(mixer_write_prog_pri) / sizeof(mixer_write_prog_pri[0]); n++)
+        for (n = 0; n < ARRAY_SIZE(mixer_write_prog_pri); n++)
         {
           *(p++) = (byte)((plci->li_bchannel_id - 1) | mixer_write_prog_pri[n].line_flags);
           for (j = a->li_base; j < a->li_base + MIXER_CHANNELS_PRI; j++)
@@ -11196,7 +11195,7 @@ static byte xconnect_write_coefs_process (dword Id, PLCI   *plci, byte Rc)
             ch_map[j+1] = (byte)(j+1);
           }
         }
-        for (n = 0; n < sizeof(mixer_write_prog_bri) / sizeof(mixer_write_prog_bri[0]); n++)
+        for (n = 0; n < ARRAY_SIZE(mixer_write_prog_bri); n++)
         {
           i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
           j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
@@ -13178,7 +13177,7 @@ static void adv_voice_write_coefs (PLCI   *plci, word write_command)
         ch_map[j] = (byte)(j + (plci->li_bchannel_id - 1));
         ch_map[j+1] = (byte)(j + (2 - plci->li_bchannel_id));
       }
-      for (n = 0; n < sizeof(mixer_write_prog_bri) / sizeof(mixer_write_prog_bri[0]); n++)
+      for (n = 0; n < ARRAY_SIZE(mixer_write_prog_bri); n++)
       {
         i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
         j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
@@ -14603,7 +14602,7 @@ static void channel_request_xon (PLCI   * plci, byte ch) {
 
 static void channel_xmit_extended_xon (PLCI   * plci) {
   DIVA_CAPI_ADAPTER   * a;
-  int max_ch = sizeof(a->ch_flow_control)/sizeof(a->ch_flow_control[0]);
+  int max_ch = ARRAY_SIZE(a->ch_flow_control);
   int i, one_requested = 0;
 
   if ((!plci) || (!plci->Id) || ((a = plci->adapter) == 0)) {
@@ -14628,7 +14627,7 @@ static void channel_xmit_extended_xon (PLCI   * plci) {
   Try to xmit next X_ON
   */
 static int find_channel_with_pending_x_on (DIVA_CAPI_ADAPTER   * a, PLCI   * plci) {
-  int max_ch = sizeof(a->ch_flow_control)/sizeof(a->ch_flow_control[0]);
+  int max_ch = ARRAY_SIZE(a->ch_flow_control);
   int i;
 
   if (!(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)) {
diff --git a/drivers/isdn/hardware/eicon/platform.h b/drivers/isdn/hardware/eicon/platform.h
index 2444811..9ddae43 100644
--- a/drivers/isdn/hardware/eicon/platform.h
+++ b/drivers/isdn/hardware/eicon/platform.h
@@ -131,10 +131,6 @@
 #define DIVA_OS_MEM_DETACH_CONFIG(a, x)	do { } while(0)
 #define DIVA_OS_MEM_DETACH_CONTROL(a, x)	do { } while(0)
 
-#if !defined(DIM)
-#define DIM(array)  (sizeof (array)/sizeof ((array)[0]))
-#endif
-
 #define DIVA_INVALID_FILE_HANDLE  ((dword)(-1))
 
 #define DIVAS_CONTAINING_RECORD(address, type, field) \

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 64%]

* [PATCH 2.6.20] KVM: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 97% [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
  2007-02-06 16:03 83% ` [PATCH 2.6.20] DVB: Use ARRAY_SIZE macro when appropriate Ahmed S. Darwish
@ 2007-02-06 16:03 94% ` Ahmed S. Darwish
  2007-02-06 16:04 64% ` [PATCH 2.6.20] isdn-eicon: " Ahmed S. Darwish
                   ` (13 subsequent siblings)
  15 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-06 16:03 UTC (permalink / raw)
  To: avi; +Cc: linux-kernel, kvm-devel

Hi all,

A patch to use ARRAY_SIZE macro already defined in kernel.h

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
diff --git a/drivers/kvm/kvm_svm.h b/drivers/kvm/kvm_svm.h
index 74cc862..624f1ca 100644
--- a/drivers/kvm/kvm_svm.h
+++ b/drivers/kvm/kvm_svm.h
@@ -1,6 +1,7 @@
 #ifndef __KVM_SVM_H
 #define __KVM_SVM_H
 
+#include <linux/kernel.h>
 #include <linux/types.h>
 #include <linux/list.h>
 #include <asm/msr.h>
@@ -18,7 +19,7 @@ static const u32 host_save_msrs[] = {
 	MSR_IA32_LASTBRANCHTOIP, MSR_IA32_LASTINTFROMIP,MSR_IA32_LASTINTTOIP,*/
 };
 
-#define NR_HOST_SAVE_MSRS (sizeof(host_save_msrs) / sizeof(*host_save_msrs))
+#define NR_HOST_SAVE_MSRS ARRAY_SIZE(host_save_msrs)
 #define NUM_DB_REGS 4
 
 struct vcpu_svm {
diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
index c79df79..dc5c172 100644
--- a/drivers/kvm/svm.c
+++ b/drivers/kvm/svm.c
@@ -15,6 +15,7 @@
  */
 
 #include <linux/module.h>
+#include <linux/kernel.h>
 #include <linux/vmalloc.h>
 #include <linux/highmem.h>
 #include <linux/profile.h>
@@ -75,7 +76,7 @@ struct svm_init_data {
 
 static u32 msrpm_ranges[] = {0, 0xc0000000, 0xc0010000};
 
-#define NUM_MSR_MAPS (sizeof(msrpm_ranges) / sizeof(*msrpm_ranges))
+#define NUM_MSR_MAPS ARRAY_SIZE(msrpm_ranges)
 #define MSRS_RANGE_SIZE 2048
 #define MSRS_IN_RANGE (MSRS_RANGE_SIZE * 8 / 2)
 
@@ -1287,7 +1288,7 @@ static int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 		       __FUNCTION__, vcpu->svm->vmcb->control.exit_int_info,
 		       exit_code);
 
-	if (exit_code >= sizeof(svm_exit_handlers) / sizeof(*svm_exit_handlers)
+	if (exit_code >= ARRAY_SIZE(svm_exit_handlers)
 	    || svm_exit_handlers[exit_code] == 0) {
 		kvm_run->exit_reason = KVM_EXIT_UNKNOWN;
 		printk(KERN_ERR "%s: 0x%x @ 0x%llx cr0 0x%lx rflags 0x%llx\n",
diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index 54c35c0..072965b 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -19,6 +19,7 @@
 #include "vmx.h"
 #include "kvm_vmx.h"
 #include <linux/module.h>
+#include <linux/kernel.h>
 #include <linux/mm.h>
 #include <linux/highmem.h>
 #include <linux/profile.h>
@@ -76,7 +77,7 @@ static const u32 vmx_msr_index[] = {
 #endif
 	MSR_EFER, MSR_K6_STAR,
 };
-#define NR_VMX_MSR (sizeof(vmx_msr_index) / sizeof(*vmx_msr_index))
+#define NR_VMX_MSR ARRAY_SIZE(vmx_msr_index)
 
 static inline int is_page_fault(u32 intr_info)
 {
@@ -1645,8 +1646,7 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu,
 	[EXIT_REASON_HLT]                     = handle_halt,
 };
 
-static const int kvm_vmx_max_exit_handlers =
-	sizeof(kvm_vmx_exit_handlers) / sizeof(*kvm_vmx_exit_handlers);
+static const int kvm_vmx_max_exit_handlers = ARRAY_SIZE(kvm_vmx_exit_handlers);
 
 /*
  * The guest has exited.  See if we can fix it or if we need userspace


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 94%]

* [PATCH 2.6.20] DVB: Use ARRAY_SIZE macro when appropriate
  2007-02-06 16:02 97% [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
@ 2007-02-06 16:03 83% ` Ahmed S. Darwish
  2007-02-06 16:03 94% ` [PATCH 2.6.20] KVM: " Ahmed S. Darwish
                   ` (14 subsequent siblings)
  15 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-06 16:03 UTC (permalink / raw)
  To: v4l-dvb-maintainer; +Cc: linux-kernel

Hi all,

A patch to use ARRAY_SIZE macro already defined in kernel.h

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
Patch is compile-tested.

diff --git a/drivers/media/dvb/bt8xx/dst.c b/drivers/media/dvb/bt8xx/dst.c
index 9f72b70..0393a3d 100644
--- a/drivers/media/dvb/bt8xx/dst.c
+++ b/drivers/media/dvb/bt8xx/dst.c
@@ -1161,7 +1161,7 @@ static int dst_get_device_id(struct dst_state *state)
 		}
 	}
 
-	if (i >= sizeof (dst_tlist) / sizeof (dst_tlist [0])) {
+	if (i >= ARRAY_SIZE(dst_tlist)) {
 		dprintk(verbose, DST_ERROR, 1, "Unable to recognize %s or %s", &state->rxbuffer[0], &state->rxbuffer[1]);
 		dprintk(verbose, DST_ERROR, 1, "please email linux-dvb@linuxtv.org with this type in");
 		use_dst_type = DST_TYPE_IS_SAT;
diff --git a/drivers/media/dvb/bt8xx/dvb-bt8xx.c b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
index 3e35931..5185a3c 100644
--- a/drivers/media/dvb/bt8xx/dvb-bt8xx.c
+++ b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
@@ -23,6 +23,7 @@
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/init.h>
+#include <linux/kernel.h>
 #include <linux/device.h>
 #include <linux/delay.h>
 #include <linux/slab.h>
@@ -213,7 +214,7 @@ static int cx24108_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend
 		freq = 2150000; /* satellite IF is 950..2150MHz */
 
 	/* decide which VCO to use for the input frequency */
-	for(i=1;(i<sizeof(osci)/sizeof(osci[0]))&&(osci[i]<freq);i++);
+	for(i=1;(i<ARRAY_SIZE(osci))&&(osci[i]<freq);i++);
 	printk("cx24108 debug: select vco #%d (f=%d)\n",i,freq);
 	band=bandsel[i];
 	/* the gain values must be set by SetSymbolrate */
diff --git a/drivers/media/dvb/frontends/cx24110.c b/drivers/media/dvb/frontends/cx24110.c
index ae96395..96ae6b1 100644
--- a/drivers/media/dvb/frontends/cx24110.c
+++ b/drivers/media/dvb/frontends/cx24110.c
@@ -254,7 +254,7 @@ static int cx24110_set_symbolrate (struct cx24110_state* state, u32 srate)
 	if (srate<500000)
 		srate=500000;
 
-	for(i=0;(i<sizeof(bands)/sizeof(bands[0]))&&(srate>bands[i]);i++)
+	for(i=0;(i<ARRAY_SIZE(bands))&&(srate>bands[i]);i++)
 		;
 	/* first, check which sample rate is appropriate: 45, 60 80 or 90 MHz,
 	   and set the PLL accordingly (R07[1:0] Fclk, R06[7:4] PLLmult,
@@ -361,7 +361,7 @@ static int cx24110_initfe(struct dvb_frontend* fe)
 
 	dprintk("%s: init chip\n", __FUNCTION__);
 
-	for(i=0;i<sizeof(cx24110_regdata)/sizeof(cx24110_regdata[0]);i++) {
+	for(i=0;i<ARRAY_SIZE(cx24110_regdata);i++) {
 		cx24110_writereg(state, cx24110_regdata[i].reg, cx24110_regdata[i].data);
 	};
 
diff --git a/drivers/media/dvb/frontends/cx24123.c b/drivers/media/dvb/frontends/cx24123.c
index a356d28..732e94a 100644
--- a/drivers/media/dvb/frontends/cx24123.c
+++ b/drivers/media/dvb/frontends/cx24123.c
@@ -507,7 +507,7 @@ static int cx24123_pll_calculate(struct dvb_frontend* fe, struct dvb_frontend_pa
 	int i = 0;
 	int pump = 2;
 	int band = 0;
-	int num_bands = sizeof(cx24123_bandselect_vals) / sizeof(cx24123_bandselect_vals[0]);
+	int num_bands = ARRAY_SIZE(cx24123_bandselect_vals);
 
 	/* Defaults for low freq, low rate */
 	state->VCAarg = cx24123_AGC_vals[0].VCAprogdata;
@@ -516,7 +516,7 @@ static int cx24123_pll_calculate(struct dvb_frontend* fe, struct dvb_frontend_pa
 	vco_div = cx24123_bandselect_vals[0].VCOdivider;
 
 	/* For the given symbol rate, determine the VCA, VGA and FILTUNE programming bits */
-	for (i = 0; i < sizeof(cx24123_AGC_vals) / sizeof(cx24123_AGC_vals[0]); i++)
+	for (i = 0; i < ARRAY_SIZE(cx24123_AGC_vals); i++)
 	{
 		if ((cx24123_AGC_vals[i].symbolrate_low <= p->u.qpsk.symbol_rate) &&
 		    (cx24123_AGC_vals[i].symbolrate_high >= p->u.qpsk.symbol_rate) ) {
@@ -658,7 +658,7 @@ static int cx24123_initfe(struct dvb_frontend* fe)
 	dprintk("%s:  init frontend\n",__FUNCTION__);
 
 	/* Configure the demod to a good set of defaults */
-	for (i = 0; i < sizeof(cx24123_regdata) / sizeof(cx24123_regdata[0]); i++)
+	for (i = 0; i < ARRAY_SIZE(cx24123_regdata); i++)
 		cx24123_writereg(state, cx24123_regdata[i].reg, cx24123_regdata[i].data);
 
 	/* Set the LNB polarity */
diff --git a/drivers/media/dvb/ttpci/av7110_ir.c b/drivers/media/dvb/ttpci/av7110_ir.c
index e4544ea..c281d78 100644
--- a/drivers/media/dvb/ttpci/av7110_ir.c
+++ b/drivers/media/dvb/ttpci/av7110_ir.c
@@ -4,6 +4,7 @@
 #include <linux/moduleparam.h>
 #include <linux/input.h>
 #include <linux/proc_fs.h>
+#include <linux/kernel.h>
 #include <asm/bitops.h>
 
 #include "av7110.h"
@@ -217,7 +218,7 @@ int __devinit av7110_ir_init(struct av7110 *av7110)
 	static struct proc_dir_entry *e;
 	int err;
 
-	if (av_cnt >= sizeof av_list/sizeof av_list[0])
+	if (av_cnt >= ARRAY_SIZE(av_list))
 		return -ENOSPC;
 
 	av7110_setup_irc_config(av7110, 0x0001);

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 83%]

* [PATCH 00] A series of patches to use ARRAY_SIZE macro
@ 2007-02-06 16:02 97% Ahmed S. Darwish
  2007-02-06 16:03 83% ` [PATCH 2.6.20] DVB: Use ARRAY_SIZE macro when appropriate Ahmed S. Darwish
                   ` (15 more replies)
  0 siblings, 16 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-06 16:02 UTC (permalink / raw)
  To: linux-kernel

Hi lovely list :),

Follows (as thread replies) is a series of patches to use ARRAY_SIZE 
macro defined in kernel.h.

It's complementary to previous patch serieses that dealt with this 
issue under `video' (drivers/media/video), `net' (drivers/net) and 
`arch' subtrees.

 drivers/acpi/toshiba_acpi.c            |    2 +-
 drivers/atm/he.c                       |    2 +-
 drivers/atm/idt77252.c                 |    8 ++++----
 drivers/atm/nicstarmac.c               |    4 +++-
 drivers/char/agp/intel-agp.c           |    3 ++-
 drivers/char/drm/drm_proc.c            |    2 +-
 drivers/infiniband/core/device.c       |    3 ++-
 drivers/isdn/capi/capi.c               |    4 ++--
 drivers/isdn/capi/capidrv.c            |    4 ++--
 drivers/isdn/hardware/eicon/debug.c    |   30 +++++++++++++++---------------
 drivers/isdn/hardware/eicon/message.c  |   23 +++++++++++------------
 drivers/isdn/hardware/eicon/platform.h |    4 ----
 drivers/kvm/kvm_svm.h                  |    3 ++-
 drivers/kvm/svm.c                      |    5 +++--
 drivers/kvm/vmx.c                      |    6 +++---
 drivers/md/md.c                        |    6 +++---
 drivers/media/dvb/bt8xx/dst.c          |    2 +-
 drivers/media/dvb/bt8xx/dvb-bt8xx.c    |    3 ++-
 drivers/media/dvb/frontends/cx24110.c  |    4 ++--
 drivers/media/dvb/frontends/cx24123.c  |    6 +++---
 drivers/media/dvb/ttpci/av7110_ir.c    |    3 ++-
 drivers/s390/cio/device_id.c           |    3 ++-
 drivers/w1/slaves/w1_therm.c           |    6 +++---
 fs/reiserfs/do_balan.c                 |    5 +++--
 kernel/rcutorture.c                    |    2 +-
 sound/oss/au1550_ac97.c                |    4 ++--
 sound/oss/es1371.c                     |    3 ++-
 sound/oss/nec_vrc5477.c                |    4 ++--
 sound/oss/soundcard.c                  |    5 +++--
 sound/oss/swarm_cs4297a.c              |    3 ++-
 30 files changed, 85 insertions(+), 77 deletions(-)

Thanks,
-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 97%]

* Re: [PATCH 2.6.20] ixgb: Use ARRAY_SIZE macro when appropriate
  @ 2007-02-06 10:00 99%       ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-06 10:00 UTC (permalink / raw)
  To: Auke Kok; +Cc: Alexey Dobriyan, jeffrey.t.kirsher, linux-kernel, netdev

On Mon, Feb 05, 2007 at 12:31:26PM -0800, Auke Kok wrote:
> Alexey Dobriyan wrote:
> >On Mon, Feb 05, 2007 at 06:59:33PM +0200, Ahmed S. Darwish wrote:
> >>A patch to use ARRAY_SIZE macro already defined in kernel.h.
> >
> >Remove it and use ARRAY_SIZE instead.
> >
> >>--- a/drivers/net/ixgb/ixgb_param.c
> >>+++ b/drivers/net/ixgb/ixgb_param.c
> >>@@ -245,7 +245,7 @@ ixgb_validate_option(int *value, struct ixgb_option 
> >>*opt)
> >> 	return -1;
> >> }
> >> 
> >>-#define LIST_LEN(l) (sizeof(l) / sizeof(l[0]))
> >>+#define LIST_LEN(l) ARRAY_SIZE(l)
> 
> yes, well spotted. Please change line 338 in this file to read:
> 
>      .arg  = { .l = { .nr = ARRAY_SIZE(fc_list),
> 
> instead, so you can remove the LIST_LEN macro completely.
 
Thanks, Here's the new patch.

Use ARRAY_SIZE macro when appropriate.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
diff --git a/drivers/net/ixgb/ixgb_param.c b/drivers/net/ixgb/ixgb_param.c
index b27442a..c38ce73 100644
--- a/drivers/net/ixgb/ixgb_param.c
+++ b/drivers/net/ixgb/ixgb_param.c
@@ -245,8 +245,6 @@ ixgb_validate_option(int *value, struct ixgb_option *opt)
 	return -1;
 }
 
-#define LIST_LEN(l) (sizeof(l) / sizeof(l[0]))
-
 /**
  * ixgb_check_options - Range Checking for Command Line Parameters
  * @adapter: board private structure
@@ -335,7 +333,7 @@ ixgb_check_options(struct ixgb_adapter *adapter)
 			.name = "Flow Control",
 			.err  = "reading default settings from EEPROM",
 			.def  = ixgb_fc_tx_pause,
-			.arg  = { .l = { .nr = LIST_LEN(fc_list),
+			.arg  = { .l = { .nr = ARRAY_SIZE(fc_list),
 					 .p = fc_list }}
 		};


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH 2.6.20] wavelan: Use ARRAY_SIZE macro when appropriate
  @ 2007-02-06  9:34 90%     ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-06  9:34 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: jt, linville, linux-kernel, netdev

On Mon, Feb 05, 2007 at 11:17:09PM +0300, Alexey Dobriyan wrote:
> On Mon, Feb 05, 2007 at 07:00:44PM +0200, Ahmed S. Darwish wrote:
> > A trivial patch to use ARRAY_SIZE macro.
> 
> You're supposed to remove it ans use ARRAY_SIZE where old macro is used.
> 
> > --- a/drivers/net/wireless/wavelan.p.h
> > +++ b/drivers/net/wireless/wavelan.p.h
> > @@ -450,7 +450,7 @@ static const char	*version	= "wavelan.c : v24 (SMP + wireless extensions) 11/12/
> >  #define	WATCHDOG_JIFFIES	(512*HZ/100)
> >
> >  /* Macro to get the number of elements in an array */
> > -#define	NELS(a)				(sizeof(a) / sizeof(a[0]))
> > +#define	NELS(a)				ARRAY_SIZE(a)

Ooh, how dumb the original patch is :). Thanks, here's the modified patch.

A patch to use ARRAY_SIZE macro when appropriate.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
diff --git a/drivers/net/wireless/wavelan.c b/drivers/net/wireless/wavelan.c
index 24221e4..2aa3c76 100644
--- a/drivers/net/wireless/wavelan.c
+++ b/drivers/net/wireless/wavelan.c
@@ -28,7 +28,7 @@
  */
 static u8 wv_irq_to_psa(int irq)
 {
-	if (irq < 0 || irq >= NELS(irqvals))
+	if (irq < 0 || irq >= ARRAY_SIZE(irqvals))
 		return 0;
 
 	return irqvals[irq];
@@ -42,7 +42,7 @@ static int __init wv_psa_to_irq(u8 irqval)
 {
 	int irq;
 
-	for (irq = 0; irq < NELS(irqvals); irq++)
+	for (irq = 0; irq < ARRAY_SIZE(irqvals); irq++)
 		if (irqvals[irq] == irqval)
 			return irq;
 
@@ -1695,7 +1695,7 @@ static int wv_frequency_list(unsigned long ioaddr,	/* I/O port of the card */
 		/* Look in the table if the frequency is allowed */
 		if (table[9 - (freq / 16)] & (1 << (freq % 16))) {
 			/* Compute approximate channel number */
-			while ((c < NELS(channel_bands)) &&
+			while ((c < ARRAY_SIZE(channel_bands)) &&
 				(((channel_bands[c] >> 1) - 24) < freq)) 
 				c++;
 			list[i].i = c;	/* Set the list index */
@@ -4269,7 +4269,7 @@ struct net_device * __init wavelan_probe(int unit)
 		printk(KERN_DEBUG "%s: <-wavelan_probe()\n", dev->name);
 #endif
 	} else { /* Scan all possible addresses of the WaveLAN hardware. */
-		for (i = 0; i < NELS(iobase); i++) {
+		for (i = 0; i < ARRAY_SIZE(iobase); i++) {
 			dev->irq = def_irq;
 			if (wavelan_config(dev, iobase[i]) == 0) {
 #ifdef DEBUG_CALLBACK_TRACE
@@ -4280,7 +4280,7 @@ struct net_device * __init wavelan_probe(int unit)
 				break;
 			}
 		}
-		if (i == NELS(iobase))
+		if (i == ARRAY_SIZE(iobase))
 			r = -ENODEV;
 	}
 	if (r) 
@@ -4327,14 +4327,14 @@ int __init init_module(void)
 #endif
 
 		/* Copy the basic set of address to be probed. */
-		for (i = 0; i < NELS(iobase); i++)
+		for (i = 0; i < ARRAY_SIZE(iobase); i++)
 			io[i] = iobase[i];
 	}
 
 
 	/* Loop on all possible base addresses. */
 	i = -1;
-	while ((io[++i] != 0) && (i < NELS(io))) {
+	while ((io[++i] != 0) && (i < ARRAY_SIZE(io))) {
 		struct net_device *dev = alloc_etherdev(sizeof(net_local));
 		if (!dev)
 			break;
diff --git a/drivers/net/wireless/wavelan.p.h b/drivers/net/wireless/wavelan.p.h
index 72b646c..fe24281 100644
--- a/drivers/net/wireless/wavelan.p.h
+++ b/drivers/net/wireless/wavelan.p.h
@@ -449,9 +449,6 @@ static const char	*version	= "wavelan.c : v24 (SMP + wireless extensions) 11/12/
 /* Watchdog temporisation */
 #define	WATCHDOG_JIFFIES	(512*HZ/100)
 
-/* Macro to get the number of elements in an array */
-#define	NELS(a)				(sizeof(a) / sizeof(a[0]))
-
 /* ------------------------ PRIVATE IOCTL ------------------------ */
 
 #define SIOCSIPQTHR	SIOCIWFIRSTPRIV		/* Set quality threshold */

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 90%]

* Re: [PATCH 2.6.20] ibm_emac: Use ARRAY_SIZE macro when appropriate
  @ 2007-02-06  9:12 99%     ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-06  9:12 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: ebs, linux-kernel, netdev, linuxppc-embedded

On Mon, Feb 05, 2007 at 11:22:06PM +0300, Alexey Dobriyan wrote:
> On Mon, Feb 05, 2007 at 06:59:16PM +0200, Ahmed S. Darwish wrote:
> > A patch to use ARRAY_SIZE macro already defined in kernel.h.
> 
> OK, but checks you're changing are strange. idx there is signed so
> 
> 	BUG_ON(idx < 0 || idx > ARRAY_SIZE());
> 
> should be more appropriate.

It's just a janitor patch. I don't like to mess with code logic in such
kind of patches (to minimize errors and because I can't find time to
understand all affected files since they are scattered allover the tree).

Thanks,
-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.20] ipw2100: Use ARRAY_SIZE macro when appropriate
  2007-02-05 16:54 99% [PATCH 00] A series of patches to use ARRAY_SIZE in `net' drivers Ahmed S. Darwish
  2007-02-05 16:55 99% ` [PATCH 2.6.20] e1000: Use ARRAY_SIZE macro when appropriate Ahmed S. Darwish
@ 2007-02-05 16:56 95% ` Ahmed S. Darwish
  2007-02-05 16:56 73% ` [PATCH 01/02] misc-net-drivers: " Ahmed S. Darwish
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-05 16:56 UTC (permalink / raw)
  To: yi.zhu, linville; +Cc: linux-kernel, netdev

Hi all,

A patch to use ARRAY_SIZE macro already defined in kernel.h.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
Patch is compile tested.

diff --git a/drivers/net/wireless/ipw2100.c b/drivers/net/wireless/ipw2100.c
index b85857a..a9d944a 100644
--- a/drivers/net/wireless/ipw2100.c
+++ b/drivers/net/wireless/ipw2100.c
@@ -2888,7 +2888,7 @@ static int __ipw2100_tx_process(struct ipw2100_priv *priv)
 
 #ifdef CONFIG_IPW2100_DEBUG
 		if (packet->info.c_struct.cmd->host_command_reg <
-		    sizeof(command_types) / sizeof(*command_types))
+		    ARRAY_SIZE(command_types))
 			IPW_DEBUG_TX("Command '%s (%d)' processed: %d.\n",
 				     command_types[packet->info.c_struct.cmd->
 						   host_command_reg],
@@ -3736,7 +3736,7 @@ static ssize_t show_registers(struct device *d, struct device_attribute *attr,
 
 	out += sprintf(out, "%30s [Address ] : Hex\n", "Register");
 
-	for (i = 0; i < (sizeof(hw_data) / sizeof(*hw_data)); i++) {
+	for (i = 0; i < ARRAY_SIZE(hw_data); i++) {
 		read_register(dev, hw_data[i].addr, &val);
 		out += sprintf(out, "%30s [%08X] : %08X\n",
 			       hw_data[i].name, hw_data[i].addr, val);
@@ -3757,7 +3757,7 @@ static ssize_t show_hardware(struct device *d, struct device_attribute *attr,
 
 	out += sprintf(out, "%30s [Address ] : Hex\n", "NIC entry");
 
-	for (i = 0; i < (sizeof(nic_data) / sizeof(*nic_data)); i++) {
+	for (i = 0; i < ARRAY_SIZE(nic_data); i++) {
 		u8 tmp8;
 		u16 tmp16;
 		u32 tmp32;
@@ -3894,13 +3894,11 @@ static ssize_t show_ordinals(struct device *d, struct device_attribute *attr,
 	if (priv->status & STATUS_RF_KILL_MASK)
 		return 0;
 
-	if (loop >= sizeof(ord_data) / sizeof(*ord_data))
+	if (loop >= ARRAY_SIZE(ord_data))
 		loop = 0;
 
 	/* sysfs provides us PAGE_SIZE buffer */
-	while (len < PAGE_SIZE - 128 &&
-	       loop < (sizeof(ord_data) / sizeof(*ord_data))) {
-
+	while (len < PAGE_SIZE - 128 && loop < ARRAY_SIZE(ord_data)) {
 		val_len = sizeof(u32);
 
 		if (ipw2100_get_ordinal(priv, ord_data[loop].index, &val,
@@ -6589,7 +6587,7 @@ static const long ipw2100_rates_11b[] = {
 	11000000
 };
 
-#define RATE_COUNT (sizeof(ipw2100_rates_11b) / sizeof(ipw2100_rates_11b[0]))
+#define RATE_COUNT ARRAY_SIZE(ipw2100_rates_11b)
 
 static int ipw2100_wx_get_name(struct net_device *dev,
 			       struct iw_request_info *info,


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 95%]

* [PATCH 2.6.20] wavelan: Use ARRAY_SIZE macro when appropriate
  2007-02-05 16:54 99% [PATCH 00] A series of patches to use ARRAY_SIZE in `net' drivers Ahmed S. Darwish
                   ` (6 preceding siblings ...)
  2007-02-05 16:59 99% ` [PATCH 2.6.20] ixgb: " Ahmed S. Darwish
@ 2007-02-05 17:00 99% ` Ahmed S. Darwish
    7 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2007-02-05 17:00 UTC (permalink / raw)
  To: jt, linville; +Cc: linux-kernel, netdev

Hi,

A trivial patch to use ARRAY_SIZE macro.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
diff --git a/drivers/net/wireless/wavelan.p.h b/drivers/net/wireless/wavelan.p.h
index 72b646c..fe12c77 100644
--- a/drivers/net/wireless/wavelan.p.h
+++ b/drivers/net/wireless/wavelan.p.h
@@ -450,7 +450,7 @@ static const char	*version	= "wavelan.c : v24 (SMP + wireless extensions) 11/12/
 #define	WATCHDOG_JIFFIES	(512*HZ/100)
 
 /* Macro to get the number of elements in an array */
-#define	NELS(a)				(sizeof(a) / sizeof(a[0]))
+#define	NELS(a)				ARRAY_SIZE(a)
 
 /* ------------------------ PRIVATE IOCTL ------------------------ */
 



-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.20] ixgb: Use ARRAY_SIZE macro when appropriate
  2007-02-05 16:54 99% [PATCH 00] A series of patches to use ARRAY_SIZE in `net' drivers Ahmed S. Darwish
                   ` (5 preceding siblings ...)
  2007-02-05 16:59 99% ` [PATCH 2.6.20] ibm_emac: " Ahmed S. Darwish
@ 2007-02-05 16:59 99% ` Ahmed S. Darwish
    2007-02-05 17:00 99% ` [PATCH 2.6.20] wavelan: " Ahmed S. Darwish
  7 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2007-02-05 16:59 UTC (permalink / raw)
  To: jeffrey.t.kirsher; +Cc: linux-kernel, netdev

Hi,

A patch to use ARRAY_SIZE macro already defined in kernel.h.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
diff --git a/drivers/net/ixgb/ixgb_param.c b/drivers/net/ixgb/ixgb_param.c
index b27442a..26031fe 100644
--- a/drivers/net/ixgb/ixgb_param.c
+++ b/drivers/net/ixgb/ixgb_param.c
@@ -245,7 +245,7 @@ ixgb_validate_option(int *value, struct ixgb_option *opt)
 	return -1;
 }
 
-#define LIST_LEN(l) (sizeof(l) / sizeof(l[0]))
+#define LIST_LEN(l) ARRAY_SIZE(l)
 
 /**
  * ixgb_check_options - Range Checking for Command Line Parameters


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.20] ibm_emac: Use ARRAY_SIZE macro when appropriate
  2007-02-05 16:54 99% [PATCH 00] A series of patches to use ARRAY_SIZE in `net' drivers Ahmed S. Darwish
                   ` (4 preceding siblings ...)
  2007-02-05 16:58 99% ` [PATCH 2.6.20] hostap: " Ahmed S. Darwish
@ 2007-02-05 16:59 99% ` Ahmed S. Darwish
    2007-02-05 16:59 99% ` [PATCH 2.6.20] ixgb: " Ahmed S. Darwish
  2007-02-05 17:00 99% ` [PATCH 2.6.20] wavelan: " Ahmed S. Darwish
  7 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2007-02-05 16:59 UTC (permalink / raw)
  To: ebs; +Cc: linux-kernel, netdev, linuxppc-embedded

Hi,

A patch to use ARRAY_SIZE macro already defined in kernel.h.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
Patch isn't compile-tested cause I don't have the needed hardware.

diff --git a/drivers/net/ibm_emac/ibm_emac_debug.c b/drivers/net/ibm_emac/ibm_emac_debug.c
index 92f970d..1f70906 100644
--- a/drivers/net/ibm_emac/ibm_emac_debug.c
+++ b/drivers/net/ibm_emac/ibm_emac_debug.c
@@ -132,7 +132,7 @@ void emac_dbg_register(int idx, struct ocp_enet_private *dev)
 {
 	unsigned long flags;
 
-	if (idx >= sizeof(__emacs) / sizeof(__emacs[0])) {
+	if (idx >= ARRAY_SIZE(__emacs)) {
 		printk(KERN_WARNING
 		       "invalid index %d when registering EMAC for debugging\n",
 		       idx);
@@ -148,7 +148,7 @@ void mal_dbg_register(int idx, struct ibm_ocp_mal *mal)
 {
 	unsigned long flags;
 
-	if (idx >= sizeof(__mals) / sizeof(__mals[0])) {
+	if (idx >= ARRAY_SIZE(__mals)) {
 		printk(KERN_WARNING
 		       "invalid index %d when registering MAL for debugging\n",
 		       idx);
@@ -167,11 +167,11 @@ void emac_dbg_dump_all(void)
 
 	local_irq_save(flags);
 
-	for (i = 0; i < sizeof(__mals) / sizeof(__mals[0]); ++i)
+	for (i = 0; i < ARRAY_SIZE(__mals); ++i)
 		if (__mals[i])
 			emac_mal_dump(__mals[i]);
 
-	for (i = 0; i < sizeof(__emacs) / sizeof(__emacs[0]); ++i)
+	for (i = 0; i < ARRAY_SIZE(__emacs); ++i)
 		if (__emacs[i])
 			emac_mac_dump(i, __emacs[i]);
 

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.20] hostap: Use ARRAY_SIZE macro when appropriate
  2007-02-05 16:54 99% [PATCH 00] A series of patches to use ARRAY_SIZE in `net' drivers Ahmed S. Darwish
                   ` (3 preceding siblings ...)
  2007-02-05 16:58 99% ` [PATCH 2.6.20] misc-wireless: " Ahmed S. Darwish
@ 2007-02-05 16:58 99% ` Ahmed S. Darwish
  2007-02-05 16:59 99% ` [PATCH 2.6.20] ibm_emac: " Ahmed S. Darwish
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-05 16:58 UTC (permalink / raw)
  To: jkmaline, linville; +Cc: linux-kernel, netdev

Hi,

A patch to use ARRAY_SIZE macro in the Host AP wireless driver.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
Patch is compile tested.

diff --git a/drivers/net/wireless/hostap/hostap.h b/drivers/net/wireless/hostap/hostap.h
index e89c890..ef37a75 100644
--- a/drivers/net/wireless/hostap/hostap.h
+++ b/drivers/net/wireless/hostap/hostap.h
@@ -2,13 +2,14 @@
 #define HOSTAP_H
 
 #include <linux/ethtool.h>
+#include <linux/kernel.h>
 
 #include "hostap_wlan.h"
 #include "hostap_ap.h"
 
 static const long freq_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442,
 				  2447, 2452, 2457, 2462, 2467, 2472, 2484 };
-#define FREQ_COUNT (sizeof(freq_list) / sizeof(freq_list[0]))
+#define FREQ_COUNT ARRAY_SIZE(freq_list)
 
 /* hostap.c */
 

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.20] misc-wireless: Use ARRAY_SIZE macro when appropriate
  2007-02-05 16:54 99% [PATCH 00] A series of patches to use ARRAY_SIZE in `net' drivers Ahmed S. Darwish
                   ` (2 preceding siblings ...)
  2007-02-05 16:56 73% ` [PATCH 01/02] misc-net-drivers: " Ahmed S. Darwish
@ 2007-02-05 16:58 99% ` Ahmed S. Darwish
  2007-02-05 16:58 99% ` [PATCH 2.6.20] hostap: " Ahmed S. Darwish
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-05 16:58 UTC (permalink / raw)
  To: linville; +Cc: linux-kernel, netdev

Hi,

A patch to use ARRAY_SIZE macro already defined in kernel.h for some
miscellaneous wireless drivers with no specific maintaners.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
Patch is compile tested.

diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
index 44a2270..4ad910b 100644
--- a/drivers/net/wireless/airo.c
+++ b/drivers/net/wireless/airo.c
@@ -1623,7 +1623,7 @@ static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen,
 
 	crypto_cipher_setkey(tfm, pkey, 16);
 	counter = 0;
-	for (i = 0; i < (sizeof(context->coeff)/sizeof(context->coeff[0])); ) {
+	for (i = 0; i < ARRAY_SIZE(context->coeff); ) {
 		aes_counter[15] = (u8)(counter >> 0);
 		aes_counter[14] = (u8)(counter >> 8);
 		aes_counter[13] = (u8)(counter >> 16);
@@ -1632,7 +1632,7 @@ static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen,
 		memcpy (plain, aes_counter, 16);
 		crypto_cipher_encrypt_one(tfm, plain, plain);
 		cipher = plain;
-		for (j=0; (j<16) && (i< (sizeof(context->coeff)/sizeof(context->coeff[0]))); ) {
+		for (j = 0; (j < 16) && (i < ARRAY_SIZE(context->coeff)); ) {
 			context->coeff[i++] = ntohl(*(u32 *)&cipher[j]);
 			j += 4;
 		}
diff --git a/drivers/net/wireless/prism54/oid_mgt.c b/drivers/net/wireless/prism54/oid_mgt.c
index e6cf9df..4278032 100644
--- a/drivers/net/wireless/prism54/oid_mgt.c
+++ b/drivers/net/wireless/prism54/oid_mgt.c
@@ -16,6 +16,8 @@
  *
  */
 
+#include <linux/kernel.h>
+
 #include "prismcompat.h"
 #include "islpci_dev.h"
 #include "islpci_mgt.h"
@@ -692,7 +694,7 @@ mgt_update_addr(islpci_private *priv)
 	return ret;
 }
 
-#define VEC_SIZE(a) (sizeof(a)/sizeof(a[0]))
+#define VEC_SIZE(a) ARRAY_SIZE(a)
 
 int
 mgt_commit(islpci_private *priv)



-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 02/02] misc-net-drivers: Use ARRAY_SIZE macro when appropriate
  2007-02-05 16:56 73% ` [PATCH 01/02] misc-net-drivers: " Ahmed S. Darwish
@ 2007-02-05 16:57 92%   ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-05 16:57 UTC (permalink / raw)
  To: linux-kernel, netdev

Hi,

A 2.6.20 patch to use ARRAY_SIZE macro already defined in kernel.h for some
miscellaneous network drivers with no specific maintaners.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
Patch isn't compile-tested due to missing hardware.

diff --git a/drivers/net/apne.c b/drivers/net/apne.c
index 9541911..8806151 100644
--- a/drivers/net/apne.c
+++ b/drivers/net/apne.c
@@ -247,7 +247,7 @@ static int __init apne_probe1(struct net_device *dev, int ioaddr)
 	    {0x00,	NE_EN0_RSARHI},
 	    {E8390_RREAD+E8390_START, NE_CMD},
 	};
-	for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++) {
+	for (i = 0; i < ARRAY_SIZE(program_seq); i++) {
 	    outb(program_seq[i].value, ioaddr + program_seq[i].offset);
 	}
 
diff --git a/drivers/net/arm/am79c961a.c b/drivers/net/arm/am79c961a.c
index ddd12d4..200cbc0 100644
--- a/drivers/net/arm/am79c961a.c
+++ b/drivers/net/arm/am79c961a.c
@@ -414,7 +414,7 @@ static void am79c961_setmulticastlist (struct net_device *dev)
 	/*
 	 * Update the multicast hash table
 	 */
-	for (i = 0; i < sizeof(multi_hash) / sizeof(multi_hash[0]); i++)
+	for (i = 0; i < ARRAY_SIZE(multi_hash); i++)
 		write_rreg(dev->base_addr, i + LADRL, multi_hash[i]);
 
 	/*
diff --git a/drivers/net/atarilance.c b/drivers/net/atarilance.c
index 7e37ac8..ef18428 100644
--- a/drivers/net/atarilance.c
+++ b/drivers/net/atarilance.c
@@ -263,7 +263,7 @@ struct lance_addr {
 									   (highest byte stripped) */
 };
 
-#define	N_LANCE_ADDR	(sizeof(lance_addr_list)/sizeof(*lance_addr_list))
+#define	N_LANCE_ADDR	ARRAY_SIZE(lance_addr_list)
 
 
 /* Definitions for the Lance */
diff --git a/drivers/net/fec_8xx/fec_mii.c b/drivers/net/fec_8xx/fec_mii.c
index d3c16b8..1fc2b43 100644
--- a/drivers/net/fec_8xx/fec_mii.c
+++ b/drivers/net/fec_8xx/fec_mii.c
@@ -310,12 +310,12 @@ int fec_mii_phy_id_detect(struct net_device *dev)
 		return -1;
 	}
 
-	for (i = 0, phy = phy_info; i < sizeof(phy_info) / sizeof(phy_info[0]);
+	for (i = 0, phy = phy_info; i < ARRAY_SIZE(phy_info));
 	     i++, phy++)
 		if (phy->id == (phy_hwid >> 4) || phy->id == 0)
 			break;
 
-	if (i >= sizeof(phy_info) / sizeof(phy_info[0])) {
+	if (i >= ARRAY_SIZE(phy_info)) {
 		printk(KERN_ERR DRV_MODULE_NAME
 		       ": %s PHY id 0x%08x is not supported!\n",
 		       dev->name, phy_hwid);
diff --git a/drivers/net/ne-h8300.c b/drivers/net/ne-h8300.c
index 38fd525..7599d77 100644
--- a/drivers/net/ne-h8300.c
+++ b/drivers/net/ne-h8300.c
@@ -259,7 +259,7 @@ static int __init ne_probe1(struct net_device *dev, int ioaddr)
 			{E8390_RREAD+E8390_START, E8390_CMD},
 		};
 
-		for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++)
+		for (i = 0; i < ARRAY_SIZE(program_seq); i++)
 			outb_p(program_seq[i].value, ioaddr + program_seq[i].offset);
 
 	}
diff --git a/drivers/net/zorro8390.c b/drivers/net/zorro8390.c
index d85e2ea..29f9750 100644
--- a/drivers/net/zorro8390.c
+++ b/drivers/net/zorro8390.c
@@ -191,7 +191,7 @@ static int __devinit zorro8390_init(struct net_device *dev,
 	    {0x00,	NE_EN0_RSARHI},
 	    {E8390_RREAD+E8390_START, NE_CMD},
 	};
-	for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++) {
+	for (i = 0; i < ARRAY_SIZE(program_seq); i++) {
 	    z_writeb(program_seq[i].value, ioaddr + program_seq[i].offset);
 	}
     }


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 92%]

* [PATCH 01/02] misc-net-drivers: Use ARRAY_SIZE macro when appropriate
  2007-02-05 16:54 99% [PATCH 00] A series of patches to use ARRAY_SIZE in `net' drivers Ahmed S. Darwish
  2007-02-05 16:55 99% ` [PATCH 2.6.20] e1000: Use ARRAY_SIZE macro when appropriate Ahmed S. Darwish
  2007-02-05 16:56 95% ` [PATCH 2.6.20] ipw2100: " Ahmed S. Darwish
@ 2007-02-05 16:56 73% ` Ahmed S. Darwish
  2007-02-05 16:57 92%   ` [PATCH 02/02] " Ahmed S. Darwish
  2007-02-05 16:58 99% ` [PATCH 2.6.20] misc-wireless: " Ahmed S. Darwish
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2007-02-05 16:56 UTC (permalink / raw)
  To: linux-kernel, netdev

Hi,

A 2.6.20 patch to use ARRAY_SIZE macro already defined in kernel.h for some
miscellaneous network drivers with no specific maintaners.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
[PATCH 01/02] is compile tested.
[PATCH 02/02] isn't compile tested cause of missing hardware.

diff --git a/drivers/net/cs89x0.c b/drivers/net/cs89x0.c
index 4612f71..d48196c 100644
--- a/drivers/net/cs89x0.c
+++ b/drivers/net/cs89x0.c
@@ -806,7 +806,7 @@ cs89x0_probe1(struct net_device *dev, int ioaddr, int modular)
 		        i = cs8900_irq_map[0];
 #else
 			/* Translate the IRQ using the IRQ mapping table. */
-			if (i >= sizeof(cs8900_irq_map)/sizeof(cs8900_irq_map[0]))
+			if (i >= ARRAY_SIZE(cs8900_irq_map))
 				printk("\ncs89x0: invalid ISA interrupt number %d\n", i);
 			else
 				i = cs8900_irq_map[i];
@@ -1248,11 +1248,11 @@ write_irq(struct net_device *dev, int chip_type, int irq)
 
 	if (chip_type == CS8900) {
 		/* Search the mapping table for the corresponding IRQ pin. */
-		for (i = 0; i != sizeof(cs8900_irq_map)/sizeof(cs8900_irq_map[0]); i++)
+		for (i = 0; i != ARRAY_SIZE(cs8900_irq_map); i++)
 			if (cs8900_irq_map[i] == irq)
 				break;
 		/* Not found */
-		if (i == sizeof(cs8900_irq_map)/sizeof(cs8900_irq_map[0]))
+		if (i == ARRAY_SIZE(cs8900_irq_map))
 			i = 3;
 		writereg(dev, PP_CS8900_ISAINT, i);
 	} else {
diff --git a/drivers/net/irda/actisys-sir.c b/drivers/net/irda/actisys-sir.c
index 9715ab5..84d7bb0 100644
--- a/drivers/net/irda/actisys-sir.c
+++ b/drivers/net/irda/actisys-sir.c
@@ -43,6 +43,7 @@
 #include <linux/module.h>
 #include <linux/delay.h>
 #include <linux/init.h>
+#include <linux/kernel.h>
 
 #include <net/irda/irda.h>
 
@@ -67,7 +68,7 @@ static int actisys_reset(struct sir_dev *);
 /* Note : the 220L doesn't support 38400, but we will fix that below */
 static unsigned baud_rates[] = { 9600, 19200, 57600, 115200, 38400 };
 
-#define MAX_SPEEDS (sizeof(baud_rates)/sizeof(baud_rates[0]))
+#define MAX_SPEEDS ARRAY_SIZE(baud_rates)
 
 static struct dongle_driver act220l = {
 	.owner		= THIS_MODULE,
diff --git a/drivers/net/lp486e.c b/drivers/net/lp486e.c
index 177c502..4b016aa 100644
--- a/drivers/net/lp486e.c
+++ b/drivers/net/lp486e.c
@@ -515,7 +515,7 @@ CLEAR_INT(void) {
 	outb(0, IOADDR+8);
 }
 
-#define SIZE(x)	(sizeof(x)/sizeof((x)[0]))
+#define SIZE(x)	ARRAY_SIZE(x)
 
 #if 0
 /* selftest or dump */
diff --git a/drivers/net/ne.c b/drivers/net/ne.c
index a5c4199..7081d08 100644
--- a/drivers/net/ne.c
+++ b/drivers/net/ne.c
@@ -379,7 +379,7 @@ static int __init ne_probe1(struct net_device *dev, int ioaddr)
 			{E8390_RREAD+E8390_START, E8390_CMD},
 		};
 
-		for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++)
+		for (i = 0; i < ARRAY_SIZE(program_seq); i++)
 			outb_p(program_seq[i].value, ioaddr + program_seq[i].offset);
 
 	}
diff --git a/drivers/net/ne2.c b/drivers/net/ne2.c
index 089b5bb..c6c2a91 100644
--- a/drivers/net/ne2.c
+++ b/drivers/net/ne2.c
@@ -432,7 +432,7 @@ static int __init ne2_probe1(struct net_device *dev, int slot)
 			{E8390_RREAD+E8390_START, E8390_CMD},
 		};
 
-		for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++)
+		for (i = 0; i < ARRAY_SIZE(program_seq); i++)
 			outb_p(program_seq[i].value, base_addr +
 				program_seq[i].offset);
 
diff --git a/drivers/net/ne2k-pci.c b/drivers/net/ne2k-pci.c
index 589785d..6bafdda 100644
--- a/drivers/net/ne2k-pci.c
+++ b/drivers/net/ne2k-pci.c
@@ -309,7 +309,7 @@ static int __devinit ne2k_pci_init_one (struct pci_dev *pdev,
 			{0x00,	EN0_RSARHI},
 			{E8390_RREAD+E8390_START, E8390_CMD},
 		};
-		for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++)
+		for (i = 0; i < ARRAY_SIZE(program_seq); i++)
 			outb(program_seq[i].value, ioaddr + program_seq[i].offset);
 
 	}
diff --git a/drivers/net/netxen/netxen_nic_hw.c b/drivers/net/netxen/netxen_nic_hw.c
index f263232..7f93c08 100644
--- a/drivers/net/netxen/netxen_nic_hw.c
+++ b/drivers/net/netxen/netxen_nic_hw.c
@@ -395,7 +395,7 @@ int netxen_is_flash_supported(struct netxen_adapter *adapter)
 	/* if the flash size less than 4Mb, make huge war cry and die */
 	for (j = 1; j < 4; j++) {
 		addr = j * NETXEN_NIC_WINDOW_MARGIN;
-		for (i = 0; i < (sizeof(locs) / sizeof(locs[0])); i++) {
+		for (i = 0; i < ARRAY_SIZE(locs); i++) {
 			if (netxen_rom_fast_read(adapter, locs[i], &val01) == 0
 			    && netxen_rom_fast_read(adapter, (addr + locs[i]),
 						    &val02) == 0) {
diff --git a/drivers/net/pcmcia/axnet_cs.c b/drivers/net/pcmcia/axnet_cs.c
index 6139048..6b64ea4 100644
--- a/drivers/net/pcmcia/axnet_cs.c
+++ b/drivers/net/pcmcia/axnet_cs.c
@@ -232,7 +232,7 @@ static int get_prom(struct pcmcia_device *link)
     axnet_reset_8390(dev);
     mdelay(10);
 
-    for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++)
+    for (i = 0; i < ARRAY_SIZE(program_seq); i++)
 	outb_p(program_seq[i].value, ioaddr + program_seq[i].offset);
 
     for (i = 0; i < 6; i += 2) {
diff --git a/drivers/net/pcmcia/pcnet_cs.c b/drivers/net/pcmcia/pcnet_cs.c
index d88e9b2..e652246 100644
--- a/drivers/net/pcmcia/pcnet_cs.c
+++ b/drivers/net/pcmcia/pcnet_cs.c
@@ -375,7 +375,7 @@ static hw_info_t *get_prom(struct pcmcia_device *link)
     pcnet_reset_8390(dev);
     mdelay(10);
 
-    for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++)
+    for (i = 0; i < ARRAY_SIZE(program_seq); i++)
 	outb_p(program_seq[i].value, ioaddr + program_seq[i].offset);
 
     for (i = 0; i < 32; i++)
diff --git a/drivers/net/sk98lin/skgemib.c b/drivers/net/sk98lin/skgemib.c
index 0a6f67a..625cb25 100644
--- a/drivers/net/sk98lin/skgemib.c
+++ b/drivers/net/sk98lin/skgemib.c
@@ -22,6 +22,8 @@
  *
  ******************************************************************************/
 
+#include <linux/kernel.h>
+
 /*
  * PRIVATE OID handler function prototypes
  */
@@ -82,7 +84,7 @@ PNMI_STATIC int DiagActions(SK_AC *pAC, SK_IOC IoC, int action, SK_U32 Id,
 
 
 /* defines *******************************************************************/
-#define ID_TABLE_SIZE (sizeof(IdTable)/sizeof(IdTable[0]))
+#define ID_TABLE_SIZE ARRAY_SIZE(IdTable)
 
 
 /* global variables **********************************************************/
diff --git a/drivers/net/sk98lin/skgesirq.c b/drivers/net/sk98lin/skgesirq.c
index 3e7aa49..83e1544 100644
--- a/drivers/net/sk98lin/skgesirq.c
+++ b/drivers/net/sk98lin/skgesirq.c
@@ -51,6 +51,7 @@ static const char SysKonnectFileId[] =
 	"@(#) $Id: skgesirq.c,v 1.92 2003/09/16 14:37:07 rschmidt Exp $ (C) Marvell.";
 #endif
 
+#include <linux/kernel.h>
 #include "h/skdrv1st.h"		/* Driver Specific Definitions */
 #ifndef SK_SLIM
 #include "h/skgepnmi.h"		/* PNMI Definitions */
@@ -892,7 +893,7 @@ int		Port)		/* Which port should be checked */
 	 */
 	RxCts = 0;
 
-	for (i = 0; i < sizeof(SkGeRxRegs)/sizeof(SkGeRxRegs[0]); i++) {
+	for (i = 0; i < ARRAY_SIZE(SkGeRxRegs); i++) {
 		
 		(void)SkXmMacStatistic(pAC, IoC, Port, SkGeRxRegs[i], &RxTmp);
 		
diff --git a/drivers/net/skfp/smt.c b/drivers/net/skfp/smt.c
index 99a776a..6820989 100644
--- a/drivers/net/skfp/smt.c
+++ b/drivers/net/skfp/smt.c
@@ -14,6 +14,7 @@
  *
  ******************************************************************************/
 
+#include <linux/kernel.h>
 #include "h/types.h"
 #include "h/fddi.h"
 #include "h/smc.h"
@@ -1655,7 +1656,7 @@ static const struct smt_pdef {
 	{ SMT_P4053,	0,	SWAP_SMT_P4053			} ,
 } ;
 
-#define N_SMT_PLEN	(sizeof(smt_pdef)/sizeof(smt_pdef[0]))
+#define N_SMT_PLEN	ARRAY_SIZE(smt_pdef)
 
 int smt_check_para(struct s_smc *smc, struct smt_header	*sm,
 		   const u_short list[])
diff --git a/drivers/net/skfp/srf.c b/drivers/net/skfp/srf.c
index 16573ac..0f47297 100644
--- a/drivers/net/skfp/srf.c
+++ b/drivers/net/skfp/srf.c
@@ -19,6 +19,8 @@
 	SRF state machine and frame generation
 */
 
+#include <linux/kernel.h>
+
 #include "h/types.h"
 #include "h/fddi.h"
 #include "h/smc.h"
@@ -43,7 +45,7 @@ static void clear_reported(struct s_smc *smc);
 static void smt_send_srf(struct s_smc *smc);
 static struct s_srf_evc *smt_get_evc(struct s_smc *smc, int code, int index);
 
-#define MAX_EVCS	(sizeof(smc->evcs)/sizeof(smc->evcs[0]))
+#define MAX_EVCS	ARRAY_SIZE(smc->evcs)
 
 struct evc_init {
 	u_char code ;
@@ -67,7 +69,7 @@ static const struct evc_init evc_inits[] = {
 	{ SMT_EVENT_PORT_PATH_CHANGE,		INDEX_PORT,NUMPHYS,SMT_P4053 } ,
 } ;
 
-#define MAX_INIT_EVC	(sizeof(evc_inits)/sizeof(evc_inits[0]))
+#define MAX_INIT_EVC	ARRAY_SIZE(evc_inits)
 
 void smt_init_evc(struct s_smc *smc)
 {


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 73%]

* [PATCH 2.6.20] e1000: Use ARRAY_SIZE macro when appropriate
  2007-02-05 16:54 99% [PATCH 00] A series of patches to use ARRAY_SIZE in `net' drivers Ahmed S. Darwish
@ 2007-02-05 16:55 99% ` Ahmed S. Darwish
  2007-02-05 16:56 95% ` [PATCH 2.6.20] ipw2100: " Ahmed S. Darwish
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-05 16:55 UTC (permalink / raw)
  To: cramerj, john.ronciak; +Cc: linux-kernel, netdev

Hi,

A patch to use ARRAY_SIZE macro already defined in kernel.h.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
Patch is compile tested.

diff --git a/drivers/net/e1000/e1000_ethtool.c b/drivers/net/e1000/e1000_ethtool.c
index fb96c87..d21706e 100644
--- a/drivers/net/e1000/e1000_ethtool.c
+++ b/drivers/net/e1000/e1000_ethtool.c
@@ -746,7 +746,7 @@ err_setup:
 	uint32_t pat, value;                                                   \
 	uint32_t test[] =                                                      \
 		{0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};              \
-	for (pat = 0; pat < sizeof(test)/sizeof(test[0]); pat++) {              \
+	for (pat = 0; pat < ARRAY_SIZE(test); pat++) {              \
 		E1000_WRITE_REG(&adapter->hw, R, (test[pat] & W));             \
 		value = E1000_READ_REG(&adapter->hw, R);                       \
 		if (value != (test[pat] & W & M)) {                             \

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 00] A series of patches to use ARRAY_SIZE in `net' drivers
@ 2007-02-05 16:54 99% Ahmed S. Darwish
  2007-02-05 16:55 99% ` [PATCH 2.6.20] e1000: Use ARRAY_SIZE macro when appropriate Ahmed S. Darwish
                   ` (7 more replies)
  0 siblings, 8 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-05 16:54 UTC (permalink / raw)
  To: linux-kernel, netdev

Hi all,

Follows is a sereis of patches to use ARRAY_SIZE macro in drivers/net. 
Patches are sent separately according to their maintaners as replies to 
this thread.

 apne.c                     |    2 +-
 arm/am79c961a.c            |    2 +-
 atarilance.c               |    2 +-
 cs89x0.c                   |    6 +++---
 e1000/e1000_ethtool.c      |    2 +-
 fec_8xx/fec_mii.c          |    4 ++--
 ibm_emac/ibm_emac_debug.c  |    8 ++++----
 irda/actisys-sir.c         |    3 ++-
 ixgb/ixgb_param.c          |    2 +-
 lp486e.c                   |    2 +-
 ne-h8300.c                 |    2 +-
 ne.c                       |    2 +-
 ne2.c                      |    2 +-
 ne2k-pci.c                 |    2 +-
 netxen/netxen_nic_hw.c     |    2 +-
 pcmcia/axnet_cs.c          |    2 +-
 pcmcia/pcnet_cs.c          |    2 +-
 sk98lin/skgemib.c          |    4 +++-
 sk98lin/skgesirq.c         |    3 ++-
 skfp/smt.c                 |    3 ++-
 skfp/srf.c                 |    6 ++++--
 wireless/airo.c            |    4 ++--
 wireless/hostap/hostap.h   |    3 ++-
 wireless/ipw2100.c         |   14 ++++++--------
 wireless/prism54/oid_mgt.c |    4 +++-
 wireless/wavelan.p.h       |    2 +-
 zorro8390.c                |    2 +-
 27 files changed, 50 insertions(+), 42 deletions(-)

Thanks,
-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.20] misc-video: use ARRAY_SIZE macro when appropriate
  2007-02-05 16:51 99% [PATCH 00] A series of patches to use ARRAY_SIZE under video subtree Ahmed S. Darwish
  2007-02-05 16:53 75% ` [PATCH 2.6.20] pvrusb2: use ARRAY_SIZE macro when appropriate (2) Ahmed S. Darwish
@ 2007-02-05 16:54 83% ` Ahmed S. Darwish
  1 sibling, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-05 16:54 UTC (permalink / raw)
  To: mchehab, v4l-dvb-maintainer; +Cc: video4linux-list, linux-kernel

Hi all,

A patch to use ARRAY_SIZE macro in miscellaneous video drivers found
with no specific maintaners.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
Patches are compile tested.

diff --git a/drivers/media/video/cpia2/cpia2_v4l.c b/drivers/media/video/cpia2/cpia2_v4l.c
index d09f499..3237c25 100644
--- a/drivers/media/video/cpia2/cpia2_v4l.c
+++ b/drivers/media/video/cpia2/cpia2_v4l.c
@@ -33,6 +33,7 @@
 
 
 #include <linux/module.h>
+#include <linux/kernel.h>
 #include <linux/time.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
@@ -105,7 +106,7 @@ static struct control_menu_info framerate_controls[] =
 	{ CPIA2_VP_FRAMERATE_25,   "25 fps"   },
 	{ CPIA2_VP_FRAMERATE_30,   "30 fps"   },
 };
-#define NUM_FRAMERATE_CONTROLS (sizeof(framerate_controls)/sizeof(framerate_controls[0]))
+#define NUM_FRAMERATE_CONTROLS ARRAY_SIZE(framerate_controls)
 
 static struct control_menu_info flicker_controls[] =
 {
@@ -113,7 +114,7 @@ static struct control_menu_info flicker_controls[] =
 	{ FLICKER_50,    "50 Hz" },
 	{ FLICKER_60,    "60 Hz"  },
 };
-#define NUM_FLICKER_CONTROLS (sizeof(flicker_controls)/sizeof(flicker_controls[0]))
+#define NUM_FLICKER_CONTROLS ARRAY_SIZE(flicker_controls)
 
 static struct control_menu_info lights_controls[] =
 {
@@ -122,7 +123,7 @@ static struct control_menu_info lights_controls[] =
 	{ 128, "Bottom"  },
 	{ 192, "Both"  },
 };
-#define NUM_LIGHTS_CONTROLS (sizeof(lights_controls)/sizeof(lights_controls[0]))
+#define NUM_LIGHTS_CONTROLS ARRAY_SIZE(lights_controls)
 #define GPIO_LIGHTS_MASK 192
 
 static struct v4l2_queryctrl controls[] = {
@@ -235,7 +236,7 @@ static struct v4l2_queryctrl controls[] = {
 		.default_value = 0,
 	},
 };
-#define NUM_CONTROLS (sizeof(controls)/sizeof(controls[0]))
+#define NUM_CONTROLS ARRAY_SIZE(controls)
 
 
 /******************************************************************************
diff --git a/drivers/media/video/ov7670.c b/drivers/media/video/ov7670.c
index 5ed0adc..0f6020e 100644
--- a/drivers/media/video/ov7670.c
+++ b/drivers/media/video/ov7670.c
@@ -11,6 +11,7 @@
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
+#include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/delay.h>
 #include <linux/videodev.h>
@@ -503,7 +504,7 @@ static struct ov7670_format_struct {
 		.cmatrix	= { 179, -179, 0, -61, -176, 228 },
 	},
 };
-#define N_OV7670_FMTS (sizeof(ov7670_formats)/sizeof(ov7670_formats[0]))
+#define N_OV7670_FMTS ARRAY_SIZE(ov7670_formats)
 
 /*
  * All formats we support are 2 bytes/pixel.
@@ -596,7 +597,7 @@ static struct ov7670_win_size {
 	},
 };
 
-#define N_WIN_SIZES (sizeof(ov7670_win_sizes)/sizeof(ov7670_win_sizes[0]))
+#define N_WIN_SIZES ARRAY_SIZE(ov7670_win_sizes)
 
 
 /*
@@ -1149,7 +1150,7 @@ static struct ov7670_control {
 		.query = ov7670_q_hflip,
 	},
 };
-#define N_CONTROLS (sizeof(ov7670_controls)/sizeof(ov7670_controls[0]))
+#define N_CONTROLS ARRAY_SIZE(ov7670_controls)
 
 static struct ov7670_control *ov7670_find_control(__u32 id)
 {
diff --git a/drivers/media/video/tveeprom.c b/drivers/media/video/tveeprom.c
index 4e7c1fa..4439080 100644
--- a/drivers/media/video/tveeprom.c
+++ b/drivers/media/video/tveeprom.c
@@ -453,7 +453,7 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
 			to indicate 4052 mux was removed in favor of using MSP
 			inputs directly. */
 			audioic = eeprom_data[i+2] & 0x7f;
-			if (audioic < sizeof(audioIC)/sizeof(*audioIC))
+			if (audioic < ARRAY_SIZE(audioIC))
 				tvee->audio_processor = audioIC[audioic].id;
 			else
 				tvee->audio_processor = AUDIO_CHIP_UNKNOWN;
@@ -486,7 +486,7 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
 			to indicate 4052 mux was removed in favor of using MSP
 			inputs directly. */
 			audioic = eeprom_data[i+1] & 0x7f;
-			if (audioic < sizeof(audioIC)/sizeof(*audioIC))
+			if (audioic < ARRAY_SIZE(audioIC))
 				tvee->audio_processor = audioIC[audioic].id;
 			else
 				tvee->audio_processor = AUDIO_CHIP_UNKNOWN;
@@ -641,7 +641,7 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
 		tveeprom_info("audio processor is unknown (no idx)\n");
 		tvee->audio_processor=AUDIO_CHIP_UNKNOWN;
 	} else {
-		if (audioic < sizeof(audioIC)/sizeof(*audioIC))
+		if (audioic < ARRAY_SIZE(audioIC))
 			tveeprom_info("audio processor is %s (idx %d)\n",
 					audioIC[audioic].name,audioic);
 		else
diff --git a/drivers/media/video/tvp5150.c b/drivers/media/video/tvp5150.c
index bc0a4fc..9eeefee 100644
--- a/drivers/media/video/tvp5150.c
+++ b/drivers/media/video/tvp5150.c
@@ -6,6 +6,7 @@
  */
 
 #include <linux/i2c.h>
+#include <linux/kernel.h>
 #include <linux/videodev.h>
 #include <linux/delay.h>
 #include <linux/video_decoder.h>
@@ -1012,7 +1013,7 @@ static int tvp5150_command(struct i2c_client *c,
 		{
 			struct v4l2_control *ctrl = arg;
 			u8 i, n;
-			n = sizeof(tvp5150_qctrl) / sizeof(tvp5150_qctrl[0]);
+			n = ARRAY_SIZE(tvp5150_qctrl);
 			for (i = 0; i < n; i++)
 				if (ctrl->id == tvp5150_qctrl[i].id) {
 					if (ctrl->value <
diff --git a/drivers/media/video/usbvideo/quickcam_messenger.c b/drivers/media/video/usbvideo/quickcam_messenger.c
index ec0ff22..082560e 100644
--- a/drivers/media/video/usbvideo/quickcam_messenger.c
+++ b/drivers/media/video/usbvideo/quickcam_messenger.c
@@ -439,7 +439,7 @@ static int qcm_sensor_init(struct uvd *uvd)
 	int ret;
 	int i;
 
-	for (i=0; i < sizeof(regval_table)/sizeof(regval_table[0]) ; i++) {
+	for (i = 0; i < ARRAY_SIZE(regval_table); i++) {
 		CHECK_RET(ret, qcm_stv_setb(uvd->dev,
 					regval_table[i].reg,
 					regval_table[i].val));

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 83%]

* [PATCH 2.6.20] pvrusb2: use ARRAY_SIZE macro when appropriate (2)
  2007-02-05 16:51 99% [PATCH 00] A series of patches to use ARRAY_SIZE under video subtree Ahmed S. Darwish
@ 2007-02-05 16:53 75% ` Ahmed S. Darwish
  2007-02-05 16:54 83% ` [PATCH 2.6.20] misc-video: use ARRAY_SIZE macro when appropriate Ahmed S. Darwish
  1 sibling, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-05 16:53 UTC (permalink / raw)
  To: pvrusb2; +Cc: video4linux-list, linux-kernel

Hi all,
A patch to use ARRAY_SIZE already defined in kernel.h. This patch is
a complementry (and does not include) the one sent one week earlier.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
It seems that the earlier grep expression I used to produce the first
patch didn't catch the below occurences. Sorry for the incovenience.

Patch is compile tested.

diff --git a/drivers/media/video/pvrusb2/pvrusb2-audio.c b/drivers/media/video/pvrusb2/pvrusb2-audio.c
index 9846c46..4a32fa2 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-audio.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-audio.c
@@ -24,6 +24,7 @@
 #include "pvrusb2-hdw-internal.h"
 #include "pvrusb2-debug.h"
 #include <linux/videodev2.h>
+#include <linux/kernel.h>
 #include <media/msp3400.h>
 #include <media/v4l2-common.h>
 
@@ -99,8 +100,7 @@ static int msp3400_check(struct pvr2_msp3400_handler *ctxt)
 	unsigned long msk;
 	unsigned int idx;
 
-	for (idx = 0; idx < sizeof(msp3400_ops)/sizeof(msp3400_ops[0]);
-	     idx++) {
+	for (idx = 0; idx < ARRAY_SIZE(msp3400_ops); idx++) {
 		msk = 1 << idx;
 		if (ctxt->stale_mask & msk) continue;
 		if (msp3400_ops[idx].check(ctxt)) {
@@ -116,8 +116,7 @@ static void msp3400_update(struct pvr2_msp3400_handler *ctxt)
 	unsigned long msk;
 	unsigned int idx;
 
-	for (idx = 0; idx < sizeof(msp3400_ops)/sizeof(msp3400_ops[0]);
-	     idx++) {
+	for (idx = 0; idx < ARRAY_SIZE(msp3400_ops); idx++) {
 		msk = 1 << idx;
 		if (!(ctxt->stale_mask & msk)) continue;
 		ctxt->stale_mask &= ~msk;
@@ -183,8 +182,7 @@ int pvr2_i2c_msp3400_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
 	ctxt->astat.ctxt = ctxt;
 	ctxt->astat.status = (int (*)(void *))get_audio_status;
 	ctxt->astat.detach = (void (*)(void *))pvr2_msp3400_detach;
-	ctxt->stale_mask = (1 << (sizeof(msp3400_ops)/
-				  sizeof(msp3400_ops[0]))) - 1;
+	ctxt->stale_mask = (1 << ARRAY_SIZE(msp3400_ops)) - 1;
 	cp->handler = &ctxt->i2c_handler;
 	hdw->audio_stat = &ctxt->astat;
 	pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x msp3400 V4L2 handler set up",
diff --git a/drivers/media/video/pvrusb2/pvrusb2-ctrl.c b/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
index c77de85..22b128c 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
@@ -24,7 +24,7 @@
 #include <linux/errno.h>
 #include <linux/string.h>
 #include <linux/mutex.h>
-
+#include <linux/kernel.h>
 
 /* Set the given control. */
 int pvr2_ctrl_set_value(struct pvr2_ctrl *cptr,int val)
@@ -507,7 +507,7 @@ int pvr2_ctrl_sym_to_value(struct pvr2_ctrl *cptr,
 		} else if (cptr->info->type == pvr2_ctl_bool) {
 			ret = parse_token(
 				ptr,len,valptr,boolNames,
-				sizeof(boolNames)/sizeof(boolNames[0]));
+				ARRAY_SIZE(boolNames));
 			if (ret == 1) {
 				*valptr = *valptr ? !0 : 0;
 			} else if (ret == 0) {
diff --git a/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c b/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c
index 848fb23..e85daf6 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c
@@ -39,6 +39,7 @@
 #include <media/v4l2-common.h>
 #include <linux/errno.h>
 #include <linux/slab.h>
+#include <linux/kernel.h>
 
 struct pvr2_v4l_cx2584x {
 	struct pvr2_i2c_handler handler;
@@ -150,8 +151,7 @@ static int decoder_check(struct pvr2_v4l_cx2584x *ctxt)
 	unsigned long msk;
 	unsigned int idx;
 
-	for (idx = 0; idx < sizeof(decoder_ops)/sizeof(decoder_ops[0]);
-	     idx++) {
+	for (idx = 0; idx < ARRAY_SIZE(decoder_ops); idx++) {
 		msk = 1 << idx;
 		if (ctxt->stale_mask & msk) continue;
 		if (decoder_ops[idx].check(ctxt)) {
@@ -167,8 +167,7 @@ static void decoder_update(struct pvr2_v4l_cx2584x *ctxt)
 	unsigned long msk;
 	unsigned int idx;
 
-	for (idx = 0; idx < sizeof(decoder_ops)/sizeof(decoder_ops[0]);
-	     idx++) {
+	for (idx = 0; idx < ARRAY_SIZE(decoder_ops); idx++) {
 		msk = 1 << idx;
 		if (!(ctxt->stale_mask & msk)) continue;
 		ctxt->stale_mask &= ~msk;
@@ -256,8 +255,7 @@ int pvr2_i2c_cx2584x_v4l_setup(struct pvr2_hdw *hdw,
 	ctxt->ctrl.force_reset = (void (*)(void*))decoder_reset;
 	ctxt->client = cp;
 	ctxt->hdw = hdw;
-	ctxt->stale_mask = (1 << (sizeof(decoder_ops)/
-				  sizeof(decoder_ops[0]))) - 1;
+	ctxt->stale_mask = (1 << ARRAY_SIZE(decoder_ops)) - 1;
 	hdw->decoder_ctrl = &ctxt->ctrl;
 	cp->handler = &ctxt->handler;
 	{
diff --git a/drivers/media/video/pvrusb2/pvrusb2-debugifc.c b/drivers/media/video/pvrusb2/pvrusb2-debugifc.c
index f985f00..0f32772 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-debugifc.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-debugifc.c
@@ -21,6 +21,7 @@
 
 #include <linux/string.h>
 #include <linux/slab.h>
+#include <linux/kernel.h>
 #include "pvrusb2-debugifc.h"
 #include "pvrusb2-hdw.h"
 #include "pvrusb2-debug.h"
@@ -152,7 +153,7 @@ static unsigned long debugifc_find_mask(const char *buf,unsigned int count)
 {
 	struct debugifc_mask_item *mip;
 	unsigned int idx;
-	for (idx = 0; idx < sizeof(mask_items)/sizeof(mask_items[0]); idx++) {
+	for (idx = 0; idx < ARRAY_SIZE(mask_items); idx++) {
 		mip = mask_items + idx;
 		if (debugifc_match_keyword(buf,count,mip->name)) {
 			return mip->msk;
@@ -169,7 +170,7 @@ static int debugifc_print_mask(char *buf,unsigned int sz,
 	unsigned int idx;
 	int bcnt = 0;
 	int ccnt;
-	for (idx = 0; idx < sizeof(mask_items)/sizeof(mask_items[0]); idx++) {
+	for (idx = 0; idx < ARRAY_SIZE(mask_items); idx++) {
 		mip = mask_items + idx;
 		if (!(mip->msk & msk)) continue;
 		ccnt = scnprintf(buf,sz,"%s%c%s",
diff --git a/drivers/media/video/pvrusb2/pvrusb2-eeprom.c b/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
index 6cff8e7..b64ebc2 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
@@ -20,6 +20,7 @@
  *
  */
 
+#include <linux/kernel.h>
 #include "pvrusb2-eeprom.h"
 #include "pvrusb2-hdw-internal.h"
 #include "pvrusb2-debug.h"
@@ -104,7 +105,7 @@ static u8 *pvr2_eeprom_fetch(struct pvr2_hdw *hdw)
 		msg[1].buf = eeprom+tcnt;
 		if ((ret = i2c_transfer(
 			     &hdw->i2c_adap,
-			     msg,sizeof(msg)/sizeof(msg[0]))) != 2) {
+			     msg,ARRAY_SIZE(msg))) != 2) {
 			pvr2_trace(PVR2_TRACE_ERROR_LEGS,
 				   "eeprom fetch set offs err=%d",ret);
 			kfree(eeprom);
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
index d200496..1b3b042 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
@@ -20,6 +20,7 @@
  */
 
 #include <linux/errno.h>
+#include <linux/kernel.h>
 #include <linux/string.h>
 #include <linux/slab.h>
 #include <linux/firmware.h>
@@ -604,7 +605,7 @@ static void ctrl_stdenumcur_clear_dirty(struct pvr2_ctrl *cptr)
 
 #define DEFENUM(tab) \
 	.type = pvr2_ctl_enum, \
-	.def.type_enum.count = (sizeof(tab)/sizeof((tab)[0])), \
+	.def.type_enum.count = ARRAY_SIZE(tab), \
 	.def.type_enum.value_names = tab
 
 #define DEFBOOL \

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 75%]

* [PATCH 00] A series of patches to use ARRAY_SIZE under video subtree
@ 2007-02-05 16:51 99% Ahmed S. Darwish
  2007-02-05 16:53 75% ` [PATCH 2.6.20] pvrusb2: use ARRAY_SIZE macro when appropriate (2) Ahmed S. Darwish
  2007-02-05 16:54 83% ` [PATCH 2.6.20] misc-video: use ARRAY_SIZE macro when appropriate Ahmed S. Darwish
  0 siblings, 2 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-05 16:51 UTC (permalink / raw)
  To: linux-kernel, video4linux-list

Hi all,

Follows is a series of patches to use ARRAY_SIZE macro in the video drivers
located under /drivers/media/video.
Patches are test compiled and can be applied cleanly on 2.6.20

 cpia2/cpia2_v4l.c             |    9 +++++----
 ov7670.c                      |    7 ++++---
 pvrusb2/pvrusb2-audio.c       |   10 ++++------
 pvrusb2/pvrusb2-ctrl.c        |    4 ++--
 pvrusb2/pvrusb2-cx2584x-v4l.c |   10 ++++------
 pvrusb2/pvrusb2-debugifc.c    |    5 +++--
 pvrusb2/pvrusb2-eeprom.c      |    3 ++-
 pvrusb2/pvrusb2-hdw.c         |    3 ++-
 tveeprom.c                    |    6 +++---
 tvp5150.c                     |    3 ++-
 usbvideo/quickcam_messenger.c |    2 +-
 11 files changed, 32 insertions(+), 30 deletions(-)

Thanks,
-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.20] arch ARM: Use ARRAY_SIZE macro when appropriate
  2007-02-05  2:39 97% [PATCH 00] A series of patches to use ARRAY_SIZE macro under arch/ Ahmed S. Darwish
                   ` (7 preceding siblings ...)
  2007-02-05  2:43 99% ` [PATCH 2.6.20] arch M68K: " Ahmed S. Darwish
@ 2007-02-05  2:43 99% ` Ahmed S. Darwish
  8 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-05  2:43 UTC (permalink / raw)
  To: spyro, kernel; +Cc: linux-kernel

Hi all,

A patch to use ARRAY_SIZE macro already defined in linux/kernel.h

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
Patch isn't compile checked cause I have no ARM machine at hand.
Thanks,

diff --git a/arch/arm/kernel/ecard.c b/arch/arm/kernel/ecard.c
index 71257e3..f1c0fb9 100644
--- a/arch/arm/kernel/ecard.c
+++ b/arch/arm/kernel/ecard.c
@@ -1009,7 +1009,7 @@ ecard_probe(int slot, card_type_t type)
 		ec->fiqmask = 4;
 	}
 
-	for (i = 0; i < sizeof(blacklist) / sizeof(*blacklist); i++)
+	for (i = 0; i < ARRAY_SIZE(blacklist); i++)
 		if (blacklist[i].manufacturer == ec->cid.manufacturer &&
 		    blacklist[i].product == ec->cid.product) {
 			ec->card_desc = blacklist[i].type;
diff --git a/arch/arm26/kernel/ecard.c b/arch/arm26/kernel/ecard.c
index 9dbc172..e2bcefc 100644
--- a/arch/arm26/kernel/ecard.c
+++ b/arch/arm26/kernel/ecard.c
@@ -665,7 +665,7 @@ ecard_probe(int slot, card_type_t type)
 		ec->fiqmask = 4;
 	}
 
-	for (i = 0; i < sizeof(blacklist) / sizeof(*blacklist); i++)
+	for (i = 0; i < ARRAY_SIZE(blacklist); i++)
 		if (blacklist[i].manufacturer == ec->cid.manufacturer &&
 		    blacklist[i].product == ec->cid.product) {
 			ec->card_desc = blacklist[i].type;

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.20] arch M68K: user ARRAY_SIZE macro when appropriate
  2007-02-05  2:39 97% [PATCH 00] A series of patches to use ARRAY_SIZE macro under arch/ Ahmed S. Darwish
                   ` (6 preceding siblings ...)
  2007-02-05  2:43 97% ` [PATCH 2.6.20] arch PPC: " Ahmed S. Darwish
@ 2007-02-05  2:43 99% ` Ahmed S. Darwish
  2007-02-05  2:43 99% ` [PATCH 2.6.20] arch ARM: Use " Ahmed S. Darwish
  8 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-05  2:43 UTC (permalink / raw)
  To: geert, linux-m68k; +Cc: linux-kernel

Hi all,

A patch to use ARRAY_SIZE macro already defined in linux/kernel.h

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
Patch isn't compile checked since I have no m68k machine at hand.

diff --git a/arch/m68k/kernel/ptrace.c b/arch/m68k/kernel/ptrace.c
index ef89060..7fd2720 100644
--- a/arch/m68k/kernel/ptrace.c
+++ b/arch/m68k/kernel/ptrace.c
@@ -76,7 +76,7 @@ static inline long get_reg(struct task_struct *task, int regno)
 
 	if (regno == PT_USP)
 		addr = &task->thread.usp;
-	else if (regno < sizeof(regoff)/sizeof(regoff[0]))
+	else if (regno < ARRAY_SIZE(regoff))
 		addr = (unsigned long *)(task->thread.esp0 + regoff[regno]);
 	else
 		return 0;
@@ -93,7 +93,7 @@ static inline int put_reg(struct task_struct *task, int regno,
 
 	if (regno == PT_USP)
 		addr = &task->thread.usp;
-	else if (regno < sizeof(regoff)/sizeof(regoff[0]))
+	else if (regno < ARRAY_SIZE(regoff))
 		addr = (unsigned long *)(task->thread.esp0 + regoff[regno]);
 	else
 		return -1;
diff --git a/arch/m68k/kernel/traps.c b/arch/m68k/kernel/traps.c
index 759fa24..a27a4fa 100644
--- a/arch/m68k/kernel/traps.c
+++ b/arch/m68k/kernel/traps.c
@@ -1011,7 +1011,7 @@ EXPORT_SYMBOL(dump_stack);
 void bad_super_trap (struct frame *fp)
 {
 	console_verbose();
-	if (fp->ptregs.vector < 4*sizeof(vec_names)/sizeof(vec_names[0]))
+	if (fp->ptregs.vector < 4 * ARRAY_SIZE(vec_names))
 		printk ("*** %s ***   FORMAT=%X\n",
 			vec_names[(fp->ptregs.vector) >> 2],
 			fp->ptregs.format);


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.20] arch PPC: user ARRAY_SIZE macro when appropriate
  2007-02-05  2:39 97% [PATCH 00] A series of patches to use ARRAY_SIZE macro under arch/ Ahmed S. Darwish
                   ` (5 preceding siblings ...)
  2007-02-05  2:42 96% ` [PATCH 2.6.20] arch PowerPC: " Ahmed S. Darwish
@ 2007-02-05  2:43 97% ` Ahmed S. Darwish
  2007-02-05  2:43 99% ` [PATCH 2.6.20] arch M68K: " Ahmed S. Darwish
  2007-02-05  2:43 99% ` [PATCH 2.6.20] arch ARM: Use " Ahmed S. Darwish
  8 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-05  2:43 UTC (permalink / raw)
  To: paulus, linuxppc-dev; +Cc: linux-kernel

Hi all,

A patch to use ARRAY_SIZE macro already defined in linux/kernel.h

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
Patch isn't compile checked cause I have no PowerPC machine at hand.
Thanks,

diff --git a/arch/ppc/lib/rheap.c b/arch/ppc/lib/rheap.c
index 31e5118..d407007 100644
--- a/arch/ppc/lib/rheap.c
+++ b/arch/ppc/lib/rheap.c
@@ -14,6 +14,7 @@
  */
 #include <linux/types.h>
 #include <linux/errno.h>
+#include <linux/kernel.h>
 #include <linux/mm.h>
 #include <linux/slab.h>
 
@@ -654,7 +655,7 @@ void rh_dump(rh_info_t * info)
 	int maxnr;
 	int i, nr;
 
-	maxnr = sizeof(st) / sizeof(st[0]);
+	maxnr = ARRAY_SIZE(st);
 
 	printk(KERN_INFO
 	       "info @0x%p (%d slots empty / %d max)\n",
diff --git a/arch/ppc/syslib/m8xx_setup.c b/arch/ppc/syslib/m8xx_setup.c
index d8d299b..01e48d8 100644
--- a/arch/ppc/syslib/m8xx_setup.c
+++ b/arch/ppc/syslib/m8xx_setup.c
@@ -77,7 +77,7 @@ static struct mtd_partition mpc8xxads_partitions[] = {
 	}
 };
 
-#define mpc8xxads_part_num (sizeof (mpc8xxads_partitions) / sizeof (mpc8xxads_partitions[0]))
+#define mpc8xxads_part_num ARRAY_SIZE(mpc8xxads_partitions)
 
 #endif
 
diff --git a/arch/ppc/xmon/ppc-opc.c b/arch/ppc/xmon/ppc-opc.c
index 533a6c9..034313c 100644
--- a/arch/ppc/xmon/ppc-opc.c
+++ b/arch/ppc/xmon/ppc-opc.c
@@ -19,6 +19,7 @@ along with this file; see the file COPYING.  If not, write to the Free
 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #include <linux/posix_types.h>
+#include <linux/kernel.h>
 #include "ansidecl.h"
 #include "ppc.h"
 
@@ -2669,8 +2670,7 @@ const struct powerpc_opcode powerpc_opcodes[] = {
 
 };
 
-const int powerpc_num_opcodes =
-  sizeof (powerpc_opcodes) / sizeof (powerpc_opcodes[0]);
+const int powerpc_num_opcodes = ARRAY_SIZE(powerpc_opcodes);
 \f
 /* The macro table.  This is only used by the assembler.  */
 
@@ -2717,5 +2717,4 @@ const struct powerpc_macro powerpc_macros[] = {
 
 };
 
-const int powerpc_num_macros =
-  sizeof (powerpc_macros) / sizeof (powerpc_macros[0]);
+const int powerpc_num_macros = ARRAY_SIZE(powerpc_macros);

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 97%]

* [PATCH 2.6.20] arch PowerPC: user ARRAY_SIZE macro when appropriate
  2007-02-05  2:39 97% [PATCH 00] A series of patches to use ARRAY_SIZE macro under arch/ Ahmed S. Darwish
                   ` (4 preceding siblings ...)
  2007-02-05  2:42 86% ` [PATCH 2.6.20] arch V850: " Ahmed S. Darwish
@ 2007-02-05  2:42 96% ` Ahmed S. Darwish
  2007-02-05  2:43 97% ` [PATCH 2.6.20] arch PPC: " Ahmed S. Darwish
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-05  2:42 UTC (permalink / raw)
  To: paulus, linuxppc-dev; +Cc: linux-kernel

Hi all,

A patch to use ARRAY_SIZE macro already defined in linux/kernel.h

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
Patch isn't compile checked cause I have no PowerPC machine at hand.
Thanks,

diff --git a/arch/powerpc/lib/rheap.c b/arch/powerpc/lib/rheap.c
index 57bf991..54b7b2b 100644
--- a/arch/powerpc/lib/rheap.c
+++ b/arch/powerpc/lib/rheap.c
@@ -14,6 +14,7 @@
  */
 #include <linux/types.h>
 #include <linux/errno.h>
+#include <linux/kernel.h>
 #include <linux/mm.h>
 #include <linux/slab.h>
 
@@ -670,7 +671,7 @@ void rh_dump(rh_info_t * info)
 	int maxnr;
 	int i, nr;
 
-	maxnr = sizeof(st) / sizeof(st[0]);
+	maxnr = ARRAY_SIZE(st);
 
 	printk(KERN_INFO
 	       "info @0x%p (%d slots empty / %d max)\n",
diff --git a/arch/powerpc/xmon/ppc-opc.c b/arch/powerpc/xmon/ppc-opc.c
index 5d841f4..af3780e 100644
--- a/arch/powerpc/xmon/ppc-opc.c
+++ b/arch/powerpc/xmon/ppc-opc.c
@@ -21,6 +21,7 @@
    02110-1301, USA.  */
 
 #include <linux/stddef.h>
+#include <linux/kernel.h>
 #include "nonstdio.h"
 #include "ppc.h"
 
@@ -4932,8 +4933,7 @@ const struct powerpc_opcode powerpc_opcodes[] = {
 
 };
 
-const int powerpc_num_opcodes =
-  sizeof (powerpc_opcodes) / sizeof (powerpc_opcodes[0]);
+const int powerpc_num_opcodes = ARRAY_SIZE(powerpc_opcodes);
 \f
 /* The macro table.  This is only used by the assembler.  */
 
@@ -4989,5 +4989,4 @@ const struct powerpc_macro powerpc_macros[] = {
 { "clrlslwi.",4,  PPCCOM,	"rlwinm. %0,%1,%3,(%2)-(%3),31-(%3)" },
 };
 
-const int powerpc_num_macros =
-  sizeof (powerpc_macros) / sizeof (powerpc_macros[0]);
+const int powerpc_num_macros = ARRAY_SIZE(powerpc_macros);
diff --git a/arch/powerpc/xmon/spu-opc.c b/arch/powerpc/xmon/spu-opc.c
index efffde9..530df3d 100644
--- a/arch/powerpc/xmon/spu-opc.c
+++ b/arch/powerpc/xmon/spu-opc.c
@@ -18,6 +18,7 @@
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
 
+#include <linux/kernel.h>
 #include "spu.h"
 
 /* This file holds the Spu opcode table */
@@ -40,5 +41,4 @@ const struct spu_opcode spu_opcodes[] = {
 #undef APUOPFB
 };
 
-const int spu_num_opcodes =
-  sizeof (spu_opcodes) / sizeof (spu_opcodes[0]);
+const int spu_num_opcodes = ARRAY_SIZE(spu_opcodes);


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 96%]

* [PATCH 2.6.20] arch V850: user ARRAY_SIZE macro when appropriate
  2007-02-05  2:39 97% [PATCH 00] A series of patches to use ARRAY_SIZE macro under arch/ Ahmed S. Darwish
                   ` (3 preceding siblings ...)
  2007-02-05  2:42 89% ` [PATCH 2.6.20] arch MIPS: " Ahmed S. Darwish
@ 2007-02-05  2:42 86% ` Ahmed S. Darwish
  2007-02-05  2:42 96% ` [PATCH 2.6.20] arch PowerPC: " Ahmed S. Darwish
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-05  2:42 UTC (permalink / raw)
  To: uclinux-v850; +Cc: linux-kernel

Hi all,

A patch to use ARRAY_SIZE macro already defined in linux/kernel.h

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
Patch isn't compile checked cause I have no V850 board at hand.
Thanks,

diff --git a/arch/v850/kernel/anna.c b/arch/v850/kernel/anna.c
index 40892d3..0e42904 100644
--- a/arch/v850/kernel/anna.c
+++ b/arch/v850/kernel/anna.c
@@ -114,7 +114,7 @@ static struct v850e_intc_irq_init irq_inits[] = {
 	{ "ST",  IRQ_INTST(0), 	IRQ_INTST_NUM, 	3, 5 },
 	{ 0 }
 };
-#define NUM_IRQ_INITS ((sizeof irq_inits / sizeof irq_inits[0]) - 1)
+#define NUM_IRQ_INITS (ARRAY_SIZE(irq_inits) - 1)
 
 static struct hw_interrupt_type hw_itypes[NUM_IRQ_INITS];
 
diff --git a/arch/v850/kernel/as85ep1.c b/arch/v850/kernel/as85ep1.c
index 5352f8a..18437bc 100644
--- a/arch/v850/kernel/as85ep1.c
+++ b/arch/v850/kernel/as85ep1.c
@@ -142,7 +142,7 @@ static struct v850e_intc_irq_init irq_inits[] = {
 	{ "ST",  IRQ_INTST(0), 	IRQ_INTST_NUM, 	3, 5 },
 	{ 0 }
 };
-#define NUM_IRQ_INITS ((sizeof irq_inits / sizeof irq_inits[0]) - 1)
+#define NUM_IRQ_INITS (ARRAY_SIZE(irq_inits) - 1)
 
 static struct hw_interrupt_type hw_itypes[NUM_IRQ_INITS];
 
diff --git a/arch/v850/kernel/fpga85e2c.c b/arch/v850/kernel/fpga85e2c.c
index cb04a69..5c49235 100644
--- a/arch/v850/kernel/fpga85e2c.c
+++ b/arch/v850/kernel/fpga85e2c.c
@@ -138,7 +138,7 @@ struct v850e_intc_irq_init irq_inits[] = {
 	{ "RPU", IRQ_RPU(0),	IRQ_RPU_NUM,	1, 6 },
 	{ 0 }
 };
-#define NUM_IRQ_INITS ((sizeof irq_inits / sizeof irq_inits[0]) - 1)
+#define NUM_IRQ_INITS (ARRAY_SIZE(irq_inits) - 1)
 
 struct hw_interrupt_type hw_itypes[NUM_IRQ_INITS];
 
diff --git a/arch/v850/kernel/gbus_int.c b/arch/v850/kernel/gbus_int.c
index 25d636e..b2bcc25 100644
--- a/arch/v850/kernel/gbus_int.c
+++ b/arch/v850/kernel/gbus_int.c
@@ -16,6 +16,7 @@
 #include <linux/irq.h>
 #include <linux/interrupt.h>
 #include <linux/signal.h>
+#include <linux/kernel.h>
 
 #include <asm/machdep.h>
 
@@ -36,7 +37,7 @@ struct used_gint {
 	{ 1, GBUS_INT_PRIORITY_HIGH },
 	{ 3, GBUS_INT_PRIORITY_LOW }
 };
-#define NUM_USED_GINTS	(sizeof used_gint / sizeof used_gint[0])
+#define NUM_USED_GINTS ARRAY_SIZE(used_gint)
 
 /* A table of which GINT is used by each GBUS interrupts (they are
    assigned based on priority).  */
@@ -231,8 +232,7 @@ struct gbus_int_irq_init gbus_irq_inits[] __initdata = {
 	{ "GBUS_INT", IRQ_GBUS_INT(0), IRQ_GBUS_INT_NUM, 1, 6},
 	{ 0 }
 };
-#define NUM_GBUS_IRQ_INITS  \
-   ((sizeof gbus_irq_inits / sizeof gbus_irq_inits[0]) - 1)
+#define NUM_GBUS_IRQ_INITS (ARRAY_SIZE(gbus_irq_inits) - 1)
 
 static struct hw_interrupt_type gbus_hw_itypes[NUM_GBUS_IRQ_INITS];
 
diff --git a/arch/v850/kernel/ma.c b/arch/v850/kernel/ma.c
index 2aa8ab0..143774d 100644
--- a/arch/v850/kernel/ma.c
+++ b/arch/v850/kernel/ma.c
@@ -43,7 +43,7 @@ static struct v850e_intc_irq_init irq_inits[] = {
 	{ "ST",  IRQ_INTST(0), 	IRQ_INTST_NUM, 	4, 5 },
 	{ 0 }
 };
-#define NUM_IRQ_INITS ((sizeof irq_inits / sizeof irq_inits[0]) - 1)
+#define NUM_IRQ_INITS (ARRAY_SIZE(irq_inits) - 1)
 
 static struct hw_interrupt_type hw_itypes[NUM_IRQ_INITS];
 
diff --git a/arch/v850/kernel/me2.c b/arch/v850/kernel/me2.c
index 14b0c88..38be5c1 100644
--- a/arch/v850/kernel/me2.c
+++ b/arch/v850/kernel/me2.c
@@ -44,7 +44,7 @@ static struct v850e_intc_irq_init irq_inits[] = {
 	{ "UBTITO", IRQ_INTUBTITO(0), IRQ_INTUBTITO_NUM, 5, 4 },
 	{ 0 }
 };
-#define NUM_IRQ_INITS ((sizeof irq_inits / sizeof irq_inits[0]) - 1)
+#define NUM_IRQ_INITS (ARRAY_SIZE(irq_inits) - 1)
 
 static struct hw_interrupt_type hw_itypes[NUM_IRQ_INITS];
 
diff --git a/arch/v850/kernel/rte_cb.c b/arch/v850/kernel/rte_cb.c
index 0f7f6cd..43018e1 100644
--- a/arch/v850/kernel/rte_cb.c
+++ b/arch/v850/kernel/rte_cb.c
@@ -15,6 +15,7 @@
 #include <linux/irq.h>
 #include <linux/fs.h>
 #include <linux/module.h>
+#include <linux/kernel.h>
 
 #include <asm/machdep.h>
 #include <asm/v850e_uart.h>
@@ -176,8 +177,7 @@ static struct gbus_int_irq_init gbus_irq_inits[] = {
 #endif
 	{ 0 }
 };
-#define NUM_GBUS_IRQ_INITS  \
-   ((sizeof gbus_irq_inits / sizeof gbus_irq_inits[0]) - 1)
+#define NUM_GBUS_IRQ_INITS (ARRAY_SIZE(gbus_irq_inits) - 1)
 
 static struct hw_interrupt_type gbus_hw_itypes[NUM_GBUS_IRQ_INITS];
 
diff --git a/arch/v850/kernel/rte_mb_a_pci.c b/arch/v850/kernel/rte_mb_a_pci.c
index 35213fa..35a4bd5 100644
--- a/arch/v850/kernel/rte_mb_a_pci.c
+++ b/arch/v850/kernel/rte_mb_a_pci.c
@@ -70,8 +70,7 @@ static struct mb_pci_dev_irq mb_pci_dev_irqs[] = {
 	/* PCI slot 2 */
 	{ 9, 	IRQ_MB_A_PCI2(0),	1 }
 };
-#define NUM_MB_PCI_DEV_IRQS \
-  (sizeof mb_pci_dev_irqs / sizeof mb_pci_dev_irqs[0])
+#define NUM_MB_PCI_DEV_IRQS ARRAY_SIZE(mb_pci_dev_irqs)
 
 \f
 /* PCI configuration primitives.  */
diff --git a/arch/v850/kernel/rte_me2_cb.c b/arch/v850/kernel/rte_me2_cb.c
index 3be355a..46803d4 100644
--- a/arch/v850/kernel/rte_me2_cb.c
+++ b/arch/v850/kernel/rte_me2_cb.c
@@ -170,8 +170,7 @@ static struct cb_pic_irq_init cb_pic_irq_inits[] = {
 	{ "CB_EXTTM2",       IRQ_CB_EXTTM2,       1, 1, 6 },
 	{ 0 }
 };
-#define NUM_CB_PIC_IRQ_INITS  \
-   ((sizeof cb_pic_irq_inits / sizeof cb_pic_irq_inits[0]) - 1)
+#define NUM_CB_PIC_IRQ_INITS (ARRAY_SIZE(cb_pic_irq_inits) - 1)
 
 static struct hw_interrupt_type cb_pic_hw_itypes[NUM_CB_PIC_IRQ_INITS];
 static unsigned char cb_pic_active_irqs = 0;
diff --git a/arch/v850/kernel/teg.c b/arch/v850/kernel/teg.c
index 290d506..699248f 100644
--- a/arch/v850/kernel/teg.c
+++ b/arch/v850/kernel/teg.c
@@ -43,7 +43,7 @@ static struct v850e_intc_irq_init irq_inits[] = {
 	{ "ST",	 IRQ_INTST(0),	IRQ_INTST_NUM,	1, 5 },
 	{ 0 }
 };
-#define NUM_IRQ_INITS ((sizeof irq_inits / sizeof irq_inits[0]) - 1)
+#define NUM_IRQ_INITS (ARRAY_SIZE(irq_inits) - 1)
 
 static struct hw_interrupt_type hw_itypes[NUM_IRQ_INITS];
 

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 86%]

* [PATCH 2.6.20] arch MIPS: user ARRAY_SIZE macro when appropriate
  2007-02-05  2:39 97% [PATCH 00] A series of patches to use ARRAY_SIZE macro under arch/ Ahmed S. Darwish
                   ` (2 preceding siblings ...)
  2007-02-05  2:41 99% ` [PATCH 2.6.20] arch M68KNOMMU: user " Ahmed S. Darwish
@ 2007-02-05  2:42 89% ` Ahmed S. Darwish
  2007-02-05  2:42 86% ` [PATCH 2.6.20] arch V850: " Ahmed S. Darwish
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-05  2:42 UTC (permalink / raw)
  To: ralf, linux-mips; +Cc: linux-kernel

Hi all,

A patch to use ARRAY_SIZE macro already defined in linux/kernel.h

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
Patch isn't compile checked cause I have no MIPS board at hand.
Thanks,

diff --git a/arch/mips/jmr3927/rbhma3100/setup.c b/arch/mips/jmr3927/rbhma3100/setup.c
index 138f25e..7ca3d6d 100644
--- a/arch/mips/jmr3927/rbhma3100/setup.c
+++ b/arch/mips/jmr3927/rbhma3100/setup.c
@@ -434,7 +434,7 @@ void __init tx3927_setup(void)
 
 	/* DMA */
 	tx3927_dmaptr->mcr = 0;
-	for (i = 0; i < sizeof(tx3927_dmaptr->ch) / sizeof(tx3927_dmaptr->ch[0]); i++) {
+	for (i = 0; i < ARRAY_SIZE(tx3927_dmaptr->ch); i++) {
 		/* reset channel */
 		tx3927_dmaptr->ch[i].ccr = TX3927_DMA_CCR_CHRST;
 		tx3927_dmaptr->ch[i].ccr = 0;
diff --git a/arch/mips/arc/identify.c b/arch/mips/arc/identify.c
index 3ba7c47..4b90736 100644
--- a/arch/mips/arc/identify.c
+++ b/arch/mips/arc/identify.c
@@ -77,7 +77,7 @@ static struct smatch * __init string_to_mach(const char *s)
 {
 	int i;
 
-	for (i = 0; i < (sizeof(mach_table) / sizeof (mach_table[0])); i++) {
+	for (i = 0; i < ARRAY_SIZE(mach_table); i++) {
 		if (!strcmp(s, mach_table[i].arcname))
 			return &mach_table[i];
 	}
diff --git a/arch/mips/mips-boards/atlas/atlas_int.c b/arch/mips/mips-boards/atlas/atlas_int.c
index 43dba6c..4929f4d 100644
--- a/arch/mips/mips-boards/atlas/atlas_int.c
+++ b/arch/mips/mips-boards/atlas/atlas_int.c
@@ -32,6 +32,7 @@
 #include <linux/slab.h>
 #include <linux/interrupt.h>
 #include <linux/kernel_stat.h>
+#include <linux/kernel.h>
 
 #include <asm/gdb-stub.h>
 #include <asm/io.h>
@@ -220,7 +221,7 @@ msc_irqmap_t __initdata msc_irqmap[] = {
 	{MSC01C_INT_TMR,		MSC01_IRQ_EDGE, 0},
 	{MSC01C_INT_PCI,		MSC01_IRQ_LEVEL, 0},
 };
-int __initdata msc_nr_irqs = sizeof(msc_irqmap) / sizeof(*msc_irqmap);
+int __initdata msc_nr_irqs = ARRAY_SIZE(msc_irqmap);
 
 msc_irqmap_t __initdata msc_eicirqmap[] = {
 	{MSC01E_INT_SW0,		MSC01_IRQ_LEVEL, 0},
@@ -231,7 +232,7 @@ msc_irqmap_t __initdata msc_eicirqmap[] = {
 	{MSC01E_INT_PERFCTR,		MSC01_IRQ_LEVEL, 0},
 	{MSC01E_INT_CPUCTR,		MSC01_IRQ_LEVEL, 0}
 };
-int __initdata msc_nr_eicirqs = sizeof(msc_eicirqmap) / sizeof(*msc_eicirqmap);
+int __initdata msc_nr_eicirqs = ARRAY_SIZE(msc_eicirqmap);
 
 void __init arch_init_irq(void)
 {
diff --git a/arch/mips/mips-boards/malta/malta_int.c b/arch/mips/mips-boards/malta/malta_int.c
index 90ad5bf..b28edf5 100644
--- a/arch/mips/mips-boards/malta/malta_int.c
+++ b/arch/mips/mips-boards/malta/malta_int.c
@@ -27,6 +27,7 @@
 #include <linux/slab.h>
 #include <linux/interrupt.h>
 #include <linux/kernel_stat.h>
+#include <linux/kernel.h>
 #include <linux/random.h>
 
 #include <asm/i8259.h>
@@ -289,7 +290,7 @@ msc_irqmap_t __initdata msc_irqmap[] = {
 	{MSC01C_INT_TMR,		MSC01_IRQ_EDGE, 0},
 	{MSC01C_INT_PCI,		MSC01_IRQ_LEVEL, 0},
 };
-int __initdata msc_nr_irqs = sizeof(msc_irqmap)/sizeof(msc_irqmap_t);
+int __initdata msc_nr_irqs = ARRAY_SIZE(msc_irqmap);
 
 msc_irqmap_t __initdata msc_eicirqmap[] = {
 	{MSC01E_INT_SW0,		MSC01_IRQ_LEVEL, 0},
@@ -303,7 +304,7 @@ msc_irqmap_t __initdata msc_eicirqmap[] = {
 	{MSC01E_INT_PERFCTR,		MSC01_IRQ_LEVEL, 0},
 	{MSC01E_INT_CPUCTR,		MSC01_IRQ_LEVEL, 0}
 };
-int __initdata msc_nr_eicirqs = sizeof(msc_eicirqmap)/sizeof(msc_irqmap_t);
+int __initdata msc_nr_eicirqs = ARRAY_SIZE(msc_eicirqmap);
 
 void __init arch_init_irq(void)
 {
diff --git a/arch/mips/pci/fixup-vr4133.c b/arch/mips/pci/fixup-vr4133.c
index 597b897..6e09f38 100644
--- a/arch/mips/pci/fixup-vr4133.c
+++ b/arch/mips/pci/fixup-vr4133.c
@@ -17,6 +17,7 @@
  */
 #include <linux/init.h>
 #include <linux/pci.h>
+#include <linux/kernel.h>
 
 #include <asm/io.h>
 #include <asm/vr41xx/cmbvr4133.h>
@@ -142,7 +143,7 @@ int rockhopper_get_irq(struct pci_dev *dev, u8 pin, u8 slot)
 	if (bus == NULL)
 		return -1;
 
-	for (i = 0; i < sizeof (int_map) / sizeof (int_map[0]); i++) {
+	for (i = 0; i < ARRAY_SIZE(int_map); i++) {
 		if (int_map[i].bus == bus->number && int_map[i].slot == slot) {
 			int line;
 			for (line = 0; line < 4; line++)

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 89%]

* [PATCH 2.6.20] arch M68KNOMMU: user ARRAY_SIZE macro when appropriate
  2007-02-05  2:39 97% [PATCH 00] A series of patches to use ARRAY_SIZE macro under arch/ Ahmed S. Darwish
  2007-02-05  2:40 99% ` [PATCH 2.6.20] arch CRIS: user ARRAY_SIZE macro when appropriate Ahmed S. Darwish
  2007-02-05  2:41 99% ` [PATCH 2.6.20] arch AVR32: Use " Ahmed S. Darwish
@ 2007-02-05  2:41 99% ` Ahmed S. Darwish
  2007-02-05  2:42 89% ` [PATCH 2.6.20] arch MIPS: " Ahmed S. Darwish
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-05  2:41 UTC (permalink / raw)
  To: gerg; +Cc: linux-kernel

Hi all,

A patch to use ARRAY_SIZE macro already defined in linux/kernel.h

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
Patch isn't compile checked cause I have no M68KNOMMU board at hand.
Thanks,

diff --git a/arch/m68knommu/kernel/ptrace.c b/arch/m68knommu/kernel/ptrace.c
index 9130119..72d3496 100644
--- a/arch/m68knommu/kernel/ptrace.c
+++ b/arch/m68knommu/kernel/ptrace.c
@@ -62,7 +62,7 @@ static inline long get_reg(struct task_struct *task, int regno)
 
 	if (regno == PT_USP)
 		addr = &task->thread.usp;
-	else if (regno < sizeof(regoff)/sizeof(regoff[0]))
+	else if (regno < ARRAY_SIZE(regoff))
 		addr = (unsigned long *)(task->thread.esp0 + regoff[regno]);
 	else
 		return 0;
@@ -79,7 +79,7 @@ static inline int put_reg(struct task_struct *task, int regno,
 
 	if (regno == PT_USP)
 		addr = &task->thread.usp;
-	else if (regno < sizeof(regoff)/sizeof(regoff[0]))
+	else if (regno < ARRAY_SIZE(regoff))
 		addr = (unsigned long *) (task->thread.esp0 + regoff[regno]);
 	else
 		return -1;
diff --git a/arch/m68knommu/kernel/traps.c b/arch/m68knommu/kernel/traps.c
index 9129b3a..bed5f47 100644
--- a/arch/m68knommu/kernel/traps.c
+++ b/arch/m68knommu/kernel/traps.c
@@ -158,7 +158,7 @@ void show_stack(struct task_struct *task, unsigned long *stack)
 void bad_super_trap(struct frame *fp)
 {
 	console_verbose();
-	if (fp->ptregs.vector < 4*sizeof(vec_names)/sizeof(vec_names[0]))
+	if (fp->ptregs.vector < 4 * ARRAY_SIZE(vec_names))
 		printk (KERN_WARNING "*** %s ***   FORMAT=%X\n",
 			vec_names[(fp->ptregs.vector) >> 2],
 			fp->ptregs.format);

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.20] arch AVR32: Use ARRAY_SIZE macro when appropriate
  2007-02-05  2:39 97% [PATCH 00] A series of patches to use ARRAY_SIZE macro under arch/ Ahmed S. Darwish
  2007-02-05  2:40 99% ` [PATCH 2.6.20] arch CRIS: user ARRAY_SIZE macro when appropriate Ahmed S. Darwish
@ 2007-02-05  2:41 99% ` Ahmed S. Darwish
  2007-02-05  2:41 99% ` [PATCH 2.6.20] arch M68KNOMMU: user " Ahmed S. Darwish
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-05  2:41 UTC (permalink / raw)
  To: hskinnemoen; +Cc: linux-kernel

Hi Haavard,

A patch to use ARRAY_SIZE macro already defined in linux/kernel.h

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
Patch isn't compile checked cause I have no AVR32 machine at hand.
Thanks,

diff --git a/arch/avr32/kernel/setup.c b/arch/avr32/kernel/setup.c
index a342116..c6734ae 100644
--- a/arch/avr32/kernel/setup.c
+++ b/arch/avr32/kernel/setup.c
@@ -16,6 +16,7 @@
 #include <linux/module.h>
 #include <linux/root_dev.h>
 #include <linux/cpu.h>
+#include <linux/kernel.h>
 
 #include <asm/sections.h>
 #include <asm/processor.h>
@@ -174,8 +175,7 @@ static int __init parse_tag_mem_range(struct tag *tag,
 	 * Copy the data so the bootmem init code doesn't need to care
 	 * about it.
 	 */
-	if (mem_range_next_free >=
-	    (sizeof(mem_range_cache) / sizeof(mem_range_cache[0])))
+	if (mem_range_next_free >= ARRAY_SIZE(mem_range_cache))
 		panic("Physical memory map too complex!\n");
 
 	new = &mem_range_cache[mem_range_next_free++];

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.20] arch CRIS: user ARRAY_SIZE macro when appropriate
  2007-02-05  2:39 97% [PATCH 00] A series of patches to use ARRAY_SIZE macro under arch/ Ahmed S. Darwish
@ 2007-02-05  2:40 99% ` Ahmed S. Darwish
  2007-02-05  2:41 99% ` [PATCH 2.6.20] arch AVR32: Use " Ahmed S. Darwish
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-05  2:40 UTC (permalink / raw)
  To: starvik; +Cc: linux-kernel

Hi all,

A patch to use ARRAY_SIZE macro already defined in linux/kernel.h

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
Patch isn't compile checked since I have no CRIS machine at hand.

diff --git a/arch/cris/arch-v10/drivers/axisflashmap.c b/arch/cris/arch-v10/drivers/axisflashmap.c
index ffade19..c5d90fc 100644
--- a/arch/cris/arch-v10/drivers/axisflashmap.c
+++ b/arch/cris/arch-v10/drivers/axisflashmap.c
@@ -359,8 +359,7 @@ static struct mtd_info *flash_probe(void)
 		 * So we use the MTD concatenation layer instead of further
 		 * complicating the probing procedure.
 		 */
-		mtd_cse = mtd_concat_create(mtds,
-					    sizeof(mtds) / sizeof(mtds[0]),
+		mtd_cse = mtd_concat_create(mtds, ARRAY_SIZE(mtds), 
 					    "cse0+cse1");
 #else
 		printk(KERN_ERR "%s and %s: Cannot concatenate due to kernel "
diff --git a/arch/cris/mm/tlb.c b/arch/cris/mm/tlb.c
index 0df390a..c4a98e2 100644
--- a/arch/cris/mm/tlb.c
+++ b/arch/cris/mm/tlb.c
@@ -8,6 +8,7 @@
  */
 
 #include <linux/init.h>
+#include <linux/kernel.h>
 #include <asm/tlb.h>
 
 #define D(x)
@@ -100,7 +101,7 @@ tlb_init(void)
 
 	/* clear the page_id map */
 
-	for (i = 1; i < sizeof (page_id_map) / sizeof (page_id_map[0]); i++)
+	for (i = 1; i < ARRAY_SIZE(page_id_map); i++)
 		page_id_map[i] = NULL;
 	
 	/* invalidate the entire TLB */

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 00] A series of patches to use ARRAY_SIZE macro under arch/
@ 2007-02-05  2:39 97% Ahmed S. Darwish
  2007-02-05  2:40 99% ` [PATCH 2.6.20] arch CRIS: user ARRAY_SIZE macro when appropriate Ahmed S. Darwish
                   ` (8 more replies)
  0 siblings, 9 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-05  2:39 UTC (permalink / raw)
  To: linux-kernel

Hi, all

A series of patches to use ARRAY_SIZE macro under the `arch' subtree. 
Each architecture has its own mail/patch as a reply to this thread.
Those patches are not compile-tested as I don't have needed machines but
I tried hard to make sure that they are hopefully correct.
Patches can be applied cleanly on 2.6.20.

arm/kernel/ecard.c                   |    2 +-
arm26/kernel/ecard.c                 |    2 +-
avr32/kernel/setup.c                 |    4 ++--
cris/arch-v10/drivers/axisflashmap.c |    3 +--
cris/mm/tlb.c                        |    3 ++-
m68k/kernel/ptrace.c                 |    4 ++--
m68k/kernel/traps.c                  |    2 +-
m68knommu/kernel/ptrace.c            |    4 ++--
m68knommu/kernel/traps.c             |    2 +-
mips/arc/identify.c                  |    2 +-
mips/jmr3927/rbhma3100/setup.c       |    2 +-
mips/mips-boards/atlas/atlas_int.c   |    5 +++--
mips/mips-boards/malta/malta_int.c   |    5 +++--
mips/pci/fixup-vr4133.c              |    3 ++-
powerpc/lib/rheap.c                  |    3 ++-
powerpc/xmon/ppc-opc.c               |    7 +++----
powerpc/xmon/spu-opc.c               |    4 ++--
ppc/lib/rheap.c                      |    3 ++-
ppc/syslib/m8xx_setup.c              |    2 +-
ppc/xmon/ppc-opc.c                   |    7 +++----
v850/kernel/anna.c                   |    2 +-
v850/kernel/as85ep1.c                |    2 +-
v850/kernel/fpga85e2c.c              |    2 +-
v850/kernel/gbus_int.c               |    6 +++---
v850/kernel/ma.c                     |    2 +-
v850/kernel/me2.c                    |    2 +-
v850/kernel/rte_cb.c                 |    4 ++--
v850/kernel/rte_mb_a_pci.c           |    3 +--
v850/kernel/rte_me2_cb.c             |    3 +--
v850/kernel/teg.c                    |    2 +-
30 files changed, 49 insertions(+), 48 deletions(-)

Thanks,
-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 97%]

* Re: A CodingStyle suggestion
  2007-02-03 21:58 99% A CodingStyle suggestion Ahmed S. Darwish
  @ 2007-02-04 12:10 99% ` Ahmed S. Darwish
  1 sibling, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-04 12:10 UTC (permalink / raw)
  To: linux-kernel

On Sat, Feb 03, 2007 at 11:58:48PM +0200, Darwish wrote:
> Hi all,
> 
> In CodingStyle Chapter 16 "Function return value and names", why not
> adding a comment about the favorable community way of checking the return
> value. ie:
> 
> ret = do_method();
> if (ret) {
>    /* deal with error */
> }

Thanks for all the replies, A patch will be sent in a new thread.  

Regards
-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: A CodingStyle suggestion
  @ 2007-02-04  0:05 99%   ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-04  0:05 UTC (permalink / raw)
  To: Richard Knutsson; +Cc: linux-kernel, randy.dunlap

On Sat, Feb 03, 2007 at 11:56:16PM +0100, Richard Knutsson wrote:
> Ahmed S. Darwish wrote:
> >Hi all,
> >
> >In CodingStyle Chapter 16 "Function return value and names", why not
> >adding a comment about the favorable community way of checking the return
> >value. ie:
> >
> >ret = do_method();
> >if (ret) {
> >   /* deal with error */
> >}
> >
> >and not other ways like:
> >
> >if (do_method()) or 
> So:
> 
> if (is_true()) {
> 	/* do something */
> }
> 
> is alright then? If so, I agree, but please make it real clear in the 
> document ;)

Good catch :). A small grep of `access_ok' reveals that it's always used in the 
form of:
if (!access_ok()) { .. }

I can conclude that verbal/imperative methods like `kmalloc, add_work' be 
checked as:
ret = do_work();
if (ret) { ... }
and predicate methods like `acess_ok, pci_dev_present' be checked like:
if (!access_ok) { ... }
if (pci_dev_present) { ...}

Any comments ?

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* A CodingStyle suggestion
@ 2007-02-03 21:58 99% Ahmed S. Darwish
    2007-02-04 12:10 99% ` Ahmed S. Darwish
  0 siblings, 2 replies; 200+ results
From: Ahmed S. Darwish @ 2007-02-03 21:58 UTC (permalink / raw)
  To: linux-kernel

Hi all,

In CodingStyle Chapter 16 "Function return value and names", why not
adding a comment about the favorable community way of checking the return
value. ie:

ret = do_method();
if (ret) {
   /* deal with error */
}

and not other ways like:

if (do_method()) or if ((ret = do_method()) > value) ...

A patch is ready if the replies are positive.

Thanks,
-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: after effects of a kernel API change
  @ 2007-01-18  9:44 99%     ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-18  9:44 UTC (permalink / raw)
  To: Rajat Jain; +Cc: Daniel Rodrick, kernelnewbies, Linux Newbie, linux-kernel

On Thu, Jan 18, 2007 at 11:05:53AM +0530, Rajat Jain wrote:
> >>
> >> Is there any way volunteers like me can help in this exercise?
> >
> >See the /APIchanges in the Kernel Janitors TODO list
> >http://kernelnewbies.org/KernelJanitors/Todo
> >
> [...]
> 1) How do I make sure if some one is NOT working on any of the
> mentioned bullet points? Who coordinates? On what mailing list?

Check latest trees to make sure the work is not duplicated. espicially 
trees like -mm and subsystem ones.

> 2) Do any patches for the above Todo list have the chances of getting
> merged into the mainstream kernel? Who approves? I suppose the
> respective maintainer of the driver / subsystem getting affected?

I advise lurking (following/reading) the list for at least 2 or 3 weeks and 
you'll automatically understand how the "system" works. Also check:

$KERNEL_TREE/Documentation/HOWTO
$KERNEL_TREE/Documentation/SubmittingPatches
$KERNEL_TREE/Documentation/CodingStyle

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: after effects of a kernel API change
  @ 2007-01-18  5:10 99% ` Ahmed S. Darwish
    0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2007-01-18  5:10 UTC (permalink / raw)
  To: Daniel Rodrick; +Cc: kernelnewbies, Linux Newbie, linux-kernel

On Thu, Jan 18, 2007 at 09:45:04AM +0530, Daniel Rodrick wrote:
> Hi list,
> 
> Whenever there is a change in the kernel API (or a new API is
> introduced), all of the drivers that use the older API need to be
> changed (or recommended to be changed). I believe it is the
> responsibility of the person changing the kernel API, to change all
> the drivers that have found their way into the kernel code?
> 
> How does this happen? Because the person who brought the change in the
> API might not know the internals of all the drivers?
> 
> Is there any way volunteers like me can help in this exercise?

See the /APIchanges in the Kernel Janitors TODO list
http://kernelnewbies.org/KernelJanitors/Todo

Also: Documentation/stable_api_nonsense.txt

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH 2.6.20-rc5 2/4] pvrusb2: Use ARRAY_SIZE macro
  @ 2007-01-16 19:07 64%     ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-16 19:07 UTC (permalink / raw)
  To: Randy Dunlap
  Cc: Robert P. J. Day, isely, video4linux-list, linux-kernel, trivial

On Tue, Jan 16, 2007 at 10:16:33AM -0800, Randy Dunlap wrote:
> On Tue, 16 Jan 2007 03:36:16 -0500 (EST) Robert P. J. Day wrote:
> 
> > On Tue, 16 Jan 2007, Ahmed S. Darwish wrote:
> > 
> > > Use ARRAY_SIZE macro in pvrusb2-hdw.c file
> > >
> > > Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
> > 
> > ... snip ...
> > 
> > i'm not sure it's worth submitting multiple patches to convert code
> > expressions to the ARRAY_SIZE() macro since i was going to wait for
> > the next kernel release, and do that in one fell swoop with a single
> > patch.
> > 
> > but if people higher up the food chain think it's a better idea to do
> > it a little at a time, that's fine.
> 
> I'm not strictly on the food chain, but these 4 patches to
> pvrusb2 should have been sent as one patch IMO.

Here's the same patch in one file as suggested.

A patch to use ARRAY_SIZE macro when appropriate. 

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

pvrusb2-encoder.c   |   19 ++++++++-----------
pvrusb2-hdw.c       |   22 ++++++++--------------
pvrusb2-i2c-core.c  |    3 +--
pvrusb2-std.c       |   25 +++++++++----------------
pvrusb2-sysfs.c     |    2 +-
pvrusb2-video-v4l.c |    9 +++------
pvrusb2-wm8775.c    |    9 +++------
7 files changed, 33 insertions(+), 56 deletions(-)

diff --git a/drivers/media/video/pvrusb2/pvrusb2-encoder.c b/drivers/media/video/pvrusb2/pvrusb2-encoder.c
index c94f97b..4ec937a 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-encoder.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-encoder.c
@@ -169,25 +169,23 @@ static int pvr2_encoder_cmd(void *ctxt,
 
 	*/
 
-	if (arg_cnt_send > (sizeof(wrData)/sizeof(wrData[0]))-4) {
+	if (arg_cnt_send > (ARRAY_SIZE(wrData) - 4)) {
 		pvr2_trace(
 			PVR2_TRACE_ERROR_LEGS,
 			"Failed to write cx23416 command"
 			" - too many input arguments"
 			" (was given %u limit %u)",
-			arg_cnt_send,
-			(unsigned int)(sizeof(wrData)/sizeof(wrData[0])) - 4);
+			arg_cnt_send, ARRAY_SIZE(wrData) - 4);
 		return -EINVAL;
 	}
 
-	if (arg_cnt_recv > (sizeof(rdData)/sizeof(rdData[0]))-4) {
+	if (arg_cnt_recv > (ARRAY_SIZE(rdData) - 4)) {
 		pvr2_trace(
 			PVR2_TRACE_ERROR_LEGS,
 			"Failed to write cx23416 command"
 			" - too many return arguments"
 			" (was given %u limit %u)",
-			arg_cnt_recv,
-			(unsigned int)(sizeof(rdData)/sizeof(rdData[0])) - 4);
+			arg_cnt_recv, ARRAY_SIZE(rdData) - 4);
 		return -EINVAL;
 	}
 
@@ -201,7 +199,7 @@ static int pvr2_encoder_cmd(void *ctxt,
 		for (idx = 0; idx < arg_cnt_send; idx++) {
 			wrData[idx+4] = argp[idx];
 		}
-		for (; idx < (sizeof(wrData)/sizeof(wrData[0]))-4; idx++) {
+		for (; idx < ARRAY_SIZE(wrData) - 4; idx++) {
 			wrData[idx+4] = 0;
 		}
 
@@ -245,8 +243,7 @@ static int pvr2_encoder_cmd(void *ctxt,
 		if (ret) break;
 		wrData[0] = 0x7;
 		ret = pvr2_encoder_read_words(
-			hdw,0,rdData,
-			sizeof(rdData)/sizeof(rdData[0]));
+			hdw,0,rdData, ARRAY_SIZE(rdData));
 		if (ret) break;
 		for (idx = 0; idx < arg_cnt_recv; idx++) {
 			argp[idx] = rdData[idx+4];
@@ -269,13 +266,13 @@ static int pvr2_encoder_vcmd(struct pvr2_hdw *hdw, int cmd,
 	unsigned int idx;
 	u32 data[12];
 
-	if (args > sizeof(data)/sizeof(data[0])) {
+	if (args > ARRAY_SIZE(data)) {
 		pvr2_trace(
 			PVR2_TRACE_ERROR_LEGS,
 			"Failed to write cx23416 command"
 			" - too many arguments"
 			" (was given %u limit %u)",
-			args,(unsigned int)(sizeof(data)/sizeof(data[0])));
+			args, ARRAY_SIZE(data));
 		return -EINVAL;
 	}
 
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
index d200496..f66f7c6 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
@@ -71,12 +71,10 @@ static const char *pvr2_client_29xxx[] = {
 
 static struct pvr2_string_table pvr2_client_lists[] = {
 	[PVR2_HDW_TYPE_29XXX] = {
-		pvr2_client_29xxx,
-		sizeof(pvr2_client_29xxx)/sizeof(pvr2_client_29xxx[0]),
+		pvr2_client_29xxx, ARRAY_SIZE(pvr2_client_29xxx)
 	},
 	[PVR2_HDW_TYPE_24XXX] = {
-		pvr2_client_24xxx,
-		sizeof(pvr2_client_24xxx)/sizeof(pvr2_client_24xxx[0]),
+		pvr2_client_24xxx, ARRAY_SIZE(pvr2_client_24xxx)
 	},
 };
 
@@ -212,7 +210,7 @@ static const struct pvr2_mpeg_ids mpeg_ids[] = {
 		.id = V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM,
 	}
 };
-#define MPEGDEF_COUNT (sizeof(mpeg_ids)/sizeof(mpeg_ids[0]))
+#define MPEGDEF_COUNT ARRAY_SIZE(mpeg_ids)
 
 
 static const char *control_values_srate[] = {
@@ -846,7 +844,7 @@ static const struct pvr2_ctl_info control_defs[] = {
 	}
 };
 
-#define CTRLDEF_COUNT (sizeof(control_defs)/sizeof(control_defs[0]))
+#define CTRLDEF_COUNT ARRAY_SIZE(control_defs)
 
 
 const char *pvr2_config_get_name(enum pvr2_config cfg)
@@ -960,12 +958,10 @@ static int pvr2_upload_firmware1(struct pvr2_hdw *hdw)
 	};
 	static const struct pvr2_string_table fw_file_defs[] = {
 		[PVR2_HDW_TYPE_29XXX] = {
-			fw_files_29xxx,
-			sizeof(fw_files_29xxx)/sizeof(fw_files_29xxx[0]),
+			fw_files_29xxx, ARRAY_SIZE(fw_files_29xxx)
 		},
 		[PVR2_HDW_TYPE_24XXX] = {
-			fw_files_24xxx,
-			sizeof(fw_files_24xxx)/sizeof(fw_files_24xxx[0]),
+			fw_files_24xxx, ARRAY_SIZE(fw_files_24xxx)
 		},
 	};
 	hdw->fw1_state = FW1_STATE_FAILED; // default result
@@ -1052,8 +1048,7 @@ int pvr2_upload_firmware2(struct pvr2_hdw *hdw)
 	trace_firmware("pvr2_upload_firmware2");
 
 	ret = pvr2_locate_firmware(hdw,&fw_entry,"encoder",
-				   sizeof(fw_files)/sizeof(fw_files[0]),
-				   fw_files);
+				   ARRAY_SIZE(fw_files), fw_files);
 	if (ret < 0) return ret;
 	fwidx = ret;
 	ret = 0;
@@ -1750,8 +1745,7 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
 	struct pvr2_ctl_info *ciptr;
 
 	hdw_type = devid - pvr2_device_table;
-	if (hdw_type >=
-	    sizeof(pvr2_device_names)/sizeof(pvr2_device_names[0])) {
+	if (hdw_type >= ARRAY_SIZE(pvr2_device_names)) {
 		pvr2_trace(PVR2_TRACE_ERROR_LEGS,
 			   "Bogus device type of %u reported",hdw_type);
 		return NULL;
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
index f9bb41d..83df9ee 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
@@ -948,8 +948,7 @@ static void do_i2c_scan(struct pvr2_hdw *hdw)
 	printk("%s: i2c scan beginning\n",hdw->name);
 	for (i = 0; i < 128; i++) {
 		msg[0].addr = i;
-		rc = i2c_transfer(&hdw->i2c_adap,msg,
-				  sizeof(msg)/sizeof(msg[0]));
+		rc = i2c_transfer(&hdw->i2c_adap,msg, ARRAY_SIZE(msg));
 		if (rc != 1) continue;
 		printk("%s: i2c scan: found device @ 0x%x\n",hdw->name,i);
 	}
diff --git a/drivers/media/video/pvrusb2/pvrusb2-std.c b/drivers/media/video/pvrusb2/pvrusb2-std.c
index f95c598..677f126 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-std.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-std.c
@@ -141,10 +141,8 @@ int pvr2_std_str_to_id(v4l2_std_id *idPtr,const char *bufPtr,
 			cnt = 0;
 			while ((cnt < bufSize) && (bufPtr[cnt] != '-')) cnt++;
 			if (cnt >= bufSize) return 0; // No more characters
-			sp = find_std_name(
-				std_groups,
-				sizeof(std_groups)/sizeof(std_groups[0]),
-				bufPtr,cnt);
+			sp = find_std_name(std_groups, ARRAY_SIZE(std_groups),
+					   bufPtr,cnt);
 			if (!sp) return 0; // Illegal color system name
 			cnt++;
 			bufPtr += cnt;
@@ -163,8 +161,7 @@ int pvr2_std_str_to_id(v4l2_std_id *idPtr,const char *bufPtr,
 			if (ch == '/') break;
 			cnt++;
 		}
-		sp = find_std_name(std_items,
-				   sizeof(std_items)/sizeof(std_items[0]),
+		sp = find_std_name(std_items, ARRAY_SIZE(std_items),
 				   bufPtr,cnt);
 		if (!sp) return 0; // Illegal modulation system ID
 		t = sp->id & cmsk;
@@ -189,14 +186,10 @@ unsigned int pvr2_std_id_to_str(char *bufPtr, unsigned int bufSize,
 	unsigned int c1,c2;
 	cfl = 0;
 	c1 = 0;
-	for (idx1 = 0;
-	     idx1 < sizeof(std_groups)/sizeof(std_groups[0]);
-	     idx1++) {
+	for (idx1 = 0; idx1 < ARRAY_SIZE(std_groups); idx1++) {
 		gp = std_groups + idx1;
 		gfl = 0;
-		for (idx2 = 0;
-		     idx2 < sizeof(std_items)/sizeof(std_items[0]);
-		     idx2++) {
+		for (idx2 = 0; idx2 < ARRAY_SIZE(std_items); idx2++) {
 			ip = std_items + idx2;
 			if (!(gp->id & ip->id & id)) continue;
 			if (!gfl) {
@@ -279,7 +272,7 @@ static struct v4l2_standard generic_standards[] = {
 	}
 };
 
-#define generic_standards_cnt (sizeof(generic_standards)/sizeof(generic_standards[0]))
+#define generic_standards_cnt ARRAY_SIZE(generic_standards)
 
 static struct v4l2_standard *match_std(v4l2_std_id id)
 {
@@ -348,7 +341,7 @@ struct v4l2_standard *pvr2_std_create_enum(unsigned int *countptr,
 		fmsk |= idmsk;
 	}
 
-	for (idx2 = 0; idx2 < sizeof(std_mixes)/sizeof(std_mixes[0]); idx2++) {
+	for (idx2 = 0; idx2 < ARRAY_SIZE(std_mixes); idx2++) {
 		if ((id & std_mixes[idx2]) == std_mixes[idx2]) std_cnt++;
 	}
 
@@ -374,8 +367,8 @@ struct v4l2_standard *pvr2_std_create_enum(unsigned int *countptr,
 	idx = 0;
 
 	/* Enumerate potential special cases */
-	for (idx2 = 0; ((idx2 < sizeof(std_mixes)/sizeof(std_mixes[0])) &&
-			(idx < std_cnt)); idx2++) {
+	for (idx2 = 0; (idx2 < ARRAY_SIZE(std_mixes)) && (idx < std_cnt);
+	     idx2++) {
 		if (!(id & std_mixes[idx2])) continue;
 		if (pvr2_std_fill(stddefs+idx,std_mixes[idx2])) idx++;
 	}
diff --git a/drivers/media/video/pvrusb2/pvrusb2-sysfs.c b/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
index c294f46..17b5a3e 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
@@ -491,7 +491,7 @@ static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id)
 	unsigned int cnt,acnt;
 	int ret;
 
-	if ((ctl_id < 0) || (ctl_id >= (sizeof(funcs)/sizeof(funcs[0])))) {
+	if ((ctl_id < 0) || (ctl_id >= ARRAY_SIZE(funcs))) {
 		return;
 	}
 
diff --git a/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c b/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c
index 05f2cdd..b3eba8a 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c
@@ -137,8 +137,7 @@ static int decoder_check(struct pvr2_v4l_decoder *ctxt)
 	unsigned long msk;
 	unsigned int idx;
 
-	for (idx = 0; idx < sizeof(decoder_ops)/sizeof(decoder_ops[0]);
-	     idx++) {
+	for (idx = 0; idx < ARRAY_SIZE(decoder_ops); idx++) {
 		msk = 1 << idx;
 		if (ctxt->stale_mask & msk) continue;
 		if (decoder_ops[idx].check(ctxt)) {
@@ -154,8 +153,7 @@ static void decoder_update(struct pvr2_v4l_decoder *ctxt)
 	unsigned long msk;
 	unsigned int idx;
 
-	for (idx = 0; idx < sizeof(decoder_ops)/sizeof(decoder_ops[0]);
-	     idx++) {
+	for (idx = 0; idx < ARRAY_SIZE(decoder_ops); idx++) {
 		msk = 1 << idx;
 		if (!(ctxt->stale_mask & msk)) continue;
 		ctxt->stale_mask &= ~msk;
@@ -230,8 +228,7 @@ int pvr2_i2c_decoder_v4l_setup(struct pvr2_hdw *hdw,
 	ctxt->ctrl.tuned = (int (*)(void *))decoder_is_tuned;
 	ctxt->client = cp;
 	ctxt->hdw = hdw;
-	ctxt->stale_mask = (1 << (sizeof(decoder_ops)/
-				  sizeof(decoder_ops[0]))) - 1;
+	ctxt->stale_mask = (1 << ARRAY_SIZE(decoder_ops)) - 1;
 	hdw->decoder_ctrl = &ctxt->ctrl;
 	cp->handler = &ctxt->handler;
 	pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x saa711x V4L2 handler set up",
diff --git a/drivers/media/video/pvrusb2/pvrusb2-wm8775.c b/drivers/media/video/pvrusb2/pvrusb2-wm8775.c
index 2413e51..3a29bb8 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-wm8775.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-wm8775.c
@@ -99,8 +99,7 @@ static int wm8775_check(struct pvr2_v4l_wm8775 *ctxt)
 	unsigned long msk;
 	unsigned int idx;
 
-	for (idx = 0; idx < sizeof(wm8775_ops)/sizeof(wm8775_ops[0]);
-	     idx++) {
+	for (idx = 0; idx < ARRAY_SIZE(wm8775_ops); idx++) {
 		msk = 1 << idx;
 		if (ctxt->stale_mask & msk) continue;
 		if (wm8775_ops[idx].check(ctxt)) {
@@ -116,8 +115,7 @@ static void wm8775_update(struct pvr2_v4l_wm8775 *ctxt)
 	unsigned long msk;
 	unsigned int idx;
 
-	for (idx = 0; idx < sizeof(wm8775_ops)/sizeof(wm8775_ops[0]);
-	     idx++) {
+	for (idx = 0; idx < ARRAY_SIZE(wm8775_ops); idx++) {
 		msk = 1 << idx;
 		if (!(ctxt->stale_mask & msk)) continue;
 		ctxt->stale_mask &= ~msk;
@@ -148,8 +146,7 @@ int pvr2_i2c_wm8775_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
 	ctxt->handler.func_table = &hfuncs;
 	ctxt->client = cp;
 	ctxt->hdw = hdw;
-	ctxt->stale_mask = (1 << (sizeof(wm8775_ops)/
-				  sizeof(wm8775_ops[0]))) - 1;
+	ctxt->stale_mask = (1 << ARRAY_SIZE(wm8775_ops)) - 1;
 	cp->handler = &ctxt->handler;
 	pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x wm8775 V4L2 handler set up",
 		   cp->client->addr);

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 64%]

* Re: [PATCH 2.6.20-rc5 2/4] pvrusb2: Use ARRAY_SIZE macro
    @ 2007-01-16 18:54 99%   ` Ahmed S. Darwish
  1 sibling, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-16 18:54 UTC (permalink / raw)
  To: Robert P. J. Day; +Cc: isely, video4linux-list, linux-kernel, trivial

On Tue, Jan 16, 2007 at 03:36:16AM -0500, Robert P. J. Day wrote:
> On Tue, 16 Jan 2007, Ahmed S. Darwish wrote:
> 
> > Use ARRAY_SIZE macro in pvrusb2-hdw.c file
> >
> > Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
> 
> ... snip ...
> 
> i'm not sure it's worth submitting multiple patches to convert code
> expressions to the ARRAY_SIZE() macro since i was going to wait for
> the next kernel release, and do that in one fell swoop with a single
> patch.

No problem :). But will a single patch be accepted ?. Grepping the tree,I found
many results that will make the patch very very big. 
Should I stop sending them till 2.6.20 ?. 
If so, I've made any way about 10 patches dealing with different subsytems. 
I can send them to you to avoid this little work duplication.


Regards
-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.20-rc5] isdn/capi: use ARRAY_SIZE when appropriate
@ 2007-01-16  9:53 99% Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-16  9:53 UTC (permalink / raw)
  To: kkeil, kai.germaschewski; +Cc: linux-kernel, trivial

Hi all,

A trivial patch to use ARRAY_SIZE macro defined in kernel.h instead
of reimplementing it.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

capi.c    |    4 ++--
capidrv.c |    4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index d22c022..3804591 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -1456,7 +1456,7 @@ static struct procfsentries {
 
 static void __init proc_init(void)
 {
-    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
+    int nelem = ARRAY_SIZE(procfsentries);
     int i;
 
     for (i=0; i < nelem; i++) {
@@ -1468,7 +1468,7 @@ static void __init proc_init(void)
 
 static void __exit proc_exit(void)
 {
-    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
+    int nelem = ARRAY_SIZE(procfsentries);
     int i;
 
     for (i=nelem-1; i >= 0; i--) {
diff --git a/drivers/isdn/capi/capidrv.c b/drivers/isdn/capi/capidrv.c
index c4d438c..8cec9c3 100644
--- a/drivers/isdn/capi/capidrv.c
+++ b/drivers/isdn/capi/capidrv.c
@@ -2218,7 +2218,7 @@ static struct procfsentries {
 
 static void __init proc_init(void)
 {
-    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
+    int nelem = ARRAY_SIZE(procfsentries);
     int i;
 
     for (i=0; i < nelem; i++) {
@@ -2230,7 +2230,7 @@ static void __init proc_init(void)
 
 static void __exit proc_exit(void)
 {
-    int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]);
+    int nelem = ARRAY_SIZE(procfsentries);
     int i;
 
     for (i=nelem-1; i >= 0; i--) {

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.20-rc5] DVB: Use ARRAY_SIZE macro when appropriate
@ 2007-01-16  9:20 88% Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-16  9:20 UTC (permalink / raw)
  To: v4l-dvb-maintainer; +Cc: linux-kernel, trivial

Hi all,

Patch uses the ARRAY_SIZE macro defined in kernel.h instead of 
reemplementing it.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

bt8xx/dvb-bt8xx.c   |    2 +-
frontends/cx24110.c |    4 ++--
frontends/cx24123.c |    6 +++---
3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/media/dvb/bt8xx/dvb-bt8xx.c b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
index 3e35931..7b76468 100644
--- a/drivers/media/dvb/bt8xx/dvb-bt8xx.c
+++ b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
@@ -213,7 +213,7 @@ static int cx24108_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend
 		freq = 2150000; /* satellite IF is 950..2150MHz */
 
 	/* decide which VCO to use for the input frequency */
-	for(i=1;(i<sizeof(osci)/sizeof(osci[0]))&&(osci[i]<freq);i++);
+	for(i=1;(i<ARRAY_SIZE(osci))&&(osci[i]<freq);i++);
 	printk("cx24108 debug: select vco #%d (f=%d)\n",i,freq);
 	band=bandsel[i];
 	/* the gain values must be set by SetSymbolrate */
diff --git a/drivers/media/dvb/frontends/cx24110.c b/drivers/media/dvb/frontends/cx24110.c
index ae96395..c3bf275 100644
--- a/drivers/media/dvb/frontends/cx24110.c
+++ b/drivers/media/dvb/frontends/cx24110.c
@@ -254,7 +254,7 @@ static int cx24110_set_symbolrate (struct cx24110_state* state, u32 srate)
 	if (srate<500000)
 		srate=500000;
 
-	for(i=0;(i<sizeof(bands)/sizeof(bands[0]))&&(srate>bands[i]);i++)
+	for(i = 0; (i < ARRAY_SIZE(bands)) && (srate > bands[i]); i++)
 		;
 	/* first, check which sample rate is appropriate: 45, 60 80 or 90 MHz,
 	   and set the PLL accordingly (R07[1:0] Fclk, R06[7:4] PLLmult,
@@ -361,7 +361,7 @@ static int cx24110_initfe(struct dvb_frontend* fe)
 
 	dprintk("%s: init chip\n", __FUNCTION__);
 
-	for(i=0;i<sizeof(cx24110_regdata)/sizeof(cx24110_regdata[0]);i++) {
+	for(i = 0; i < ARRAY_SIZE(cx24110_regdata); i++) {
 		cx24110_writereg(state, cx24110_regdata[i].reg, cx24110_regdata[i].data);
 	};
 
diff --git a/drivers/media/dvb/frontends/cx24123.c b/drivers/media/dvb/frontends/cx24123.c
index a356d28..732e94a 100644
--- a/drivers/media/dvb/frontends/cx24123.c
+++ b/drivers/media/dvb/frontends/cx24123.c
@@ -507,7 +507,7 @@ static int cx24123_pll_calculate(struct dvb_frontend* fe, struct dvb_frontend_pa
 	int i = 0;
 	int pump = 2;
 	int band = 0;
-	int num_bands = sizeof(cx24123_bandselect_vals) / sizeof(cx24123_bandselect_vals[0]);
+	int num_bands = ARRAY_SIZE(cx24123_bandselect_vals);
 
 	/* Defaults for low freq, low rate */
 	state->VCAarg = cx24123_AGC_vals[0].VCAprogdata;
@@ -516,7 +516,7 @@ static int cx24123_pll_calculate(struct dvb_frontend* fe, struct dvb_frontend_pa
 	vco_div = cx24123_bandselect_vals[0].VCOdivider;
 
 	/* For the given symbol rate, determine the VCA, VGA and FILTUNE programming bits */
-	for (i = 0; i < sizeof(cx24123_AGC_vals) / sizeof(cx24123_AGC_vals[0]); i++)
+	for (i = 0; i < ARRAY_SIZE(cx24123_AGC_vals); i++)
 	{
 		if ((cx24123_AGC_vals[i].symbolrate_low <= p->u.qpsk.symbol_rate) &&
 		    (cx24123_AGC_vals[i].symbolrate_high >= p->u.qpsk.symbol_rate) ) {
@@ -658,7 +658,7 @@ static int cx24123_initfe(struct dvb_frontend* fe)
 	dprintk("%s:  init frontend\n",__FUNCTION__);
 
 	/* Configure the demod to a good set of defaults */
-	for (i = 0; i < sizeof(cx24123_regdata) / sizeof(cx24123_regdata[0]); i++)
+	for (i = 0; i < ARRAY_SIZE(cx24123_regdata); i++)
 		cx24123_writereg(state, cx24123_regdata[i].reg, cx24123_regdata[i].data);
 
 	/* Set the LNB polarity */

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 88%]

* [PATCH 2.6.20-rc5 1/4] pvrusb2: Use ARRAY_SIZE macro
@ 2007-01-16  8:02 93% Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-16  8:02 UTC (permalink / raw)
  To: isely, video4linux-list; +Cc: linux-kernel, trivial

Hi all,

A cleanup series for the pvrusb2 code to use the ARRAY_SIZE macro. Since
The size of the patch is big, I've splitted it to 4 pieces according to
the files they touch.

PATCH 1/4: Use ARRAY_SIZE in pvrusb2-encoder.c

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
diff --git a/drivers/media/video/pvrusb2/pvrusb2-encoder.c b/drivers/media/video/pvrusb2/pvrusb2-encoder.c
index c94f97b..4ec937a 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-encoder.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-encoder.c
@@ -169,25 +169,23 @@ static int pvr2_encoder_cmd(void *ctxt,
 
 	*/
 
-	if (arg_cnt_send > (sizeof(wrData)/sizeof(wrData[0]))-4) {
+	if (arg_cnt_send > (ARRAY_SIZE(wrData) - 4)) {
 		pvr2_trace(
 			PVR2_TRACE_ERROR_LEGS,
 			"Failed to write cx23416 command"
 			" - too many input arguments"
 			" (was given %u limit %u)",
-			arg_cnt_send,
-			(unsigned int)(sizeof(wrData)/sizeof(wrData[0])) - 4);
+			arg_cnt_send, ARRAY_SIZE(wrData) - 4);
 		return -EINVAL;
 	}
 
-	if (arg_cnt_recv > (sizeof(rdData)/sizeof(rdData[0]))-4) {
+	if (arg_cnt_recv > (ARRAY_SIZE(rdData) - 4)) {
 		pvr2_trace(
 			PVR2_TRACE_ERROR_LEGS,
 			"Failed to write cx23416 command"
 			" - too many return arguments"
 			" (was given %u limit %u)",
-			arg_cnt_recv,
-			(unsigned int)(sizeof(rdData)/sizeof(rdData[0])) - 4);
+			arg_cnt_recv, ARRAY_SIZE(rdData) - 4);
 		return -EINVAL;
 	}
 
@@ -201,7 +199,7 @@ static int pvr2_encoder_cmd(void *ctxt,
 		for (idx = 0; idx < arg_cnt_send; idx++) {
 			wrData[idx+4] = argp[idx];
 		}
-		for (; idx < (sizeof(wrData)/sizeof(wrData[0]))-4; idx++) {
+		for (; idx < ARRAY_SIZE(wrData) - 4; idx++) {
 			wrData[idx+4] = 0;
 		}
 
@@ -245,8 +243,7 @@ static int pvr2_encoder_cmd(void *ctxt,
 		if (ret) break;
 		wrData[0] = 0x7;
 		ret = pvr2_encoder_read_words(
-			hdw,0,rdData,
-			sizeof(rdData)/sizeof(rdData[0]));
+			hdw,0,rdData, ARRAY_SIZE(rdData));
 		if (ret) break;
 		for (idx = 0; idx < arg_cnt_recv; idx++) {
 			argp[idx] = rdData[idx+4];
@@ -269,13 +266,13 @@ static int pvr2_encoder_vcmd(struct pvr2_hdw *hdw, int cmd,
 	unsigned int idx;
 	u32 data[12];
 
-	if (args > sizeof(data)/sizeof(data[0])) {
+	if (args > ARRAY_SIZE(data)) {
 		pvr2_trace(
 			PVR2_TRACE_ERROR_LEGS,
 			"Failed to write cx23416 command"
 			" - too many arguments"
 			" (was given %u limit %u)",
-			args,(unsigned int)(sizeof(data)/sizeof(data[0])));
+			args, ARRAY_SIZE(data));
 		return -EINVAL;
 	}
 

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 93%]

* [PATCH 2.6.20-rc5 4/4] pvrusb2: Use ARRAY_SIZE macro
@ 2007-01-16  8:02 86% Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-16  8:02 UTC (permalink / raw)
  To: isely, video4linux-list; +Cc: linux-kernel, trivial

Use ARRAY_SIZE macro in miscellaneous pvrusb2 files found

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
This patch ofcourse don't include previous patches in the set. I've just 
included the remaining modifications  in one patch/mail cause every file
touched here has only one or two lines of changes.

diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
index f9bb41d..83df9ee 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
@@ -948,8 +948,7 @@ static void do_i2c_scan(struct pvr2_hdw *hdw)
 	printk("%s: i2c scan beginning\n",hdw->name);
 	for (i = 0; i < 128; i++) {
 		msg[0].addr = i;
-		rc = i2c_transfer(&hdw->i2c_adap,msg,
-				  sizeof(msg)/sizeof(msg[0]));
+		rc = i2c_transfer(&hdw->i2c_adap,msg, ARRAY_SIZE(msg));
 		if (rc != 1) continue;
 		printk("%s: i2c scan: found device @ 0x%x\n",hdw->name,i);
 	}

diff --git a/drivers/media/video/pvrusb2/pvrusb2-sysfs.c b/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
index c294f46..17b5a3e 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
@@ -491,7 +491,7 @@ static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id)
 	unsigned int cnt,acnt;
 	int ret;
 
-	if ((ctl_id < 0) || (ctl_id >= (sizeof(funcs)/sizeof(funcs[0])))) {
+	if ((ctl_id < 0) || (ctl_id >= ARRAY_SIZE(funcs))) {
 		return;
 	}
 
diff --git a/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c b/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c
index 05f2cdd..b3eba8a 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c
@@ -137,8 +137,7 @@ static int decoder_check(struct pvr2_v4l_decoder *ctxt)
 	unsigned long msk;
 	unsigned int idx;
 
-	for (idx = 0; idx < sizeof(decoder_ops)/sizeof(decoder_ops[0]);
-	     idx++) {
+	for (idx = 0; idx < ARRAY_SIZE(decoder_ops); idx++) {
 		msk = 1 << idx;
 		if (ctxt->stale_mask & msk) continue;
 		if (decoder_ops[idx].check(ctxt)) {
@@ -154,8 +153,7 @@ static void decoder_update(struct pvr2_v4l_decoder *ctxt)
 	unsigned long msk;
 	unsigned int idx;
 
-	for (idx = 0; idx < sizeof(decoder_ops)/sizeof(decoder_ops[0]);
-	     idx++) {
+	for (idx = 0; idx < ARRAY_SIZE(decoder_ops); idx++) {
 		msk = 1 << idx;
 		if (!(ctxt->stale_mask & msk)) continue;
 		ctxt->stale_mask &= ~msk;
@@ -230,8 +228,7 @@ int pvr2_i2c_decoder_v4l_setup(struct pvr2_hdw *hdw,
 	ctxt->ctrl.tuned = (int (*)(void *))decoder_is_tuned;
 	ctxt->client = cp;
 	ctxt->hdw = hdw;
-	ctxt->stale_mask = (1 << (sizeof(decoder_ops)/
-				  sizeof(decoder_ops[0]))) - 1;
+	ctxt->stale_mask = (1 << ARRAY_SIZE(decoder_ops)) - 1;
 	hdw->decoder_ctrl = &ctxt->ctrl;
 	cp->handler = &ctxt->handler;
 	pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x saa711x V4L2 handler set up",
diff --git a/drivers/media/video/pvrusb2/pvrusb2-wm8775.c b/drivers/media/video/pvrusb2/pvrusb2-wm8775.c
index 2413e51..3a29bb8 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-wm8775.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-wm8775.c
@@ -99,8 +99,7 @@ static int wm8775_check(struct pvr2_v4l_wm8775 *ctxt)
 	unsigned long msk;
 	unsigned int idx;
 
-	for (idx = 0; idx < sizeof(wm8775_ops)/sizeof(wm8775_ops[0]);
-	     idx++) {
+	for (idx = 0; idx < ARRAY_SIZE(wm8775_ops); idx++) {
 		msk = 1 << idx;
 		if (ctxt->stale_mask & msk) continue;
 		if (wm8775_ops[idx].check(ctxt)) {
@@ -116,8 +115,7 @@ static void wm8775_update(struct pvr2_v4l_wm8775 *ctxt)
 	unsigned long msk;
 	unsigned int idx;
 
-	for (idx = 0; idx < sizeof(wm8775_ops)/sizeof(wm8775_ops[0]);
-	     idx++) {
+	for (idx = 0; idx < ARRAY_SIZE(wm8775_ops); idx++) {
 		msk = 1 << idx;
 		if (!(ctxt->stale_mask & msk)) continue;
 		ctxt->stale_mask &= ~msk;
@@ -148,8 +146,7 @@ int pvr2_i2c_wm8775_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
 	ctxt->handler.func_table = &hfuncs;
 	ctxt->client = cp;
 	ctxt->hdw = hdw;
-	ctxt->stale_mask = (1 << (sizeof(wm8775_ops)/
-				  sizeof(wm8775_ops[0]))) - 1;
+	ctxt->stale_mask = (1 << ARRAY_SIZE(wm8775_ops)) - 1;
 	cp->handler = &ctxt->handler;
 	pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x wm8775 V4L2 handler set up",
 		   cp->client->addr);

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 86%]

* [PATCH 2.6.20-rc5 3/4] pvrusb2: Use ARRAY_SIZE macro
@ 2007-01-16  8:01 93% Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-16  8:01 UTC (permalink / raw)
  To: isely, video4linux-list; +Cc: linux-kernel, trivial

Use ARRAY_SIZE macro in pvrusb2-std.c file

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
diff --git a/drivers/media/video/pvrusb2/pvrusb2-std.c b/drivers/media/video/pvrusb2/pvrusb2-std.c
index f95c598..677f126 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-std.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-std.c
@@ -141,10 +141,8 @@ int pvr2_std_str_to_id(v4l2_std_id *idPtr,const char *bufPtr,
 			cnt = 0;
 			while ((cnt < bufSize) && (bufPtr[cnt] != '-')) cnt++;
 			if (cnt >= bufSize) return 0; // No more characters
-			sp = find_std_name(
-				std_groups,
-				sizeof(std_groups)/sizeof(std_groups[0]),
-				bufPtr,cnt);
+			sp = find_std_name(std_groups, ARRAY_SIZE(std_groups),
+					   bufPtr,cnt);
 			if (!sp) return 0; // Illegal color system name
 			cnt++;
 			bufPtr += cnt;
@@ -163,8 +161,7 @@ int pvr2_std_str_to_id(v4l2_std_id *idPtr,const char *bufPtr,
 			if (ch == '/') break;
 			cnt++;
 		}
-		sp = find_std_name(std_items,
-				   sizeof(std_items)/sizeof(std_items[0]),
+		sp = find_std_name(std_items, ARRAY_SIZE(std_items),
 				   bufPtr,cnt);
 		if (!sp) return 0; // Illegal modulation system ID
 		t = sp->id & cmsk;
@@ -189,14 +186,10 @@ unsigned int pvr2_std_id_to_str(char *bufPtr, unsigned int bufSize,
 	unsigned int c1,c2;
 	cfl = 0;
 	c1 = 0;
-	for (idx1 = 0;
-	     idx1 < sizeof(std_groups)/sizeof(std_groups[0]);
-	     idx1++) {
+	for (idx1 = 0; idx1 < ARRAY_SIZE(std_groups); idx1++) {
 		gp = std_groups + idx1;
 		gfl = 0;
-		for (idx2 = 0;
-		     idx2 < sizeof(std_items)/sizeof(std_items[0]);
-		     idx2++) {
+		for (idx2 = 0; idx2 < ARRAY_SIZE(std_items); idx2++) {
 			ip = std_items + idx2;
 			if (!(gp->id & ip->id & id)) continue;
 			if (!gfl) {
@@ -279,7 +272,7 @@ static struct v4l2_standard generic_standards[] = {
 	}
 };
 
-#define generic_standards_cnt (sizeof(generic_standards)/sizeof(generic_standards[0]))
+#define generic_standards_cnt ARRAY_SIZE(generic_standards)
 
 static struct v4l2_standard *match_std(v4l2_std_id id)
 {
@@ -348,7 +341,7 @@ struct v4l2_standard *pvr2_std_create_enum(unsigned int *countptr,
 		fmsk |= idmsk;
 	}
 
-	for (idx2 = 0; idx2 < sizeof(std_mixes)/sizeof(std_mixes[0]); idx2++) {
+	for (idx2 = 0; idx2 < ARRAY_SIZE(std_mixes); idx2++) {
 		if ((id & std_mixes[idx2]) == std_mixes[idx2]) std_cnt++;
 	}
 
@@ -374,8 +367,8 @@ struct v4l2_standard *pvr2_std_create_enum(unsigned int *countptr,
 	idx = 0;
 
 	/* Enumerate potential special cases */
-	for (idx2 = 0; ((idx2 < sizeof(std_mixes)/sizeof(std_mixes[0])) &&
-			(idx < std_cnt)); idx2++) {
+	for (idx2 = 0; (idx2 < ARRAY_SIZE(std_mixes)) && (idx < std_cnt);
+	     idx2++) {
 		if (!(id & std_mixes[idx2])) continue;
 		if (pvr2_std_fill(stddefs+idx,std_mixes[idx2])) idx++;
 	}

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 93%]

* [PATCH 2.6.20-rc5 2/4] pvrusb2: Use ARRAY_SIZE macro
@ 2007-01-16  8:01 97% Ahmed S. Darwish
    0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2007-01-16  8:01 UTC (permalink / raw)
  To: isely, video4linux-list; +Cc: linux-kernel, trivial

Use ARRAY_SIZE macro in pvrusb2-hdw.c file

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
index d200496..f66f7c6 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
@@ -71,12 +71,10 @@ static const char *pvr2_client_29xxx[] = {
 
 static struct pvr2_string_table pvr2_client_lists[] = {
 	[PVR2_HDW_TYPE_29XXX] = {
-		pvr2_client_29xxx,
-		sizeof(pvr2_client_29xxx)/sizeof(pvr2_client_29xxx[0]),
+		pvr2_client_29xxx, ARRAY_SIZE(pvr2_client_29xxx)
 	},
 	[PVR2_HDW_TYPE_24XXX] = {
-		pvr2_client_24xxx,
-		sizeof(pvr2_client_24xxx)/sizeof(pvr2_client_24xxx[0]),
+		pvr2_client_24xxx, ARRAY_SIZE(pvr2_client_24xxx)
 	},
 };
 
@@ -212,7 +210,7 @@ static const struct pvr2_mpeg_ids mpeg_ids[] = {
 		.id = V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM,
 	}
 };
-#define MPEGDEF_COUNT (sizeof(mpeg_ids)/sizeof(mpeg_ids[0]))
+#define MPEGDEF_COUNT ARRAY_SIZE(mpeg_ids)
 
 
 static const char *control_values_srate[] = {
@@ -846,7 +844,7 @@ static const struct pvr2_ctl_info control_defs[] = {
 	}
 };
 
-#define CTRLDEF_COUNT (sizeof(control_defs)/sizeof(control_defs[0]))
+#define CTRLDEF_COUNT ARRAY_SIZE(control_defs)
 
 
 const char *pvr2_config_get_name(enum pvr2_config cfg)
@@ -960,12 +958,10 @@ static int pvr2_upload_firmware1(struct pvr2_hdw *hdw)
 	};
 	static const struct pvr2_string_table fw_file_defs[] = {
 		[PVR2_HDW_TYPE_29XXX] = {
-			fw_files_29xxx,
-			sizeof(fw_files_29xxx)/sizeof(fw_files_29xxx[0]),
+			fw_files_29xxx, ARRAY_SIZE(fw_files_29xxx)
 		},
 		[PVR2_HDW_TYPE_24XXX] = {
-			fw_files_24xxx,
-			sizeof(fw_files_24xxx)/sizeof(fw_files_24xxx[0]),
+			fw_files_24xxx, ARRAY_SIZE(fw_files_24xxx)
 		},
 	};
 	hdw->fw1_state = FW1_STATE_FAILED; // default result
@@ -1052,8 +1048,7 @@ int pvr2_upload_firmware2(struct pvr2_hdw *hdw)
 	trace_firmware("pvr2_upload_firmware2");
 
 	ret = pvr2_locate_firmware(hdw,&fw_entry,"encoder",
-				   sizeof(fw_files)/sizeof(fw_files[0]),
-				   fw_files);
+				   ARRAY_SIZE(fw_files), fw_files);
 	if (ret < 0) return ret;
 	fwidx = ret;
 	ret = 0;
@@ -1750,8 +1745,7 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
 	struct pvr2_ctl_info *ciptr;
 
 	hdw_type = devid - pvr2_device_table;
-	if (hdw_type >=
-	    sizeof(pvr2_device_names)/sizeof(pvr2_device_names[0])) {
+	if (hdw_type >= ARRAY_SIZE(pvr2_device_names)) {
 		pvr2_trace(PVR2_TRACE_ERROR_LEGS,
 			   "Bogus device type of %u reported",hdw_type);
 		return NULL;

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 97%]

* Re: [PATCH 2.6.20-rc5] intel_rng: substitue magic PCI IDs with macros
@ 2007-01-15 20:38 99% Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-15 20:38 UTC (permalink / raw)
  To: Greg KH; +Cc: jgarzik, linux-kernel

On Sun, Jan 14, 2007 at 04:29:48PM -0800, Greg KH wrote:
> On Sun, Jan 14, 2007 at 07:24:21PM +0200, Ahmed S. Darwish wrote:
> > Substitue intel_rng magic PCI IDs values used in the IDs table
> > with the macros defined in pci_ids.h
>
> Why not use the PCI_DEVICE() macro too?  It should make the lines even
> smaller.

Just for the patch applier, It seems that my mailer got insane. 
I've updated the patch to include PCI_DEVICE as Mr. Greg KH said But it 
appears in the LKML above his mail. 

So if no more suggestions come, the final patch is in:
http://lkml.org/lkml/2007/1/15/110

Thanks,
-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH 2.6.20-rc5] intel_rng: substitue magic PCI IDs with macros
      2007-01-15  7:16 99%   ` Ahmed S. Darwish
@ 2007-01-15 17:50 80%   ` Ahmed S. Darwish
  2 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-15 17:50 UTC (permalink / raw)
  To: greg; +Cc: jgarzik, arjan, linux-kernel, trivial

On Sun, Jan 14, 2007 at 04:29:48PM -0800, Greg KH wrote:
> Why not use the PCI_DEVICE() macro too? It should make the lines even
> smaller.

Hi all, Here's the updated patch. 

Substitue magic values used in the PCI IDs table with macros defined in 
pci_ids.h + using the PCI_DEVICE macro.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

I've used a script to generate that patch, then checked the results manually
to make sure that it's (hopefully) correct.

#!/bin/bash

INTEL_RNG_FILE=drivers/char/hw_random/intel-rng.c
TMP_FILE=$(mktemp)
# File to hold Magic PCI deviceIDs in the "pci_device_id pci_tbl[]"
MAGIC_DEVICE_IDS=$(mktemp)

# All pci_tbl[] contents begin with a "{ 0x8086"
grep "{ 0x8086"  drivers/char/hw_random/intel-rng.c > $TMP_FILE
awk ' { print $3 } ' $TMP_FILE | cut -d, -f1 | grep "0x" > $MAGIC_DEVICE_IDS

sed -i "s/{ 0x8086/{ PCI_VENDOR_ID_INTEL/g" $INTEL_RNG_FILE

# For each magic number in MAGIC_DEVICE_IDS, find its defined macro 
# in pci_ids.h then use it in the PCI IDs table.

for i in $(cat $MAGIC_DEVICE_IDS); do 
    macro=$(grep "PCI_DEVICE_ID" include/linux/pci_ids.h | grep "$i" | awk ' { print $2 } ')
    if [[ -n "$macro" ]] ; then
	sed -i "s/{ PCI_VENDOR_ID_INTEL, ${i},.*}/{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, ${macro}) }/" \
	    $INTEL_RNG_FILE
    else
	sed -i "s/{ PCI_VENDOR_ID_INTEL, ${i},.*}/{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, ${i}) }/" \
	    $INTEL_RNG_FILE
    fi
done

rm -f $TMP_FILE
rm -f $MAGIC_DEVICE_IDS

diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
index f22e78e..d25d5e1 100644
--- a/drivers/char/hw_random/intel-rng.c
+++ b/drivers/char/hw_random/intel-rng.c
@@ -96,49 +96,49 @@
  */
 static const struct pci_device_id pci_tbl[] = {
 /* AA
-	{ 0x8086, 0x2418, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */
-	{ 0x8086, 0x2410, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* AA */
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_8) }, */
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_0) },
 /* AB
-	{ 0x8086, 0x2428, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */
-	{ 0x8086, 0x2420, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* AB */
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_8) }, */
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_0) },
 /* ??
-	{ 0x8086, 0x2430, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2430) }, */
 /* BAM, CAM, DBM, FBM, GxM
-	{ 0x8086, 0x2448, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */
-	{ 0x8086, 0x244c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* BAM */
-	{ 0x8086, 0x248c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* CAM */
-	{ 0x8086, 0x24cc, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* DBM */
-	{ 0x8086, 0x2641, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* FBM */
-	{ 0x8086, 0x27b9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* GxM */
-	{ 0x8086, 0x27bd, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* GxM DH */
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_6) }, */
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_10) },
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12) },
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12) },
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1) }, 
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_1) }, 
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_31) },
 /* BA, CA, DB, Ex, 6300, Fx, 631x/632x, Gx
-	{ 0x8086, 0x244e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */
-	{ 0x8086, 0x2440, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* BA */
-	{ 0x8086, 0x2480, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* CA */
-	{ 0x8086, 0x24c0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* DB */
-	{ 0x8086, 0x24d0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Ex */
-	{ 0x8086, 0x25a1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 6300 */
-	{ 0x8086, 0x2640, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Fx */
-	{ 0x8086, 0x2670, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x2671, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x2672, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x2673, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x2674, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x2675, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x2676, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x2677, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x2678, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x2679, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x267a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x267b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x267c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x267d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x267e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x267f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x27b8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Gx */
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_11) }, */
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0) },
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0) },
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0) },
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0) },
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_1) },
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_0) },
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_0) },
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2671) }, /* 631x/632x */
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2672) }, /* 631x/632x */
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2673) }, /* 631x/632x */
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2674) }, /* 631x/632x */
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2675) }, /* 631x/632x */
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2676) }, /* 631x/632x */
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2677) }, /* 631x/632x */
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2678) }, /* 631x/632x */
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2679) }, /* 631x/632x */
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x267a) }, /* 631x/632x */
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x267b) }, /* 631x/632x */
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x267c) }, /* 631x/632x */
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x267d) }, /* 631x/632x */
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x267e) }, /* 631x/632x */
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x267f) }, /* 631x/632x */
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_0) },
 /* E
-	{ 0x8086, 0x245e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */
-	{ 0x8086, 0x2450, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* E  */
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x245e) }, */
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801E_0) },
 	{ 0, },	/* terminate list */
 };
 MODULE_DEVICE_TABLE(pci, pci_tbl);


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 80%]

* Re: [PATCH 2.6.20-rc5] intel_rng: substitue magic PCI IDs with macros
  @ 2007-01-15  9:17 99%   ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-15  9:17 UTC (permalink / raw)
  To: Greg KH; +Cc: jgarzik, linux-kernel

On Sun, Jan 14, 2007 at 04:29:48PM -0800, Greg KH wrote:
> On Sun, Jan 14, 2007 at 07:24:21PM +0200, Ahmed S. Darwish wrote:
> > Substitue intel_rng magic PCI IDs values used in the IDs table
> > with the macros defined in pci_ids.h
> 
> Why not use the PCI_DEVICE() macro too?  It should make the lines even
> smaller.

Ooh yes, I forgot about this macro.
Updating the patch. Thanks :).

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH 2.6.20-rc5] intel_rng: substitue magic PCI IDs with macros
    @ 2007-01-15  7:16 99%   ` Ahmed S. Darwish
  2007-01-15 17:50 80%   ` Ahmed S. Darwish
  2 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-15  7:16 UTC (permalink / raw)
  To: Arjan van de Ven; +Cc: jgarzik, linux-kernel

On Sun, Jan 14, 2007 at 09:37:21AM -0800, Arjan van de Ven wrote:
> On Sun, 2007-01-14 at 19:24 +0200, Ahmed S. Darwish wrote:
> > Substitue intel_rng magic PCI IDs values used in the IDs table
> > with the macros defined in pci_ids.h
> > 
> Hi,
> 
> 
> hmm this is actually the opposite direction than most of the kernel is
> heading in, mostly because the pci_ids.h file is a major maintenance
> pain.
> 
> Afaik the current "rule" is: if a PCI ID is only used in one driver, use
> the numeric value and not (add) a symbolic constant.

I think you understood me wrong .. I haven't added new macros in pci_ids.h,
I've just used the macros already defined there like the PCI_VENDOR_ID_INTEL
and others.

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH 2.6.20-rc5] intel_rng: substitue magic PCI IDs with macros
  @ 2007-01-14 23:07 99%     ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-14 23:07 UTC (permalink / raw)
  To: Dave Airlie; +Cc: Arjan van de Ven, jgarzik, linux-kernel

On Mon, Jan 15, 2007 at 06:31:01AM +1100, Dave Airlie wrote:
> On 1/15/07, Arjan van de Ven <arjan@infradead.org> wrote:
> >On Sun, 2007-01-14 at 19:24 +0200, Ahmed S. Darwish wrote:
> >> Substitue intel_rng magic PCI IDs values used in the IDs table
> >> with the macros defined in pci_ids.h
> >>
> >Hi,
> >
> >hmm this is actually the opposite direction than most of the kernel is
> >heading in, mostly because the pci_ids.h file is a major maintenance
> >pain.
> >
> >Afaik the current "rule" is: if a PCI ID is only used in one driver, use
> >the numeric value and not (add) a symbolic constant.
> >
> 
> My guess is that the RNG is on the LPC so the values are used in a few 
> places..
> 

Will pci_ids.h be removed from the tree some time in the future then ?

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.20-rc5] intel_rng: substitue magic PCI IDs with macros
@ 2007-01-14 17:24 76% Ahmed S. Darwish
      0 siblings, 2 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-14 17:24 UTC (permalink / raw)
  To: jgarzik; +Cc: linux-kernel

Substitue intel_rng magic PCI IDs values used in the IDs table
with the macros defined in pci_ids.h


Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---

I've used a small script to generate this patch then manually tried to 
make sure it's (hopefully) correct. 

#!/bin/bash

INTEL_RNG_FILE=drivers/char/hw_random/intel-rng.c
TMP_FILE=$(mktemp)
MAGIC_NUMS_FILE=$(mktemp)

# grep the contents of "pci_device_id pci_tbl[]"
grep "{ 0x8086"  drivers/char/hw_random/intel-rng.c > $TMP_FILE
# Extract the magic numbers to be replaced
cat $TMP_FILE | awk ' { print $3 } ' | cut -d, -f1 | grep "0x" > $MAGIC_NUMS_FILE

sed -i "s/0x8086/PCI_VENDOR_ID_INTEL/g" $INTEL_RNG_FILE

# For each magic number in MAGIC_NUMS_FILE, find its defined macro 
# in pci_ids.h then replace them.

for i in $(cat $MAGIC_NUMS_FILE); do 
    var=$(grep "PCI_DEVICE_ID" include/linux/pci_ids.h | grep "$i" | awk ' { print $2 } ')
    if [[ -n "$var" ]] ; then
	# sed: Side effect of replacing the magic number in the whole file
	# Collisions with other magics belonging to another family ?
	# Manual checking reveals no bad collisions happen.
	sed -i "s/${i}/${var}/g" $INTEL_RNG_FILE
    fi
done

rm -f $TMP_FILE
rm -f $MAGIC_NUMS_FILE

diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
index f22e78e..85b0374 100644
--- a/drivers/char/hw_random/intel-rng.c
+++ b/drivers/char/hw_random/intel-rng.c
@@ -95,50 +95,96 @@
  * want to register another driver on the same PCI id.
  */
 static const struct pci_device_id pci_tbl[] = {
-/* AA
-	{ 0x8086, 0x2418, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */
-	{ 0x8086, 0x2410, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* AA */
-/* AB
-	{ 0x8086, 0x2428, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */
-	{ 0x8086, 0x2420, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* AB */
-/* ??
-	{ 0x8086, 0x2430, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */
-/* BAM, CAM, DBM, FBM, GxM
-	{ 0x8086, 0x2448, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */
-	{ 0x8086, 0x244c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* BAM */
-	{ 0x8086, 0x248c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* CAM */
-	{ 0x8086, 0x24cc, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* DBM */
-	{ 0x8086, 0x2641, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* FBM */
-	{ 0x8086, 0x27b9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* GxM */
-	{ 0x8086, 0x27bd, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* GxM DH */
-/* BA, CA, DB, Ex, 6300, Fx, 631x/632x, Gx
-	{ 0x8086, 0x244e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */
-	{ 0x8086, 0x2440, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* BA */
-	{ 0x8086, 0x2480, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* CA */
-	{ 0x8086, 0x24c0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* DB */
-	{ 0x8086, 0x24d0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Ex */
-	{ 0x8086, 0x25a1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 6300 */
-	{ 0x8086, 0x2640, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Fx */
-	{ 0x8086, 0x2670, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x2671, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x2672, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x2673, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x2674, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x2675, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x2676, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x2677, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x2678, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x2679, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x267a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x267b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x267c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x267d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x267e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x267f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-	{ 0x8086, 0x27b8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Gx */
-/* E
-	{ 0x8086, 0x245e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */
-	{ 0x8086, 0x2450, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* E  */
+/* 
+ * AA
+ *	{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_8, PCI_ANY_ID, 
+ *	PCI_ANY_ID, 0, 0, 0, }, 
+ */
+	{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_0, PCI_ANY_ID,
+	  PCI_ANY_ID, 0, 0, 0, },
+/* 
+ * AB
+ *	{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_8, PCI_ANY_ID, 
+ *	PCI_ANY_ID, 0, 0, 0, }, 
+ */
+	{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_0, PCI_ANY_ID, 
+	  PCI_ANY_ID, 0, 0, 0, },
+/* 
+ * ??
+ *	{ PCI_VENDOR_ID_INTEL, 0x2430, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, 
+ *
+ * BAM, CAM, DBM, FBM, GxM
+ *	{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_6, PCI_ANY_ID, 
+ *	PCI_ANY_ID, 0, 0, 0, }, 
+ */
+	{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_10, PCI_ANY_ID,
+	  PCI_ANY_ID, 0, 0, 0, },
+	{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, PCI_ANY_ID,
+	  PCI_ANY_ID, 0, 0, 0, },
+	{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, PCI_ANY_ID,
+	  PCI_ANY_ID, 0, 0, 0, },
+	{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, PCI_ANY_ID, 
+	  PCI_ANY_ID, 0, 0, 0, }, /* FBM */
+	{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_1, PCI_ANY_ID, 
+	  PCI_ANY_ID, 0, 0, 0, }, /* GxM */
+	{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_31, PCI_ANY_ID, 
+	  PCI_ANY_ID, 0, 0, 0, }, /* GxM DH */
+/*
+ * BA, CA, DB, Ex, 6300, Fx, 631x/632x, Gx
+ *	{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_11, PCI_ANY_ID, 
+ *	PCI_ANY_ID, 0, 0, 0, }, 
+ */
+	{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0, PCI_ANY_ID, 
+	  PCI_ANY_ID, 0, 0, 0, },
+	{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0, PCI_ANY_ID, 
+	  PCI_ANY_ID, 0, 0, 0, },
+	{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0, PCI_ANY_ID, 
+	  PCI_ANY_ID, 0, 0, 0, },
+	{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, PCI_ANY_ID, 
+	  PCI_ANY_ID, 0, 0, 0, }, /* Ex */
+	{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_1, PCI_ANY_ID, 
+	  PCI_ANY_ID, 0, 0, 0, }, /* 6300 */
+	{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_0, PCI_ANY_ID,
+	  PCI_ANY_ID, 0, 0, 0, }, /* Fx */
+	{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_0, PCI_ANY_ID,
+	  PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
+	{ PCI_VENDOR_ID_INTEL, 0x2671, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
+	{ PCI_VENDOR_ID_INTEL, 0x2672, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, 
+	/* 631x/632x */
+	{ PCI_VENDOR_ID_INTEL, 0x2673, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, 
+        /* 631x/632x */
+	{ PCI_VENDOR_ID_INTEL, 0x2674, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
+	/* 631x/632x */
+	{ PCI_VENDOR_ID_INTEL, 0x2675, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
+	/* 631x/632x */
+	{ PCI_VENDOR_ID_INTEL, 0x2676, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
+	/* 631x/632x */
+	{ PCI_VENDOR_ID_INTEL, 0x2677, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
+	/* 631x/632x */
+	{ PCI_VENDOR_ID_INTEL, 0x2678, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
+	/* 631x/632x */
+	{ PCI_VENDOR_ID_INTEL, 0x2679, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
+	/* 631x/632x */
+	{ PCI_VENDOR_ID_INTEL, 0x267a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
+	/* 631x/632x */
+	{ PCI_VENDOR_ID_INTEL, 0x267b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
+	/* 631x/632x */
+	{ PCI_VENDOR_ID_INTEL, 0x267c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
+	/* 631x/632x */
+	{ PCI_VENDOR_ID_INTEL, 0x267d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, 
+	/* 631x/632x */
+	{ PCI_VENDOR_ID_INTEL, 0x267e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
+	/* 631x/632x */
+	{ PCI_VENDOR_ID_INTEL, 0x267f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
+	/* 631x/632x */
+	{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_0, PCI_ANY_ID, 
+	  PCI_ANY_ID, 0, 0, 0, }, /* Gx */
+/* 
+ * E
+ *	{ PCI_VENDOR_ID_INTEL, 0x245e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, 
+ */
+	{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801E_0, PCI_ANY_ID, 
+	  PCI_ANY_ID, 0, 0, 0, }, /* E  */
 	{ 0, },	/* terminate list */
 };
 MODULE_DEVICE_TABLE(pci, pci_tbl);
@@ -251,7 +297,7 @@ static int __init mod_init(void)
 	}
 
 	/* Check for Intel 82802 */
-	if (dev->device < 0x2640) {
+	if (dev->device < PCI_DEVICE_ID_INTEL_ICH6_0) {
 		fwh_dec_en1_off = FWH_DEC_EN1_REG_OLD;
 		bios_cntl_off = BIOS_CNTL_REG_OLD;
 	} else {

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 76%]

* Re: [PATCH UPDATED 2.6.20-rc3] Remove all the unneeded k[mzc]alloc casts
  @ 2007-01-08 19:21 99%   ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-08 19:21 UTC (permalink / raw)
  To: Rolf Eike Beer; +Cc: linux-kernel

On Mon, Jan 08, 2007 at 01:10:19PM +0100, Rolf Eike Beer wrote:
> Ahmed S. Darwish wrote:
> > Hi all,
> > This is a patch to remove the unneeded k[mzc]alloc casts in the whole
> >
> > Signed-off-by: Ahmed Darwish
> >
> > diff --git a/arch/cris/arch-v32/mm/intmem.c
> > b/arch/cris/arch-v32/mm/intmem.c index 41ee7f7..acb4e21 100644
> > --- a/arch/cris/arch-v32/mm/intmem.c
> > +++ b/arch/cris/arch-v32/mm/intmem.c
> > @@ -27,8 +27,8 @@ static void crisv32_intmem_init(void)
> >  {
> >  	static int initiated = 0;
> >  	if (!initiated) {
> > -		struct intmem_allocation* alloc =
> > -		  (struct intmem_allocation*)kmalloc(sizeof *alloc, GFP_KERNEL);
> > +		struct intmem_allocation* alloc = kmalloc(sizeof *alloc,
> > +							  GFP_KERNEL);
> sizeof(*alloc) (see Documentation/CodingStyle)
> 
> There are some more of this kind.
> 

I had to do so since the whole file already uses a different coding style
than the one found in CodingStyle (uses type* foo, ..).
About the sizeof issue it seems every one here have his own opinion (readability
vs. reliability).

Anyway I've splitted the patch and resent them to lkml with CCing the 
appropriate maintainers since I was told that no one would accept this
big patch.

Regards
-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH 2.6.20-rc3] UCC Ether driver: kmalloc casting cleanups
    2007-01-08  4:26 99%   ` Ahmed S. Darwish
@ 2007-01-08  4:54 95%   ` Ahmed S. Darwish
  1 sibling, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-08  4:54 UTC (permalink / raw)
  To: Li Yang-r58472; +Cc: linux-kernel, netdev

On Mon, Jan 08, 2007 at 11:12:28AM +0800, Li Yang-r58472 wrote:
>
> NACK about the 2 clean-ups above.  Cast from pointer to integer is
> required here.
> 

Hi, here's the modified patch.

A patch to switch kmalloc to kzalloc and clean some redundant kmalloc
casts.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
---
diff --git a/drivers/net/ucc_geth.c b/drivers/net/ucc_geth.c
index 8243150..0f58f5f 100644
--- a/drivers/net/ucc_geth.c
+++ b/drivers/net/ucc_geth.c
@@ -2926,10 +2926,9 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
 	/* Init Tx bds */
 	for (j = 0; j < ug_info->numQueuesTx; j++) {
 		/* Setup the skbuff rings */
-		ugeth->tx_skbuff[j] =
-		    (struct sk_buff **)kmalloc(sizeof(struct sk_buff *) *
-					       ugeth->ug_info->bdRingLenTx[j],
-					       GFP_KERNEL);
+		ugeth->tx_skbuff[j] = kmalloc(sizeof(struct sk_buff *) *
+					      ugeth->ug_info->bdRingLenTx[j],
+					      GFP_KERNEL);
 
 		if (ugeth->tx_skbuff[j] == NULL) {
 			ugeth_err("%s: Could not allocate tx_skbuff",
@@ -2958,10 +2957,9 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
 	/* Init Rx bds */
 	for (j = 0; j < ug_info->numQueuesRx; j++) {
 		/* Setup the skbuff rings */
-		ugeth->rx_skbuff[j] =
-		    (struct sk_buff **)kmalloc(sizeof(struct sk_buff *) *
-					       ugeth->ug_info->bdRingLenRx[j],
-					       GFP_KERNEL);
+		ugeth->rx_skbuff[j] = kmalloc(sizeof(struct sk_buff *) *
+					      ugeth->ug_info->bdRingLenRx[j],
+					      GFP_KERNEL);
 
 		if (ugeth->rx_skbuff[j] == NULL) {
 			ugeth_err("%s: Could not allocate rx_skbuff",
@@ -3450,19 +3448,16 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
 	 * resource.
 	 * This shadow structure keeps a copy of what was done so that the
 	 * allocated resources can be released when the channel is freed.
+	 * *p_init_enet_param_shadow is zeroed by kzalloc
 	 */
-	if (!(ugeth->p_init_enet_param_shadow =
-	     (struct ucc_geth_init_pram *) kmalloc(sizeof(struct ucc_geth_init_pram),
-					      GFP_KERNEL))) {
+	if (!(ugeth->p_init_enet_param_shadow = 
+	      kzalloc(sizeof(struct ucc_geth_init_pram), GFP_KERNEL))) {
 		ugeth_err
 		    ("%s: Can not allocate memory for"
 			" p_UccInitEnetParamShadows.", __FUNCTION__);
 		ucc_geth_memclean(ugeth);
 		return -ENOMEM;
 	}
-	/* Zero out *p_init_enet_param_shadow */
-	memset((char *)ugeth->p_init_enet_param_shadow,
-	       0, sizeof(struct ucc_geth_init_pram));
 
 	/* Fill shadow InitEnet command parameter structure */
 


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 95%]

* Re: [PATCH 2.6.20-rc3] UCC Ether driver: kmalloc casting cleanups
  @ 2007-01-08  4:26 99%   ` Ahmed S. Darwish
  2007-01-08  4:54 95%   ` Ahmed S. Darwish
  1 sibling, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-08  4:26 UTC (permalink / raw)
  To: Li Yang-r58472; +Cc: linux-kernel, netdev

On Mon, Jan 08, 2007 at 11:12:28AM +0800, Li Yang-r58472 wrote:
> > From: Ahmed S. Darwish [mailto:darwish.07@gmail.com]
> > 
> > Hi,
> > A kmalloc casting cleanup patch.
> > Signed-off-by: Ahmed Darwish <darwish.07@gmail.com>

[..]

> > -				(u32) (kmalloc((u32) (length + align),
> > -				GFP_KERNEL));
> > +				kmalloc((u32) (length + align), GFP_KERNEL);
> > +
> >  			if (ugeth->tx_bd_ring_offset[j] != 0)
> >  				ugeth->p_tx_bd_ring[j] =

[..]

> > -			    (u32) (kmalloc((u32) (length + align), GFP_KERNEL));
> > +				kmalloc((u32) (length + align), GFP_KERNEL);
> 
> NACK about the 2 clean-ups above.  Cast from pointer to integer is
> required here.

Are the casts from pointer to integer just needed to suppress gcc 
warnings or there's something technically important about them ?

I'll send the modified patch without the NACKed parts in minutes ..

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH 2.6.20-rc3] DAC960: kmalloc->kzalloc/Casting cleanups
  @ 2007-01-07  2:00 99%   ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-07  2:00 UTC (permalink / raw)
  To: Randy Dunlap; +Cc: linux-kernel

On Sat, Jan 06, 2007 at 09:46:30AM -0800, Randy Dunlap wrote:

> On Sat, 6 Jan 2007 15:17:25 +0200 Ahmed S. Darwish wrote:
> 
> > Hi all,
> > I'm not able to find the DAC960 block driver maintainer. If someones knows
> > please reply :).
> 
> It's orphaned.  Andrew can decide to merge this, or one of the
> storage or block maintainers could possibly do that.
> or it could go thru KJ, but then Andrew may still end up
> merging it.

Should Kernel janitors then care of cleaning orphaned files ?.
If so, I should forward it to Andrew Morton without CCing LKML again, right ?

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH 2.6.20-rc3] DAC960: kmalloc->kzalloc/Casting cleanups
  @ 2007-01-06 14:55 99%   ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-06 14:55 UTC (permalink / raw)
  To: Robert P. J. Day; +Cc: linux-kernel

On Sat, Jan 06, 2007 at 08:36:23AM -0500, Robert P. J. Day wrote:
>   a couple bits of advice here.  you should start your patch
> submission with *only* that descriptive text you want included in the
> log, followed by your "Signed-off-by" line, then a line containing
> "---".
> 
>   *after* that "---" line, and *before* you start the actual patch,
> you can add superfluous text, like asking about who the maintainer is,
> so that informal dialogue like that doesn't become part of the
> permanent patch record.

> rday

Thanks for all the good notes ..

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.20-rc3] HID-Core: Tiny patch to remove a kmalloc cast
@ 2007-01-06 13:18 99% Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-06 13:18 UTC (permalink / raw)
  To: jkosina; +Cc: linux-kernel

I'm really shy from the size of the patch :).

Signed-off-by: Ahmed Darwish <darwish.07@gmail.com>

diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 18c2b3c..2fcfdbb 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -656,7 +656,7 @@ struct hid_device *hid_parse_report(__u8 *start, unsigned size)
 	for (i = 0; i < HID_REPORT_TYPES; i++)
 		INIT_LIST_HEAD(&device->report_enum[i].report_list);
 
-	if (!(device->rdesc = (__u8 *)kmalloc(size, GFP_KERNEL))) {
+	if (!(device->rdesc = kmalloc(size, GFP_KERNEL))) {
 		kfree(device->collection);
 		kfree(device);
 		return NULL;


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.20-rc3] UCC Ether driver: kmalloc casting cleanups
@ 2007-01-06 13:18 93% Ahmed S. Darwish
    0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2007-01-06 13:18 UTC (permalink / raw)
  To: leoli; +Cc: linux-kernel

[Please inform me if you are not the maintaner cause I'm not sure:)]

Hi,
A kmalloc casting cleanup patch.

I wasn't able to compile the file drivers/net/ucc_geth.c cause of
some not found headers (asm/of_platform.h, asm/qe.h, and others )

Signed-off-by: Ahmed Darwish <darwish.07@gmail.com>

diff --git a/drivers/net/ucc_geth.c b/drivers/net/ucc_geth.c
index 8243150..001109e 100644
--- a/drivers/net/ucc_geth.c
+++ b/drivers/net/ucc_geth.c
@@ -2864,8 +2864,8 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
 			if (UCC_GETH_TX_BD_RING_ALIGNMENT > 4)
 				align = UCC_GETH_TX_BD_RING_ALIGNMENT;
 			ugeth->tx_bd_ring_offset[j] =
-				(u32) (kmalloc((u32) (length + align),
-				GFP_KERNEL));
+				kmalloc((u32) (length + align), GFP_KERNEL);
+					 
 			if (ugeth->tx_bd_ring_offset[j] != 0)
 				ugeth->p_tx_bd_ring[j] =
 					(void*)((ugeth->tx_bd_ring_offset[j] +
@@ -2900,7 +2900,7 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
 			if (UCC_GETH_RX_BD_RING_ALIGNMENT > 4)
 				align = UCC_GETH_RX_BD_RING_ALIGNMENT;
 			ugeth->rx_bd_ring_offset[j] =
-			    (u32) (kmalloc((u32) (length + align), GFP_KERNEL));
+				kmalloc((u32) (length + align), GFP_KERNEL);
 			if (ugeth->rx_bd_ring_offset[j] != 0)
 				ugeth->p_rx_bd_ring[j] =
 					(void*)((ugeth->rx_bd_ring_offset[j] +
@@ -2926,10 +2926,9 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
 	/* Init Tx bds */
 	for (j = 0; j < ug_info->numQueuesTx; j++) {
 		/* Setup the skbuff rings */
-		ugeth->tx_skbuff[j] =
-		    (struct sk_buff **)kmalloc(sizeof(struct sk_buff *) *
-					       ugeth->ug_info->bdRingLenTx[j],
-					       GFP_KERNEL);
+		ugeth->tx_skbuff[j] = kmalloc(sizeof(struct sk_buff *) *
+					      ugeth->ug_info->bdRingLenTx[j],
+					      GFP_KERNEL);
 
 		if (ugeth->tx_skbuff[j] == NULL) {
 			ugeth_err("%s: Could not allocate tx_skbuff",
@@ -2958,10 +2957,9 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
 	/* Init Rx bds */
 	for (j = 0; j < ug_info->numQueuesRx; j++) {
 		/* Setup the skbuff rings */
-		ugeth->rx_skbuff[j] =
-		    (struct sk_buff **)kmalloc(sizeof(struct sk_buff *) *
-					       ugeth->ug_info->bdRingLenRx[j],
-					       GFP_KERNEL);
+		ugeth->rx_skbuff[j] = kmalloc(sizeof(struct sk_buff *) *
+					      ugeth->ug_info->bdRingLenRx[j],
+					      GFP_KERNEL);
 
 		if (ugeth->rx_skbuff[j] == NULL) {
 			ugeth_err("%s: Could not allocate rx_skbuff",
@@ -3452,8 +3450,7 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
 	 * allocated resources can be released when the channel is freed.
 	 */
 	if (!(ugeth->p_init_enet_param_shadow =
-	     (struct ucc_geth_init_pram *) kmalloc(sizeof(struct ucc_geth_init_pram),
-					      GFP_KERNEL))) {
+	      kmalloc(sizeof(struct ucc_geth_init_pram), GFP_KERNEL))) {
 		ugeth_err
 		    ("%s: Can not allocate memory for"
 			" p_UccInitEnetParamShadows.", __FUNCTION__);

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 93%]

* [PATCH 2.6.20-rc3] S390: kmalloc->kzalloc/casting cleanups
@ 2007-01-06 13:18 90% Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-06 13:18 UTC (permalink / raw)
  To: fpavlic, linux390; +Cc: linux-kernel

[Please inform me if you are not the maintaner]

A patch for the CTC / ESCON network driver. Switch from kmalloc to kzalloc
when appropriate, remove some unnecessary kmalloc casts too.
Since I have no s390 machine, I didn't compile it but I examined it carefully.

Signed-off-by: Ahmed Darwish <darwish.07@gmail.com>

diff --git a/drivers/s390/net/ctcmain.c b/drivers/s390/net/ctcmain.c
index 03cc263..ee914ab 100644
--- a/drivers/s390/net/ctcmain.c
+++ b/drivers/s390/net/ctcmain.c
@@ -1639,21 +1639,19 @@ add_channel(struct ccw_device *cdev, enum channel_types type)
 	struct channel *ch;
 
 	DBF_TEXT(trace, 2, __FUNCTION__);
-	if ((ch =
-	     (struct channel *) kmalloc(sizeof (struct channel),
-					GFP_KERNEL)) == NULL) {
+	ch = kzalloc(sizeof (struct channel), GFP_KERNEL);
+	if (!ch) {
 		ctc_pr_warn("ctc: Out of memory in add_channel\n");
 		return -1;
 	}
-	memset(ch, 0, sizeof (struct channel));
-	if ((ch->ccw = kmalloc(8*sizeof(struct ccw1),
-					       GFP_KERNEL | GFP_DMA)) == NULL) {
+	/* assure all flags and counters are reset */
+	ch->ccw = kzalloc(8 * sizeof(struct ccw1), GFP_KERNEL | GFP_DMA);
+	if (!ch->ccw) {
 		kfree(ch);
 		ctc_pr_warn("ctc: Out of memory in add_channel\n");
 		return -1;
 	}
 
-	memset(ch->ccw, 0, 8*sizeof(struct ccw1));	// assure all flags and counters are reset
 
 	/**
 	 * "static" ccws are used in the following way:
@@ -1693,15 +1691,14 @@ add_channel(struct ccw_device *cdev, enum channel_types type)
 		return -1;
 	}
 	fsm_newstate(ch->fsm, CH_STATE_IDLE);
-	if ((ch->irb = kmalloc(sizeof (struct irb),
-					      GFP_KERNEL)) == NULL) {
+	ch->irb = kzalloc(sizeof (struct irb), GFP_KERNEL);
+	if (!ch->irb) {
 		ctc_pr_warn("ctc: Out of memory in add_channel\n");
 		kfree_fsm(ch->fsm);
 		kfree(ch->ccw);
 		kfree(ch);
 		return -1;
 	}
-	memset(ch->irb, 0, sizeof (struct irb));
 	while (*c && less_than((*c)->id, ch->id))
 		c = &(*c)->next;
 	if (*c && (!strncmp((*c)->id, ch->id, CTC_ID_SIZE))) {
@@ -2746,14 +2743,13 @@ ctc_probe_device(struct ccwgroup_device *cgdev)
 	if (!get_device(&cgdev->dev))
 		return -ENODEV;
 
-	priv = kmalloc(sizeof (struct ctc_priv), GFP_KERNEL);
+	priv = kzalloc(sizeof (struct ctc_priv), GFP_KERNEL);
 	if (!priv) {
 		ctc_pr_err("%s: Out of memory\n", __func__);
 		put_device(&cgdev->dev);
 		return -ENOMEM;
 	}
 
-	memset(priv, 0, sizeof (struct ctc_priv));
 	rc = ctc_add_files(&cgdev->dev);
 	if (rc) {
 		kfree(priv);
@@ -2794,10 +2790,9 @@ ctc_init_netdevice(struct net_device * dev, int alloc_device,
 	DBF_TEXT(setup, 3, __FUNCTION__);
 
 	if (alloc_device) {
-		dev = kmalloc(sizeof (struct net_device), GFP_KERNEL);
+		dev = kzalloc(sizeof (struct net_device), GFP_KERNEL);
 		if (!dev)
 			return NULL;
-		memset(dev, 0, sizeof (struct net_device));
 	}
 
 	dev->priv = privptr;

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 90%]

* [PATCH 2.6.20-rc3] CIFS: Remove 2 unneeded kzalloc casts
@ 2007-01-06 13:17 99% Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-06 13:17 UTC (permalink / raw)
  To: sfrench; +Cc: linux-kernel

Hi, 
A patch to remove two unnecessary kzalloc casts found

Signed-off-by: Ahmed Darwish <darwish.07@gmail.com>

diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
index aedf683..90f95ed 100644
--- a/fs/cifs/misc.c
+++ b/fs/cifs/misc.c
@@ -71,9 +71,7 @@ sesInfoAlloc(void)
 {
 	struct cifsSesInfo *ret_buf;
 
-	ret_buf =
-	    (struct cifsSesInfo *) kzalloc(sizeof (struct cifsSesInfo),
-					   GFP_KERNEL);
+	ret_buf = kzalloc(sizeof (struct cifsSesInfo), GFP_KERNEL);
 	if (ret_buf) {
 		write_lock(&GlobalSMBSeslock);
 		atomic_inc(&sesInfoAllocCount);
@@ -109,9 +107,8 @@ struct cifsTconInfo *
 tconInfoAlloc(void)
 {
 	struct cifsTconInfo *ret_buf;
-	ret_buf =
-	    (struct cifsTconInfo *) kzalloc(sizeof (struct cifsTconInfo),
-					    GFP_KERNEL);
+	ret_buf = kzalloc(sizeof (struct cifsTconInfo),
+			  GFP_KERNEL);
 	if (ret_buf) {
 		write_lock(&GlobalSMBSeslock);
 		atomic_inc(&tconInfoAllocCount);

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.20-rc3] DAC960: kmalloc->kzalloc/Casting cleanups
@ 2007-01-06 13:17 93% Ahmed S. Darwish
      0 siblings, 2 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-06 13:17 UTC (permalink / raw)
  To: linux-kernel

Hi all,
I'm not able to find the DAC960 block driver maintainer. If someones knows
please reply :).

A patch to switch kmalloc->kzalloc and to clean unneeded kammloc,
pci_alloc_consistent casts

Signed-off-by: Ahmed Darwish <darwish.07@gmail.com>

diff --git a/drivers/block/DAC960.c b/drivers/block/DAC960.c
index 8d81a3a..4febe7f 100644
--- a/drivers/block/DAC960.c
+++ b/drivers/block/DAC960.c
@@ -1373,8 +1373,7 @@ static boolean DAC960_V2_EnableMemoryMailboxInterface(DAC960_Controller_T
   Controller->BounceBufferLimit = DAC690_V2_PciDmaMask;
 
   /* This is a temporary dma mapping, used only in the scope of this function */
-  CommandMailbox =
-	  (DAC960_V2_CommandMailbox_T *)pci_alloc_consistent( PCI_Device,
+  CommandMailbox = pci_alloc_consistent(PCI_Device,
 		sizeof(DAC960_V2_CommandMailbox_T), &CommandMailboxDMA);
   if (CommandMailbox == NULL)
 	  return false;
@@ -1879,8 +1878,8 @@ static boolean DAC960_V2_ReadControllerConfiguration(DAC960_Controller_T
       if (NewLogicalDeviceInfo->LogicalDeviceState !=
 	  DAC960_V2_LogicalDevice_Offline)
 	Controller->LogicalDriveInitiallyAccessible[LogicalDeviceNumber] = true;
-      LogicalDeviceInfo = (DAC960_V2_LogicalDeviceInfo_T *)
-	kmalloc(sizeof(DAC960_V2_LogicalDeviceInfo_T), GFP_ATOMIC);
+      LogicalDeviceInfo = kmalloc(sizeof(DAC960_V2_LogicalDeviceInfo_T),
+				   GFP_ATOMIC);
       if (LogicalDeviceInfo == NULL)
 	return DAC960_Failure(Controller, "LOGICAL DEVICE ALLOCATION");
       Controller->V2.LogicalDeviceInformation[LogicalDeviceNumber] =
@@ -2113,8 +2112,8 @@ static boolean DAC960_V2_ReadDeviceConfiguration(DAC960_Controller_T
       if (!DAC960_V2_NewPhysicalDeviceInfo(Controller, Channel, TargetID, LogicalUnit))
 	  break;
 
-      PhysicalDeviceInfo = (DAC960_V2_PhysicalDeviceInfo_T *)
-		kmalloc(sizeof(DAC960_V2_PhysicalDeviceInfo_T), GFP_ATOMIC);
+      PhysicalDeviceInfo = kmalloc(sizeof(DAC960_V2_PhysicalDeviceInfo_T),
+				    GFP_ATOMIC);
       if (PhysicalDeviceInfo == NULL)
 		return DAC960_Failure(Controller, "PHYSICAL DEVICE ALLOCATION");
       Controller->V2.PhysicalDeviceInformation[PhysicalDeviceIndex] =
@@ -2122,8 +2121,8 @@ static boolean DAC960_V2_ReadDeviceConfiguration(DAC960_Controller_T
       memcpy(PhysicalDeviceInfo, NewPhysicalDeviceInfo,
 		sizeof(DAC960_V2_PhysicalDeviceInfo_T));
 
-      InquiryUnitSerialNumber = (DAC960_SCSI_Inquiry_UnitSerialNumber_T *)
-	kmalloc(sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T), GFP_ATOMIC);
+      InquiryUnitSerialNumber = kmalloc(
+	      sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T), GFP_ATOMIC);
       if (InquiryUnitSerialNumber == NULL) {
 	kfree(PhysicalDeviceInfo);
 	return DAC960_Failure(Controller, "SERIAL NUMBER ALLOCATION");
@@ -4949,8 +4948,8 @@ static void DAC960_V2_ProcessCompletedCommand(DAC960_Command_T *Command)
 	      PhysicalDevice.LogicalUnit = NewLogicalDeviceInfo->LogicalUnit;
 	      Controller->V2.LogicalDriveToVirtualDevice[LogicalDeviceNumber] =
 		PhysicalDevice;
-	      LogicalDeviceInfo = (DAC960_V2_LogicalDeviceInfo_T *)
-		kmalloc(sizeof(DAC960_V2_LogicalDeviceInfo_T), GFP_ATOMIC);
+	      LogicalDeviceInfo = kmalloc(sizeof(DAC960_V2_LogicalDeviceInfo_T),
+					  GFP_ATOMIC);
 	      Controller->V2.LogicalDeviceInformation[LogicalDeviceNumber] =
 		LogicalDeviceInfo;
 	      DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) "
@@ -5709,14 +5708,14 @@ static boolean DAC960_CheckStatusBuffer(DAC960_Controller_T *Controller,
       unsigned int NewStatusBufferLength = DAC960_InitialStatusBufferSize;
       while (NewStatusBufferLength < ByteCount)
 	NewStatusBufferLength *= 2;
-      Controller->CombinedStatusBuffer =
-	(unsigned char *) kmalloc(NewStatusBufferLength, GFP_ATOMIC);
+      Controller->CombinedStatusBuffer = kmalloc(NewStatusBufferLength, 
+						  GFP_ATOMIC);
       if (Controller->CombinedStatusBuffer == NULL) return false;
       Controller->CombinedStatusBufferLength = NewStatusBufferLength;
       return true;
     }
-  NewStatusBuffer = (unsigned char *)
-    kmalloc(2 * Controller->CombinedStatusBufferLength, GFP_ATOMIC);
+  NewStatusBuffer = kmalloc(2 * Controller->CombinedStatusBufferLength, 
+			     GFP_ATOMIC);
   if (NewStatusBuffer == NULL)
     {
       DAC960_Warning("Unable to expand Combined Status Buffer - Truncating\n",


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 93%]

* [PATCH 2.6.20-rc3] JSM_TTY: kmalloc->kzalloc/Casting cleanups
@ 2007-01-06 13:16 95% Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-06 13:16 UTC (permalink / raw)
  To: Scott_Kilau, mansarov; +Cc: linux-kernel

[ Please inform me if you are(n't) the maintaner, I'm not sure.]

Hi all, 
A small patch to transform kmalloc to kzalloc and removing their unneeded 
casts

Signed-off-by: Ahmed Darwish <darwish.07@gmail.com>

diff --git a/drivers/serial/jsm/jsm_tty.c b/drivers/serial/jsm/jsm_tty.c
index 7cf1c60..be22bbd 100644
--- a/drivers/serial/jsm/jsm_tty.c
+++ b/drivers/serial/jsm/jsm_tty.c
@@ -194,31 +194,28 @@ static int jsm_tty_open(struct uart_port *port)
 	/* Drop locks, as malloc with GFP_KERNEL can sleep */
 
 	if (!channel->ch_rqueue) {
-		channel->ch_rqueue = (u8 *) kmalloc(RQUEUESIZE, GFP_KERNEL);
+		channel->ch_rqueue = kzalloc(RQUEUESIZE, GFP_KERNEL);
 		if (!channel->ch_rqueue) {
 			jsm_printk(INIT, ERR, &channel->ch_bd->pci_dev,
 				"unable to allocate read queue buf");
 			return -ENOMEM;
 		}
-		memset(channel->ch_rqueue, 0, RQUEUESIZE);
 	}
 	if (!channel->ch_equeue) {
-		channel->ch_equeue = (u8 *) kmalloc(EQUEUESIZE, GFP_KERNEL);
+		channel->ch_equeue = kzalloc(EQUEUESIZE, GFP_KERNEL);
 		if (!channel->ch_equeue) {
 			jsm_printk(INIT, ERR, &channel->ch_bd->pci_dev,
 				"unable to allocate error queue buf");
 			return -ENOMEM;
 		}
-		memset(channel->ch_equeue, 0, EQUEUESIZE);
 	}
 	if (!channel->ch_wqueue) {
-		channel->ch_wqueue = (u8 *) kmalloc(WQUEUESIZE, GFP_KERNEL);
+		channel->ch_wqueue = kzalloc(WQUEUESIZE, GFP_KERNEL);
 		if (!channel->ch_wqueue) {
 			jsm_printk(INIT, ERR, &channel->ch_bd->pci_dev,
 				"unable to allocate write queue buf");
 			return -ENOMEM;
 		}
-		memset(channel->ch_wqueue, 0, WQUEUESIZE);
 	}
 
 	channel->ch_flags &= ~(CH_OPENING);
@@ -392,13 +389,12 @@ int jsm_tty_init(struct jsm_board *brd)
 			 * Okay to malloc with GFP_KERNEL, we are not at
 			 * interrupt context, and there are no locks held.
 			 */
-			brd->channels[i] = kmalloc(sizeof(struct jsm_channel), GFP_KERNEL);
+			brd->channels[i] = kzalloc(sizeof(struct jsm_channel), GFP_KERNEL);
 			if (!brd->channels[i]) {
 				jsm_printk(CORE, ERR, &brd->pci_dev,
 					"%s:%d Unable to allocate memory for channel struct\n",
 							 __FILE__, __LINE__);
 			}
-			memset(brd->channels[i], 0, sizeof(struct jsm_channel));
 		}
 	}
 

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 95%]

* Re: [PATCH 2.6.20-rc3] TTY_IO: Remove unnecessary kmalloc casts
    @ 2007-01-06  2:36 99%       ` Ahmed S. Darwish
  1 sibling, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-06  2:36 UTC (permalink / raw)
  To: Robert P. J. Day; +Cc: linux-kernel

> On Fri, Jan 05, 2007 at 09:10:01AM +0100, rday wrote:
> > Ahmed S. Darwish wrote:
> > Remove unnecessary kmalloc casts in drivers/char/tty_io.c
> > Signed-off-by: Ahmed Darwish <darwish.07@gmail.com>
>
> rday
> 
> p.s.  just FYI, i have a patch that does most of this, but i was going
> to hold off submitting it until 2.6.20 had arrived.  but if you want
> to take a shot at it, it's all yours.

OK, then I should stop sending new patches related to that matter to avoid
patch conflicts. right ?

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH 2.6.20-rc3] TTY_IO code cleanups
@ 2007-01-06  0:08 91% Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-06  0:08 UTC (permalink / raw)
  To: alan; +Cc: linux-kernel

> Signed-off-by: Ahmed Darwish <darwish.07@gmail.com>
> 	struct tty_ldisc *ld;
>-	int ret = 0;
> 	
> 	spin_lock_irqsave(&tty_ldisc_lock, flags);
> 	ld = &tty->ldisc;
>-	if(test_bit(TTY_LDISC, &tty->flags))
>-	{
>+	if(test_bit(TTY_LDISC, &tty->flags)) {
> 		ld->refcount++;
>-		ret = 1;
>+		return 1;
> 	}
> 	spin_unlock_irqrestore(&tty_ldisc_lock, flags);
>-	return ret;
>+	return 0;
> }

Very sorry, Didn't mention the spin_unlock_irqrestore().
Here's the modified patch without this hunk.

Signed-off-by: Ahmed S. Darwish

diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 47a6eac..9da9537 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -331,7 +331,7 @@ static struct tty_buffer *tty_buffer_alloc(struct tty_struct *tty, size_t size)
 	p->next = NULL;
 	p->commit = 0;
 	p->read = 0;
-	p->char_buf_ptr = (char *)(p->data);
+	p->char_buf_ptr = (char *)p->data;
 	p->flag_buf_ptr = (unsigned char *)p->char_buf_ptr + size;
 	tty->buf.memory_used += size;
 	return p;
@@ -640,7 +640,6 @@ static struct tty_ldisc tty_ldiscs[NR_LDISCS];	/* line disc dispatch table */
 int tty_register_ldisc(int disc, struct tty_ldisc *new_ldisc)
 {
 	unsigned long flags;
-	int ret = 0;
 	
 	if (disc < N_TTY || disc >= NR_LDISCS)
 		return -EINVAL;
@@ -652,7 +651,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc *new_ldisc)
 	tty_ldiscs[disc].refcount = 0;
 	spin_unlock_irqrestore(&tty_ldisc_lock, flags);
 	
-	return ret;
+	return 0;
 }
 EXPORT_SYMBOL(tty_register_ldisc);
 
@@ -1932,19 +1931,16 @@ static int init_dev(struct tty_driver *driver, int idx,
 	}
 
 	if (!*tp_loc) {
-		tp = (struct ktermios *) kmalloc(sizeof(struct ktermios),
-						GFP_KERNEL);
+		tp = kmalloc(sizeof(struct ktermios), GFP_KERNEL);
 		if (!tp)
 			goto free_mem_out;
 		*tp = driver->init_termios;
 	}
 
 	if (!*ltp_loc) {
-		ltp = (struct ktermios *) kmalloc(sizeof(struct ktermios),
-						 GFP_KERNEL);
+		ltp = kzalloc(sizeof(struct ktermios), GFP_KERNEL);
 		if (!ltp)
 			goto free_mem_out;
-		memset(ltp, 0, sizeof(struct ktermios));
 	}
 
 	if (driver->type == TTY_DRIVER_TYPE_PTY) {
@@ -1965,19 +1961,16 @@ static int init_dev(struct tty_driver *driver, int idx,
 		}
 
 		if (!*o_tp_loc) {
-			o_tp = (struct ktermios *)
-				kmalloc(sizeof(struct ktermios), GFP_KERNEL);
+			o_tp = kmalloc(sizeof(struct ktermios), GFP_KERNEL);
 			if (!o_tp)
 				goto free_mem_out;
 			*o_tp = driver->other->init_termios;
 		}
 
 		if (!*o_ltp_loc) {
-			o_ltp = (struct ktermios *)
-				kmalloc(sizeof(struct ktermios), GFP_KERNEL);
+			o_ltp = kzalloc(sizeof(struct ktermios), GFP_KERNEL);
 			if (!o_ltp)
 				goto free_mem_out;
-			memset(o_ltp, 0, sizeof(struct ktermios));
 		}
 
 		/*
@@ -3605,9 +3598,8 @@ struct tty_driver *alloc_tty_driver(int lines)
 {
 	struct tty_driver *driver;
 
-	driver = kmalloc(sizeof(struct tty_driver), GFP_KERNEL);
+	driver = kzalloc(sizeof(struct tty_driver), GFP_KERNEL);
 	if (driver) {
-		memset(driver, 0, sizeof(struct tty_driver));
 		driver->magic = TTY_DRIVER_MAGIC;
 		driver->num = lines;
 		/* later we'll move allocation of tables here */
@@ -3667,10 +3659,9 @@ int tty_register_driver(struct tty_driver *driver)
 		return 0;
 
 	if (!(driver->flags & TTY_DRIVER_DEVPTS_MEM)) {
-		p = kmalloc(driver->num * 3 * sizeof(void *), GFP_KERNEL);
+		p = kzalloc(driver->num * 3 * sizeof(void *), GFP_KERNEL);
 		if (!p)
 			return -ENOMEM;
-		memset(p, 0, driver->num * 3 * sizeof(void *));
 	}
 
 	if (!driver->major) {

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 91%]

* [PATCH 2.6.20-rc3] TTY_IO code cleanups
@ 2007-01-05 23:56 88% Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-05 23:56 UTC (permalink / raw)
  To: alan; +Cc: linux-kernel

Hi all,

>From Alan:
> if you can send me a patch for the tty_io/tty_ioctl code which
> switches to kzalloc where it makes sense and removes un-needed casts I'll
> review it and push the bits that look sane upstream. 

Cleanups to switch kmalloc->kzalloc and to remove little redundant code found
(including the k[mz]alloc casts).

Thanks for your time.

Signed-off-by: Ahmed Darwish <darwish.07@gmail.com>

diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 47a6eac..7b42c55 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -331,7 +331,7 @@ static struct tty_buffer *tty_buffer_alloc(struct tty_struct *tty, size_t size)
 	p->next = NULL;
 	p->commit = 0;
 	p->read = 0;
-	p->char_buf_ptr = (char *)(p->data);
+	p->char_buf_ptr = (char *)p->data;
 	p->flag_buf_ptr = (unsigned char *)p->char_buf_ptr + size;
 	tty->buf.memory_used += size;
 	return p;
@@ -640,7 +640,6 @@ static struct tty_ldisc tty_ldiscs[NR_LDISCS];	/* line disc dispatch table */
 int tty_register_ldisc(int disc, struct tty_ldisc *new_ldisc)
 {
 	unsigned long flags;
-	int ret = 0;
 	
 	if (disc < N_TTY || disc >= NR_LDISCS)
 		return -EINVAL;
@@ -652,7 +651,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc *new_ldisc)
 	tty_ldiscs[disc].refcount = 0;
 	spin_unlock_irqrestore(&tty_ldisc_lock, flags);
 	
-	return ret;
+	return 0;
 }
 EXPORT_SYMBOL(tty_register_ldisc);
 
@@ -791,17 +790,15 @@ static int tty_ldisc_try(struct tty_struct *tty)
 {
 	unsigned long flags;
 	struct tty_ldisc *ld;
-	int ret = 0;
 	
 	spin_lock_irqsave(&tty_ldisc_lock, flags);
 	ld = &tty->ldisc;
-	if(test_bit(TTY_LDISC, &tty->flags))
-	{
+	if(test_bit(TTY_LDISC, &tty->flags)) {
 		ld->refcount++;
-		ret = 1;
+		return 1;
 	}
 	spin_unlock_irqrestore(&tty_ldisc_lock, flags);
-	return ret;
+	return 0;
 }
 
 /**
@@ -1932,19 +1929,16 @@ static int init_dev(struct tty_driver *driver, int idx,
 	}
 
 	if (!*tp_loc) {
-		tp = (struct ktermios *) kmalloc(sizeof(struct ktermios),
-						GFP_KERNEL);
+		tp = kmalloc(sizeof(struct ktermios), GFP_KERNEL);
 		if (!tp)
 			goto free_mem_out;
 		*tp = driver->init_termios;
 	}
 
 	if (!*ltp_loc) {
-		ltp = (struct ktermios *) kmalloc(sizeof(struct ktermios),
-						 GFP_KERNEL);
+		ltp = kzalloc(sizeof(struct ktermios), GFP_KERNEL);
 		if (!ltp)
 			goto free_mem_out;
-		memset(ltp, 0, sizeof(struct ktermios));
 	}
 
 	if (driver->type == TTY_DRIVER_TYPE_PTY) {
@@ -1965,19 +1959,16 @@ static int init_dev(struct tty_driver *driver, int idx,
 		}
 
 		if (!*o_tp_loc) {
-			o_tp = (struct ktermios *)
-				kmalloc(sizeof(struct ktermios), GFP_KERNEL);
+			o_tp = kmalloc(sizeof(struct ktermios), GFP_KERNEL);
 			if (!o_tp)
 				goto free_mem_out;
 			*o_tp = driver->other->init_termios;
 		}
 
 		if (!*o_ltp_loc) {
-			o_ltp = (struct ktermios *)
-				kmalloc(sizeof(struct ktermios), GFP_KERNEL);
+			o_ltp = kzalloc(sizeof(struct ktermios), GFP_KERNEL);
 			if (!o_ltp)
 				goto free_mem_out;
-			memset(o_ltp, 0, sizeof(struct ktermios));
 		}
 
 		/*
@@ -3605,9 +3596,8 @@ struct tty_driver *alloc_tty_driver(int lines)
 {
 	struct tty_driver *driver;
 
-	driver = kmalloc(sizeof(struct tty_driver), GFP_KERNEL);
+	driver = kzalloc(sizeof(struct tty_driver), GFP_KERNEL);
 	if (driver) {
-		memset(driver, 0, sizeof(struct tty_driver));
 		driver->magic = TTY_DRIVER_MAGIC;
 		driver->num = lines;
 		/* later we'll move allocation of tables here */
@@ -3667,10 +3657,9 @@ int tty_register_driver(struct tty_driver *driver)
 		return 0;
 
 	if (!(driver->flags & TTY_DRIVER_DEVPTS_MEM)) {
-		p = kmalloc(driver->num * 3 * sizeof(void *), GFP_KERNEL);
+		p = kzalloc(driver->num * 3 * sizeof(void *), GFP_KERNEL);
 		if (!p)
 			return -ENOMEM;
-		memset(p, 0, driver->num * 3 * sizeof(void *));
 	}
 
 	if (!driver->major) {


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 88%]

* Re: [PATCH 2.6.20-rc3] TTY_IO: Remove unnecessary kmalloc casts
  @ 2007-01-05 11:03 99%         ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-05 11:03 UTC (permalink / raw)
  To: Alan; +Cc: linux-kernel

On Fri, Jan 05, 2007 at 10:51:13AM +0000, Alan wrote:

> Ahmed - if you can send me a patch for the tty_io/tty_ioctl code which
> switches to kzalloc where it makes sense and removes un-needed casts I'll
> review it and push the bits that look sane upstream. 
> 
> Alan

OK I'll try this now.
Are you Mr. Alan Cox. ?. Sorry, "Alan" alone is ambiguous.

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH 2.6.20-rc3] TTY_IO: Remove unnecessary kmalloc casts
  @ 2007-01-05 10:32 99%       ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-05 10:32 UTC (permalink / raw)
  To: Rolf Eike Beer; +Cc: linux-kernel

On Fri, Jan 05, 2007 at 11:26:07AM +0100, Rolf Eike Beer wrote:

> One big patch for the whole kernel will not work anyway. You have to split it 
> up to allow subsystems to integrate them in their own trees. With one big 
> patch you would get collisions all over the tree causing the complete patch 
> to get dropped. Also CC subsystem maintainers on their parts. And please send 
> the patches as replies to the first one as it cleans up readability of lkml a 
> lot :)

Oops, Just read this warning after sending the (big) patch. Sorry It's my first
patch :). I'll split it and do as written. Thanks alot :).

> > I think this will be better done in another patch to let every patch do one
> > single thing. right ?
> 
> Yes. But I would suggest starting with the kmalloc()->kzalloc() things. When 
> you do this conversions just remove the casts of the lines you're touching. 
> This will reduce the size of the complete thing avoiding two rather trivial 
> patches touching the same line twice.
> 
> Eike

OK. In progress

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH UPDATED 2.6.20-rc3] Remove all the unneeded k[mzc]alloc casts
@ 2007-01-05 10:26 52% Ahmed S. Darwish
    0 siblings, 1 reply; 200+ results
From: Ahmed S. Darwish @ 2007-01-05 10:26 UTC (permalink / raw)
  To: linux-kernel

Hi all, 
This is a patch to remove the unneeded k[mzc]alloc casts in the whole 
2.6.20-rc3 tree. I tried to put this patch in a patchset but I couldn't
cause the modified files have nothing in common (except the unneeded casts 
ofcourse).

This patch includes http://lkml.org/lkml/fancy/2007/1/5/12 and
http://lkml.org/lkml/2007/1/5/6.

Signed-off-by: Ahmed Darwish

diff --git a/arch/cris/arch-v32/mm/intmem.c b/arch/cris/arch-v32/mm/intmem.c
index 41ee7f7..acb4e21 100644
--- a/arch/cris/arch-v32/mm/intmem.c
+++ b/arch/cris/arch-v32/mm/intmem.c
@@ -27,8 +27,8 @@ static void crisv32_intmem_init(void)
 {
 	static int initiated = 0;
 	if (!initiated) {
-		struct intmem_allocation* alloc =
-		  (struct intmem_allocation*)kmalloc(sizeof *alloc, GFP_KERNEL);
+		struct intmem_allocation* alloc = kmalloc(sizeof *alloc, 
+							  GFP_KERNEL);
 		INIT_LIST_HEAD(&intmem_allocations);
 		intmem_virtual = ioremap(MEM_INTMEM_START, MEM_INTMEM_SIZE);
 		initiated = 1;
@@ -56,7 +56,6 @@ void* crisv32_intmem_alloc(unsigned size, unsigned align)
 		    allocation->size >= size + alignment) {
 			if (allocation->size > size + alignment) {
 				struct intmem_allocation* alloc =
-					(struct intmem_allocation*)
 					kmalloc(sizeof *alloc, GFP_ATOMIC);
 				alloc->status = STATUS_FREE;
 				alloc->size = allocation->size - size - alignment;
@@ -65,8 +64,7 @@ void* crisv32_intmem_alloc(unsigned size, unsigned align)
 
 				if (alignment) {
 					struct intmem_allocation* tmp;
-					tmp = (struct intmem_allocation*)
-						kmalloc(sizeof *tmp, GFP_ATOMIC);
+					tmp = kmalloc(sizeof *tmp, GFP_ATOMIC);
 					tmp->offset = allocation->offset;
 					tmp->size = alignment;
 					tmp->status = STATUS_FREE;
diff --git a/drivers/block/DAC960.c b/drivers/block/DAC960.c
index 8d81a3a..72b998b 100644
--- a/drivers/block/DAC960.c
+++ b/drivers/block/DAC960.c
@@ -1879,8 +1879,8 @@ static boolean DAC960_V2_ReadControllerConfiguration(DAC960_Controller_T
       if (NewLogicalDeviceInfo->LogicalDeviceState !=
 	  DAC960_V2_LogicalDevice_Offline)
 	Controller->LogicalDriveInitiallyAccessible[LogicalDeviceNumber] = true;
-      LogicalDeviceInfo = (DAC960_V2_LogicalDeviceInfo_T *)
-	kmalloc(sizeof(DAC960_V2_LogicalDeviceInfo_T), GFP_ATOMIC);
+      LogicalDeviceInfo = kmalloc(sizeof(DAC960_V2_LogicalDeviceInfo_T),
+				   GFP_ATOMIC);
       if (LogicalDeviceInfo == NULL)
 	return DAC960_Failure(Controller, "LOGICAL DEVICE ALLOCATION");
       Controller->V2.LogicalDeviceInformation[LogicalDeviceNumber] =
@@ -2113,8 +2113,8 @@ static boolean DAC960_V2_ReadDeviceConfiguration(DAC960_Controller_T
       if (!DAC960_V2_NewPhysicalDeviceInfo(Controller, Channel, TargetID, LogicalUnit))
 	  break;
 
-      PhysicalDeviceInfo = (DAC960_V2_PhysicalDeviceInfo_T *)
-		kmalloc(sizeof(DAC960_V2_PhysicalDeviceInfo_T), GFP_ATOMIC);
+      PhysicalDeviceInfo = kmalloc(sizeof(DAC960_V2_PhysicalDeviceInfo_T),
+				    GFP_ATOMIC);
       if (PhysicalDeviceInfo == NULL)
 		return DAC960_Failure(Controller, "PHYSICAL DEVICE ALLOCATION");
       Controller->V2.PhysicalDeviceInformation[PhysicalDeviceIndex] =
@@ -2122,8 +2122,8 @@ static boolean DAC960_V2_ReadDeviceConfiguration(DAC960_Controller_T
       memcpy(PhysicalDeviceInfo, NewPhysicalDeviceInfo,
 		sizeof(DAC960_V2_PhysicalDeviceInfo_T));
 
-      InquiryUnitSerialNumber = (DAC960_SCSI_Inquiry_UnitSerialNumber_T *)
-	kmalloc(sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T), GFP_ATOMIC);
+      InquiryUnitSerialNumber = kmalloc(
+	      sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T), GFP_ATOMIC);
       if (InquiryUnitSerialNumber == NULL) {
 	kfree(PhysicalDeviceInfo);
 	return DAC960_Failure(Controller, "SERIAL NUMBER ALLOCATION");
@@ -4949,8 +4949,8 @@ static void DAC960_V2_ProcessCompletedCommand(DAC960_Command_T *Command)
 	      PhysicalDevice.LogicalUnit = NewLogicalDeviceInfo->LogicalUnit;
 	      Controller->V2.LogicalDriveToVirtualDevice[LogicalDeviceNumber] =
 		PhysicalDevice;
-	      LogicalDeviceInfo = (DAC960_V2_LogicalDeviceInfo_T *)
-		kmalloc(sizeof(DAC960_V2_LogicalDeviceInfo_T), GFP_ATOMIC);
+	      LogicalDeviceInfo = kmalloc(sizeof(DAC960_V2_LogicalDeviceInfo_T),
+					  GFP_ATOMIC);
 	      Controller->V2.LogicalDeviceInformation[LogicalDeviceNumber] =
 		LogicalDeviceInfo;
 	      DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) "
@@ -5709,14 +5709,14 @@ static boolean DAC960_CheckStatusBuffer(DAC960_Controller_T *Controller,
       unsigned int NewStatusBufferLength = DAC960_InitialStatusBufferSize;
       while (NewStatusBufferLength < ByteCount)
 	NewStatusBufferLength *= 2;
-      Controller->CombinedStatusBuffer =
-	(unsigned char *) kmalloc(NewStatusBufferLength, GFP_ATOMIC);
+      Controller->CombinedStatusBuffer = kmalloc(NewStatusBufferLength, 
+						 GFP_ATOMIC);
       if (Controller->CombinedStatusBuffer == NULL) return false;
       Controller->CombinedStatusBufferLength = NewStatusBufferLength;
       return true;
     }
-  NewStatusBuffer = (unsigned char *)
-    kmalloc(2 * Controller->CombinedStatusBufferLength, GFP_ATOMIC);
+  NewStatusBuffer = kmalloc(2 * Controller->CombinedStatusBufferLength, 
+			    GFP_ATOMIC);
   if (NewStatusBuffer == NULL)
     {
       DAC960_Warning("Unable to expand Combined Status Buffer - Truncating\n",
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 47a6eac..ad4d32b 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -1932,16 +1932,16 @@ static int init_dev(struct tty_driver *driver, int idx,
 	}
 
 	if (!*tp_loc) {
-		tp = (struct ktermios *) kmalloc(sizeof(struct ktermios),
-						GFP_KERNEL);
+		tp = kmalloc(sizeof(struct ktermios),
+			     GFP_KERNEL);
 		if (!tp)
 			goto free_mem_out;
 		*tp = driver->init_termios;
 	}
 
 	if (!*ltp_loc) {
-		ltp = (struct ktermios *) kmalloc(sizeof(struct ktermios),
-						 GFP_KERNEL);
+		ltp = kmalloc(sizeof(struct ktermios),
+			      GFP_KERNEL);
 		if (!ltp)
 			goto free_mem_out;
 		memset(ltp, 0, sizeof(struct ktermios));
@@ -1965,16 +1965,14 @@ static int init_dev(struct tty_driver *driver, int idx,
 		}
 
 		if (!*o_tp_loc) {
-			o_tp = (struct ktermios *)
-				kmalloc(sizeof(struct ktermios), GFP_KERNEL);
+			o_tp = kmalloc(sizeof(struct ktermios), GFP_KERNEL);
 			if (!o_tp)
 				goto free_mem_out;
 			*o_tp = driver->other->init_termios;
 		}
 
 		if (!*o_ltp_loc) {
-			o_ltp = (struct ktermios *)
-				kmalloc(sizeof(struct ktermios), GFP_KERNEL);
+			o_ltp = kmalloc(sizeof(struct ktermios), GFP_KERNEL);
 			if (!o_ltp)
 				goto free_mem_out;
 			memset(o_ltp, 0, sizeof(struct ktermios));
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 18c2b3c..2fcfdbb 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -656,7 +656,7 @@ struct hid_device *hid_parse_report(__u8 *start, unsigned size)
 	for (i = 0; i < HID_REPORT_TYPES; i++)
 		INIT_LIST_HEAD(&device->report_enum[i].report_list);
 
-	if (!(device->rdesc = (__u8 *)kmalloc(size, GFP_KERNEL))) {
+	if (!(device->rdesc = kmalloc(size, GFP_KERNEL))) {
 		kfree(device->collection);
 		kfree(device);
 		return NULL;
diff --git a/drivers/media/video/zoran_driver.c b/drivers/media/video/zoran_driver.c
index 862a984..f83059d 100644
--- a/drivers/media/video/zoran_driver.c
+++ b/drivers/media/video/zoran_driver.c
@@ -343,10 +343,8 @@ v4l_fbuffer_alloc (struct file *file)
 		if (fh->v4l_buffers.buffer_size <= MAX_KMALLOC_MEM) {
 			/* Use kmalloc */
 
-			mem =
-			    (unsigned char *) kmalloc(fh->v4l_buffers.
-						      buffer_size,
-						      GFP_KERNEL);
+			mem = kmalloc(fh->v4l_buffers.buffer_size, GFP_KERNEL);
+
 			if (mem == 0) {
 				dprintk(1,
 					KERN_ERR
@@ -569,10 +567,7 @@ jpg_fbuffer_alloc (struct file *file)
 
 		//if (alloc_contig) {
 		if (fh->jpg_buffers.need_contiguous) {
-			mem =
-			    (unsigned long) kmalloc(fh->jpg_buffers.
-						    buffer_size,
-						    GFP_KERNEL);
+			mem = kmalloc(fh->jpg_buffers.buffer_size, GFP_KERNEL);
 			if (mem == 0) {
 				dprintk(1,
 					KERN_ERR
diff --git a/drivers/message/i2o/i2o_config.c b/drivers/message/i2o/i2o_config.c
index e33d446..e25993a 100644
--- a/drivers/message/i2o/i2o_config.c
+++ b/drivers/message/i2o/i2o_config.c
@@ -1039,8 +1039,7 @@ static int i2o_cfg_ioctl(struct inode *inode, struct file *fp, unsigned int cmd,
 
 static int cfg_open(struct inode *inode, struct file *file)
 {
-	struct i2o_cfg_info *tmp =
-	    (struct i2o_cfg_info *)kmalloc(sizeof(struct i2o_cfg_info),
+	struct i2o_cfg_info *tmp = kmalloc(sizeof(struct i2o_cfg_info),
 					   GFP_KERNEL);
 	unsigned long flags;
 
diff --git a/drivers/mtd/chips/amd_flash.c b/drivers/mtd/chips/amd_flash.c
index 16eaca6..7689155 100644
--- a/drivers/mtd/chips/amd_flash.c
+++ b/drivers/mtd/chips/amd_flash.c
@@ -643,7 +643,7 @@ static struct mtd_info *amd_flash_probe(struct map_info *map)
 	int reg_idx;
 	int offset;
 
-	mtd = (struct mtd_info*)kmalloc(sizeof(*mtd), GFP_KERNEL);
+	mtd = kmalloc(sizeof(*mtd), GFP_KERNEL);
 	if (!mtd) {
 		printk(KERN_WARNING
 		       "%s: kmalloc failed for info structure\n", map->name);
diff --git a/drivers/mtd/maps/tqm834x.c b/drivers/mtd/maps/tqm834x.c
index 58e5912..30c292e 100644
--- a/drivers/mtd/maps/tqm834x.c
+++ b/drivers/mtd/maps/tqm834x.c
@@ -132,15 +132,14 @@ static int __init init_tqm834x_mtd(void)
 
 		pr_debug("%s: chip probing count %d\n", __FUNCTION__, idx);
 
-		map_banks[idx] =
-			(struct map_info *)kmalloc(sizeof(struct map_info),
-						   GFP_KERNEL);
+		map_banks[idx] = kmalloc(sizeof(struct map_info),
+					 GFP_KERNEL);
 		if (map_banks[idx] == NULL) {
 			ret = -ENOMEM;
 			goto error_mem;
 		}
 		memset((void *)map_banks[idx], 0, sizeof(struct map_info));
-		map_banks[idx]->name = (char *)kmalloc(16, GFP_KERNEL);
+		map_banks[idx]->name = kmalloc(16, GFP_KERNEL);
 		if (map_banks[idx]->name == NULL) {
 			ret = -ENOMEM;
 			goto error_mem;
diff --git a/drivers/mtd/maps/tqm8xxl.c b/drivers/mtd/maps/tqm8xxl.c
index 19578ba..73f2245 100644
--- a/drivers/mtd/maps/tqm8xxl.c
+++ b/drivers/mtd/maps/tqm8xxl.c
@@ -134,7 +134,7 @@ int __init init_tqm_mtd(void)
 
 		printk(KERN_INFO "%s: chip probing count %d\n", __FUNCTION__, idx);
 
-		map_banks[idx] = (struct map_info *)kmalloc(sizeof(struct map_info), GFP_KERNEL);
+		map_banks[idx] = kmalloc(sizeof(struct map_info), GFP_KERNEL);
 		if(map_banks[idx] == NULL) {
 			ret = -ENOMEM;
 			/* FIXME: What if some MTD devices were probed already? */
@@ -142,7 +142,7 @@ int __init init_tqm_mtd(void)
 		}
 
 		memset((void *)map_banks[idx], 0, sizeof(struct map_info));
-		map_banks[idx]->name = (char *)kmalloc(16, GFP_KERNEL);
+		map_banks[idx]->name = kmalloc(16, GFP_KERNEL);
 
 		if (!map_banks[idx]->name) {
 			ret = -ENOMEM;
diff --git a/drivers/net/ucc_geth.c b/drivers/net/ucc_geth.c
index 8243150..001109e 100644
--- a/drivers/net/ucc_geth.c
+++ b/drivers/net/ucc_geth.c
@@ -2864,8 +2864,8 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
 			if (UCC_GETH_TX_BD_RING_ALIGNMENT > 4)
 				align = UCC_GETH_TX_BD_RING_ALIGNMENT;
 			ugeth->tx_bd_ring_offset[j] =
-				(u32) (kmalloc((u32) (length + align),
-				GFP_KERNEL));
+				kmalloc((u32) (length + align), GFP_KERNEL);
+					 
 			if (ugeth->tx_bd_ring_offset[j] != 0)
 				ugeth->p_tx_bd_ring[j] =
 					(void*)((ugeth->tx_bd_ring_offset[j] +
@@ -2900,7 +2900,7 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
 			if (UCC_GETH_RX_BD_RING_ALIGNMENT > 4)
 				align = UCC_GETH_RX_BD_RING_ALIGNMENT;
 			ugeth->rx_bd_ring_offset[j] =
-			    (u32) (kmalloc((u32) (length + align), GFP_KERNEL));
+				kmalloc((u32) (length + align), GFP_KERNEL);
 			if (ugeth->rx_bd_ring_offset[j] != 0)
 				ugeth->p_rx_bd_ring[j] =
 					(void*)((ugeth->rx_bd_ring_offset[j] +
@@ -2926,10 +2926,9 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
 	/* Init Tx bds */
 	for (j = 0; j < ug_info->numQueuesTx; j++) {
 		/* Setup the skbuff rings */
-		ugeth->tx_skbuff[j] =
-		    (struct sk_buff **)kmalloc(sizeof(struct sk_buff *) *
-					       ugeth->ug_info->bdRingLenTx[j],
-					       GFP_KERNEL);
+		ugeth->tx_skbuff[j] = kmalloc(sizeof(struct sk_buff *) *
+					      ugeth->ug_info->bdRingLenTx[j],
+					      GFP_KERNEL);
 
 		if (ugeth->tx_skbuff[j] == NULL) {
 			ugeth_err("%s: Could not allocate tx_skbuff",
@@ -2958,10 +2957,9 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
 	/* Init Rx bds */
 	for (j = 0; j < ug_info->numQueuesRx; j++) {
 		/* Setup the skbuff rings */
-		ugeth->rx_skbuff[j] =
-		    (struct sk_buff **)kmalloc(sizeof(struct sk_buff *) *
-					       ugeth->ug_info->bdRingLenRx[j],
-					       GFP_KERNEL);
+		ugeth->rx_skbuff[j] = kmalloc(sizeof(struct sk_buff *) *
+					      ugeth->ug_info->bdRingLenRx[j],
+					      GFP_KERNEL);
 
 		if (ugeth->rx_skbuff[j] == NULL) {
 			ugeth_err("%s: Could not allocate rx_skbuff",
@@ -3452,8 +3450,7 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
 	 * allocated resources can be released when the channel is freed.
 	 */
 	if (!(ugeth->p_init_enet_param_shadow =
-	     (struct ucc_geth_init_pram *) kmalloc(sizeof(struct ucc_geth_init_pram),
-					      GFP_KERNEL))) {
+	      kmalloc(sizeof(struct ucc_geth_init_pram), GFP_KERNEL))) {
 		ugeth_err
 		    ("%s: Can not allocate memory for"
 			" p_UccInitEnetParamShadows.", __FUNCTION__);
diff --git a/drivers/net/wireless/ipw2100.c b/drivers/net/wireless/ipw2100.c
index 0e94fbb..e270732 100644
--- a/drivers/net/wireless/ipw2100.c
+++ b/drivers/net/wireless/ipw2100.c
@@ -3361,11 +3361,9 @@ static int ipw2100_msg_allocate(struct ipw2100_priv *priv)
 	void *v;
 	dma_addr_t p;
 
-	priv->msg_buffers =
-	    (struct ipw2100_tx_packet *)kmalloc(IPW_COMMAND_POOL_SIZE *
-						sizeof(struct
-						       ipw2100_tx_packet),
-						GFP_KERNEL);
+	priv->msg_buffers = kmalloc(IPW_COMMAND_POOL_SIZE *
+				    sizeof(struct ipw2100_tx_packet),
+				    GFP_KERNEL);
 	if (!priv->msg_buffers) {
 		printk(KERN_ERR DRV_NAME ": %s: PCI alloc failed for msg "
 		       "buffers.\n", priv->net_dev->name);
@@ -4395,11 +4393,9 @@ static int ipw2100_tx_allocate(struct ipw2100_priv *priv)
 		return err;
 	}
 
-	priv->tx_buffers =
-	    (struct ipw2100_tx_packet *)kmalloc(TX_PENDED_QUEUE_LENGTH *
-						sizeof(struct
-						       ipw2100_tx_packet),
-						GFP_ATOMIC);
+	priv->tx_buffers = kmalloc(TX_PENDED_QUEUE_LENGTH *
+				   sizeof(struct ipw2100_tx_packet),
+				   GFP_ATOMIC);
 	if (!priv->tx_buffers) {
 		printk(KERN_ERR DRV_NAME
 		       ": %s: alloc failed form tx buffers.\n",
@@ -4548,9 +4544,9 @@ static int ipw2100_rx_allocate(struct ipw2100_priv *priv)
 	/*
 	 * allocate packets
 	 */
-	priv->rx_buffers = (struct ipw2100_rx_packet *)
-	    kmalloc(RX_QUEUE_LENGTH * sizeof(struct ipw2100_rx_packet),
-		    GFP_KERNEL);
+	priv->rx_buffers = kmalloc(RX_QUEUE_LENGTH * 
+				   sizeof(struct ipw2100_rx_packet),
+				   GFP_KERNEL);
 	if (!priv->rx_buffers) {
 		IPW_DEBUG_INFO("can't allocate rx packet buffer table\n");
 
diff --git a/drivers/s390/net/ctcmain.c b/drivers/s390/net/ctcmain.c
index 03cc263..d2a3d48 100644
--- a/drivers/s390/net/ctcmain.c
+++ b/drivers/s390/net/ctcmain.c
@@ -1639,9 +1639,7 @@ add_channel(struct ccw_device *cdev, enum channel_types type)
 	struct channel *ch;
 
 	DBF_TEXT(trace, 2, __FUNCTION__);
-	if ((ch =
-	     (struct channel *) kmalloc(sizeof (struct channel),
-					GFP_KERNEL)) == NULL) {
+	if ((ch = kmalloc(sizeof (struct channel), GFP_KERNEL)) == NULL) {
 		ctc_pr_warn("ctc: Out of memory in add_channel\n");
 		return -1;
 	}
diff --git a/drivers/scsi/advansys.c b/drivers/scsi/advansys.c
index 2b34435..df76b7c 100644
--- a/drivers/scsi/advansys.c
+++ b/drivers/scsi/advansys.c
@@ -5256,8 +5256,7 @@ advansys_detect(struct scsi_host_template *tpnt)
                  * Allocate buffer carrier structures. The total size
                  * is about 4 KB, so allocate all at once.
                  */
-                carrp =
-                    (ADV_CARR_T *) kmalloc(ADV_CARRIER_BUFSIZE, GFP_ATOMIC);
+                carrp = kmalloc(ADV_CARRIER_BUFSIZE, GFP_ATOMIC);
                 ASC_DBG1(1, "advansys_detect: carrp 0x%lx\n", (ulong) carrp);
 
                 if (carrp == NULL) {
@@ -5273,8 +5272,7 @@ advansys_detect(struct scsi_host_template *tpnt)
                 for (req_cnt = adv_dvc_varp->max_host_qng;
                     req_cnt > 0; req_cnt--) {
 
-                    reqp = (adv_req_t *)
-                        kmalloc(sizeof(adv_req_t) * req_cnt, GFP_ATOMIC);
+                    reqp = kmalloc(sizeof(adv_req_t) * req_cnt, GFP_ATOMIC);
 
                     ASC_DBG3(1,
                         "advansys_detect: reqp 0x%lx, req_cnt %d, bytes %lu\n",
@@ -5297,8 +5295,7 @@ advansys_detect(struct scsi_host_template *tpnt)
                 boardp->adv_sgblkp = NULL;
                 for (sg_cnt = 0; sg_cnt < ADV_TOT_SG_BLOCK; sg_cnt++) {
 
-                    sgp = (adv_sgblk_t *)
-                        kmalloc(sizeof(adv_sgblk_t), GFP_ATOMIC);
+                    sgp = kmalloc(sizeof(adv_sgblk_t), GFP_ATOMIC);
 
                     if (sgp == NULL) {
                         break;
diff --git a/drivers/serial/jsm/jsm_tty.c b/drivers/serial/jsm/jsm_tty.c
index 7cf1c60..610290a 100644
--- a/drivers/serial/jsm/jsm_tty.c
+++ b/drivers/serial/jsm/jsm_tty.c
@@ -194,7 +194,7 @@ static int jsm_tty_open(struct uart_port *port)
 	/* Drop locks, as malloc with GFP_KERNEL can sleep */
 
 	if (!channel->ch_rqueue) {
-		channel->ch_rqueue = (u8 *) kmalloc(RQUEUESIZE, GFP_KERNEL);
+		channel->ch_rqueue = kmalloc(RQUEUESIZE, GFP_KERNEL);
 		if (!channel->ch_rqueue) {
 			jsm_printk(INIT, ERR, &channel->ch_bd->pci_dev,
 				"unable to allocate read queue buf");
@@ -203,7 +203,7 @@ static int jsm_tty_open(struct uart_port *port)
 		memset(channel->ch_rqueue, 0, RQUEUESIZE);
 	}
 	if (!channel->ch_equeue) {
-		channel->ch_equeue = (u8 *) kmalloc(EQUEUESIZE, GFP_KERNEL);
+		channel->ch_equeue = kmalloc(EQUEUESIZE, GFP_KERNEL);
 		if (!channel->ch_equeue) {
 			jsm_printk(INIT, ERR, &channel->ch_bd->pci_dev,
 				"unable to allocate error queue buf");
@@ -212,7 +212,7 @@ static int jsm_tty_open(struct uart_port *port)
 		memset(channel->ch_equeue, 0, EQUEUESIZE);
 	}
 	if (!channel->ch_wqueue) {
-		channel->ch_wqueue = (u8 *) kmalloc(WQUEUESIZE, GFP_KERNEL);
+		channel->ch_wqueue = kmalloc(WQUEUESIZE, GFP_KERNEL);
 		if (!channel->ch_wqueue) {
 			jsm_printk(INIT, ERR, &channel->ch_bd->pci_dev,
 				"unable to allocate write queue buf");
diff --git a/drivers/usb/host/ohci-pnx4008.c b/drivers/usb/host/ohci-pnx4008.c
index 3a8cbfb..f3c9e61 100644
--- a/drivers/usb/host/ohci-pnx4008.c
+++ b/drivers/usb/host/ohci-pnx4008.c
@@ -134,7 +134,7 @@ static int isp1301_attach(struct i2c_adapter *adap, int addr, int kind)
 {
 	struct i2c_client *c;
 
-	c = (struct i2c_client *)kzalloc(sizeof(*c), GFP_KERNEL);
+	c = kzalloc(sizeof(*c), GFP_KERNEL);
 
 	if (!c)
 		return -ENOMEM;
diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
index aedf683..90f95ed 100644
--- a/fs/cifs/misc.c
+++ b/fs/cifs/misc.c
@@ -71,9 +71,7 @@ sesInfoAlloc(void)
 {
 	struct cifsSesInfo *ret_buf;
 
-	ret_buf =
-	    (struct cifsSesInfo *) kzalloc(sizeof (struct cifsSesInfo),
-					   GFP_KERNEL);
+	ret_buf = kzalloc(sizeof (struct cifsSesInfo), GFP_KERNEL);
 	if (ret_buf) {
 		write_lock(&GlobalSMBSeslock);
 		atomic_inc(&sesInfoAllocCount);
@@ -109,9 +107,8 @@ struct cifsTconInfo *
 tconInfoAlloc(void)
 {
 	struct cifsTconInfo *ret_buf;
-	ret_buf =
-	    (struct cifsTconInfo *) kzalloc(sizeof (struct cifsTconInfo),
-					    GFP_KERNEL);
+	ret_buf = kzalloc(sizeof (struct cifsTconInfo),
+			  GFP_KERNEL);
 	if (ret_buf) {
 		write_lock(&GlobalSMBSeslock);
 		atomic_inc(&tconInfoAllocCount);
diff --git a/fs/jfs/jfs_dtree.c b/fs/jfs/jfs_dtree.c
index 6d62f32..7c7195a 100644
--- a/fs/jfs/jfs_dtree.c
+++ b/fs/jfs/jfs_dtree.c
@@ -592,9 +592,8 @@ int dtSearch(struct inode *ip, struct component_name * key, ino_t * data,
 	struct component_name ciKey;
 	struct super_block *sb = ip->i_sb;
 
-	ciKey.name =
-	    (wchar_t *) kmalloc((JFS_NAME_MAX + 1) * sizeof(wchar_t),
-				GFP_NOFS);
+	ciKey.name = kmalloc((JFS_NAME_MAX + 1) * sizeof(wchar_t),
+			     GFP_NOFS);
 	if (ciKey.name == 0) {
 		rc = -ENOMEM;
 		goto dtSearch_Exit2;
@@ -957,9 +956,7 @@ static int dtSplitUp(tid_t tid,
 	smp = split->mp;
 	sp = DT_PAGE(ip, smp);
 
-	key.name =
-	    (wchar_t *) kmalloc((JFS_NAME_MAX + 2) * sizeof(wchar_t),
-				GFP_NOFS);
+	key.name = kmalloc((JFS_NAME_MAX + 2) * sizeof(wchar_t), GFP_NOFS);
 	if (key.name == 0) {
 		DT_PUTPAGE(smp);
 		rc = -ENOMEM;

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 52%]

* Re: [PATCH 2.6.20-rc3] TTY_IO: Remove unnecessary kmalloc casts
  @ 2007-01-05 10:06 99%   ` Ahmed S. Darwish
      0 siblings, 2 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-05 10:06 UTC (permalink / raw)
  To: Rolf Eike Beer; +Cc: linux-kernel

On Fri, Jan 05, 2007 at 09:10:01AM +0100, Rolf Eike Beer wrote:
> Ahmed S. Darwish wrote:
> > Remove unnecessary kmalloc casts in drivers/char/tty_io.c
> >
> > Signed-off-by: Ahmed Darwish <darwish.07@gmail.com>
> 
>   	if (!*ltp_loc) {
>  -		ltp = (struct ktermios *) kmalloc(sizeof(struct ktermios),
>  -						 GFP_KERNEL);
>  +		ltp = kmalloc(sizeof(struct ktermios), GFP_KERNEL);
>                       ^^^^^^^
>   		if (!ltp)
>   			goto free_mem_out;
>   		memset(ltp, 0, sizeof(struct ktermios));
>                 ^^^^^^ 
> kzalloc
> 
>   		if (!*o_ltp_loc) {
>  -			o_ltp = (struct ktermios *)
>  -				kmalloc(sizeof(struct ktermios), GFP_KERNEL);
>  +			o_ltp = kmalloc(sizeof(struct ktermios), GFP_KERNEL);
>                                 ^^^^^^^
>   			if (!o_ltp)
>   				goto free_mem_out;
>   			memset(o_ltp, 0, sizeof(struct ktermios));
>                         ^^^^^^
> kzalloc

Currently I'm dropping this patch and writing a big patch to remove all the 
k[mzc]alloc castings in the 20-rc3 tree as suggested by Mr. Robert Day.
I think this will be better done in another patch to let every patch do one
single thing. right ?

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* Re: [PATCH 2.6.20-rc3] TTY_IO: Remove unnecessary kmalloc casts
  @ 2007-01-05  7:14 99%   ` Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-05  7:14 UTC (permalink / raw)
  To: Robert P. J. Day; +Cc: linux-kernel

On Fri, Jan 05, 2007 at 01:56:09AM -0500, Robert P. J. Day wrote:
> On Fri, 5 Jan 2007, Ahmed S. Darwish wrote:
> 
> > Remove unnecessary kmalloc casts in drivers/char/tty_io.c
> 
> rather than remove these casts a file or two at a time, why not just
> do them all at once and submit a single patch?  there aren't that many
> of them:

OK, Thanks for the tip ..

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.20-rc3] TTY_IO: Remove unnecessary kmalloc casts
@ 2007-01-05  6:36 99% Ahmed S. Darwish
      0 siblings, 2 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-05  6:36 UTC (permalink / raw)
  To: linux-kernel

Remove unnecessary kmalloc casts in drivers/char/tty_io.c

Signed-off-by: Ahmed Darwish <darwish.07@gmail.com>

diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 47a6eac..97f54b0 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -1932,16 +1932,14 @@ static int init_dev(struct tty_driver *driver, int idx,
 	}
 
 	if (!*tp_loc) {
-		tp = (struct ktermios *) kmalloc(sizeof(struct ktermios),
-						GFP_KERNEL);
+		tp = kmalloc(sizeof(struct ktermios), GFP_KERNEL);
 		if (!tp)
 			goto free_mem_out;
 		*tp = driver->init_termios;
 	}
 
 	if (!*ltp_loc) {
-		ltp = (struct ktermios *) kmalloc(sizeof(struct ktermios),
-						 GFP_KERNEL);
+		ltp = kmalloc(sizeof(struct ktermios), GFP_KERNEL);
 		if (!ltp)
 			goto free_mem_out;
 		memset(ltp, 0, sizeof(struct ktermios));
@@ -1965,16 +1963,14 @@ static int init_dev(struct tty_driver *driver, int idx,
 		}
 
 		if (!*o_tp_loc) {
-			o_tp = (struct ktermios *)
-				kmalloc(sizeof(struct ktermios), GFP_KERNEL);
+			o_tp = kmalloc(sizeof(struct ktermios), GFP_KERNEL);
 			if (!o_tp)
 				goto free_mem_out;
 			*o_tp = driver->other->init_termios;
 		}
 
 		if (!*o_ltp_loc) {
-			o_ltp = (struct ktermios *)
-				kmalloc(sizeof(struct ktermios), GFP_KERNEL);
+			o_ltp = kmalloc(sizeof(struct ktermios), GFP_KERNEL);
 			if (!o_ltp)
 				goto free_mem_out;
 			memset(o_ltp, 0, sizeof(struct ktermios));

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.20-rc3] Remove unneeded kmalloc casts
@ 2007-01-05  5:41 99% Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-05  5:41 UTC (permalink / raw)
  To: yi.zhu, jketreno, ipw2100-devel, linux-kernel

Remove unneeded kmalloc casts

Signed-off-by: Ahmed Darwish <darwish.07@gmail.com>

diff --git a/drivers/net/wireless/ipw2100.c b/drivers/net/wireless/ipw2100.c
index 0e94fbb..682b1bb 100644
--- a/drivers/net/wireless/ipw2100.c
+++ b/drivers/net/wireless/ipw2100.c
@@ -3361,11 +3361,9 @@ static int ipw2100_msg_allocate(struct ipw2100_priv *priv)
 	void *v;
 	dma_addr_t p;
 
-	priv->msg_buffers =
-	    (struct ipw2100_tx_packet *)kmalloc(IPW_COMMAND_POOL_SIZE *
-						sizeof(struct
-						       ipw2100_tx_packet),
-						GFP_KERNEL);
+	priv->msg_buffers = kmalloc(IPW_COMMAND_POOL_SIZE * 
+				    sizeof(struct ipw2100_tx_packet), 
+				    GFP_KERNEL);
 	if (!priv->msg_buffers) {
 		printk(KERN_ERR DRV_NAME ": %s: PCI alloc failed for msg "
 		       "buffers.\n", priv->net_dev->name);
@@ -4395,11 +4393,9 @@ static int ipw2100_tx_allocate(struct ipw2100_priv *priv)
 		return err;
 	}
 
-	priv->tx_buffers =
-	    (struct ipw2100_tx_packet *)kmalloc(TX_PENDED_QUEUE_LENGTH *
-						sizeof(struct
-						       ipw2100_tx_packet),
-						GFP_ATOMIC);
+	priv->tx_buffers = kmalloc(TX_PENDED_QUEUE_LENGTH *
+				   sizeof(struct ipw2100_tx_packet), 
+				   GFP_ATOMIC);
 	if (!priv->tx_buffers) {
 		printk(KERN_ERR DRV_NAME
 		       ": %s: alloc failed form tx buffers.\n",
@@ -4548,9 +4544,9 @@ static int ipw2100_rx_allocate(struct ipw2100_priv *priv)
 	/*
 	 * allocate packets
 	 */
-	priv->rx_buffers = (struct ipw2100_rx_packet *)
-	    kmalloc(RX_QUEUE_LENGTH * sizeof(struct ipw2100_rx_packet),
-		    GFP_KERNEL);
+	priv->rx_buffers = kmalloc(RX_QUEUE_LENGTH * 
+				   sizeof(struct ipw2100_rx_packet),
+				   GFP_KERNEL);
 	if (!priv->rx_buffers) {
 		IPW_DEBUG_INFO("can't allocate rx packet buffer table\n");
 

-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* [PATCH 2.6.20-rc3] cpufreq: check sysfs_create_link return value
@ 2007-01-05  3:44 99% Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-05  3:44 UTC (permalink / raw)
  To: davej; +Cc: linux-kernel, cpufreq

Trivial patch to check sysfs_create_link return values. Fail gracefully 
if needed.

Signed-off-by: Ahmed Darwish <darwish.07@gmail.com>

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index d913304..72ee576 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -722,8 +722,13 @@ static int cpufreq_add_dev (struct sys_device * sys_dev)
 			spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
 
 			dprintk("CPU already managed, adding link\n");
-			sysfs_create_link(&sys_dev->kobj,
-					  &managed_policy->kobj, "cpufreq");
+			ret = sysfs_create_link(&sys_dev->kobj,
+						&managed_policy->kobj, 
+						"cpufreq");
+			if (ret) {
+				mutex_unlock(&policy->lock);
+				goto err_out_driver_exit;
+			}
 
 			cpufreq_debug_enable_ratelimit();
 			mutex_unlock(&policy->lock);
@@ -770,8 +775,12 @@ static int cpufreq_add_dev (struct sys_device * sys_dev)
 		dprintk("CPU %u already managed, adding link\n", j);
 		cpufreq_cpu_get(cpu);
 		cpu_sys_dev = get_cpu_sysdev(j);
-		sysfs_create_link(&cpu_sys_dev->kobj, &policy->kobj,
-				  "cpufreq");
+		ret = sysfs_create_link(&cpu_sys_dev->kobj, &policy->kobj,
+					"cpufreq");
+		if (ret) {
+			mutex_unlock(&policy->lock);
+			goto err_out_unregister;
+		}
 	}
 
 	policy->governor = NULL; /* to assure that the starting sequence is


-- 
Ahmed S. Darwish
http://darwish-07.blogspot.com

^ permalink raw reply	[relevance 99%]

* /sbin/depmod Segmentation fault (Reproducable)
@ 2007-01-03 19:53 97% Ahmed S. Darwish
  0 siblings, 0 replies; 200+ results
From: Ahmed S. Darwish @ 2007-01-03 19:53 UTC (permalink / raw)
  To: linux-kernel


[-- Attachment #1: Type: text/plain, Size: 1856 bytes --]

Hi all,

* After compiling 2.6.20-rc3 and typing "make modules_install" I get:
INSTALL **
..
if [ -r System.map -a -x /sbin/depmod ]; then /sbin/depmod -ae -F System.map \
2.6.20-rc3-1; fi
/bin/sh: line 1: 10727 Segmentation fault   /sbin/depmod -ae -F System.map \
2.6.20-rc3-1
make: *** [_modinst_post] Error 139

* I found sbin/depmod tries to open a non-existent file before being killed:
$ strace /sbin/depmod -ae -F System.map 2.6.20-rc3-1
... (Opening 
readlink("/lib/modules/2.6.20-rc3-1/source", "/", 1) = 1
readlink("/lib/modules/2.6.20-rc3-1/build", "/", 1) = 1
getdents64(4, /* 0 entries */, 4096)    = 0
close(4)                                = 0
open("/lib/modules/2.6.20-rc3-1/updates", O_RDONLY|O_NONBLOCK|O_LARGEFILE|\
O_DIRECTORY) = -1 ENOENT (No such file or directory)
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV +++

I've compiled 2.6.20-rc3 several times before (I'm on a 20-rc3 now actually).
It's the first time to see this problem (maybe cause I changed the .conf file ?).

.conf file that caused the problem is gzipped and attached. Thanks ..

System tools versions:
Linux darwish-laptop 2.6.20-rc3-1 #16 Wed Jan 3 07:17:36 EET 2007 i686 GNU/Linux
Gnu C                  4.0.3
Gnu make               3.81beta4
binutils               2.16.91
util-linux             2.12r
mount                  2.12r
module-init-tools      3.2.2
e2fsprogs              1.38
jfsutils               1.1.8
reiserfsprogs          3.6.19
reiser4progs           1.0.5
xfsprogs               2.7.7
pcmciautils            012
pcmcia-cs              3.2.8
PPP                    2.4.4b1
Linux C Library        2.3.6
Dynamic linker (ldd)   2.3.6
Procps                 3.2.6
Net-tools              1.60
Console-tools          0.2.3
Sh-utils               5.93
udev                   079
wireless-tools         28

-- 
Ahmed S. Darwish

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 15641 bytes --]

^ permalink raw reply	[relevance 97%]

Results 1-200 of 680 (estimated)   | reverse results
2007-01-03 19:53 97% /sbin/depmod Segmentation fault (Reproducable) Ahmed S. Darwish
2007-01-05  3:44 99% [PATCH 2.6.20-rc3] cpufreq: check sysfs_create_link return value Ahmed S. Darwish
2007-01-05  5:41 99% [PATCH 2.6.20-rc3] Remove unneeded kmalloc casts Ahmed S. Darwish
2007-01-05  6:36 99% [PATCH 2.6.20-rc3] TTY_IO: Remove unnecessary " Ahmed S. Darwish
2007-01-05  6:56     ` Robert P. J. Day
2007-01-05  7:14 99%   ` Ahmed S. Darwish
2007-01-05  8:10     ` Rolf Eike Beer
2007-01-05 10:06 99%   ` Ahmed S. Darwish
2007-01-05 10:18         ` Robert P. J. Day
2007-01-05 10:51           ` Alan
2007-01-05 11:03 99%         ` Ahmed S. Darwish
2007-01-06  2:36 99%       ` Ahmed S. Darwish
2007-01-05 10:26         ` Rolf Eike Beer
2007-01-05 10:32 99%       ` Ahmed S. Darwish
2007-01-05 10:26 52% [PATCH UPDATED 2.6.20-rc3] Remove all the unneeded k[mzc]alloc casts Ahmed S. Darwish
2007-01-08 12:10     ` Rolf Eike Beer
2007-01-08 19:21 99%   ` Ahmed S. Darwish
2007-01-05 23:56 88% [PATCH 2.6.20-rc3] TTY_IO code cleanups Ahmed S. Darwish
2007-01-06  0:08 91% Ahmed S. Darwish
2007-01-06 13:16 95% [PATCH 2.6.20-rc3] JSM_TTY: kmalloc->kzalloc/Casting cleanups Ahmed S. Darwish
2007-01-06 13:17 93% [PATCH 2.6.20-rc3] DAC960: " Ahmed S. Darwish
2007-01-06 13:36     ` Robert P. J. Day
2007-01-06 14:55 99%   ` Ahmed S. Darwish
2007-01-06 17:46     ` Randy Dunlap
2007-01-07  2:00 99%   ` Ahmed S. Darwish
2007-01-06 13:17 99% [PATCH 2.6.20-rc3] CIFS: Remove 2 unneeded kzalloc casts Ahmed S. Darwish
2007-01-06 13:18 90% [PATCH 2.6.20-rc3] S390: kmalloc->kzalloc/casting cleanups Ahmed S. Darwish
2007-01-06 13:18 93% [PATCH 2.6.20-rc3] UCC Ether driver: kmalloc casting cleanups Ahmed S. Darwish
2007-01-08  3:12     ` Li Yang-r58472
2007-01-08  4:26 99%   ` Ahmed S. Darwish
2007-01-08  4:54 95%   ` Ahmed S. Darwish
2007-01-06 13:18 99% [PATCH 2.6.20-rc3] HID-Core: Tiny patch to remove a kmalloc cast Ahmed S. Darwish
2007-01-14 17:24 76% [PATCH 2.6.20-rc5] intel_rng: substitue magic PCI IDs with macros Ahmed S. Darwish
2007-01-14 17:37     ` Arjan van de Ven
2007-01-14 19:31       ` Dave Airlie
2007-01-14 23:07 99%     ` Ahmed S. Darwish
2007-01-15  7:16 99%   ` Ahmed S. Darwish
2007-01-15 17:50 80%   ` Ahmed S. Darwish
2007-01-15  0:29     ` Greg KH
2007-01-15  9:17 99%   ` Ahmed S. Darwish
2007-01-15 20:38 99% Ahmed S. Darwish
2007-01-16  8:01 97% [PATCH 2.6.20-rc5 2/4] pvrusb2: Use ARRAY_SIZE macro Ahmed S. Darwish
2007-01-16  8:36     ` Robert P. J. Day
2007-01-16 18:16       ` Randy Dunlap
2007-01-16 19:07 64%     ` Ahmed S. Darwish
2007-01-16 18:54 99%   ` Ahmed S. Darwish
2007-01-16  8:01 93% [PATCH 2.6.20-rc5 3/4] " Ahmed S. Darwish
2007-01-16  8:02 86% [PATCH 2.6.20-rc5 4/4] " Ahmed S. Darwish
2007-01-16  8:02 93% [PATCH 2.6.20-rc5 1/4] " Ahmed S. Darwish
2007-01-16  9:20 88% [PATCH 2.6.20-rc5] DVB: Use ARRAY_SIZE macro when appropriate Ahmed S. Darwish
2007-01-16  9:53 99% [PATCH 2.6.20-rc5] isdn/capi: use ARRAY_SIZE " Ahmed S. Darwish
2007-01-18  4:15     after effects of a kernel API change Daniel Rodrick
2007-01-18  5:10 99% ` Ahmed S. Darwish
2007-01-18  5:35       ` Rajat Jain
2007-01-18  9:44 99%     ` Ahmed S. Darwish
2007-02-03 21:58 99% A CodingStyle suggestion Ahmed S. Darwish
2007-02-03 22:56     ` Richard Knutsson
2007-02-04  0:05 99%   ` Ahmed S. Darwish
2007-02-04 12:10 99% ` Ahmed S. Darwish
2007-02-05  2:39 97% [PATCH 00] A series of patches to use ARRAY_SIZE macro under arch/ Ahmed S. Darwish
2007-02-05  2:40 99% ` [PATCH 2.6.20] arch CRIS: user ARRAY_SIZE macro when appropriate Ahmed S. Darwish
2007-02-05  2:41 99% ` [PATCH 2.6.20] arch AVR32: Use " Ahmed S. Darwish
2007-02-05  2:41 99% ` [PATCH 2.6.20] arch M68KNOMMU: user " Ahmed S. Darwish
2007-02-05  2:42 89% ` [PATCH 2.6.20] arch MIPS: " Ahmed S. Darwish
2007-02-05  2:42 86% ` [PATCH 2.6.20] arch V850: " Ahmed S. Darwish
2007-02-05  2:42 96% ` [PATCH 2.6.20] arch PowerPC: " Ahmed S. Darwish
2007-02-05  2:43 97% ` [PATCH 2.6.20] arch PPC: " Ahmed S. Darwish
2007-02-05  2:43 99% ` [PATCH 2.6.20] arch M68K: " Ahmed S. Darwish
2007-02-05  2:43 99% ` [PATCH 2.6.20] arch ARM: Use " Ahmed S. Darwish
2007-02-05 16:51 99% [PATCH 00] A series of patches to use ARRAY_SIZE under video subtree Ahmed S. Darwish
2007-02-05 16:53 75% ` [PATCH 2.6.20] pvrusb2: use ARRAY_SIZE macro when appropriate (2) Ahmed S. Darwish
2007-02-05 16:54 83% ` [PATCH 2.6.20] misc-video: use ARRAY_SIZE macro when appropriate Ahmed S. Darwish
2007-02-05 16:54 99% [PATCH 00] A series of patches to use ARRAY_SIZE in `net' drivers Ahmed S. Darwish
2007-02-05 16:55 99% ` [PATCH 2.6.20] e1000: Use ARRAY_SIZE macro when appropriate Ahmed S. Darwish
2007-02-05 16:56 95% ` [PATCH 2.6.20] ipw2100: " Ahmed S. Darwish
2007-02-05 16:56 73% ` [PATCH 01/02] misc-net-drivers: " Ahmed S. Darwish
2007-02-05 16:57 92%   ` [PATCH 02/02] " Ahmed S. Darwish
2007-02-05 16:58 99% ` [PATCH 2.6.20] misc-wireless: " Ahmed S. Darwish
2007-02-05 16:58 99% ` [PATCH 2.6.20] hostap: " Ahmed S. Darwish
2007-02-05 16:59 99% ` [PATCH 2.6.20] ibm_emac: " Ahmed S. Darwish
2007-02-05 20:22       ` Alexey Dobriyan
2007-02-06  9:12 99%     ` Ahmed S. Darwish
2007-02-05 16:59 99% ` [PATCH 2.6.20] ixgb: " Ahmed S. Darwish
2007-02-05 20:18       ` Alexey Dobriyan
2007-02-05 20:31         ` Auke Kok
2007-02-06 10:00 99%       ` Ahmed S. Darwish
2007-02-05 17:00 99% ` [PATCH 2.6.20] wavelan: " Ahmed S. Darwish
2007-02-05 20:17       ` Alexey Dobriyan
2007-02-06  9:34 90%     ` Ahmed S. Darwish
2007-02-06 16:02 97% [PATCH 00] A series of patches to use ARRAY_SIZE macro Ahmed S. Darwish
2007-02-06 16:03 83% ` [PATCH 2.6.20] DVB: Use ARRAY_SIZE macro when appropriate Ahmed S. Darwish
2007-02-06 16:03 94% ` [PATCH 2.6.20] KVM: " Ahmed S. Darwish
2007-02-06 16:04 64% ` [PATCH 2.6.20] isdn-eicon: " Ahmed S. Darwish
2007-02-06 16:04 99% ` [PATCH 2.6.20] isdn-capi: " Ahmed S. Darwish
2007-02-06 17:52       ` Joe Perches
2007-02-06 20:41 95%     ` Ahmed S. Darwish
2007-02-06 21:18           ` Philippe De Muyter
2007-02-07 19:41 99%         ` Ahmed S. Darwish
2007-02-06 16:05 96% ` [PATCH 2.6.20 1/2] OSS: " Ahmed S. Darwish
2007-02-06 16:05 94% ` [PATCH 2.6.20 2/2] " Ahmed S. Darwish
2007-02-06 16:06 94% ` [PATCH 2.6.20] atm: " Ahmed S. Darwish
2007-02-06 16:06 99% ` [PATCH 2.6.20] drivers/md.c: " Ahmed S. Darwish
2007-02-06 16:07 99% ` [PATCH 2.6.20] infinband: " Ahmed S. Darwish
2007-02-06 16:07 99% ` [PATCH 2.6.20] s390-drivers: " Ahmed S. Darwish
2007-02-06 16:08 99% ` [PATCH 2.6.20] rcutorture: " Ahmed S. Darwish
2007-02-06 16:08 99% ` [PATCH 2.6.20] intel-agp: " Ahmed S. Darwish
2007-02-06 16:08 99% ` [PATCH 2.6.20] reiserfs: " Ahmed S. Darwish
2007-02-06 16:09 99% ` [PATCH 2.6.20] toshiba-acpi: " Ahmed S. Darwish
2007-02-06 16:09 99% ` [PATCH 2.6.20] w1: " Ahmed S. Darwish
2007-02-06 16:10 99% ` [PATCH 2.6.20] drm: " Ahmed S. Darwish
2007-02-14 10:02     [patch 0/2] natsemi: Support Aculab E1/T1 cPCI carrier cards Mark Brown
2007-02-14 10:02     ` [patch 1/2] natsemi: Add support for using MII port with no PHY Mark Brown
2007-02-14 13:28 99%   ` Ahmed S. Darwish
2007-02-23 18:07 99% Video GL rendering worked only between 2.6.20 and 2.6.21-rc1 Ahmed S. Darwish
2007-03-09  7:14     [PATCH] drivers/media/video/videocodec.c: check kmalloc() return value Amit Choudhary
2007-03-12 10:45 99% ` Ahmed S. Darwish
2007-03-17  6:21 99% [PATCH 2.6.21-rc4] kernel/exit: Fix a comment and code contradiction Ahmed S. Darwish
2007-03-17  9:45     ` Johannes Weiner
2007-03-17 15:00 99%   ` Ahmed S. Darwish
2007-03-18 22:58 99% i386: Why putting __USER_DS in kernel threads stack initialization? Ahmed S. Darwish
2007-03-18 23:15 99% ` Ahmed S. Darwish
2007-03-19 11:23     ` linux-os (Dick Johnson)
2007-03-21 19:25 99%   ` Ahmed S. Darwish
     [not found]     <45E6BF26.7080607@bristyle.com>
     [not found]     ` <45E73715.9030909@qualcomm.com>
2007-03-24  8:56       ` PATCH: tun/tap driver hw address handling Brian Braunstein
2007-03-24 17:04 99%     ` Ahmed S. Darwish
2007-03-25  8:29     [PATCH] net: tun/tap: fixed " Brian Braunstein
2007-03-26 20:55 99% ` Ahmed S. Darwish
2007-03-26 21:05 99%   ` Ahmed S. Darwish
2007-03-26 19:14 99% [PATCH] IRQ: Check for PERCPU flag only when adding first irqaction Ahmed S. Darwish
2007-03-27  8:54 99% ` Ahmed S. Darwish
2007-03-29 10:04     Student Project Ideas Russ Meyerriecks
2007-03-29 10:32     ` Cong WANG
2007-03-29 20:59 99%   ` Ahmed S. Darwish
2007-03-29 20:44 99% ` Ahmed S. Darwish
2007-05-17 14:45     Fork Bombing Attack Anand Jahagirdar
2007-05-17 15:01     ` Valdis.Kletnieks
2007-05-18 11:13       ` Anand Jahagirdar
2007-05-18 13:19 99%     ` Ahmed S. Darwish
2007-07-01 20:38 96% [i386] Questions regarding provisional page tables initialization Ahmed S. Darwish
2007-07-01 22:19     ` Jeremy Fitzhardinge
2007-07-02  1:13 99%   ` Ahmed S. Darwish
2007-07-02  9:18         ` Andreas Schwab
2007-07-02 10:23 99%       ` Ahmed S. Darwish
2007-07-02 11:34             ` Brian Gerst
2007-07-02 15:43 99%           ` Ahmed S. Darwish
2007-09-19  8:45     PROBLEM: System Freeze on Particular workload with kernel 2.6.22.6 Low Yucheng
2007-09-19 15:47     ` Oleg Verych
2007-09-19 16:16       ` Low Yucheng
2007-09-19 19:25 99%     ` Ahmed S. Darwish
2007-09-20 10:00           ` Jarek Poplawski
2007-09-20 15:24 99%         ` Ahmed S. Darwish
2007-09-24 22:08 99% i386: Fix null interrupt handler (ignore_int) message ? Ahmed S. Darwish
2007-09-26 22:33 98% [PATCH 1/3] Completely remove deprecated IRQ flags (SA_*) Ahmed S. Darwish
2007-09-26 22:35 99% ` [PATCH 2/3] MIPS: Remove " Ahmed S. Darwish
2007-09-26 22:36 81% ` [PATCH 3/3] NCR53C8XX: " Ahmed S. Darwish
2007-10-05  5:30 83% [PATCH RFC 1/2] IRQ: Modularize the setup_irq code (1) Ahmed S. Darwish
2007-10-05  5:36 88% ` [PATCH RFC 2/2] IRQ: Modularize the setup_irq code (2) Ahmed S. Darwish
2007-10-06 20:14 70% [Oops] on 2.6.23-rc9 sysRq Show Tasks (t) Ahmed S. Darwish
2007-10-06 20:52 99% ` Ahmed S. Darwish
2007-10-06 21:12     ` Alexey Dobriyan
2007-10-07 19:39 99%   ` Ahmed S. Darwish
2007-10-08 12:34     PROBLEM: kernel 2.6.22.9-cfs-v22 compile warnings Konstantin Oshovskij
2007-10-08 18:11 99% ` Ahmed S. Darwish
2007-10-08 21:55     [PATCH] NTFS error messages: replace static char pointers by static char arrays Dmitri Vorobiev
2007-10-09 12:40 99% ` Ahmed S. Darwish
2007-10-09 18:33       ` Philipp Matthias Hahn
2007-10-09 22:03 99%     ` Ahmed S. Darwish
2007-10-09  6:25     [PATCH] Stop docproc segfaulting when SRCTREE isn't set Rob Landley
2007-10-09 13:03 99% ` Ahmed S. Darwish
2007-10-09 15:55       ` Randy Dunlap
2007-10-09 17:19 99%     ` Ahmed S. Darwish
2007-10-09 17:24           ` Randy Dunlap
2007-10-09 17:51 99%         ` Ahmed S. Darwish
2007-10-09 10:43     [PATCH -mm] fix wrong /proc/cpuinfo output Akinobu Mita
2007-10-09 13:32 99% ` Ahmed S. Darwish
2007-10-12  7:38     [PATCH try #2] Input/Joystick Driver: add support AD7142 joystick driver Bryan Wu
2007-10-12 16:41 99% ` Ahmed S. Darwish
2007-10-12 17:29       ` Dmitry Torokhov
2007-10-12 19:21 99%     ` Ahmed S. Darwish
2007-10-13  7:15     2.6.23-git2 buid failure Kamalesh Babulal
2007-10-14 11:18 99% ` Ahmed S. Darwish
2007-10-14 17:15     [PATCH] Version 7 (2.6.23) Smack: Simplified Mandatory Access Control Kernel Casey Schaufler
2007-10-14 23:13 90% ` Ahmed S. Darwish
2007-10-15 14:47     [PATCH try #3] Input/Joystick Driver: add support AD7142 joystick driver Bryan Wu
2007-10-15 15:48     ` Dmitry Torokhov
2007-10-15 18:27 99%   ` Ahmed S. Darwish
2007-10-16  6:08         ` Bryan Wu
2007-10-16 16:40 99%       ` Ahmed S. Darwish
2007-10-17  4:17     [PATCH] Version 8 (2.6.23) Smack: Simplified Mandatory Access Control Kernel Casey Schaufler
2007-10-18  4:57     ` Al Viro
2007-10-18  5:10       ` Al Viro
2007-10-19 12:39 99%     ` Ahmed S. Darwish
2007-10-21  1:40 96% ` [PATCH] Smackv8: Omit non-cipso labels in cipso_seq_start Ahmed S. Darwish
2007-10-21  2:25 93%   ` [PATCH] Smackv8: Safe lockless {cipso,load} read operation Ahmed S. Darwish
2007-10-24 11:00 99% Rule parsing from a virtual FS write() syscall Ahmed S. Darwish
2007-10-25  3:46     [PATCH 0/2] Version 9 (2.6.24-rc1) Smack: Simplified Mandatory Access Control Kernel Casey Schaufler
2007-11-01 15:54 74% ` [PATCH] Smackv9: Use a stateful parser for parsing Smack rules Ahmed S. Darwish
2007-11-01 17:29       ` Jan Engelhardt
2007-11-02 18:50 99%     ` Ahmed S. Darwish
2007-10-25  3:46     [PATCH 2/2] Version 9 (2.6.24-rc1) Smack: Simplified Mandatory Access Control Kernel Casey Schaufler
2007-10-27  3:00 85% ` Ahmed S. Darwish
2007-10-27  9:01 96% ` Ahmed S. Darwish
2007-10-27 23:47       ` Al Viro
2007-10-28 12:46 99%     ` Ahmed S. Darwish
2007-11-02 20:50     [PATCH] Version 10 " Casey Schaufler
2007-11-03 16:43 65% ` [PATCH] Smackv10: Smack rules grammar + their stateful parser Ahmed S. Darwish
2007-11-03 18:30       ` Kyle Moffett
2007-11-03 22:12 99%     ` Ahmed S. Darwish
2007-11-04 12:28       ` Pavel Machek
2007-11-04 13:23 99%     ` Ahmed S. Darwish
2007-11-05  9:41 99%     ` Ahmed S. Darwish
2007-11-05 16:21           ` Linus Torvalds
2007-11-05 23:38 99%         ` Ahmed S. Darwish
2007-11-04 20:06 99%   ` Ahmed S. Darwish
2007-11-05  0:56 69%   ` [PATCH] Smackv10: Smack rules grammar + their stateful parser(2) Ahmed S. Darwish
2007-11-10 17:05         ` Jakob Oestergaard
2007-11-10 19:45 99%       ` Ahmed S. Darwish
2007-11-11 12:44         ` Pavel Machek
2007-11-11 18:37 99%       ` Ahmed S. Darwish
2007-11-06  6:33       ` [PATCH] Smackv10: Smack rules grammar + their stateful parser Adrian Bunk
2007-11-06  8:26         ` Kyle Moffett
2007-11-06  8:56           ` Adrian Bunk
2007-11-06 11:34 99%         ` Ahmed S. Darwish
2007-11-06 11:47               ` Adrian Bunk
2007-11-06 12:23 99%             ` Ahmed S. Darwish
2007-11-06 12:49                   ` Kyle Moffett
2007-11-06 13:34                     ` Adrian Bunk
2007-11-06 14:05 99%                   ` Ahmed S. Darwish
2007-11-06 14:10                         ` Adrian Bunk
2007-11-06 14:30 99%                       ` Ahmed S. Darwish
2008-02-06 23:21 98% [Lguest/x86]: Clash with ioremap_nocache() + _PAGE_PWT Ahmed S. Darwish
2008-02-06 23:59     ` Ingo Molnar
2008-02-07  0:51 99%   ` [PATCH] lguest: Accept guest _PAGE_PWT page table entries Ahmed S. Darwish
2008-02-11 18:26     BUG with 2.6.25-rc1 and smack Joerg Platte
2008-02-11 23:23 96% ` [PATCH - BUGFIX] Smack: Check for 'struct socket' with NULL sk Ahmed S. Darwish
2008-02-13  1:25 96% [PATCH BUGFIX 25-rc1] Smack: Don't fail against Nulled sk sockets Ahmed S. Darwish
2008-02-15 18:42 98% Linux i386 clone(): %ebx 'frobbing' ? Ahmed S. Darwish
2008-02-15 20:07     ` Andreas Schwab
2008-02-15 23:07 99%   ` Ahmed S. Darwish
2008-02-15 23:28         ` Andreas Schwab
2008-02-15 23:54 99%       ` Ahmed S. Darwish
2008-02-17 22:59 98% [PATCH x86] i8259A_32: Remove redundant irq_desc[NR_IRQ] initialization Ahmed S. Darwish
2008-02-19 15:37 99% [PATCH] Tasklets: Avoid duplicating __tasklet_{,hi_}schedule() code Ahmed S. Darwish
2008-02-19 15:52     ` Ingo Molnar
2008-02-19 16:27 99%   ` Ahmed S. Darwish
2008-02-20 10:41         ` Ingo Molnar
2008-02-20 13:37 99%       ` Ahmed S. Darwish
2008-02-20 14:20             ` Dmitry Adamushko
2008-02-20 19:39 99%           ` Ahmed S. Darwish
2008-02-24 15:55 78% [BUG + PATCH/Bugfix] x86/lguest: fix pgdir pmd index calculation Ahmed S. Darwish
2008-02-24 16:18     ` Ingo Molnar
2008-02-24 16:26 99%   ` Ahmed S. Darwish
2008-02-25  0:18 97%     ` Ahmed S. Darwish
2008-02-29  0:32 89%       ` Ahmed S. Darwish
2008-03-04 12:55     ` Rusty Russell
2008-03-04 15:11 99%   ` Ahmed S. Darwish
2008-02-25  1:41     2.6.25-rc3: Reported regressions from 2.6.24 Rafael J. Wysocki
2008-02-25 18:24 99% ` Ahmed S. Darwish
2008-02-26 23:22 94% [PATCH -mm 0/4] LSM interfaced Audit (SELinux audit separation) Ahmed S. Darwish
2008-02-26 23:24 75% ` [PATCH -mm 1/4] LSM: Introduce inode_getsecid and ipc_getsecid hooks Ahmed S. Darwish
2008-02-27 16:04       ` Paul Moore
2008-02-27 16:45 99%     ` Ahmed S. Darwish
2008-02-26 23:25 74% ` [PATCH -mm 2/4] SELinux: Remove various exported symbols Ahmed S. Darwish
2008-02-26 23:28 65% ` [PATCH -mm 3/4] Audit: start not to use SELinux " Ahmed S. Darwish
2008-02-27 16:00       ` Paul Moore
2008-02-27 17:11 98%     ` Ahmed S. Darwish
2008-02-26 23:31 99% ` [PATCH -mm 4/4] Netlink: Use LSM interface instead of SELinux one Ahmed S. Darwish
2008-03-01 19:07 77% [RFC PATCH -mm] LSM: Add lsm= boot parameter Ahmed S. Darwish
2008-03-01 19:47 95% [PATCH-v2 -mm 0/9] LSM-neutral Audit (SELinux audit separation) Ahmed S. Darwish
2008-03-01 19:51 70% ` [PATCH 1/9] LSM: Introduce inode_getsecid and ipc_getsecid hooks Ahmed S. Darwish
2008-03-01 19:52 93% ` [PATCH 2/9] SELinux: setup new inode/ipc getsecid hooks Ahmed S. Darwish
2008-03-01 19:54 67% ` [PATCH 3/9] Audit: use new LSM hooks instead of SELinux exports Ahmed S. Darwish
2008-03-01 19:56 98% ` [PATCH 4/9] Netlink: Use generic LSM hook Ahmed S. Darwish
2008-03-01 19:58 81% ` [PATCH 5/9] SELinux: remove redundant exports Ahmed S. Darwish
2008-03-01 20:00 75% ` [PATCH 6/9] LSM/Audit: Introduce generic Audit LSM hooks Ahmed S. Darwish
2008-03-01 20:01 63% ` [PATCH 7/9] Audit: internally use the new LSM audit hooks Ahmed S. Darwish
2008-03-03 23:51       ` Paul Moore
2008-03-04  3:31 99%     ` Ahmed S. Darwish
2008-03-01 20:03 57% ` [PATCH 8/9] SELinux: use new audit hooks, remove redundant exports Ahmed S. Darwish
2008-03-01 20:05 71% ` [PATCH 9/9] Audit: Final renamings and cleanup Ahmed S. Darwish
2008-03-01 21:11     [RFC PATCH -mm] LSM: Add lsm= boot parameter Adrian Bunk
2008-03-01 21:29     ` Casey Schaufler
2008-03-01 23:27 70%   ` [PATCH -v2 -mm] LSM: Add security= " Ahmed S. Darwish
2008-03-02  3:41         ` Casey Schaufler
2008-03-02  7:55 99%       ` Ahmed S. Darwish
2008-03-02  7:49 99%     ` Ahmed S. Darwish
2008-03-02 10:59 67%       ` [PATCH -v3 " Ahmed S. Darwish
2008-03-03  8:29             ` James Morris
2008-03-03 15:35 98%           ` Ahmed S. Darwish
2008-03-03 15:54                 ` Stephen Smalley
2008-03-03 21:24 67%               ` [PATCH -v4 " Ahmed S. Darwish
2008-03-03 22:16                     ` James Morris
2008-03-04  3:04 71%                   ` [PATCH -v5 " Ahmed S. Darwish
2008-03-04 13:10 91% [PATCH BUGFIX -rc3] Smack: Don't register smackfs if we're not loaded Ahmed S. Darwish
2008-03-04 13:58 69% ` [PATCH -rc3] Security: Introduce security= boot parameter Ahmed S. Darwish
2008-03-04 17:21     ` [PATCH BUGFIX -rc3] Smack: Don't register smackfs if we're not loaded Linus Torvalds
2008-03-04 18:24 92%   ` Ahmed S. Darwish


LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lkml.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lkml.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lkml.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lkml.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lkml.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lkml.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lkml.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lkml.kernel.org/lkml/7 lkml/git/7.git
	git clone --mirror https://lkml.kernel.org/lkml/8 lkml/git/8.git
	git clone --mirror https://lkml.kernel.org/lkml/9 lkml/git/9.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lkml.kernel.org/lkml \
		linux-kernel@vger.kernel.org
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git