Correction to kmod.c control loop
Quoted 14 lines · Jesper Juhl
Quoted 3 lines
That is the right way of course, but the portion of
kmod.cI look is the same from 2.2.x series.That may be so, but if you don't work against the latest kernel your patches are unlikely to apply cleanly (other nearby bits of the file may have changed causing patch to become confused), and also, maintainers will usually request that you submit a re-diff'ed patch against the latest kernel *anyway* before they will consider merging your patch, so by working against an old kernel you are only creating more work for both yourself and people reviewing and/or considering applying your patches.
Work to make review and merging as easy on everyone else as you can - starting out by submitting patches only against latest 2.4.x or 2.6.x is a good place to start.
I look in the kmod.c for 2.6.x that you have linked below, actually it was reimplemented, so the patch is only for 2.4.x.
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
Why are you changing the type of
waitpid_result?Because the man page for waitpid function tells the return type is
pid_t.Ok, but you just created a potential problem by then later returning
pid_tfrom a function supposed to be returning int.
When making changes like this you should explain in your mail that go along with your patch *why* you are changing things and how you've made sure they are safe - you need to be able to explain that.
It would be only a formal change, and as you have reported below pid_t is an integer.
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines
You changed
MAX_KMOD_CONCURRENTfrom a constant to a variable above, but you never assign a value to it, so here you are comparing i to an uninitialized variable, not good.It is a _static_ local variable so it is assigned automatically to zero, I think.
Not good enough. Either you *know* that it will be initialized to zero, and if so you should state that in your explanation of what the patch does or you should explicitly initialize it.
I have read the K&R: now I know.
Quoted 10 lines
Quoted 10 lines
Quoted 4 lines
Review line 207
Quoted 4 lines
if (atomic_read(&kmod_concurrent) > i) {(quoted diff) +0
-0@@ -208,6 +206,7 @@ printk(KERN_ERR "kmod: runaway modprobeloop assumed
Quoted 5 lines
Quoted 4 lines
(quoted diff) +1
-0and stopped\n"); atomic_dec(&kmod_concurrent); + MAX_KMOD_CONCURRENT = 2*MAX_KMOD_CONCURRENT+1;
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
why multiply by two and add 1 here?
For to grow up the previously zero value at each failure loop. See (ii) below.
Yes, I understand that you wish to grow it, it's just not clear to me why you want to grow it like that.
To tune system capability to user request.
Quoted 33 lines
Quoted 14 lines
Quoted 12 lines
Review line 240
Quoted 9 lines
(quoted diff) +0
-0return -ENOMEM;}(quoted diff) +1
-0@@ -237,6 +236,7 @@ if (waitpid_result != pid) { printk(KERN_ERR "request_module[%s]: waitpid(%d,...) failed, errno %d\n", module_name, pid, -waitpid_result); + return waitpid_result;Ehh, the function returns an int, but you just changed the type of
waitpid_resulttopid_tabove...Quoted 2 lines
True, I had better control with grep that
pid_tis an integer type.
pid_tis defined as
typedef__kernel_pid_tpid_t;
and__kernel_pid_tis
typedef int__kernel_pid_t;
on all archs as far as I know, so you end up actually being safe, but the problem is you didn't make that clear.
But, the point I was trying to make was mainly that you shouldn't count on that always being true. if the function needs to return an int you should return an int, not apid_t.Also, take a look at how the function is implemented in recent kernels :
http://sosdg.org/~coywolf/lxr/source/kernel/kmod.c#L66Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0
-0} return 0;}
Quoted 9 lines · Jesper Juhl
Quoted 8 lines · Jesper Juhl
Quoted 8 lines
Quoted 6 lines
Review
Quoted 2 lines
(quoted diff) +1
-1- if (i > MAX_KMOD_CONCURRENT) + if (i < MAX_KMOD_CONCURRENT)You changed
MAX_KMOD_CONCURRENTfrom a constant to a variable above, but you never assign a value to it, so here you are comparing i to an uninitialized variable, not good.
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
It is a _static_ local variable so it is assigned automatically to zero, I think.
Hmm, yes, I wonder at that a bit as well, why static?
To maintain the value through a call of modprobe and a following one, so if the first fails you can maybe have the loading with the others.