netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* net: intel/e1000e/netdev.c __ew32_prepare parameter not used?
@ 2021-08-02 14:55 Leandro Coutinho
  2021-08-03  8:50 ` Michael Walle
  0 siblings, 1 reply; 3+ messages in thread
From: Leandro Coutinho @ 2021-08-02 14:55 UTC (permalink / raw)
  To: netdev

Hi,

I'm a newbie and I was just looking at the code to learn.

It seems the parameter `*hw` is not used.
Although I didn't find where `FWSM` is defined.

Should it be removed? Or is the parameter really needed?

```c
static void __ew32_prepare(struct e1000_hw *hw)
{
    s32 i = E1000_ICH_FWSM_PCIM2PCI_COUNT;

    while ((er32(FWSM) & E1000_ICH_FWSM_PCIM2PCI) && --i)
        udelay(50);
}
```

It's because it gives an impression that "hw" is being changed somehow.

If you think it should be removed, I can send a patch.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: net: intel/e1000e/netdev.c __ew32_prepare parameter not used?
  2021-08-02 14:55 net: intel/e1000e/netdev.c __ew32_prepare parameter not used? Leandro Coutinho
@ 2021-08-03  8:50 ` Michael Walle
  2021-08-03 13:15   ` Leandro Coutinho
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Walle @ 2021-08-03  8:50 UTC (permalink / raw)
  To: lescoutinhovr; +Cc: netdev, Michael Walle

Hi,

> It seems the parameter `*hw` is not used.
> Although I didn't find where `FWSM` is defined.
> 
> Should it be removed? Or is the parameter really needed?
> 
> static void __ew32_prepare(struct e1000_hw *hw)
> {
>     s32 i = E1000_ICH_FWSM_PCIM2PCI_COUNT;
> 
>     while ((er32(FWSM) & E1000_ICH_FWSM_PCIM2PCI) && --i)
>         udelay(50);
> }

If you have a look at the definition of er32() (which is a macro and
is defined in e1000.h, you'll see that the hw parameter is used
there without being a parameter of the macro itself. Thus if you'd
rename the parameter you'd get a build error. Not really the best
code to look at when you want to learn coding, because that's an
example how not to do things, IMHO.

-michael

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: net: intel/e1000e/netdev.c __ew32_prepare parameter not used?
  2021-08-03  8:50 ` Michael Walle
@ 2021-08-03 13:15   ` Leandro Coutinho
  0 siblings, 0 replies; 3+ messages in thread
From: Leandro Coutinho @ 2021-08-03 13:15 UTC (permalink / raw)
  To: Michael Walle; +Cc: netdev

On Tue, Aug 3, 2021 at 5:50 AM Michael Walle <michael@walle.cc> wrote:
>
> Hi,
>
> > It seems the parameter `*hw` is not used.
> > Although I didn't find where `FWSM` is defined.
> >
> > Should it be removed? Or is the parameter really needed?
> >
> > static void __ew32_prepare(struct e1000_hw *hw)
> > {
> >     s32 i = E1000_ICH_FWSM_PCIM2PCI_COUNT;
> >
> >     while ((er32(FWSM) & E1000_ICH_FWSM_PCIM2PCI) && --i)
> >         udelay(50);
> > }
>
> If you have a look at the definition of er32() (which is a macro and
> is defined in e1000.h, you'll see that the hw parameter is used
> there without being a parameter of the macro itself. Thus if you'd
> rename the parameter you'd get a build error.Not really the best
> code to look at when you want to learn coding, because that's an
> example how not to do things, IMHO.
>
> -michael

Thank you very much Michael! =)

er32 is defined as:
#define er32(reg)   __er32(hw, E1000_##reg)

That's why I didn't find any definition for `FWSM` ... because of the
token concatenation https://gcc.gnu.org/onlinedocs/cpp/Concatenation.html

I think this way it would be more clear:
#define er32(hw, reg)   __er32(hw, reg)

I don't know if they did it that way just to avoid typing, or if there is some
other reason.

That is one advantage of Rust: macros have an ! at the end, eg: println!
So you can easily distinguish macros from functions.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-03 13:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-02 14:55 net: intel/e1000e/netdev.c __ew32_prepare parameter not used? Leandro Coutinho
2021-08-03  8:50 ` Michael Walle
2021-08-03 13:15   ` Leandro Coutinho

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).