From: Bard Liao <yung-chuan.liao@linux.intel.com>
To: linux-sound@vger.kernel.org, vkoul@kernel.org
Cc: vinod.koul@linaro.org, linux-kernel@vger.kernel.org,
pierre-louis.bossart@linux.intel.com, bard.liao@intel.com
Subject: [PATCH v2 09/14] soundwire: mipi-disco: add error handling for property array read
Date: Wed, 11 Sep 2024 19:58:22 +0800 [thread overview]
Message-ID: <20240911115827.233171-10-yung-chuan.liao@linux.intel.com> (raw)
In-Reply-To: <20240911115827.233171-1-yung-chuan.liao@linux.intel.com>
From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
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: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
---
drivers/soundwire/mipi_disco.c | 32 ++++++++++++++++++++++++--------
1 file changed, 24 insertions(+), 8 deletions(-)
diff --git a/drivers/soundwire/mipi_disco.c b/drivers/soundwire/mipi_disco.c
index 79cf8212f97a..99253f4c9a38 100644
--- a/drivers/soundwire/mipi_disco.c
+++ b/drivers/soundwire/mipi_disco.c
@@ -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,
--
2.43.0
next prev parent reply other threads:[~2024-09-11 11:59 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-11 11:58 [PATCH v2 00/14] soundwire: mipi-disco: add partial SoundWire Disco 2.1 Bard Liao
2024-09-11 11:58 ` [PATCH v2 01/14] soundwire: mipi_disco: add MIPI-specific property_read_bool() helpers Bard Liao
2024-09-11 11:58 ` [PATCH v2 02/14] soundwire: optimize sdw_stream_runtime memory layout Bard Liao
2024-09-11 11:58 ` [PATCH v2 03/14] soundwire: optimize sdw_master_prop Bard Liao
2024-09-11 11:58 ` [PATCH v2 04/14] soundwire: optimize sdw_bus structure Bard Liao
2024-09-11 11:58 ` [PATCH v2 05/14] soundwire: optimize sdw_slave_prop Bard Liao
2024-09-11 11:58 ` [PATCH v2 06/14] soundwire: optimize sdw_dp0_prop Bard Liao
2024-09-11 11:58 ` [PATCH v2 07/14] soundwire: optimize sdw_dpn_prop Bard Liao
2024-09-11 11:58 ` [PATCH v2 08/14] soundwire: mipi-disco: remove DPn audio-modes Bard Liao
2024-09-11 11:58 ` Bard Liao [this message]
2024-09-11 11:58 ` [PATCH v2 10/14] soundwire: mipi_disco: add support for clock-scales property Bard Liao
2024-09-11 11:58 ` [PATCH v2 11/14] soundwire: mipi-disco: add support for peripheral channelprepare timeout Bard Liao
2024-09-11 11:58 ` [PATCH v2 12/14] soundwire: mipi-disco: add comment on DP0-supported property Bard Liao
2024-09-11 11:58 ` [PATCH v2 13/14] soundwire: mipi-disco: add new properties from 2.0 spec Bard Liao
2024-09-11 11:58 ` [PATCH v2 14/14] soundwire: mipi-disco: add support for DP0/DPn 'lane-list' property Bard Liao
2024-09-12 14:41 ` [PATCH v2 00/14] soundwire: mipi-disco: add partial SoundWire Disco 2.1 Charles Keepax
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240911115827.233171-10-yung-chuan.liao@linux.intel.com \
--to=yung-chuan.liao@linux.intel.com \
--cc=bard.liao@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=pierre-louis.bossart@linux.intel.com \
--cc=vinod.koul@linaro.org \
--cc=vkoul@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox