random.c changes for sparse irq_desc are crap
I just noticed you merged a change that pointlessly converts two random.c functions into ugly random.h inlines without going through the maintainer.
I also don't like the look of the newly-introduced sparse variants of these functions. Failure to find an irq descriptor in get_timer_rand_state is a BUG_ON should-never-happen sort of condition, not something to silently ignore. Letting the code try to dereference NULL is preferred here: we'll actually be able to find and fix the broken driver that's throwing around meaningless irq vectors.
Throwing away the timer_state pointer in the set_timer_rand_state function is similarly bogus in addition to being a memory leak.
Please fix this up.
Signature · 1 line
Mathematics is the supreme nostalgia of our time.
Quoted 11 lines · Matt Mackall
I just noticed you merged a change that pointlessly converts two
random.cfunctions into uglyrandom.hinlines without going through the maintainer.I also don't like the look of the newly-introduced sparse variants of these functions. Failure to find an irq descriptor in
get_timer_rand_stateis aBUG_ONshould-never-happen sort of condition, not something to silently ignore. Letting the code try to dereference NULL is preferred here: we'll actually be able to find and fix the broken driver that's throwing around meaningless irq vectors.
Quoted 5 lines
Throwing away the
timer_statepointer in theset_timer_rand_statefunction is similarly bogus in addition to being a memory leak.Please fix this up.
want something like this?
--- include/linux/random.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
include/linux/random.h +2 -4
@@ -75,8 +75,7 @@ static inline struct timer_rand_state *g desc =irq_to_desc (irq); -if (!desc) -return NULL ; +BUG_ON (!desc);return desc->timer_rand_state; }
@@ -87,8 +86,7 @@ static inline void set_timer_rand_state( desc =irq_to_desc (irq); -if (!desc) -return ; +BUG_ON (!desc); desc->timer_rand_state = state; }
Quoted 12 lines · Yinghai Lu
Quoted 11 lines · Matt Mackall
I just noticed you merged a change that pointlessly converts two
random.cfunctions into uglyrandom.hinlines without going through the maintainer.I also don't like the look of the newly-introduced sparse variants of these functions. Failure to find an irq descriptor in
get_timer_rand_stateis aBUG_ONshould-never-happen sort of condition, not something to silently ignore. Letting the code try to dereference NULL is preferred here: we'll actually be able to find and fix the broken driver that's throwing around meaningless irq vectors.
Quoted 7 lines
Quoted 5 lines
Throwing away the
timer_statepointer in theset_timer_rand_statefunction is similarly bogus in addition to being a memory leak.Please fix this up.
want something like this?
Not quite.
First, please turn these back into normal functions in random.c. Inlining functions is generally discouraged these days unless you have a good reason and numbers to back it up.
Second, as I tried to explain above, BUG_ON(!desc) is doing very little that the subsequent desc->timer_rand_state wouldn't already do (generating a traceback). In cases where dereferencing NULL should never happen, it's preferable to not add the extra check and just let the oops happen. We'll still get a backtrace if anything ever goes wrong, but we won't have wasted any code space or CPU cycles when it doesn't.
Signature · 1 line
Mathematics is the supreme nostalgia of our time.
Quoted 19 lines · Matt Mackall
Quoted 18 lines · Yinghai Lu
Quoted 16 lines · Matt Mackall
I just noticed you merged a change that pointlessly converts two
random.cfunctions into uglyrandom.hinlines without going through the maintainer.I also don't like the look of the newly-introduced sparse variants of these functions. Failure to find an irq descriptor in
get_timer_rand_stateis aBUG_ONshould-never-happen sort of condition, not something to silently ignore. Letting the code try to dereference NULL is preferred here: we'll actually be able to find and fix the broken driver that's throwing around meaningless irq vectors.Throwing away the
timer_statepointer in theset_timer_rand_statefunction is similarly bogus in addition to being a memory leak.Please fix this up.
Quoted 7 lines
Quoted 1 line
want something like this?
Not quite.
First, please turn these back into normal functions in
random.c. Inlining functions is generally discouraged these days unless you have a good reason and numbers to back it up.
Ingo wanted to hide that #ifdef to .h
Quoted 7 lines
Second, as I tried to explain above,
BUG_ON(!desc)is doing very little that the subsequentdesc->timer_rand_statewouldn't already do (generating a traceback). In cases where dereferencing NULL should never happen, it's preferable to not add the extra check and just let the oops happen. We'll still get a backtrace if anything ever goes wrong, but we won't have wasted any code space or CPU cycles when it doesn't.
ok
YH
Quoted 22 lines · Yinghai Lu
Quoted 21 lines · Matt Mackall
Quoted 19 lines · Yinghai Lu
Quoted 11 lines · Matt Mackall
I just noticed you merged a change that pointlessly converts two
random.cfunctions into uglyrandom.hinlines without going through the maintainer.I also don't like the look of the newly-introduced sparse variants of these functions. Failure to find an irq descriptor in
get_timer_rand_stateis aBUG_ONshould-never-happen sort of condition, not something to silently ignore. Letting the code try to dereference NULL is preferred here: we'll actually be able to find and fix the broken driver that's throwing around meaningless irq vectors.Quoted 5 lines
Throwing away the
timer_statepointer in theset_timer_rand_statefunction is similarly bogus in addition to being a memory leak.Please fix this up.
want something like this?
Quoted 7 lines
Quoted 5 lines
Not quite.
First, please turn these back into normal functions in
random.c. Inlining functions is generally discouraged these days unless you have a good reason and numbers to back it up.Ingo wanted to hide that #ifdef to .h
Ahh. I think that makes sense in some situations, but I'd prefer not to do that here. Some headers are actually meant to be more readable than the corresponding .c file. Also, we still end up with an ifdef in the .c file so we're not actually winning.
Signature · 1 line
Mathematics is the supreme nostalgia of our time.
Quoted 29 lines · Matt Mackall
Quoted 28 lines · Yinghai Lu
Quoted 26 lines · Matt Mackall
Quoted 12 lines · Yinghai Lu
Quoted 11 lines · Matt Mackall
I just noticed you merged a change that pointlessly converts two
random.cfunctions into uglyrandom.hinlines without going through the maintainer.I also don't like the look of the newly-introduced sparse variants of these functions. Failure to find an irq descriptor in
get_timer_rand_stateis aBUG_ONshould-never-happen sort of condition, not something to silently ignore. Letting the code try to dereference NULL is preferred here: we'll actually be able to find and fix the broken driver that's throwing around meaningless irq vectors.Quoted 7 lines
Quoted 5 lines
Throwing away the
timer_statepointer in theset_timer_rand_statefunction is similarly bogus in addition to being a memory leak.Please fix this up.
want something like this?
Not quite.
First, please turn these back into normal functions in
random.c. Inlining functions is generally discouraged these days unless you have a good reason and numbers to back it up.
Quoted 6 lines
Quoted 1 line
Ingo wanted to hide that #ifdef to .h
Ahh. I think that makes sense in some situations, but I'd prefer not to do that here. Some headers are actually meant to be more readable than the corresponding .c file. Also, we still end up with an ifdef in the .c file so we're not actually winning.
Yinghai - i think Matt is right and there are a number of things we could do to improve cleanliness here. (Matt, sorry about this - we'll quickly fix it.)
The most important thing to observe is that the irq_desc->timer_rand_state cleanup you did should be made unconditional, and should not depend on SPARSE_IRQ. That will eliminate most of the #ifdefs, and it makes the random.c and random.h impact rather straightforward.
Another cleanliness detail is that these types of checks:
#ifndef CONFIG_SPARSE_IRQ
if (irq >= nr_irqs)
return;#endif
can go away completely. They were needed from the sparseirq data model that had a dynamic array size - but that is not so anymore, so we can remove these complications.
Agreed?
Ingo
PATCH 1/1 sparseirq: move set/get_timer_rand_state back to .c
Impact: cleanup
those two functions only used in that .c
--- drivers/char/random.c | 40 +++++++++++++++++++++++++++++++++------ include/linux/random.h | 50 ------------------------------------------------- 2 files changed, 34 insertions(+), 56 deletions(-)
drivers/char/random.c +34 -6
@@ -559,7 +559,40 @@ struct timer_rand_state { };#ifndef CONFIG_SPARSE_IRQ -struct timer_rand_state *irq_timer_state[NR_IRQS ]; + +static struct timer_rand_state *irq_timer_state[NR_IRQS ]; + +static struct timer_rand_state *get_timer_rand_state (unsigned int irq) +{ +return irq_timer_state[irq]; +} + +static void set_timer_rand_state (unsigned int irq, +struct timer_rand_state *state) +{ + irq_timer_state[irq] = state; +} + +#else + +static struct timer_rand_state *get_timer_rand_state (unsigned int irq) +{ +struct irq_desc *desc; + + desc =irq_to_desc (irq); + +return desc->timer_rand_state; +} + +static void set_timer_rand_state (unsigned int irq, +struct timer_rand_state *state) +{ +struct irq_desc *desc; + + desc =irq_to_desc (irq); + + desc->timer_rand_state = state; +}#endif static struct timer_rand_state input_timer_state;
@@ -919,11 +952,6 @@ void rand_initialize_irq(int irq) {struct timer_rand_state *state; -#ifndef CONFIG_SPARSE_IRQ -if (irq >= nr_irqs) -return ; -#endif - state =get_timer_rand_state (irq);if (state)
include/linux/random.h +0 -50
56 lines not on this page · raw message