From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oo1-f51.google.com (mail-oo1-f51.google.com [209.85.161.51]) (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 00B3740863B for ; Tue, 30 Jun 2026 12:13:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782821619; cv=none; b=TizgwpWO54c1scBdcfkmU0Ui0G/Xc+xIPcJJ6AEhJs87UZE8+kgj/15y3zp1ltS5jP0OD2D5vAmRL74d6xg/s2vbgPNOtQrv+WsvE4UZpElfgoMdcJvTYq9eMmczJtNW7nakeokJVuiQEX5QVJDCSxlr/yF2R4cmqjMkgkYzhqw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782821619; c=relaxed/simple; bh=EkTtoqFledxZU9O2TF2oKU/N+Oh0m18upvQnRnw/AM0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hP1N/JTqk9mC+TgReJHRuKpg367TE/U04RhbFv1QcFHsaVNkEG8nzIefWda8Uwl2ZepN6iVcdakHiNV0lEVqdBvxuQOM8K9+dW7sacm+04R/BgKPwAH2+Q0tUBq3eHjoHsDX1081x70lB0GHVuz6VME8LL6tWg8B59GNPHfSWn0= 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=pPSX9XRi; arc=none smtp.client-ip=209.85.161.51 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="pPSX9XRi" Received: by mail-oo1-f51.google.com with SMTP id 006d021491bc7-69de16f5e80so2258319eaf.0 for ; Tue, 30 Jun 2026 05:13:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782821617; x=1783426417; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=BIdV6zIifVX8xXJTc1qP/yM+e/D3Xonrexw/DMWskVo=; b=pPSX9XRiQhLZf9et7536iFZL9husKn6vL/M1qNf9wA4jExssbKEJT2x3jC5kkWrR5j H2EkWz8nF8n9G9dXDDEqx8czgYNoMWEUUUjaVp4A6ujtsF+WPplZLQpmVVYEeaCR3DG/ 4RUBgiIuwp+5znc0ZjrL4/Gt1fThSfgsStP/IaevlrDOly5D8aVY/6NL5tXjkSnLsOYa 4Vbp8w2IrjeWGbnWrkim9YcGI8VBG50eAJX1qU5raZP40eEjgeaQaMza52e9oYpjPwPE dLhcfaExjwn2qe6YfiSc0ol1uXGAegF6M7f/KOOl1shOhG2DW+Pjfhnotjkusj1Ydcl/ YXlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782821617; x=1783426417; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BIdV6zIifVX8xXJTc1qP/yM+e/D3Xonrexw/DMWskVo=; b=CZy0QSqRCs2XFcyU+exB5FXyofZ1Y1lBTWFHtgRjF3QGxHm5ru2mpolR9VFYmkyOLz u1TNONipKgpaS0ukafSVM6QNzaoGza0LGIDNL6VWWlKiAmsh5e4skEli9XXRBmjJw9Aa 1EXLqUj+Jf8qD6tyIfnefKWLh7s2HRnlm4DqzPl1PmR2lDycvLRVzbmJg98ejeNbNXR9 nXs2KzRu10eW6L6AfESC7+eOUQd13pngulFKfyatgTt7bOnYkDC1i/BYsG5EOJQRmf+H U08WafvPsFs5tvRDNZ06qGJEZgByxbG7tYJ3X5a68vnHIh6gL4m0UinaR149LDmPYYG4 aRAQ== X-Forwarded-Encrypted: i=1; AFNElJ9PksYFuyNmmkqdKWR5bLCL6PRta4/Tw225grBH0oQyXVT2qUee2l1ZzxBBEgz6WqDEnZs1fLGWO7/cSMo=@vger.kernel.org X-Gm-Message-State: AOJu0Yz8Yoq534NnWQBwzi/HZgjw+EbLjmkkYimYNK7I9cahuR0+HQb9 cdC8PcN/37fu7YysC7sTxzT44kZEIUyhhQsRbAT2st6J1/XUyIKcv1XH X-Gm-Gg: AfdE7cm7T/SrLdvTUf2IyiDj8ofPFuW7IULiLTJw/tzf4+6E+RDm9XCRE5RYuKBwXot 5j/oiunERKON8tBhPTShF1irnvNL1xgOjzbMNP1Gde5+wwUXb7fliRrK0QG9TMsIVSgBXNlSKnl EmA80HH07+WaA7Yb2IVVDTZG2huanaAsYlq+Q2/+P9rhqbULaJLqhhHgpAzKhcH7BiAzhhItSIC Y95unKxTCJTMlDQa9UXr+V87M58iRCpMoS5AFo4G4Pp3hGM5SvP6VChIKMQNkOC/x5MF6/KgS9i +aVSRpJFAtRq5nEU0udG5oLlP78WuIMEi5kXBDvdnsaWuqpE1mlIDyIU1Y7yADOmXuVAd9S34jK b70lMgthj0iVZldVs0d6NBQ2P2wCy/tHf9UiytvVtFM+tERSgqwmbNQ1DgUpwTAwTBNDeh7BcJE SMF0zz5g== X-Received: by 2002:a05:6808:318e:b0:489:6c24:9d26 with SMTP id 5614622812f47-495fd72d80dmr81857b6e.27.1782821616728; Tue, 30 Jun 2026 05:13:36 -0700 (PDT) Received: from localhost ([74.80.182.100]) by smtp.gmail.com with ESMTPSA id 5614622812f47-49354e517dfsm8484496b6e.11.2026.06.30.05.13.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2026 05:13:34 -0700 (PDT) Date: Tue, 30 Jun 2026 15:13:28 +0300 From: Dan Carpenter To: adi25charis@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 Subject: Re: [PATCH] staging: greybus: audio: split topology get into size and data calls Message-ID: 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260629144941.33818-1-adi25charis@gmail.com> On Mon, Jun 29, 2026 at 08:19:41PM +0530, adi25charis@gmail.com wrote: > 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). Put this sort of meta commentary under the --- cut off line. Also compile the whole module, not just the modified files. > > 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); Please store sizes in size_t. > 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; This check should be done in gb_audio_probe() before the kzalloc(). > > - 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); 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. > + 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 > + goto free_topology; > + } > + > /* process topology data */ > ret = gbaudio_tplg_parse_data(gbmodule, topology); > if (ret) { > -- > 2.53.0 >