From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ADDF43FBB6F for ; Mon, 29 Jun 2026 14:50:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782744603; cv=none; b=R2FwYlPt6nDratN8pXyR84rwg0vjFl+GSMx0+LlUspc8NBEnnINgEJSCVUsuyZCTNrAoyoDppIROJ8o68BTlSUrAstwLNGECM0E50iAlXGzgDf4ehvBJnVgArE4ybmNBTVakR/7MyLFu6H9vKxblsga63Zk+b2t4nEpnO7blhKw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782744603; c=relaxed/simple; bh=MfPygXF5akVPsKxz3CGdHJDI2hAoehZ7pchI2qJH/ow=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=aWbf9giCAYTL5YoffXYYpjxLGentM35ZIr6u3bawHSXW+4/0eTBwAnEIGJ4bJnZdlGxVCU4PwxfETPWGvzAbaJOZny5Pqt76j5Vrmswvkl2gbVCVfsl8A42uzCWUAxDI0Jm1F5q6i43djoJTVrLDJP6bR2vBDhjKrPD5nNF7F98= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=b0wKODcH; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="b0wKODcH" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2c9e8a1d256so13053795ad.1 for ; Mon, 29 Jun 2026 07:50:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782744600; x=1783349400; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=U3IH7lTasgN8z7TKzZJYuQBYYqraZCPUHS7aDOkklfQ=; b=b0wKODcHPmzz+1ijGL9UhlqjT6MdbtilTtTyT5zYx364uPlzDitgCivZ61Hj/Z+sjC A84+g8n/MwgeBcuNkRg/MzO2yJT92QGcUqk63TQrKQCkA+4OEp1Rqv754Vs1DNHNBxX0 JGjwliaxomFcKI6iLYq4g4+wnEM2XyJurvi5/96kkLNwLfGddkO2dtR5kogtUEWBcinY DM/uxhkS63dcQNzR8NCCGusoVTfJvlhQy0VKd2DgEw50vD6RUC8RYlH2XYa51/+alyW7 iwgnoDjqFu7v4LCjTVLkyCOZTDOnx7IkHnflPnzpMqDswe/TRP41cWc7s6/HcArBERrk 4pAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782744600; x=1783349400; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=U3IH7lTasgN8z7TKzZJYuQBYYqraZCPUHS7aDOkklfQ=; b=Rvvk10YJFp7q95x8eMxFTlvISEQPc7vHxZ66xrC6/rWnAnzKQRe5dd0hFJr1AC6cwN KQbm5iKerTpvWl+cqoLTwZm7EounWddWUAgFLzO9reNLG7SRId7D9PzUdupxSR53yOKR 0ruZg//Ik8BhjlvOhJxIUlNPS3MzEN83KqoVUCRPlGlijYSU6039gJFxa1y9yC30/xvI d8gtkWiON32J421Yybmc1Ki+dhOe3Noee3300M0LGdgSuJNOYhFhKe5TThyM46Nycp8d L6Bn+Hf/cJmS+7CL71z4RGAHRIQLXd54hnF5OVpCkRh3qBuREKI279eodRiSjXhN2fVP taMA== X-Forwarded-Encrypted: i=1; AHgh+RozD3Z/Hcyz9tqjPR9hop8EWwRZA+TfxECxuEbbmQjsUTMlknj5diDboqgJzgfni4PXTve+GUR2dqkdKDk=@vger.kernel.org X-Gm-Message-State: AOJu0YyYKuFgJUcj9EEZC/j4zI02pHayLu9NzFjUORWQU5D0hdDYkflO M4PYYhMDDPLjd4P0uRnKIP+XHa+veWUwj8XI70GEljOBMmDAt+awpO6c X-Gm-Gg: AfdE7clX+6GmhIx3QdoFsXEZwF0Hz48FAH8CZtuXBT+V8B6svRSD8I/fGE00Rmfczg8 6gnJStNIfcgpx8vD3KqBvwYDuaepZzzGFL+WhNPVgMsCCgRVG+h6IfIevuAUiQRrq9dNa2zSnIQ 5RxCz/Wgns/m5QDBTWWPSjVuIMFoNw2AR9qzcVIwrTjPjkCHL5BD4x7U6bh3u2wX71NdWsEktAT k16Gwduk7kE1nHPLqxXYND3azjqM4IDW/8E0C9JVjjqWRxjBvLuxEKE3KxW/AjpQECOxmh6qvZs +eIdIGh2GFBNL8YxNkBRN+CZ46LmjvEaAnRqHhm0Em8ELcHT22zJR14SAPJA6Qlm/AG69YR1HcR /TyZLPO0qmSgkDr0i1WqNLcYC6bM/KykGPw+RwJq0kPvtfShnH2rv6J+4OTVmfy+DQ9iiHcO9GV ja2c8m3M1Qg36dYns/5EUXnVXEHEl9LD/mOK4KhIaXCr9g6MhLxpQIPoU= X-Received: by 2002:a17:903:1a24:b0:2ca:329:3d96 with SMTP id d9443c01a7336-2ca03293fd1mr28737305ad.3.1782744599684; Mon, 29 Jun 2026 07:49:59 -0700 (PDT) Received: from kernel-dev.multipass ([49.36.101.14]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ca0e498ff5sm17873205ad.38.2026.06.29.07.49.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jun 2026 07:49:59 -0700 (PDT) From: adi25charis@gmail.com To: vaibhav.sr@gmail.com, mgreer@animalcreek.com, johan@kernel.org, elder@kernel.org, gregkh@linuxfoundation.org Cc: greybus-dev@lists.linaro.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Aditya Chari S Subject: [PATCH] staging: greybus: audio: split topology get into size and data calls Date: Mon, 29 Jun 2026 20:19:41 +0530 Message-ID: <20260629144941.33818-1-adi25charis@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Aditya Chari S 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). Signed-off-by: Aditya Chari S --- 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(-) diff --git a/drivers/staging/greybus/audio_codec.h b/drivers/staging/greybus/audio_codec.h index f3f7a7ec6..be5a2a86b 100644 --- a/drivers/staging/greybus/audio_codec.h +++ b/drivers/staging/greybus/audio_codec.h @@ -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); diff --git a/drivers/staging/greybus/audio_gb.c b/drivers/staging/greybus/audio_gb.c index 9d8994fdb..e6356643d 100644 --- a/drivers/staging/greybus/audio_gb.c +++ b/drivers/staging/greybus/audio_gb.c @@ -8,13 +8,10 @@ #include #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); diff --git a/drivers/staging/greybus/audio_module.c b/drivers/staging/greybus/audio_module.c index 12c376c47..1163cf093 100644 --- a/drivers/staging/greybus/audio_module.c +++ b/drivers/staging/greybus/audio_module.c @@ -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) { -- 2.53.0