All of lore.kernel.org
 help / color / mirror / Atom feed
From: adi25charis@gmail.com
To: error27@gmail.com
Cc: vaibhav.sr@gmail.com, mgreer@animalcreek.com, johan@kernel.org,
	elder@kernel.org, gregkh@linuxfoundation.org,
	greybus-dev@lists.linaro.org, linux-staging@lists.linux.dev,
	linux-kernel@vger.kernel.org,
	Aditya Chari S <adi25charis@gmail.com>
Subject: [PATCH v2] staging: greybus: audio: split gb_audio_gb_get_topology()
Date: Tue, 30 Jun 2026 22:16:02 +0530	[thread overview]
Message-ID: <20260630164602.37663-1-adi25charis@gmail.com> (raw)
In-Reply-To: <akOy6ORYkzHxodYU@stanley.mountain>

From: Aditya Chari S <adi25charis@gmail.com>

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.

Signed-off-by: Aditya Chari S <adi25charis@gmail.com>
---
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(-)

diff --git a/drivers/staging/greybus/audio_codec.h b/drivers/staging/greybus/audio_codec.h
index be5a2a86b..b45cd257d 100644
--- a/drivers/staging/greybus/audio_codec.h
+++ b/drivers/staging/greybus/audio_codec.h
@@ -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);
diff --git a/drivers/staging/greybus/audio_gb.c b/drivers/staging/greybus/audio_gb.c
index e6356643d..2e6f155d8 100644
--- a/drivers/staging/greybus/audio_gb.c
+++ b/drivers/staging/greybus/audio_gb.c
@@ -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);
 }
diff --git a/drivers/staging/greybus/audio_module.c b/drivers/staging/greybus/audio_module.c
index 1163cf093..806533f03 100644
--- a/drivers/staging/greybus/audio_module.c
+++ b/drivers/staging/greybus/audio_module.c
@@ -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;
 	}
 
-- 
2.53.0


  parent reply	other threads:[~2026-06-30 16:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-29 14:49 [PATCH] staging: greybus: audio: split topology get into size and data calls adi25charis
2026-06-30 12:13 ` Dan Carpenter
2026-06-30 12:16   ` Dan Carpenter
2026-06-30 16:46   ` adi25charis [this message]
2026-06-30 18:59     ` [PATCH v2] staging: greybus: audio: split gb_audio_gb_get_topology() Dan Carpenter
2026-06-30 20:49 ` [PATCH v2] staging: greybus: audio: split topology get into size and data calls adi25charis
2026-07-01  5:04   ` Dan Carpenter

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=20260630164602.37663-1-adi25charis@gmail.com \
    --to=adi25charis@gmail.com \
    --cc=elder@kernel.org \
    --cc=error27@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=greybus-dev@lists.linaro.org \
    --cc=johan@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=mgreer@animalcreek.com \
    --cc=vaibhav.sr@gmail.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.