From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f173.google.com (mail-dy1-f173.google.com [74.125.82.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 7651D3BE628 for ; Tue, 30 Jun 2026 20:49:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782852562; cv=none; b=pUO++pAQr4QVuYnlSaMCqWf33pYtyGq88wNGu+8L7CT7Ede738b8dcG7UiJihQW5uJVyGA46/cula4taDv3NLk0dxRtN5iihWAdYzg3cfkROk72jySpyITCQ+vGPVqnCqU7KYf8JjNyANa6j14BGRp63vqccMEKT0typezjq1SY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782852562; c=relaxed/simple; bh=rTNXmBVWAS5n2+/3LHVSjM6xu9gkPeS4/DADE/TX0Cw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dtOwtzntPTYfOQ0Y8zTBJpk1XDQwt4+IyXohOmpfMA00BME8BcskxlOCGSsQysjzY6SQ19J7o3aUYdesSC81cmXz8VeXzuJc9jkPmO7dZJ4817HFNs5RLScjvGH2xnCqhv6jFlVAfUnsBbWkMEvjYOV0XHGPmmLuRaC3Z/0rH6M= 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=qQnRrxN3; arc=none smtp.client-ip=74.125.82.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="qQnRrxN3" Received: by mail-dy1-f173.google.com with SMTP id 5a478bee46e88-30df5854e1eso893516eec.0 for ; Tue, 30 Jun 2026 13:49:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782852560; x=1783457360; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QH7GLHNGfwBkJqHxvx3I3p3T8oUpVImJRLd2zYY0WZg=; b=qQnRrxN3zsWWCSP74vRj7U5y68h7y60gKn+ypk5wsPddDfER4YJ9Hz+uJSaN4NPtHG 3aHiMZ8r50SED57b3QlnEkqB5BJLTD5JOQhWReGfqe1MaIAXa3WAmCUElY+YHBXXth0S trM2QAubU7Qe6UC+BPJV+IRd2DhTaQKpVI7tgdjxHp4s3sSVt8CF5lG0guzt2NAYeOSK DIKBteyaze11fDKllkyJA0mpjP81wtr2lFhHcs0GE0YS/g/xsMRZr78R1i5iANdu0e6b RtUPaeI2b/9MK2iBXg3I6ifIGOjKC42hKGQpAodgDaJm7X0nEr/6L2kIWbUE46UX8vH5 WLXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782852560; x=1783457360; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=QH7GLHNGfwBkJqHxvx3I3p3T8oUpVImJRLd2zYY0WZg=; b=bTYFxAHA9iPia/ILdt0h+OAhq813zEFZ5kBl0lu2axmQBSB+6ZN8BJM1P/Sh8vNOj5 +NGaEK8hF3gwddE1EZKtzdE8YMbA8Yiy6cZ/KS+xz254Rey1rBxymjRkW5umDXDWYHsF 5d6wXAIk93yoUGG5doqOj1R91vozdMxkjlRN4ZtFwwJKtmsUSt7E0iTHPThZu8DcClCt spKYhQHGrOWiTMML+fZnhcAQ0ncvyz4aSLa9uyFFguhUudIdt5GbNotSnyJaFECltSor K0wLdRuqIfi+XIsWy1T3zlI5THm2GGqkdQiy6Y8/nr49nSEjmbQo24GSDmRDXYXc+IWb plOw== X-Forwarded-Encrypted: i=1; AHgh+RqsSEFArdRSw4XR1Ydced1oBFqxSEo1sV/6rQrHdabRQvTVxhQbsTXSep6iQ+FcPvALlJvF19SghMMKUyU=@vger.kernel.org X-Gm-Message-State: AOJu0Yyc1zrP4aRow1VvKDwIdu2fJUMYeNhQ7NC5NJPJK9e1+dcVYGH5 Kx7qEdPYq38c7O+Vhlb8Y6gXrt5CU87XYtFwlQrzbTh1ZblnR6t3s6oV X-Gm-Gg: AfdE7cmMTtXCx1IcuhMobzExlPalHCCrW6w61NjqFQwg7yKKROniA+Fj7SApyhDo+Yt Xn5JqJrw4ioISCPDr+mnwvxefSbwECh27ReUUTCwELjzH8SqAmcs4xnkdpm0Jh+QJxYRp9WM+Ik jgB0TX8rnx+4Hd43WkgNYyZ0gbaDDxM1x+tJlmjaW1YrGWeaauGyVDxI1MyTbV0u8SggN7Vvm7X AR6qXlKp5PsMGuYvbkHE96gylN3KAu0n4RvslLaUgBYsORsP8J7Cz8IY+d+Y/OUM98a+rJd3Inb sltT2QSwvIwP3X0yMYMGoFUKvvImKZ+oEyDZXD2XzibVKBtFx1WUP4zR1zAYLYS8Ar52XbeoCEX RzQ20XEgaT6oAniR304J9zwovrhswa/VhCKICU2twcBgy6s5CieuSGxTBPxlZjgFUfJx0IEtFTs 2Sx4kF5ZPzKrKzw8VrO3/y3vGZL45fOAntPUbab/4zpWOd+ERWFMZQkIQ= X-Received: by 2002:a05:7301:7191:b0:30c:829a:f67c with SMTP id 5a478bee46e88-30ee9f6ce52mr1786800eec.3.1782852560400; Tue, 30 Jun 2026 13:49:20 -0700 (PDT) Received: from kernel-dev.multipass ([49.36.101.14]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30ee32519aesm10902297eec.27.2026.06.30.13.49.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2026 13:49:19 -0700 (PDT) From: adi25charis@gmail.com To: vaibhav.sr@gmail.com, mgreer@animalcreek.com, johan@kernel.org, elder@kernel.org, gregkh@linuxfoundation.org Cc: error27@gmail.com, greybus-dev@lists.linaro.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Aditya Chari S Subject: [PATCH v2] staging: greybus: audio: split topology get into size and data calls Date: Wed, 1 Jul 2026 02:19:08 +0530 Message-ID: <20260630204908.40206-1-adi25charis@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260629144941.33818-1-adi25charis@gmail.com> References: <20260629144941.33818-1-adi25charis@gmail.com> 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 ---------- 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(-) diff --git a/drivers/staging/greybus/audio_codec.h b/drivers/staging/greybus/audio_codec.h index f3f7a7ec6..b45cd257d 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, + 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); diff --git a/drivers/staging/greybus/audio_gb.c b/drivers/staging/greybus/audio_gb.c index 9d8994fdb..2e6f155d8 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, + 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, diff --git a/drivers/staging/greybus/audio_module.c b/drivers/staging/greybus/audio_module.c index 12c376c47..4cd1f42c1 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; + 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) { -- 2.53.0