Skip to contentSkip to conversation

device property: Return -ENXIO if there is no suitable FW interface

PATCH Superseded Guenter Roeck 3 participants 6 messages Aug 26, 2015 – Aug 27, 2015

Subsystems (5)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 device property: Return -ENXIO if there is no suitable FW interface

Return -ENXIO if device property array access functions don't find a suitable firmware interface.

This lets drivers decide if they should use available platform data instead.

Cc Rafael J. Wysocki <[email protected]>

---
v2: Added patch

 drivers/base/property.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/base/property.c +7 -0
index 287704d680bf..9600b824d138 100644
@@ -69,6 +69,9 @@ static int pset_prop_read_array(struct property_set *pset, const char *name,
 	struct property_entry *prop;
 	unsigned int item_size;
 
+	if (!pset)
+		return -ENXIO;
+
 	prop = pset_prop_get(pset, name);
 	if (!prop)
 		return -ENODATA;
@@ -156,6 +159,7 @@ EXPORT_SYMBOL_GPL(fwnode_property_present);
  *	   %-ENODATA if the property does not have a value,
  *	   %-EPROTO if the property is not an array of numbers,
  *	   %-EOVERFLOW if the size of the property is not as expected.
+ *	   %-ENXIO if no suitable firmware interface is present.
  */
 int device_property_read_u8_array(struct device *dev, const char *propname,
 				  u8 *val, size_t nval)
@@ -180,6 +184,7 @@ EXPORT_SYMBOL_GPL(device_property_read_u8_array);
  *	   %-ENODATA if the property does not have a value,
  *	   %-EPROTO if the property is not an array of numbers,
  *	   %-EOVERFLOW if the size of the property is not as expected.
+ *	   %-ENXIO if no suitable firmware interface is present.
  */
 int device_property_read_u16_array(struct device *dev, const char *propname,
 				   u16 *val, size_t nval)
@@ -204,6 +209,7 @@ EXPORT_SYMBOL_GPL(device_property_read_u16_array);
  *	   %-ENODATA if the property does not have a value,
  *	   %-EPROTO if the property is not an array of numbers,
  *	   %-EOVERFLOW if the size of the property is not as expected.
+ *	   %-ENXIO if no suitable firmware interface is present.
  */
 int device_property_read_u32_array(struct device *dev, const char *propname,
 				   u32 *val, size_t nval)
@@ -228,6 +234,7 @@ EXPORT_SYMBOL_GPL(device_property_read_u32_array);
  *	   %-ENODATA if the property does not have a value,
  *	   %-EPROTO if the property is not an array of numbers,
  *	   %-EOVERFLOW if the size of the property is not as expected.
+ *	   %-ENXIO if no suitable firmware interface is present.
  */
 int device_property_read_u64_array(struct device *dev, const char *propname,
 				   u64 *val, size_t nval)
Signature · 1 line
2.1.4
#1 lore raw

PATCH v2 2/2 smsc911x: Ignore error return from device_get_phy_mode()

Commit 62ee783bf1f8 ("smsc911x: Fix crash seen if neither ACPI nor OF is configured or used") introduces an error check for the return value from device_get_phy_mode() and bails out if there is an error. Unfortunately, there are configurations where no phy is configured. Those configurations now fail.

To fix the problem, accept error returns from device_get_phy_mode(), and use the return value from device_property_read_u32() to determine if there is a suitable firmware interface to read the configuration.

Fixes 62ee783bf1f8 ("smsc911x: Fix crash seen if neither ACPI nor OF is configured or used")

---
v2: Dropped RFC
Removed check for -ENODATA
Depends on patch 1/2

Tested with non-devicetree configuration. Should be tested with ACPI and FDT configurations.

 drivers/net/ethernet/smsc/smsc911x.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/net/ethernet/smsc/smsc911x.c +8 -6
index 6eef3251d833..c8b26259c9cf 100644
@@ -2369,23 +2369,25 @@ static int smsc911x_probe_config(struct smsc911x_platform_config *config,
 {
 	int phy_interface;
 	u32 width = 0;
+	int err;
 
 	phy_interface = device_get_phy_mode(dev);
 	if (phy_interface < 0)
-		return phy_interface;
-
+		phy_interface = PHY_INTERFACE_MODE_NA;
 	config->phy_interface = phy_interface;
 
 	device_get_mac_address(dev, config->mac, ETH_ALEN);
 
-	device_property_read_u32(dev, "reg-shift", &config->shift);
-
-	device_property_read_u32(dev, "reg-io-width", &width);
-	if (width == 4)
+	err = device_property_read_u32(dev, "reg-io-width", &width);
+	if (err == -ENXIO)
+		return err;
+	if (!err && width == 4)
 		config->flags |= SMSC911X_USE_32BIT;
 	else
 		config->flags |= SMSC911X_USE_16BIT;
 
+	device_property_read_u32(dev, "reg-shift", &config->shift);
+
 	if (device_property_present(dev, "smsc,irq-active-high"))
 		config->irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_HIGH;
 
Signature · 1 line
2.1.4
Tested-by on v2 2/2
#2 lore raw

Re: [PATCH -next v2 2/2] smsc911x: Ignore error return from device_get_phy_mode()

Quoted 12 lines · Guenter Roeck

Commit 62ee783bf1f8 ("smsc911x: Fix crash seen if neither ACPI nor OF is configured or used") introduces an error check for the return value from device_get_phy_mode() and bails out if there is an error. Unfortunately, there are configurations where no phy is configured. Those configurations now fail.

To fix the problem, accept error returns from device_get_phy_mode(), and use the return value from device_property_read_u32() to determine if there is a suitable firmware interface to read the configuration.

Fixes 62ee783bf1f8 ("smsc911x: Fix crash seen if neither ACPI nor OF is configured or used")
Quoted 7 lines

---
v2: Dropped RFC
Removed check for -ENODATA
Depends on patch 1/2

Tested with non-devicetree configuration. Should be tested with ACPI and FDT configurations.

Thanks this fixes smsc911x regression in Linux next for me with FDT:

Quoted 42 lines
 drivers/net/ethernet/smsc/smsc911x.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/net/ethernet/smsc/smsc911x.c +8 -6
index 6eef3251d833..c8b26259c9cf 100644
@@ -2369,23 +2369,25 @@ static int smsc911x_probe_config(struct smsc911x_platform_config *config,
 {
 	int phy_interface;
 	u32 width = 0;
+	int err;
 
 	phy_interface = device_get_phy_mode(dev);
 	if (phy_interface < 0)
-		return phy_interface;
-
+		phy_interface = PHY_INTERFACE_MODE_NA;
 	config->phy_interface = phy_interface;
 
 	device_get_mac_address(dev, config->mac, ETH_ALEN);
 
-	device_property_read_u32(dev, "reg-shift", &config->shift);
-
-	device_property_read_u32(dev, "reg-io-width", &width);
-	if (width == 4)
+	err = device_property_read_u32(dev, "reg-io-width", &width);
+	if (err == -ENXIO)
+		return err;
+	if (!err && width == 4)
 		config->flags |= SMSC911X_USE_32BIT;
 	else
 		config->flags |= SMSC911X_USE_16BIT;
 
+	device_property_read_u32(dev, "reg-shift", &config->shift);
+
 	if (device_property_present(dev, "smsc,irq-active-high"))
 		config->irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_HIGH;
 
Signature · 1 line
2.1.4
#3 lore raw
In reply to Guenter Roeck
Quoted 19 lines · Guenter Roeck

Return -ENXIO if device property array access functions don't find a suitable firmware interface.

This lets drivers decide if they should use available platform data instead.

Cc Rafael J. Wysocki <[email protected]>

---
v2: Added patch

 drivers/base/property.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/base/property.c +0 -0
index 287704d680bf..9600b824d138 100644

drivers/base/property.c static int pset_prop_read_array(struct property_set *pset, const char *name, · line 74

Quoted 6 lines
drivers/base/property.c +3 -0
@@ -69,6 +69,9 @@ static int pset_prop_read_array(struct property_set *pset, const char *name,
 	struct property_entry *prop;
 	unsigned int item_size;
 
+	if (!pset)
+		return -ENXIO;
+

This isn't exactly straightforward, because it relies on the fact that pset_prop_read_array() is the last thing tried by FWNODE_PROP_READ_ARRAY() and fwnode_property_read_string_array(). A comment about that might be helpful.

Thanks,
Rafael

#4 lore raw
Quoted 23 lines · Rafael J. Wysocki
Quoted 22 lines · Guenter Roeck

Return -ENXIO if device property array access functions don't find a suitable firmware interface.

This lets drivers decide if they should use available platform data instead.

Cc Rafael J. Wysocki <[email protected]>

---
v2: Added patch

  drivers/base/property.c | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/base/property.c +0 -0
index 287704d680bf..9600b824d138 100644
@@ -69,6 +69,9 @@ static int pset_prop_read_array(struct property_set *pset, const char *name,
  	struct property_entry *prop;
  	unsigned int item_size;
 
Quoted 9 lines

drivers/base/property.c static int pset_prop_read_array(struct property_set *pset, const char *name, · line 74

Quoted 3 lines
drivers/base/property.c +3 -0
+	if (!pset)
+		return -ENXIO;
+

This isn't exactly straightforward, because it relies on the fact that pset_prop_read_array() is the last thing tried by FWNODE_PROP_READ_ARRAY() and fwnode_property_read_string_array(). A comment about that might be helpful.

I see two options: Add a comment above, or change the calling code to

	...
	else if (is_pset(fwnode))
		return pset_prop_read_array(to_pset(fwnode), propname,
                         	            DEV_PROP_STRING, val, nval);
	return -ENXIO;

which would make it obvious and avoid side effects if the code is changed later on. Would you be ok with this ?

Thanks,
Guenter

#5 lore raw
Quoted 35 lines · Guenter Roeck
Quoted 23 lines · Rafael J. Wysocki
Quoted 22 lines · Guenter Roeck

Return -ENXIO if device property array access functions don't find a suitable firmware interface.

This lets drivers decide if they should use available platform data instead.

Cc Rafael J. Wysocki <[email protected]>

---
v2: Added patch

  drivers/base/property.c | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/base/property.c +0 -0
index 287704d680bf..9600b824d138 100644
@@ -69,6 +69,9 @@ static int pset_prop_read_array(struct property_set *pset, const char *name,
  	struct property_entry *prop;
  	unsigned int item_size;
 
Quoted 9 lines

drivers/base/property.c static int pset_prop_read_array(struct property_set *pset, const char *name, · line 74

Quoted 3 lines
drivers/base/property.c +3 -0
+	if (!pset)
+		return -ENXIO;
+

This isn't exactly straightforward, because it relies on the fact that pset_prop_read_array() is the last thing tried by FWNODE_PROP_READ_ARRAY() and fwnode_property_read_string_array(). A comment about that might be helpful.

I see two options: Add a comment above, or change the calling code to

Quoted 8 lines
	...
	else if (is_pset(fwnode))
		return pset_prop_read_array(to_pset(fwnode), propname,
                          	            DEV_PROP_STRING, val, nval);
	return -ENXIO;

which would make it obvious and avoid side effects if the code is changed later on. Would you be ok with this ?

The second option is obviously cleaner to me and I prefer cleaner code. :-)

Thanks,
Rafael