From: hayeswang <hayeswang@realtek.com>
To: 'Ben Hutchings' <benh@debian.org>
Cc: <romieu@fr.zoreil.com>, <netdev@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Subject: RE: [PATCH] net/r8169: Update the function of parsing firmware
Date: Mon, 10 Jan 2011 10:25:15 +0800 [thread overview]
Message-ID: <BB1CAEB2DB6746D39E020502E48AB45F@realtek.com.tw> (raw)
In-Reply-To: <20110107151755.GN3702@decadent.org.uk>
> From: Ben Hutchings [mailto:benh@debian.org]
> Sent: Friday, January 07, 2011 11:18 PM
> To: Hayeswang
> Cc: romieu@fr.zoreil.com; netdev@vger.kernel.org;
> linux-kernel@vger.kernel.org
> Subject: Re: [PATCH] net/r8169: Update the function of
> parsing firmware
>
> On Fri, 2011-01-07 at 17:45 +0800, Hayes Wang wrote:
> > Update rtl_phy_write_fw function. The new function could parse the
> > complex firmware which is used by RTL8111E and later.
> > The new firmware may read data and do some operations, not just do
> > writing only.
> >
> > Signed-off-by: Hayes Wang <hayeswang@realtek.com>
> > ---
> > drivers/net/r8169.c | 112
> > ++++++++++++++++++++++++++++++++++++++++++++-------
> > 1 files changed, 97 insertions(+), 15 deletions(-)
> >
> > diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c index
> > 27a7c20..2115424 100644
> > --- a/drivers/net/r8169.c
> > +++ b/drivers/net/r8169.c
> [...]
> > - while (i-- != 0) {
> > - u32 action = le32_to_cpu(*phytable);
> > - u32 data = action & 0x0000ffff;
> > - u32 reg = (action & 0x0fff0000) >> 16;
> > + predata = 0;
> > + count = 0;
> > +
> > + for (index = 0; index < fw->size / sizeof(*phytable); ) {
> > + u32 action = le32_to_cpu(phytable[index]);
> > + u32 data = action & 0x0000FFFF;
> > + u32 regno = (action & 0x0FFF0000) >> 16;
> > +
> > + if (!action)
> > + break;
> >
> > - switch(action & 0xf0000000) {
> > + switch(action & 0xF0000000) {
> [...]
> > + case PHY_BJMPN:
> > + index -= regno;
> > + break;
> [...]
>
> I'm concerned that this is being extended from a firmware
> upload interface to a quite general interpreter for PHY
> initialisation. I realise that this will make it easier to
> fix PHY firmware bugs in future but it also allows you to
> accidentally introduce infinite loops.
> The initialisation programs will obviously not be subject to
> the same sort of review on netdev that new C code is.
>
I know the situation which you worry. However, the real action is depend to the
status of the hardware, and it is hard that I couldn't assume any situation to
check the firmware. Thus, I just check if every commands are valid. I could only
promise that there is no infinite loop if the firmware is correct.
> > + case PHY_DELAY_MS:
> > + mdelay(data);
> > + index++;
> > + break;
>
> Why mdelay() and not msleep()? This is not an atomic context.
>
Accounding to the document, the msleep have to larger than 10ms. It would run
more than 10ms if you set less than 10 for msleep. I think it takes more delay
than which I need. Beside, I don't sure if it would be run during atomic
context, so I think using mdelay is safer.
> > + case PHY_READ_MAC_BYTE:
> > + case PHY_WRITE_MAC_BYTE:
> > + case PHY_WRITE_ERI_WORD:
> > default:
> > BUG();
> > }
> > +
> > + if (index < 0)
> > + BUG();
> [...]
>
> index is unsigned so it can't be < 0. It looks like the loop
> condition should catch an out-of-range index, but really the
> range-checking should be done in the first loop.
>
I would try to fix this.
> Ben.
>
> --
> Ben Hutchings
> We get into the habit of living before acquiring the habit of
> thinking.
>
> - Albert Camus
>
>
> ------Please consider the environment before printing this e-mail.
>
>
prev parent reply other threads:[~2011-01-10 2:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-07 9:45 [PATCH] net/r8169: Update the function of parsing firmware Hayes Wang
2011-01-07 11:44 ` Francois Romieu
2011-01-07 15:17 ` Ben Hutchings
2011-01-10 2:25 ` hayeswang [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=BB1CAEB2DB6746D39E020502E48AB45F@realtek.com.tw \
--to=hayeswang@realtek.com \
--cc=benh@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=romieu@fr.zoreil.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox