On Thursday 07 January 2010 00:22:11 Rafał Miłecki wrote:
> W dniu 6 stycznia 2010 22:30 użytkownik Gábor Stefanik
> <[email protected]> napisał:
> > On Wed, Jan 6, 2010 at 10:09 PM, Rafał Miłecki <[email protected]> wrote:
> >> diff --git a/drivers/net/wireless/b43/phy_lp.c
> >> b/drivers/net/wireless/b43/phy_lp.c
> >> index 1e318d8..43a9fcc 100644
> >> --- a/drivers/net/wireless/b43/phy_lp.c
> >> +++ b/drivers/net/wireless/b43/phy_lp.c
> >> @@ -198,6 +198,17 @@ static void lpphy_table_init(struct b43_wldev *dev)
> >>
> >>        lpphy_init_tx_gain_table(dev);
> >>
> >> +       if (dev->phy.rev >=2) {
> >> +               int i;
> >> +               for (i = 0; i < 128; ++i) {
> >
> > Two style comments:
> > 1. Declare i at the beginning of the function.
> > 2. The preferred style in b43 is i++.
> 
> 1. May I ask, why? I don't know much about kernel programming, so
> that's not obvious for me. I declared this at beginning of rev2+
> block, because it's used only here. I didn't want to waste memory of
> (rev < 2) users (yeah, it's just 1 int but let's imagine 1 int in 100
> drivers...)

It does not waste memory, because the compiler will either:
        a) sink it into the branch
or
        b) allocate the stack space in any case on the beginning of
        the func, because it's only one operation for allocating all stack 
space.
So the compiler simply won't care and do the right thing anyway.
Declaring variables inside of branches is hardly used in the kernel.
And besides that, variables on the stack don't really waste anything. The stack 
is
permanently allocated and the compiler is smart enough to manage it properly.
The only thing we need to take care of w.r.t. the stack is to now overflow it. 
But
that's only an issue if we allocate large arrays on the stack. It's hardly 
possible
to overflow it with ordinary variables.

> 2. I read in many places ++i is faster than i++, but it wasn't about
> kernel programming actually. Thanks for tip.

There are some places in C++ (iterators) where ++i _can_ be faster. In C, 
however,
there is no speed difference. So we prefer i++, unless the semantics of ++i are 
required.

-- 
Greetings, Michael.
_______________________________________________
Bcm43xx-dev mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/bcm43xx-dev

Reply via email to