net: mdio-gpio: Allow for unspecified bus id
Subsystems (3)
PATCH 1/1 net: mdio-gpio: Allow for unspecified bus id
When the bus id was supplied via a struct platform_device, the driver wasn't handling -1 to mean an unspecified id of the only instance of this driver, as the platform spec requires.
--- drivers/net/phy/mdio-gpio.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/phy/mdio-gpio.c +4 -1
@@ -165,7 +165,10 @@ static struct mii_bus *mdio_gpio_bus_init(struct device *dev,if (!new_bus->irq[i]) new_bus->irq[i] =PHY_POLL ; -snprintf (new_bus->id,MII_BUS_ID_SIZE ,"gpio-%x" , bus_id); +if (bus_id !=-1 ) +snprintf (new_bus->id,MII_BUS_ID_SIZE ,"gpio-%x" , bus_id); +else +strncpy (new_bus->id,"gpio" ,MII_BUS_ID_SIZE );if (devm_gpio_request (dev, bitbang->mdc,"mdc" )) goto out_free_bus;
Signature · 1 line
1.9.1
Andrew Lunn
maintainerQuoted 14 lines · Bert Vermeulen
When the bus id was supplied via a struct
platform_device, the driver wasn't handling -1 to mean an unspecified id of the only instance of this driver, as the platform spec requires.Signed-off-by Bert Vermeulen <[email protected]>--- drivers/net/phy/mdio-gpio.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/net/phy/mdio-gpio.c +0
-0
drivers/net/phy/mdio-gpio.c static struct mii_bus *mdio_gpio_bus_init(struct device *dev, · line 171
Quoted 8 lines
drivers/net/phy/mdio-gpio.c +4
-1@@ -165,7 +165,10 @@ static struct mii_bus *mdio_gpio_bus_init(struct device *dev,if (!new_bus->irq[i]) new_bus->irq[i] =PHY_POLL ; -snprintf (new_bus->id,MII_BUS_ID_SIZE ,"gpio-%x" , bus_id); +if (bus_id !=-1 ) +snprintf (new_bus->id,MII_BUS_ID_SIZE ,"gpio-%x" , bus_id); +else +strncpy (new_bus->id,"gpio" ,MII_BUS_ID_SIZE );
Hi Bert
What happens if there are multiple platform_device's with -1? You should probably be using use idr_alloc().
Andrew
Quoted 26 lines · Andrew Lunn
Quoted 14 lines · Bert Vermeulen
When the bus id was supplied via a struct
platform_device, the driver wasn't handling -1 to mean an unspecified id of the only instance of this driver, as the platform spec requires.Signed-off-by Bert Vermeulen <[email protected]>--- drivers/net/phy/mdio-gpio.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/net/phy/mdio-gpio.c +0
-0drivers/net/phy/mdio-gpio.c static struct mii_bus *mdio_gpio_bus_init(struct device *dev, · line 171
Quoted 8 lines
drivers/net/phy/mdio-gpio.c +4
-1@@ -165,7 +165,10 @@ static struct mii_bus *mdio_gpio_bus_init(struct device *dev,if (!new_bus->irq[i]) new_bus->irq[i] =PHY_POLL ; -snprintf (new_bus->id,MII_BUS_ID_SIZE ,"gpio-%x" , bus_id); +if (bus_id !=-1 ) +snprintf (new_bus->id,MII_BUS_ID_SIZE ,"gpio-%x" , bus_id); +else +strncpy (new_bus->id,"gpio" ,MII_BUS_ID_SIZE );Hi Bert
Quoted 2 lines
What happens if there are multiple platform_device's with -1? You should probably be using use
idr_alloc().
It's an instance id per driver, not globally, and -1 specifically means it's the only instance. From Documentation/driver-model/platform.txt:
Quoted 4 lines
These are concatenated, so name/id "serial"/0 indicates
bus_id"serial.0", and "serial/3" indicatesbus_id"serial.3"; both would use theplatform_drivernamed "serial". While "my_rtc"/-1 would bebus_id"my_rtc" (no instance id) and use theplatform_drivercalled "my_rtc".
Signature · 1 line
Bert Vermeulen [email protected] email/xmpp
Andrew Lunn
maintainerQuoted 8 lines
Quoted 8 lines
drivers/net/phy/mdio-gpio.c static struct mii_bus *mdio_gpio_bus_init(struct device *dev, · line 171
Quoted 5 lines
drivers/net/phy/mdio-gpio.c +4
-1-snprintf (new_bus->id,MII_BUS_ID_SIZE ,"gpio-%x" , bus_id); +if (bus_id !=-1 ) +snprintf (new_bus->id,MII_BUS_ID_SIZE ,"gpio-%x" , bus_id); +else +strncpy (new_bus->id,"gpio" ,MII_BUS_ID_SIZE );Hi Bert
Quoted 5 lines
Quoted 2 lines
What happens if there are multiple platform_device's with -1? You should probably be using use
idr_alloc().It's an instance id per driver, not globally, and -1 specifically means it's the only instance. From
Documentation/driver-model/platform.txt:
Ah, did not know there can only be one with -1. I've used i2c where this does not apply when registering adaptors. It will allocate a unique id to each added with id = -1.
Andrew
Quoted 16 lines · Bert Vermeulen
When the bus id was supplied via a struct
platform_device, the driver wasn't handling -1 to mean an unspecified id of the only instance of this driver, as the platform spec requires.Signed-off-by Bert Vermeulen <[email protected]>--- drivers/net/phy/mdio-gpio.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/net/phy/mdio-gpio.c +0
-0@@ -165,7 +165,10 @@ static struct mii_bus *mdio_gpio_bus_init(struct device *dev,if (!new_bus->irq[i])
drivers/net/phy/mdio-gpio.c static struct mii_bus *mdio_gpio_bus_init(struct device *dev, · line 174
Quoted 10 lines
drivers/net/phy/mdio-gpio.c +4
-1new_bus->irq[i] =PHY_POLL ; -snprintf (new_bus->id,MII_BUS_ID_SIZE ,"gpio-%x" , bus_id); +if (bus_id !=-1 ) +snprintf (new_bus->id,MII_BUS_ID_SIZE ,"gpio-%x" , bus_id); +else +strncpy (new_bus->id,"gpio" ,MII_BUS_ID_SIZE );if (devm_gpio_request (dev, bitbang->mdc,"mdc" )) goto out_free_bus;
Andrew
From: Bert Vermeulen <[email protected]>
Date: Fri, 8 May 2015 16:18:49 +0200
Quoted 5 lines
When the bus id was supplied via a struct
platform_device, the driver wasn't handling -1 to mean an unspecified id of the only instance of this driver, as the platform spec requires.Signed-off-by Bert Vermeulen <[email protected]>
Applied, thanks.