* [PATCH net] net: phy: Decrement phy_fixed_addr during unregister
@ 2016-06-24 22:44 Florian Fainelli
2016-06-24 22:55 ` Russell King - ARM Linux
0 siblings, 1 reply; 5+ messages in thread
From: Florian Fainelli @ 2016-06-24 22:44 UTC (permalink / raw)
To: netdev; +Cc: davem, andrew, thomas.petazzoni, linux, Florian Fainelli
If we have a system which uses fixed PHY devices and calls
fixed_phy_register() then fixed_phy_unregister() we can exhaust the
number of fixed PHYs available after a while, since we keep incrementing
the variable phy_fixed_addr, but we never decrement it.
This patch fixes that by decrementing phy_fixed_addr during
fixed_phy_del(), and in order to do that, we need to move the
phy_fixed_addr integer and its spinlock above that function.
Fixes: a75951217472 ("net: phy: extend fixed driver with fixed_phy_register()")
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
drivers/net/phy/fixed_phy.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/net/phy/fixed_phy.c b/drivers/net/phy/fixed_phy.c
index 2d2e4339f0df..050bc5657b9d 100644
--- a/drivers/net/phy/fixed_phy.c
+++ b/drivers/net/phy/fixed_phy.c
@@ -286,6 +286,9 @@ err_regs:
}
EXPORT_SYMBOL_GPL(fixed_phy_add);
+static int phy_fixed_addr;
+static DEFINE_SPINLOCK(phy_fixed_addr_lock);
+
static void fixed_phy_del(int phy_addr)
{
struct fixed_mdio_bus *fmb = &platform_fmb;
@@ -297,14 +300,14 @@ static void fixed_phy_del(int phy_addr)
if (gpio_is_valid(fp->link_gpio))
gpio_free(fp->link_gpio);
kfree(fp);
+ spin_lock(&phy_fixed_addr_lock);
+ phy_fixed_addr--;
+ spin_unlock(&phy_fixed_addr_lock);
return;
}
}
}
-static int phy_fixed_addr;
-static DEFINE_SPINLOCK(phy_fixed_addr_lock);
-
struct phy_device *fixed_phy_register(unsigned int irq,
struct fixed_phy_status *status,
int link_gpio,
--
2.7.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net] net: phy: Decrement phy_fixed_addr during unregister
2016-06-24 22:44 [PATCH net] net: phy: Decrement phy_fixed_addr during unregister Florian Fainelli
@ 2016-06-24 22:55 ` Russell King - ARM Linux
2016-06-24 22:58 ` Florian Fainelli
0 siblings, 1 reply; 5+ messages in thread
From: Russell King - ARM Linux @ 2016-06-24 22:55 UTC (permalink / raw)
To: Florian Fainelli; +Cc: netdev, davem, andrew, thomas.petazzoni
On Fri, Jun 24, 2016 at 03:44:11PM -0700, Florian Fainelli wrote:
> If we have a system which uses fixed PHY devices and calls
> fixed_phy_register() then fixed_phy_unregister() we can exhaust the
> number of fixed PHYs available after a while, since we keep incrementing
> the variable phy_fixed_addr, but we never decrement it.
>
> This patch fixes that by decrementing phy_fixed_addr during
> fixed_phy_del(), and in order to do that, we need to move the
> phy_fixed_addr integer and its spinlock above that function.
Is this really a good idea?
What if we have two fixed phys register, and the first one is
unregistered and a new one subsequently registered?
First phy registered, gets address 0, phy_fixed_addr becomes 1.
Second phy registered, gets address 1, phy_fixed_addr becomes 2.
First phy is unregistered, phy_fixed_addr becomes 1.
Third phy registered, gets address 1, conflicts with the second phy.
Obviously not a good outcome.
--
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] net: phy: Decrement phy_fixed_addr during unregister
2016-06-24 22:55 ` Russell King - ARM Linux
@ 2016-06-24 22:58 ` Florian Fainelli
2016-06-24 23:06 ` Russell King - ARM Linux
0 siblings, 1 reply; 5+ messages in thread
From: Florian Fainelli @ 2016-06-24 22:58 UTC (permalink / raw)
To: Russell King - ARM Linux; +Cc: netdev, davem, andrew, thomas.petazzoni
On 06/24/2016 03:55 PM, Russell King - ARM Linux wrote:
> On Fri, Jun 24, 2016 at 03:44:11PM -0700, Florian Fainelli wrote:
>> If we have a system which uses fixed PHY devices and calls
>> fixed_phy_register() then fixed_phy_unregister() we can exhaust the
>> number of fixed PHYs available after a while, since we keep incrementing
>> the variable phy_fixed_addr, but we never decrement it.
>>
>> This patch fixes that by decrementing phy_fixed_addr during
>> fixed_phy_del(), and in order to do that, we need to move the
>> phy_fixed_addr integer and its spinlock above that function.
>
> Is this really a good idea?
In the sense that it is symetrical to the register code, probably.
>
> What if we have two fixed phys register, and the first one is
> unregistered and a new one subsequently registered?
>
> First phy registered, gets address 0, phy_fixed_addr becomes 1.
> Second phy registered, gets address 1, phy_fixed_addr becomes 2.
> First phy is unregistered, phy_fixed_addr becomes 1.
> Third phy registered, gets address 1, conflicts with the second phy.
>
> Obviously not a good outcome.
>
What would you suggest we do instead? Would switching to IDA/IDR give us
better results for instance (I have not looked too closely yet)?
--
Florian
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] net: phy: Decrement phy_fixed_addr during unregister
2016-06-24 22:58 ` Florian Fainelli
@ 2016-06-24 23:06 ` Russell King - ARM Linux
2016-06-24 23:18 ` Florian Fainelli
0 siblings, 1 reply; 5+ messages in thread
From: Russell King - ARM Linux @ 2016-06-24 23:06 UTC (permalink / raw)
To: Florian Fainelli; +Cc: netdev, davem, andrew, thomas.petazzoni
On Fri, Jun 24, 2016 at 03:58:39PM -0700, Florian Fainelli wrote:
> On 06/24/2016 03:55 PM, Russell King - ARM Linux wrote:
> > On Fri, Jun 24, 2016 at 03:44:11PM -0700, Florian Fainelli wrote:
> >> If we have a system which uses fixed PHY devices and calls
> >> fixed_phy_register() then fixed_phy_unregister() we can exhaust the
> >> number of fixed PHYs available after a while, since we keep incrementing
> >> the variable phy_fixed_addr, but we never decrement it.
> >>
> >> This patch fixes that by decrementing phy_fixed_addr during
> >> fixed_phy_del(), and in order to do that, we need to move the
> >> phy_fixed_addr integer and its spinlock above that function.
> >
> > Is this really a good idea?
>
> In the sense that it is symetrical to the register code, probably.
>
> >
> > What if we have two fixed phys register, and the first one is
> > unregistered and a new one subsequently registered?
> >
> > First phy registered, gets address 0, phy_fixed_addr becomes 1.
> > Second phy registered, gets address 1, phy_fixed_addr becomes 2.
> > First phy is unregistered, phy_fixed_addr becomes 1.
> > Third phy registered, gets address 1, conflicts with the second phy.
> >
> > Obviously not a good outcome.
> >
>
> What would you suggest we do instead? Would switching to IDA/IDR give us
> better results for instance (I have not looked too closely yet)?
I would expect an IDA to be suitable, because the IDA would track which
indexes (==addresses) are currently in-use.
If you want to go further, using an IDR would allow fixed_mdio_read() to
find the right fixed_phy struct without needing to loop over fmb->phys.
Whether that's worth it or not depends if you have a large number of
fixed phys. I suspect we're talking about small quantities here though.
--
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] net: phy: Decrement phy_fixed_addr during unregister
2016-06-24 23:06 ` Russell King - ARM Linux
@ 2016-06-24 23:18 ` Florian Fainelli
0 siblings, 0 replies; 5+ messages in thread
From: Florian Fainelli @ 2016-06-24 23:18 UTC (permalink / raw)
To: Russell King - ARM Linux; +Cc: netdev, davem, andrew, thomas.petazzoni
On 06/24/2016 04:06 PM, Russell King - ARM Linux wrote:
> On Fri, Jun 24, 2016 at 03:58:39PM -0700, Florian Fainelli wrote:
>> On 06/24/2016 03:55 PM, Russell King - ARM Linux wrote:
>>> On Fri, Jun 24, 2016 at 03:44:11PM -0700, Florian Fainelli wrote:
>>>> If we have a system which uses fixed PHY devices and calls
>>>> fixed_phy_register() then fixed_phy_unregister() we can exhaust the
>>>> number of fixed PHYs available after a while, since we keep incrementing
>>>> the variable phy_fixed_addr, but we never decrement it.
>>>>
>>>> This patch fixes that by decrementing phy_fixed_addr during
>>>> fixed_phy_del(), and in order to do that, we need to move the
>>>> phy_fixed_addr integer and its spinlock above that function.
>>>
>>> Is this really a good idea?
>>
>> In the sense that it is symetrical to the register code, probably.
>>
>>>
>>> What if we have two fixed phys register, and the first one is
>>> unregistered and a new one subsequently registered?
>>>
>>> First phy registered, gets address 0, phy_fixed_addr becomes 1.
>>> Second phy registered, gets address 1, phy_fixed_addr becomes 2.
>>> First phy is unregistered, phy_fixed_addr becomes 1.
>>> Third phy registered, gets address 1, conflicts with the second phy.
>>>
>>> Obviously not a good outcome.
>>>
>>
>> What would you suggest we do instead? Would switching to IDA/IDR give us
>> better results for instance (I have not looked too closely yet)?
>
> I would expect an IDA to be suitable, because the IDA would track which
> indexes (==addresses) are currently in-use.
OK, thanks!
>
> If you want to go further, using an IDR would allow fixed_mdio_read() to
> find the right fixed_phy struct without needing to loop over fmb->phys.
Since I am targetting this as a bugfix, the switch to IDA seems more
appropriate to be backported, but yes, that's a good idea though.
> Whether that's worth it or not depends if you have a large number of
> fixed phys. I suspect we're talking about small quantities here though.
>
Yes, at the moment we are limited to 32 PHYs maximum, just like a real
MDIO bus, which in some systems could actually be not enough, but then
you run into other problems, like the need to register more than a
single fixed MDIO bus driver to get a larger address space...
--
Florian
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-06-24 23:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-24 22:44 [PATCH net] net: phy: Decrement phy_fixed_addr during unregister Florian Fainelli
2016-06-24 22:55 ` Russell King - ARM Linux
2016-06-24 22:58 ` Florian Fainelli
2016-06-24 23:06 ` Russell King - ARM Linux
2016-06-24 23:18 ` Florian Fainelli
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).