Commit a489afc1 authored by Pierre-Louis Bossart's avatar Pierre-Louis Bossart Committed by Vinod Koul
Browse files

soundwire: mipi-disco: add error handling for property array read



The existing code assumes that there are no possible errors when using
fwnode_property_read_u32_array(), because fwnode_property_count_u32()
reads this array to determine its number of elements. We need to also
protect the second read to be completely bullet-proof.

Suggested-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: default avatarBard Liao <yung-chuan.liao@linux.intel.com>
Link: https://lore.kernel.org/r/20241003070650.62787-10-yung-chuan.liao@linux.intel.com


Signed-off-by: default avatarVinod Koul <vkoul@kernel.org>
parent 1ae4aa59
Loading
Loading
Loading
Loading
+24 −8
Original line number Diff line number Diff line
@@ -52,7 +52,9 @@ int sdw_master_read_prop(struct sdw_bus *bus)
	struct sdw_master_prop *prop = &bus->prop;
	struct fwnode_handle *link;
	char name[32];
	int nval, i;
	int nval;
	int ret;
	int i;

	device_property_read_u32(bus->dev,
				 "mipi-sdw-sw-interface-revision",
@@ -91,9 +93,11 @@ int sdw_master_read_prop(struct sdw_bus *bus)
			return -ENOMEM;
		}

		fwnode_property_read_u32_array(link,
		ret = fwnode_property_read_u32_array(link,
				"mipi-sdw-clock-frequencies-supported",
				prop->clk_freq, prop->num_clk_freq);
		if (ret < 0)
			return ret;
	}

	/*
@@ -119,10 +123,12 @@ int sdw_master_read_prop(struct sdw_bus *bus)
			return -ENOMEM;
		}

		fwnode_property_read_u32_array(link,
		ret = fwnode_property_read_u32_array(link,
					       "mipi-sdw-supported-clock-gears",
					       prop->clk_gears,
					       prop->num_clk_gears);
		if (ret < 0)
			return ret;
	}

	fwnode_property_read_u32(link, "mipi-sdw-default-frame-rate",
@@ -151,6 +157,7 @@ static int sdw_slave_read_dp0(struct sdw_slave *slave,
			      struct sdw_dp0_prop *dp0)
{
	int nval;
	int ret;

	fwnode_property_read_u32(port, "mipi-sdw-port-max-wordlength",
				 &dp0->max_word);
@@ -168,9 +175,11 @@ static int sdw_slave_read_dp0(struct sdw_slave *slave,
		if (!dp0->words)
			return -ENOMEM;

		fwnode_property_read_u32_array(port,
		ret = fwnode_property_read_u32_array(port,
				"mipi-sdw-port-wordlength-configs",
				dp0->words, dp0->num_words);
		if (ret < 0)
			return ret;
	}

	dp0->BRA_flow_controlled = mipi_fwnode_property_read_bool(port,
@@ -191,9 +200,10 @@ static int sdw_slave_read_dpn(struct sdw_slave *slave,
{
	struct fwnode_handle *node;
	u32 bit, i = 0;
	int nval;
	unsigned long addr;
	char name[40];
	int nval;
	int ret;

	addr = ports;
	/* valid ports are 1 to 14 so apply mask */
@@ -228,9 +238,11 @@ static int sdw_slave_read_dpn(struct sdw_slave *slave,
				return -ENOMEM;
			}

			fwnode_property_read_u32_array(node,
			ret = fwnode_property_read_u32_array(node,
					"mipi-sdw-port-wordlength-configs",
					dpn[i].words, dpn[i].num_words);
			if (ret < 0)
				return ret;
		}

		fwnode_property_read_u32(node, "mipi-sdw-data-port-type",
@@ -269,9 +281,11 @@ static int sdw_slave_read_dpn(struct sdw_slave *slave,
				return -ENOMEM;
			}

			fwnode_property_read_u32_array(node,
			ret = fwnode_property_read_u32_array(node,
					"mipi-sdw-channel-number-list",
					dpn[i].channels, dpn[i].num_channels);
			if (ret < 0)
				return ret;
		}

		nval = fwnode_property_count_u32(node, "mipi-sdw-channel-combination-list");
@@ -286,10 +300,12 @@ static int sdw_slave_read_dpn(struct sdw_slave *slave,
				return -ENOMEM;
			}

			fwnode_property_read_u32_array(node,
			ret = fwnode_property_read_u32_array(node,
					"mipi-sdw-channel-combination-list",
					dpn[i].ch_combinations,
					dpn[i].num_ch_combinations);
			if (ret < 0)
				return ret;
		}

		fwnode_property_read_u32(node,