All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] net: phy: switch to lockdep_assert_held in phylib
@ 2018-11-11 21:33 Heiner Kallweit
  2018-11-12 17:44 ` Andrew Lunn
  0 siblings, 1 reply; 3+ messages in thread
From: Heiner Kallweit @ 2018-11-11 21:33 UTC (permalink / raw)
  To: Andrew Lunn, Florian Fainelli, David Miller; +Cc: netdev@vger.kernel.org

These checks are relevant during development / testing only,
therefore switch to lockdep_assert_held and friends.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/net/phy/mdio_bus.c   | 4 ++--
 drivers/net/phy/phy.c        | 2 +-
 drivers/net/phy/phy_device.c | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 2e59a8419..5cb06f021 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -541,7 +541,7 @@ int __mdiobus_read(struct mii_bus *bus, int addr, u32 regnum)
 {
 	int retval;
 
-	WARN_ON_ONCE(!mutex_is_locked(&bus->mdio_lock));
+	lockdep_assert_held_once(&bus->mdio_lock);
 
 	retval = bus->read(bus, addr, regnum);
 
@@ -566,7 +566,7 @@ int __mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val)
 {
 	int err;
 
-	WARN_ON_ONCE(!mutex_is_locked(&bus->mdio_lock));
+	lockdep_assert_held_once(&bus->mdio_lock);
 
 	err = bus->write(bus, addr, regnum, val);
 
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 083977d2f..b0b3c9ac4 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -514,7 +514,7 @@ static int phy_check_link_status(struct phy_device *phydev)
 {
 	int err;
 
-	WARN_ON(!mutex_is_locked(&phydev->lock));
+	lockdep_assert_held(&phydev->lock);
 
 	err = phy_read_status(phydev);
 	if (err)
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 0f56d408b..1c20a0df3 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1340,7 +1340,7 @@ int __phy_resume(struct phy_device *phydev)
 	struct phy_driver *phydrv = to_phy_driver(phydev->mdio.dev.driver);
 	int ret = 0;
 
-	WARN_ON(!mutex_is_locked(&phydev->lock));
+	lockdep_assert_held(&phydev->lock);
 
 	if (phydev->drv && phydrv->resume)
 		ret = phydrv->resume(phydev);
-- 
2.19.1

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

* Re: [PATCH net-next] net: phy: switch to lockdep_assert_held in phylib
  2018-11-11 21:33 [PATCH net-next] net: phy: switch to lockdep_assert_held in phylib Heiner Kallweit
@ 2018-11-12 17:44 ` Andrew Lunn
  2018-11-12 18:58   ` Florian Fainelli
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Lunn @ 2018-11-12 17:44 UTC (permalink / raw)
  To: Heiner Kallweit; +Cc: Florian Fainelli, David Miller, netdev@vger.kernel.org

On Sun, Nov 11, 2018 at 10:33:08PM +0100, Heiner Kallweit wrote:
> diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
> index 2e59a8419..5cb06f021 100644
> --- a/drivers/net/phy/mdio_bus.c
> +++ b/drivers/net/phy/mdio_bus.c
> @@ -541,7 +541,7 @@ int __mdiobus_read(struct mii_bus *bus, int addr, u32 regnum)
>  {
>  	int retval;
>  
> -	WARN_ON_ONCE(!mutex_is_locked(&bus->mdio_lock));
> +	lockdep_assert_held_once(&bus->mdio_lock);

Hi Heiner

I don't think there is a clear right/wrong here. This is not hot path
code. The cost for checking the lock is held is very small compared to
the actual MDIO transaction. So i don't think we really need to
optimise this. I do sometimes build with lockdep on, but not
always. So it is good to know when locking is broken on normal builds.

Florian, what do you think?

	 Andrew

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

* Re: [PATCH net-next] net: phy: switch to lockdep_assert_held in phylib
  2018-11-12 17:44 ` Andrew Lunn
@ 2018-11-12 18:58   ` Florian Fainelli
  0 siblings, 0 replies; 3+ messages in thread
From: Florian Fainelli @ 2018-11-12 18:58 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit; +Cc: David Miller, netdev@vger.kernel.org

On 11/12/18 9:44 AM, Andrew Lunn wrote:
> On Sun, Nov 11, 2018 at 10:33:08PM +0100, Heiner Kallweit wrote:
>> diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
>> index 2e59a8419..5cb06f021 100644
>> --- a/drivers/net/phy/mdio_bus.c
>> +++ b/drivers/net/phy/mdio_bus.c
>> @@ -541,7 +541,7 @@ int __mdiobus_read(struct mii_bus *bus, int addr, u32 regnum)
>>  {
>>  	int retval;
>>  
>> -	WARN_ON_ONCE(!mutex_is_locked(&bus->mdio_lock));
>> +	lockdep_assert_held_once(&bus->mdio_lock);
> 
> Hi Heiner
> 
> I don't think there is a clear right/wrong here. This is not hot path
> code. The cost for checking the lock is held is very small compared to
> the actual MDIO transaction. So i don't think we really need to
> optimise this. I do sometimes build with lockdep on, but not
> always. So it is good to know when locking is broken on normal builds.
> 
> Florian, what do you think?

lockdep_assert_held_once() also looks at debug_locks (global variable)
so it sounds like in that regard, it would be superior in that it allows
an user-configurable, general debugging facility to behave consistently
as opposed to always having opt-in debugging within the mdio_bus.c file,
but that also has a lot of value. I have to admit debugging MDIO bus
locking issues is not particularly fun, so I would probably stick with
the current code in that regard.
-- 
Florian

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

end of thread, other threads:[~2018-11-13  4:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-11 21:33 [PATCH net-next] net: phy: switch to lockdep_assert_held in phylib Heiner Kallweit
2018-11-12 17:44 ` Andrew Lunn
2018-11-12 18:58   ` Florian Fainelli

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.