From: Charles Keepax <ckeepax@opensource.cirrus.com>
To: broonie@kernel.org
Cc: lgirdwood@gmail.com, yung-chuan.liao@linux.intel.com,
pierre-louis.bossart@linux.dev, shenghao-ding@ti.com,
kevin-lu@ti.com, baojun.xu@ti.com, sen@ti.com,
niranjan.hy@ti.com, oder_chiou@realtek.com, shumingf@realtek.com,
linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
patches@opensource.cirrus.com
Subject: [PATCH 5/8] ASoC: SDCA: Update HID DisCo parsing
Date: Wed, 5 Aug 2026 13:42:02 +0100 [thread overview]
Message-ID: <20260805124205.4152543-6-ckeepax@opensource.cirrus.com> (raw)
In-Reply-To: <20260805124205.4152543-1-ckeepax@opensource.cirrus.com>
Add more error checking on the parsing of the HID DisCo and bring
the code more inline with the rest of the DisCo parsing.
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
sound/soc/sdca/sdca_functions.c | 119 ++++++++++++++++++++------------
1 file changed, 74 insertions(+), 45 deletions(-)
diff --git a/sound/soc/sdca/sdca_functions.c b/sound/soc/sdca/sdca_functions.c
index e49acfe49e289..1196cc09389ae 100644
--- a/sound/soc/sdca/sdca_functions.c
+++ b/sound/soc/sdca/sdca_functions.c
@@ -7,6 +7,7 @@
*/
#include <linux/acpi.h>
+#include <linux/array_size.h>
#include <linux/byteorder/generic.h>
#include <linux/cleanup.h>
#include <linux/device.h>
@@ -1369,59 +1370,71 @@ static int find_sdca_entity_hide(struct device *dev,
struct sdca_entity *entity)
{
struct sdca_entity_hide *hide = &entity->hide;
- unsigned int delay, *af_list = hide->af_number_list;
- int nval, ret;
+ int num_reports, ret;
+ unsigned int delay;
ret = fwnode_property_read_u32(entity_node,
- "mipi-sdca-RxUMP-ownership-transition-max-delay", &delay);
+ "mipi-sdca-RxUMP-ownership-transition-max-delay",
+ &delay);
if (!ret)
hide->max_delay = delay;
- nval = fwnode_property_count_u32(entity_node, "mipi-sdca-HIDTx-supported-report-ids");
- if (nval > 0) {
- hide->num_hidtx_ids = nval;
+ num_reports = fwnode_property_count_u32(entity_node,
+ "mipi-sdca-HIDTx-supported-report-ids");
+ if (num_reports < 0 && num_reports != -EINVAL) {
+ dev_err(dev, "%pfwP: failed to read hid tx ids: %d\n",
+ entity_node, num_reports);
+ return num_reports;
+ } else if (num_reports > 0) {
+ hide->num_hidtx_ids = num_reports;
hide->hidtx_ids = devm_kcalloc(dev, hide->num_hidtx_ids,
sizeof(*hide->hidtx_ids), GFP_KERNEL);
if (!hide->hidtx_ids)
return -ENOMEM;
- ret = fwnode_property_read_u32_array(entity_node,
- "mipi-sdca-HIDTx-supported-report-ids",
- hide->hidtx_ids,
- hide->num_hidtx_ids);
- if (ret < 0)
- return ret;
+ fwnode_property_read_u32_array(entity_node,
+ "mipi-sdca-HIDTx-supported-report-ids",
+ hide->hidtx_ids, hide->num_hidtx_ids);
}
- nval = fwnode_property_count_u32(entity_node, "mipi-sdca-HIDRx-supported-report-ids");
- if (nval > 0) {
- hide->num_hidrx_ids = nval;
+ num_reports = fwnode_property_count_u32(entity_node,
+ "mipi-sdca-HIDRx-supported-report-ids");
+ if (num_reports < 0 && num_reports != -EINVAL) {
+ dev_err(dev, "%pfwP: failed to read hid rx ids: %d\n",
+ entity_node, num_reports);
+ return num_reports;
+ } else if (num_reports > 0) {
+ hide->num_hidrx_ids = num_reports;
hide->hidrx_ids = devm_kcalloc(dev, hide->num_hidrx_ids,
sizeof(*hide->hidrx_ids), GFP_KERNEL);
if (!hide->hidrx_ids)
return -ENOMEM;
- ret = fwnode_property_read_u32_array(entity_node,
- "mipi-sdca-HIDRx-supported-report-ids",
- hide->hidrx_ids,
- hide->num_hidrx_ids);
- if (ret < 0)
- return ret;
+ fwnode_property_read_u32_array(entity_node,
+ "mipi-sdca-HIDRx-supported-report-ids",
+ hide->hidrx_ids, hide->num_hidrx_ids);
}
- nval = fwnode_property_count_u32(entity_node, "mipi-sdca-hide-related-audio-function-list");
- if (nval <= 0) {
+ /*
+ * FIXME: This should probably link to the actual sdca_function_data pointer,
+ * but updating to do so should probably wait until we have a user.
+ */
+ num_reports = fwnode_property_count_u32(entity_node,
+ "mipi-sdca-hide-related-audio-function-list");
+ if (num_reports <= 0) {
dev_err(dev, "%pfwP: audio function numbers list missing: %d\n",
- entity_node, nval);
+ entity_node, num_reports);
return -EINVAL;
- } else if (nval > SDCA_MAX_FUNCTION_COUNT) {
- dev_err(dev, "%pfwP: maximum number of audio function exceeded\n", entity_node);
+ } else if (num_reports > ARRAY_SIZE(hide->af_number_list)) {
+ dev_err(dev, "%pfwP: maximum number of audio function exceeded\n",
+ entity_node);
return -EINVAL;
}
- hide->hide_reside_function_num = nval;
+ hide->hide_reside_function_num = num_reports;
fwnode_property_read_u32_array(entity_node,
- "mipi-sdca-hide-related-audio-function-list", af_list, nval);
+ "mipi-sdca-hide-related-audio-function-list",
+ hide->af_number_list, num_reports);
return 0;
}
@@ -2152,29 +2165,45 @@ static int find_sdca_filesets(struct device *dev, struct sdw_slave *sdw,
static int find_sdca_hid(struct device *dev, struct fwnode_handle *function_node,
struct sdca_function_data *function)
{
- int nval;
+ int num_desc;
- nval = fwnode_property_count_u8(function_node, "mipi-sdca-hid-descriptor");
- if (nval)
- fwnode_property_read_u8_array(function_node, "mipi-sdca-hid-descriptor",
- (u8 *)&function->hid.desc, nval);
+ num_desc = fwnode_property_count_u8(function_node, "mipi-sdca-hid-descriptor");
+ if (!num_desc) {
+ return 0;
+ } else if (num_desc < 0) {
+ dev_err(dev, "%pfwP: failed to read hid descriptor: %d\n",
+ function_node, num_desc);
+ return num_desc;
+ } else if (num_desc > sizeof(function->hid.desc)) {
+ dev_err(dev, "%pfwP: hid descriptor too large: %d\n",
+ function_node, num_desc);
+ return -EINVAL;
+ }
- if (function->hid.desc.bNumDescriptors) {
- nval = fwnode_property_count_u8(function_node, "mipi-sdca-report-descriptor");
- if (nval) {
- unsigned char *report_desc;
+ fwnode_property_read_u8_array(function_node, "mipi-sdca-hid-descriptor",
+ (u8 *)&function->hid.desc, num_desc);
- report_desc = devm_kzalloc(dev, nval, GFP_KERNEL);
- if (!report_desc)
- return -ENOMEM;
+ if (!function->hid.desc.bNumDescriptors)
+ return 0;
- function->hid.report_desc = report_desc;
- fwnode_property_read_u8_array(function_node,
- "mipi-sdca-report-descriptor",
- report_desc, nval);
- }
+ num_desc = fwnode_property_count_u8(function_node, "mipi-sdca-report-descriptor");
+ if (num_desc <= 0) {
+ dev_err(dev, "%pfwP: failed to read report descriptor: %d\n",
+ function_node, num_desc);
+
+ if (!num_desc)
+ return -EINVAL;
+
+ return num_desc;
}
+ function->hid.report_desc = devm_kzalloc(dev, num_desc, GFP_KERNEL);
+ if (!function->hid.report_desc)
+ return -ENOMEM;
+
+ fwnode_property_read_u8_array(function_node, "mipi-sdca-report-descriptor",
+ function->hid.report_desc, num_desc);
+
return 0;
}
--
2.47.3
next prev parent reply other threads:[~2026-08-05 12:42 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-05 12:41 [PATCH 0/8] Reword the SDCA HID code Charles Keepax
2026-08-05 12:41 ` [PATCH 1/8] ASoC: SDCA: Tidy up error message Charles Keepax
2026-08-05 12:41 ` [PATCH 2/8] ASoC: SDCA: Remove unused dev pointer argument Charles Keepax
2026-08-05 12:42 ` [PATCH 3/8] ASoC: SDCA: Move HID registration to IRQ time Charles Keepax
2026-08-05 12:42 ` [PATCH 4/8] ASoC: SDCA: Move HID descriptors to function Charles Keepax
2026-08-05 12:42 ` Charles Keepax [this message]
2026-08-05 12:42 ` [PATCH 6/8] ASoC: SDCA: Add missing destroy for HID device Charles Keepax
2026-08-05 12:42 ` [PATCH 7/8] ASoC: SDCA: Add missing HID kernel doc Charles Keepax
2026-08-05 12:42 ` [PATCH 8/8] ASoC: SDCA: Pass swft table through sdca_dev_register() Charles Keepax
2026-08-06 8:57 ` [PATCH 0/8] Reword the SDCA HID code Pierre-Louis Bossart
2026-08-06 12:42 ` Mark Brown
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=20260805124205.4152543-6-ckeepax@opensource.cirrus.com \
--to=ckeepax@opensource.cirrus.com \
--cc=baojun.xu@ti.com \
--cc=broonie@kernel.org \
--cc=kevin-lu@ti.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=niranjan.hy@ti.com \
--cc=oder_chiou@realtek.com \
--cc=patches@opensource.cirrus.com \
--cc=pierre-louis.bossart@linux.dev \
--cc=sen@ti.com \
--cc=shenghao-ding@ti.com \
--cc=shumingf@realtek.com \
--cc=yung-chuan.liao@linux.intel.com \
/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 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.