public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Heiko Schocher <hs@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2] net, phy, cpsw: fix NULL pointer deference
Date: Thu, 05 Sep 2013 11:40:19 +0200	[thread overview]
Message-ID: <52285183.8000304@denx.de> (raw)
In-Reply-To: <5228408B.9000105@ti.com>

Hello Mugunthan,

Am 05.09.2013 10:27, schrieb Mugunthan V N:
> On Thursday 05 September 2013 11:35 AM, Heiko Schocher wrote:
>> if phy_connect() did not find a phy, phydev is NULL and
>> following code in cpsw_phy_init() crashes. Fix this.
>>
>> Signed-off-by: Heiko Schocher<hs@denx.de>
>> Cc: Joe Hershberger<joe.hershberger@gmail.com>
>> Cc: Mugunthan V N<mugunthanvnm@ti.com>
>> Cc: Tom Rini<trini@ti.com>
>>
>> ---
[...]
>> diff --git a/drivers/net/cpsw.c b/drivers/net/cpsw.c
>> index 9bab71a..186665b 100644
>> --- a/drivers/net/cpsw.c
>> +++ b/drivers/net/cpsw.c
>> @@ -561,6 +561,9 @@ static inline void setbit_and_wait_for_clear32(void *addr)
>>   static void cpsw_set_slave_mac(struct cpsw_slave *slave,
>>   			       struct cpsw_priv *priv)
>>   {
>> +	if (!priv)
>> +		return;
>> +
>>   	__raw_writel(mac_hi(priv->dev->enetaddr),&slave->regs->sa_hi);
>>   	__raw_writel(mac_lo(priv->dev->enetaddr),&slave->regs->sa_lo);
>>   }
>> @@ -568,9 +571,17 @@ static void cpsw_set_slave_mac(struct cpsw_slave *slave,
>>   static void cpsw_slave_update_link(struct cpsw_slave *slave,
>>   				   struct cpsw_priv *priv, int *link)
>>   {
>> -	struct phy_device *phy = priv->phydev;
>> +	struct phy_device *phy;
>>   	u32 mac_control = 0;
>>
>> +	if (!priv)
>> +		return;
>> +
>> +	phy = priv->phydev;
>> +
>> +	if (!phy)
>> +		return;
>> +
>>   	phy_startup(phy);
>>   	*link = phy->link;
>>
>> @@ -604,8 +615,12 @@ static int cpsw_update_link(struct cpsw_priv *priv)
>>   	int link = 0;
>>   	struct cpsw_slave *slave;
>>
>> +	if (!priv)
>> +		return -1;
>> +
>>   	for_each_slave(slave, priv)
>>   		cpsw_slave_update_link(slave, priv,&link);
>> +
>>   	priv->mdio_link = readl(&mdio_regs->link);
>>   	return link;
>>   }
>> @@ -614,6 +629,9 @@ static int cpsw_check_link(struct cpsw_priv *priv)
>>   {
>>   	u32 link = 0;
>
> All the above *priv* check can be remove as priv is already validated in
> this function and all the above functions are called only from this
> function.

No, cpsw_update_link() is called for example directly from cpsw_init()
cpsw_set_slave_mac() from cpsw_slave_init()

>> +	if (!priv)
>> +		return -1;
>> +
>>   	link = __raw_readl(&mdio_regs->link)&  priv->phy_mask;
>>   	if ((link)&&  (link == priv->mdio_link))
>>   		return 1;
>> @@ -623,6 +641,9 @@ static int cpsw_check_link(struct cpsw_priv *priv)
>>
>>   static inline u32  cpsw_get_slave_port(struct cpsw_priv *priv, u32 slave_num)
>>   {
>> +	if (!priv)
>> +		return -1;
>> +
>>   	if (priv->host_port == 0)
>>   		return slave_num + 1;
>>   	else
>> @@ -947,6 +968,9 @@ static int cpsw_phy_init(struct eth_device *dev, struct cpsw_slave *slave)
>>   			dev,
>>   			slave->data->phy_if);
>>
>> +	if (!phydev)
>> +		return -1;
>> +
>>   	phydev->supported&= supported;
>>   	phydev->advertising = phydev->supported;
>>
> I don't think you need to validate *priv* as it is already validated in
> driver register (cpsw_register()). In any case priv is NULL, then there
> is some corruption in dev structure as without priv, dev should not
> exist and stack is not supposed to call any cpsw apis.

Yes, you are right. Checked it on the dxr2 board. We do not need
the "priv check" ... Thanks!

bye,
Heiko
-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

  reply	other threads:[~2013-09-05  9:40 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-04 12:16 [U-Boot] [PATCH] net, phy, cpsw: fix unaligned access if no phy found Heiko Schocher
2013-09-04 13:14 ` Tom Rini
2013-09-05  5:56   ` Heiko Schocher
2013-09-04 19:11 ` Joe Hershberger
2013-09-05  6:05 ` [U-Boot] [PATCH v2] net, phy, cpsw: fix NULL pointer deference Heiko Schocher
2013-09-05  8:27   ` Mugunthan V N
2013-09-05  9:40     ` Heiko Schocher [this message]
2013-09-05  9:50   ` [U-Boot] [PATCH v3] " Heiko Schocher
2013-09-05 10:04     ` Mugunthan V N

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=52285183.8000304@denx.de \
    --to=hs@denx.de \
    --cc=u-boot@lists.denx.de \
    /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