staging: greybus: audio: split topology get into size and data calls
Subsystems (3)
PATCH 1/1 staging: greybus: audio: split topology get into size and data calls
From: Aditya Chari S <[email protected]>
gb_audio_gb_get_topology() combined three separate responsibilities into a single call: querying the topology size, allocating a buffer for it, and fetching the topology data into that buffer. This left callers with no way to perform any of these steps independently, and forced the kzalloc() allocation to live inside the protocol-layer driver rather than the caller, as already flagged by a FIXME comment at the call site in audio_module.c.
Split the function into two:
gb_audio_gb_get_topology_size() - queries only the topology size
gb_audio_gb_get_topology() - fetches topology data into a
caller-supplied buffer of a given size
Update the only caller, gb_audio_probe() in audio_module.c, to query the size first, allocate the topology buffer itself, then fetch the data into it, freeing the buffer via the existing free_topology error path on failure.
This resolves both the "TODO: Split into separate calls" comment above the original function in audio_gb.c and the FIXME comment at the call site in audio_module.c, both of which are removed as part of this change.
No functional change in behavior for the existing probe path.
Compile-tested with W=1, sparse (C=2), and checkpatch.pl; all clean on the three changed files (audio_gb.c, audio_module.c, audio_codec.h).
--- drivers/staging/greybus/audio_codec.h | 4 +++- drivers/staging/greybus/audio_gb.c | 33 ++++++++++---------------- drivers/staging/greybus/audio_module.c | 21 +++++++++++----- 3 files changed, 31 insertions(+), 27 deletions(-)
drivers/staging/greybus/audio_codec.h +3 -1
@@ -178,8 +178,10 @@ int gbaudio_register_module(struct gbaudio_module_info *module);void gbaudio_unregister_module (struct gbaudio_module_info *module);/* protocol related */ +int gb_audio_gb_get_topology_size (struct gb_connection *connection, +u16 *size);int gb_audio_gb_get_topology (struct gb_connection *connection, -struct gb_audio_topology **topology); +struct gb_audio_topology *topology,u16 size);int gb_audio_gb_get_control (struct gb_connection *connection,u8 control_id,u8 index,struct gb_audio_ctl_elem_value *value);
drivers/staging/greybus/audio_gb.c +13 -20
@@ -8,13 +8,10 @@#include <linux/greybus.h> #include "audio_codec.h" -/* TODO: Split into separate calls */ -int gb_audio_gb_get_topology (struct gb_connection *connection, -struct gb_audio_topology **topology) +int gb_audio_gb_get_topology_size (struct gb_connection *connection, +u16 *size) {struct gb_audio_get_topology_size_response size_resp; -struct gb_audio_topology *topo; -u16 size;int ret; ret = gb_operation_sync(connection, GB_AUDIO_TYPE_GET_TOPOLOGY_SIZE,
@@ -22,24 +19,20 @@ int gb_audio_gb_get_topology(struct gb_connection *connection,if (ret)return ret; - size =le16_to_cpu (size_resp.size); -if (size <sizeof (*topo)) -return -ENODATA ; - - topo =kzalloc (size,GFP_KERNEL ); -if (!topo) -return -ENOMEM ; + *size =le16_to_cpu (size_resp.size); - ret =gb_operation_sync (connection,GB_AUDIO_TYPE_GET_TOPOLOGY ,NULL ,0 , - topo, size); -if (ret) { -kfree (topo); -return ret; - } +return 0 ; +} +EXPORT_SYMBOL_GPL (gb_audio_gb_get_topology_size); - *topology = topo; +int gb_audio_gb_get_topology (struct gb_connection *connection, +struct gb_audio_topology *topology,u16 size) +{ +if (size <sizeof (*topology)) +return -ENODATA ; -return 0 ; +return gb_operation_sync (connection,GB_AUDIO_TYPE_GET_TOPOLOGY ,NULL ,0 , + topology, size); }EXPORT_SYMBOL_GPL (gb_audio_gb_get_topology);
drivers/staging/greybus/audio_module.c +15 -6
@@ -239,6 +239,7 @@ static int gb_audio_probe(struct gb_bundle *bundle,struct gb_audio_manager_module_descriptor desc;struct gbaudio_data_connection *dai, *_dai;int ret, i; +u16 size;struct gb_audio_topology *topology;/* There should be at least one Management and one Data cport */
@@ -304,16 +305,24 @@ static int gb_audio_probe(struct gb_bundle *bundle, } gbmodule->dev_id = gbmodule->mgmt_connection->intf->interface_id; -/* -* FIXME: malloc for topology happens via audio_gb driver -* should be done within codec driver itself -*/ - ret =gb_audio_gb_get_topology (gbmodule->mgmt_connection, &topology); + ret =gb_audio_gb_get_topology_size (gbmodule->mgmt_connection, &size);if (ret) { -dev_err (dev,"%d:Error while fetching topology\n" , ret); +dev_err (dev,"%d:Error while fetching topology size\n" , ret); + goto disable_connection; + } + + topology =kzalloc (size,GFP_KERNEL ); +if (!topology) { + ret = -ENOMEM ; goto disable_connection; } + ret =gb_audio_gb_get_topology (gbmodule->mgmt_connection, topology, size); +if (ret) { +dev_err (dev,"%d:Error while fetching topology\n" , ret); + goto free_topology; + } +/* process topology data */ ret =gbaudio_tplg_parse_data (gbmodule, topology);if (ret) {
Signature · 1 line
2.53.0
Quoted 27 lines · On Mon, Jun 29, 2026 at 08:19:41PM +0530, [email protected] wrote:
From: Aditya Chari S <[email protected]>
gb_audio_gb_get_topology()combined three separate responsibilities into a single call: querying the topology size, allocating a buffer for it, and fetching the topology data into that buffer. This left callers with no way to perform any of these steps independently, and forced thekzalloc()allocation to live inside the protocol-layer driver rather than the caller, as already flagged by a FIXME comment at the call site inaudio_module.c.Split the function into two:
gb_audio_gb_get_topology_size()- queries only the topology size
gb_audio_gb_get_topology()- fetches topology data into a
caller-supplied buffer of a given sizeUpdate the only caller,
gb_audio_probe()inaudio_module.c, to query the size first, allocate the topology buffer itself, then fetch the data into it, freeing the buffer via the existingfree_topologyerror path on failure.This resolves both the "TODO: Split into separate calls" comment above the original function in
audio_gb.cand the FIXME comment at the call site inaudio_module.c, both of which are removed as part of this change.
Quoted 4 lines
No functional change in behavior for the existing probe path.
Compile-tested with W=1, sparse (C=2), and checkpatch.pl; all clean on the three changed files (
audio_gb.c,audio_module.c,audio_codec.h).
Put this sort of meta commentary under the --- cut off line. Also compile the whole module, not just the modified files.
Quoted 3 lines
Signed-off-by Aditya Chari S <[email protected]>---
^^^
Quoted 10 lines
drivers/staging/greybus/audio_codec.h | 4 +++- drivers/staging/greybus/audio_gb.c | 33 ++++++++++---------------- drivers/staging/greybus/audio_module.c | 21 +++++++++++----- 3 files changed, 31 insertions(+), 27 deletions(-)drivers/staging/greybus/audio_codec.h +0
-0
drivers/staging/greybus/audio_codec.h int gbaudio_register_module(struct gbaudio_module_info *module); · line 182
Quoted 5 lines
drivers/staging/greybus/audio_codec.h +2
-0@@ -178,8 +178,10 @@ int gbaudio_register_module(struct gbaudio_module_info *module);void gbaudio_unregister_module (struct gbaudio_module_info *module);/* protocol related */ +int gb_audio_gb_get_topology_size (struct gb_connection *connection, +u16 *size);
Please store sizes in size_t.
Quoted 45 lines
drivers/staging/greybus/audio_codec.h +1
-1int gb_audio_gb_get_topology (struct gb_connection *connection, -struct gb_audio_topology **topology); +struct gb_audio_topology *topology,u16 size);int gb_audio_gb_get_control (struct gb_connection *connection,u8 control_id,u8 index,struct gb_audio_ctl_elem_value *value);drivers/staging/greybus/audio_gb.c +3
-18@@ -8,13 +8,10 @@#include <linux/greybus.h> #include "audio_codec.h" -/* TODO: Split into separate calls */ -int gb_audio_gb_get_topology (struct gb_connection *connection, -struct gb_audio_topology **topology) +int gb_audio_gb_get_topology_size (struct gb_connection *connection, +u16 *size) {struct gb_audio_get_topology_size_response size_resp; -struct gb_audio_topology *topo; -u16 size;int ret; ret = gb_operation_sync(connection, GB_AUDIO_TYPE_GET_TOPOLOGY_SIZE,@@ -22,24 +19,20 @@ int gb_audio_gb_get_topology(struct gb_connection *connection,if (ret)return ret; - size =le16_to_cpu (size_resp.size); -if (size <sizeof (*topo)) -return -ENODATA ; - - topo =kzalloc (size,GFP_KERNEL ); -if (!topo) -return -ENOMEM ; + *size =le16_to_cpu (size_resp.size); - ret =gb_operation_sync (connection,GB_AUDIO_TYPE_GET_TOPOLOGY ,NULL ,0 , - topo, size); -if (ret) { -kfree (topo); -return ret; - }
drivers/staging/greybus/audio_gb.c int gb_audio_gb_get_topology(struct gb_connection *connection, · line 32
Quoted 10 lines
drivers/staging/greybus/audio_gb.c +8
-1+return 0 ; +} +EXPORT_SYMBOL_GPL (gb_audio_gb_get_topology_size); - *topology = topo; +int gb_audio_gb_get_topology (struct gb_connection *connection, +struct gb_audio_topology *topology,u16 size) +{ +if (size <sizeof (*topology)) +return -ENODATA ;
This check should be done in gb_audio_probe() before the kzalloc().
Quoted 32 lines
drivers/staging/greybus/audio_gb.c +2
-1-return 0 ; +return gb_operation_sync (connection,GB_AUDIO_TYPE_GET_TOPOLOGY ,NULL ,0 , + topology, size); }EXPORT_SYMBOL_GPL (gb_audio_gb_get_topology);drivers/staging/greybus/audio_module.c +3
-6@@ -239,6 +239,7 @@ static int gb_audio_probe(struct gb_bundle *bundle,struct gb_audio_manager_module_descriptor desc;struct gbaudio_data_connection *dai, *_dai;int ret, i; +u16 size;struct gb_audio_topology *topology;/* There should be at least one Management and one Data cport */ @@ -304,16 +305,24 @@ static int gb_audio_probe(struct gb_bundle *bundle, } gbmodule->dev_id = gbmodule->mgmt_connection->intf->interface_id; -/* -* FIXME: malloc for topology happens via audio_gb driver -* should be done within codec driver itself -*/ - ret =gb_audio_gb_get_topology (gbmodule->mgmt_connection, &topology); + ret =gb_audio_gb_get_topology_size (gbmodule->mgmt_connection, &size);if (ret) { -dev_err (dev,"%d:Error while fetching topology\n" , ret); +dev_err (dev,"%d:Error while fetching topology size\n" , ret);
drivers/staging/greybus/audio_module.c static int gb_audio_probe(struct gb_bundle *bundle, · line 320
Quoted 10 lines
drivers/staging/greybus/audio_module.c +7
-0+ goto disable_connection; + } + + topology =kzalloc (size,GFP_KERNEL ); +if (!topology) { + ret = -ENOMEM ; goto disable_connection; } + ret =gb_audio_gb_get_topology (gbmodule->mgmt_connection, topology, size);
It's unfortunate that we don't save the size anywhere. This code relies on trusting the firmware for its security. It would be better to move away from that.
drivers/staging/greybus/audio_module.c static int gb_audio_probe(struct gb_bundle *bundle, · line 322
Quoted 2 lines
drivers/staging/greybus/audio_module.c +2
-0+if (ret) { +dev_err (dev,"%d:Error while fetching topology\n" , ret);
This is a weird format for a warning. Normally it %d would come last. I see that you copied the other printk from earlier, but don't do that. Only copy good code, not the weirdo stuff.
regards,
dan carpenter
Quoted 9 lines
drivers/staging/greybus/audio_module.c +3
-0+ goto free_topology; + } +/* process topology data */ ret =gbaudio_tplg_parse_data (gbmodule, topology);if (ret) {Signature · 1 line
2.53.0
Quoted 7 lines · Dan Carpenter
Quoted 6 lines · On Mon, Jun 29, 2026 at 08:19:41PM +0530, [email protected] wrote:
drivers/staging/greybus/audio_module.c +3
-0+ topology =kzalloc (size,GFP_KERNEL ); +if (!topology) { + ret = -ENOMEM ; goto disable_connection; }
Quoted 6 lines
drivers/staging/greybus/audio_module.c static int gb_audio_probe(struct gb_bundle *bundle, · line 320
Quoted 1 line
drivers/staging/greybus/audio_module.c +1
-0+ ret =gb_audio_gb_get_topology (gbmodule->mgmt_connection, topology, size);It's unfortunate that we don't save the size anywhere. This code relies on trusting the firmware for its security. It would be better to move away from that.
(just ignore this comment. It's just random thoughts, not related to your patch. Someone took some steps to try make this code less trusting recently).
regards,
dan carpenter
PATCH v2 1/1 staging: greybus: audio: split gb_audio_gb_get_topology()
In reply to Dan CarpenterFrom: Aditya Chari S <[email protected]>
Split gb_audio_gb_get_topology() into two functions:gb_audio_gb_get_topology_size() to fetch the topology size, and gb_audio_gb_get_topology() to fetch the topology data into a caller-provided buffer. This moves buffer allocation out of the audio_gb protocol helper and into gb_audio_probe(), where it belongs, addressing a long-standing FIXME.
---
v2:
- Store size as size_t instead of u16, per Dan Carpenter.
- Move the size validation (size < sizeof(*topology)) out of gb_audio_gb_get_topology() and into gb_audio_probe(), before the kzalloc(), per Dan Carpenter.
- Fix dev_err() format strings so %d is no longer printed first; put it at the end of the message instead, per Dan Carpenter.
Compile-tested with make M=drivers/staging/greybus modules. All modified files (audio_codec.h, audio_gb.c, audio_module.c) compile without errors or warnings. checkpatch.pl --no-tree passes clean on all three files.
--- drivers/staging/greybus/audio_codec.h | 4 ++-- drivers/staging/greybus/audio_gb.c | 7 ++----- drivers/staging/greybus/audio_module.c | 12 +++++++++--- 3 files changed, 13 insertions(+), 10 deletions(-)
drivers/staging/greybus/audio_codec.h +2 -2
@@ -179,9 +179,9 @@ void gbaudio_unregister_module(struct gbaudio_module_info *module);/* protocol related */ int gb_audio_gb_get_topology_size (struct gb_connection *connection, -u16 *size); +size_t *size);int gb_audio_gb_get_topology (struct gb_connection *connection, -struct gb_audio_topology *topology,u16 size); +struct gb_audio_topology *topology,size_t size);int gb_audio_gb_get_control (struct gb_connection *connection,u8 control_id,u8 index,struct gb_audio_ctl_elem_value *value);
drivers/staging/greybus/audio_gb.c +2 -5
@@ -9,7 +9,7 @@#include "audio_codec.h" int gb_audio_gb_get_topology_size (struct gb_connection *connection, -u16 *size) +size_t *size) {struct gb_audio_get_topology_size_response size_resp;int ret;
@@ -26,11 +26,8 @@ int gb_audio_gb_get_topology_size(struct gb_connection *connection,EXPORT_SYMBOL_GPL (gb_audio_gb_get_topology_size);int gb_audio_gb_get_topology (struct gb_connection *connection, -struct gb_audio_topology *topology,u16 size) +struct gb_audio_topology *topology,size_t size) { -if (size <sizeof (*topology)) -return -ENODATA ; -return gb_operation_sync (connection,GB_AUDIO_TYPE_GET_TOPOLOGY ,NULL ,0 , topology, size); }
drivers/staging/greybus/audio_module.c +9 -3
@@ -239,7 +239,7 @@ static int gb_audio_probe(struct gb_bundle *bundle,struct gb_audio_manager_module_descriptor desc;struct gbaudio_data_connection *dai, *_dai;int ret, i; -u16 size; +size_t size;struct gb_audio_topology *topology;/* There should be at least one Management and one Data cport */
@@ -307,7 +307,13 @@ static int gb_audio_probe(struct gb_bundle *bundle, ret =gb_audio_gb_get_topology_size (gbmodule->mgmt_connection, &size);if (ret) { -dev_err (dev,"%d:Error while fetching topology size\n" , ret); +dev_err (dev,"Error while fetching topology size: %d\n" , ret); + goto disable_connection; + } + +if (size <sizeof (*topology)) { +dev_err (dev,"Invalid topology size: %zu\n" , size); + ret = -ENODATA ; goto disable_connection; }
@@ -319,7 +325,7 @@ static int gb_audio_probe(struct gb_bundle *bundle, ret =gb_audio_gb_get_topology (gbmodule->mgmt_connection, topology, size);if (ret) { -dev_err (dev,"%d:Error while fetching topology\n" , ret); +dev_err (dev,"Error while fetching topology: %d\n" , ret); goto free_topology; }
Signature · 1 line
2.53.0
Re: [PATCH v2] staging: greybus: audio: split gb_audio_gb_get_topology()
Quoted 19 lines · On Tue, Jun 30, 2026 at 10:16:02PM +0530, [email protected] wrote:
From: Aditya Chari S <[email protected]>
Split
gb_audio_gb_get_topology()into two functions:gb_audio_gb_get_topology_size()to fetch the topology size, andgb_audio_gb_get_topology()to fetch the topology data into a caller-provided buffer. This moves buffer allocation out of theaudio_gbprotocol helper and intogb_audio_probe(), where it belongs, addressing a long-standing FIXME.Signed-off-by Aditya Chari S <[email protected]>---
v2:
- Store size assize_tinstead of u16, per Dan Carpenter.
- Move the size validation (size <sizeof(*topology)) out ofgb_audio_gb_get_topology()and intogb_audio_probe(), before thekzalloc(), per Dan Carpenter.
- Fixdev_err()format strings so %d is no longer printed first; put it at the end of the message instead, per Dan Carpenter.
Quoted 5 lines
Compile-tested with
make M=drivers/staging/greybus modules. All modified files (audio_codec.h,audio_gb.c,audio_module.c) compile without errors or warnings. checkpatch.pl --no-tree passes clean on all three files.
---
This v2 patch is built on top of the v1 patch which we're not going to apply. It needs to be folded into the v1 patch instead.
Quoted 61 lines
drivers/staging/greybus/audio_codec.h | 4 ++-- drivers/staging/greybus/audio_gb.c | 7 ++----- drivers/staging/greybus/audio_module.c | 12 +++++++++--- 3 files changed, 13 insertions(+), 10 deletions(-)drivers/staging/greybus/audio_codec.h +2
-2@@ -179,9 +179,9 @@ void gbaudio_unregister_module(struct gbaudio_module_info *module);/* protocol related */ int gb_audio_gb_get_topology_size (struct gb_connection *connection, -u16 *size); +size_t *size);int gb_audio_gb_get_topology (struct gb_connection *connection, -struct gb_audio_topology *topology,u16 size); +struct gb_audio_topology *topology,size_t size);int gb_audio_gb_get_control (struct gb_connection *connection,u8 control_id,u8 index,struct gb_audio_ctl_elem_value *value);drivers/staging/greybus/audio_gb.c +2
-5@@ -9,7 +9,7 @@#include "audio_codec.h" int gb_audio_gb_get_topology_size (struct gb_connection *connection, -u16 *size) +size_t *size) {struct gb_audio_get_topology_size_response size_resp;int ret;@@ -26,11 +26,8 @@ int gb_audio_gb_get_topology_size(struct gb_connection *connection,EXPORT_SYMBOL_GPL (gb_audio_gb_get_topology_size);int gb_audio_gb_get_topology (struct gb_connection *connection, -struct gb_audio_topology *topology,u16 size) +struct gb_audio_topology *topology,size_t size) { -if (size <sizeof (*topology)) -return -ENODATA ; -return gb_operation_sync (connection,GB_AUDIO_TYPE_GET_TOPOLOGY ,NULL ,0 , topology, size); }drivers/staging/greybus/audio_module.c +1
-1@@ -239,7 +239,7 @@ static int gb_audio_probe(struct gb_bundle *bundle,struct gb_audio_manager_module_descriptor desc;struct gbaudio_data_connection *dai, *_dai;int ret, i; -u16 size; +size_t size;struct gb_audio_topology *topology;/* There should be at least one Management and one Data cport */
drivers/staging/greybus/audio_module.c static int gb_audio_probe(struct gb_bundle *bundle, · line 310
Quoted 5 lines
drivers/staging/greybus/audio_module.c +1
-1@@ -307,7 +307,13 @@ static int gb_audio_probe(struct gb_bundle *bundle, ret =gb_audio_gb_get_topology_size (gbmodule->mgmt_connection, &size);if (ret) { -dev_err (dev,"%d:Error while fetching topology size\n" , ret); +dev_err (dev,"Error while fetching topology size: %d\n" , ret);
Just leave this one as-is. It's from the original code. Although you added the word "size" so I guess that kind of makes changing it acceptable as well. The rule is you're allowed to make minor white space changes to line you're touching. So I guess either way is fine.
drivers/staging/greybus/audio_module.c static int gb_audio_probe(struct gb_bundle *bundle, · line 316
Quoted 6 lines
drivers/staging/greybus/audio_module.c +6
-0+ goto disable_connection; + } + +if (size <sizeof (*topology)) { +dev_err (dev,"Invalid topology size: %zu\n" , size); + ret = -ENODATA ;
I would probably have said -EINVAL is more appropriate.
drivers/staging/greybus/audio_module.c static int gb_audio_probe(struct gb_bundle *bundle, · line 328
Quoted 9 lines
drivers/staging/greybus/audio_module.c +1
-1goto disable_connection; }@@ -319,7 +325,7 @@ static int gb_audio_probe(struct gb_bundle *bundle, ret =gb_audio_gb_get_topology (gbmodule->mgmt_connection, topology, size);if (ret) { -dev_err (dev,"%d:Error while fetching topology\n" , ret); +dev_err (dev,"Error while fetching topology: %d\n" , ret);
This change is entirely unrelated so it's not allowed.
regards,
dan carpenter
Quoted 5 lines
drivers/staging/greybus/audio_module.c +0
-0goto free_topology; }Signature · 1 line
2.53.0
PATCH v2 1/1 staging: greybus: audio: split topology get into size and data calls
In reply to [email protected]From: Aditya Chari S <[email protected]>
gb_audio_gb_get_topology() combined three separate responsibilities into a single call: querying the topology size, allocating a buffer for it, and fetching the topology data into that buffer. This left callers with no way to perform any of these steps independently, and forced the kzalloc() allocation to live inside the protocol-layer driver rather than the caller, as already flagged by a FIXME comment at the call site in audio_module.c.
Split the function into two:
gb_audio_gb_get_topology_size() - queries only the topology size
gb_audio_gb_get_topology() - fetches topology data into a
caller-supplied buffer of a given size
Update the only caller, gb_audio_probe() in audio_module.c, to query the size first, allocate the topology buffer itself, then fetch the data into it, freeing the buffer via the existing free_topology error path on failure.
This resolves both the "TODO: Split into separate calls" comment above the original function in audio_gb.c and the FIXME comment at the call site in audio_module.c, both of which are removed as part of this change.
No functional change in behavior for the existing probe path.
Compile-tested with W=1, sparse (C=2), and checkpatch.pl; all clean on the three changed files (audio_gb.c, audio_module.c, audio_codec.h).
----------
v2:
- Fold in review feedback from Dan Carpenter.
- Store topology size as size_t instead of u16.
- Move topology size validation into gb_audio_probe() before kzalloc().
- Use -EINVAL for invalid topology size.
- Drop unrelated dev_err() formatting cleanup.
- Compile-tested with make M=drivers/staging/greybus.
- Run checkpatch.pl on the updated patch; no issues reported.
--- drivers/staging/greybus/audio_codec.h | 4 +++- drivers/staging/greybus/audio_gb.c | 32 +++++++++----------------- drivers/staging/greybus/audio_module.c | 27 +++++++++++++++++----- 3 files changed, 35 insertions(+), 28 deletions(-)
drivers/staging/greybus/audio_codec.h +3 -1
@@ -178,8 +178,10 @@ int gbaudio_register_module(struct gbaudio_module_info *module);void gbaudio_unregister_module (struct gbaudio_module_info *module);/* protocol related */ +int gb_audio_gb_get_topology_size (struct gb_connection *connection, +size_t *size);int gb_audio_gb_get_topology (struct gb_connection *connection, -struct gb_audio_topology **topology); +struct gb_audio_topology *topology,size_t size);int gb_audio_gb_get_control (struct gb_connection *connection,u8 control_id,u8 index,struct gb_audio_ctl_elem_value *value);
drivers/staging/greybus/audio_gb.c +11 -21
@@ -8,13 +8,10 @@#include <linux/greybus.h> #include "audio_codec.h" -/* TODO: Split into separate calls */ -int gb_audio_gb_get_topology (struct gb_connection *connection, -struct gb_audio_topology **topology) +int gb_audio_gb_get_topology_size (struct gb_connection *connection, +size_t *size) {struct gb_audio_get_topology_size_response size_resp; -struct gb_audio_topology *topo; -u16 size;int ret; ret = gb_operation_sync(connection, GB_AUDIO_TYPE_GET_TOPOLOGY_SIZE,
@@ -22,25 +19,18 @@ int gb_audio_gb_get_topology(struct gb_connection *connection,if (ret)return ret; - size =le16_to_cpu (size_resp.size); -if (size <sizeof (*topo)) -return -ENODATA ; - - topo =kzalloc (size,GFP_KERNEL ); -if (!topo) -return -ENOMEM ; - - ret =gb_operation_sync (connection,GB_AUDIO_TYPE_GET_TOPOLOGY ,NULL ,0 , - topo, size); -if (ret) { -kfree (topo); -return ret; - } - - *topology = topo; + *size =le16_to_cpu (size_resp.size);return 0 ; } +EXPORT_SYMBOL_GPL (gb_audio_gb_get_topology_size); + +int gb_audio_gb_get_topology (struct gb_connection *connection, +struct gb_audio_topology *topology,size_t size) +{ +return gb_operation_sync (connection,GB_AUDIO_TYPE_GET_TOPOLOGY ,NULL ,0 , + topology, size); +}EXPORT_SYMBOL_GPL (gb_audio_gb_get_topology); int gb_audio_gb_get_control(struct gb_connection *connection,
drivers/staging/greybus/audio_module.c +21 -6
@@ -239,6 +239,7 @@ static int gb_audio_probe(struct gb_bundle *bundle,struct gb_audio_manager_module_descriptor desc;struct gbaudio_data_connection *dai, *_dai;int ret, i; +size_t size;struct gb_audio_topology *topology;/* There should be at least one Management and one Data cport */
@@ -304,16 +305,30 @@ static int gb_audio_probe(struct gb_bundle *bundle, } gbmodule->dev_id = gbmodule->mgmt_connection->intf->interface_id; -/* -* FIXME: malloc for topology happens via audio_gb driver -* should be done within codec driver itself -*/ - ret =gb_audio_gb_get_topology (gbmodule->mgmt_connection, &topology); + ret =gb_audio_gb_get_topology_size (gbmodule->mgmt_connection, &size);if (ret) { -dev_err (dev,"%d:Error while fetching topology\n" , ret); +dev_err (dev,"%d:Error while fetching topology size\n" , ret); + goto disable_connection; + } + +if (size <sizeof (*topology)) { +dev_err (dev,"Invalid topology size: %zu\n" , size); + ret = -EINVAL ; goto disable_connection; } + topology =kzalloc (size,GFP_KERNEL ); +if (!topology) { + ret = -ENOMEM ; + goto disable_connection; + } + + ret =gb_audio_gb_get_topology (gbmodule->mgmt_connection, topology, size); +if (ret) { +dev_err (dev,"%d:Error while fetching topology\n" , ret); + goto free_topology; + } +/* process topology data */ ret =gbaudio_tplg_parse_data (gbmodule, topology);if (ret) {
Signature · 1 line
2.53.0
Quoted 34 lines · On Wed, Jul 01, 2026 at 02:19:08AM +0530, [email protected] wrote:
From: Aditya Chari S <[email protected]>
gb_audio_gb_get_topology()combined three separate responsibilities into a single call: querying the topology size, allocating a buffer for it, and fetching the topology data into that buffer. This left callers with no way to perform any of these steps independently, and forced thekzalloc()allocation to live inside the protocol-layer driver rather than the caller, as already flagged by a FIXME comment at the call site inaudio_module.c.Split the function into two:
gb_audio_gb_get_topology_size()- queries only the topology size
gb_audio_gb_get_topology()- fetches topology data into a
caller-supplied buffer of a given sizeUpdate the only caller,
gb_audio_probe()inaudio_module.c, to query the size first, allocate the topology buffer itself, then fetch the data into it, freeing the buffer via the existingfree_topologyerror path on failure.This resolves both the "TODO: Split into separate calls" comment above the original function in
audio_gb.cand the FIXME comment at the call site inaudio_module.c, both of which are removed as part of this change.No functional change in behavior for the existing probe path.
Compile-tested with W=1, sparse (C=2), and checkpatch.pl; all clean on the three changed files (
audio_gb.c,audio_module.c,audio_codec.h).Signed-off-by Aditya Chari S <[email protected]>
Quoted 10 lines
----------
v2:
- Fold in review feedback from Dan Carpenter.
- Store topology size assize_tinstead of u16.
- Move topology size validation intogb_audio_probe()beforekzalloc().
- Use-EINVALfor invalid topology size.
- Drop unrelateddev_err()formatting cleanup.
- Compile-tested withmake M=drivers/staging/greybus.
- Run checkpatch.pl on the updated patch; no issues reported.
---
Thanks!
regards,
dan carpenter
Greg KH
maintainerQuoted 27 lines · On Wed, Jul 01, 2026 at 02:19:08AM +0530, [email protected] wrote:
From: Aditya Chari S <[email protected]>
gb_audio_gb_get_topology()combined three separate responsibilities into a single call: querying the topology size, allocating a buffer for it, and fetching the topology data into that buffer. This left callers with no way to perform any of these steps independently, and forced thekzalloc()allocation to live inside the protocol-layer driver rather than the caller, as already flagged by a FIXME comment at the call site inaudio_module.c.Split the function into two:
gb_audio_gb_get_topology_size()- queries only the topology size
gb_audio_gb_get_topology()- fetches topology data into a
caller-supplied buffer of a given sizeUpdate the only caller,
gb_audio_probe()inaudio_module.c, to query the size first, allocate the topology buffer itself, then fetch the data into it, freeing the buffer via the existingfree_topologyerror path on failure.This resolves both the "TODO: Split into separate calls" comment above the original function in
audio_gb.cand the FIXME comment at the call site inaudio_module.c, both of which are removed as part of this change.
Quoted 6 lines
No functional change in behavior for the existing probe path.
Compile-tested with W=1, sparse (C=2), and checkpatch.pl; all clean on the three changed files (
audio_gb.c,audio_module.c,audio_codec.h).Signed-off-by Aditya Chari S <[email protected]>
Does not apply to my tree :(
Hi Greg,
Thanks for the heads up — I'll rebase against your current staging tree and resend as v3.
Regards,
Aditya
Quoted 37 lines · Greg KH
Quoted 27 lines · On Wed, Jul 01, 2026 at 02:19:08AM +0530, [email protected] wrote:
From: Aditya Chari S <[email protected]>
gb_audio_gb_get_topology()combined three separate responsibilities into a single call: querying the topology size, allocating a buffer for it, and fetching the topology data into that buffer. This left callers with no way to perform any of these steps independently, and forced thekzalloc()allocation to live inside the protocol-layer driver rather than the caller, as already flagged by a FIXME comment at the call site inaudio_module.c.Split the function into two:
gb_audio_gb_get_topology_size()- queries only the topology size
gb_audio_gb_get_topology()- fetches topology data into a
caller-supplied buffer of a given sizeUpdate the only caller,
gb_audio_probe()inaudio_module.c, to query the size first, allocate the topology buffer itself, then fetch the data into it, freeing the buffer via the existingfree_topologyerror path on failure.This resolves both the "TODO: Split into separate calls" comment above the original function in
audio_gb.cand the FIXME comment at the call site inaudio_module.c, both of which are removed as part of this change.Quoted 6 lines
No functional change in behavior for the existing probe path.
Compile-tested with W=1, sparse (C=2), and checkpatch.pl; all clean on the three changed files (
audio_gb.c,audio_module.c,audio_codec.h).Signed-off-by Aditya Chari S <[email protected]>Does not apply to my tree :(