From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 2ACD03C4B83 for ; Tue, 30 Jun 2026 16:46:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782837976; cv=none; b=SlxPtmEsmZ0xcmuDmZQva8WaYLMRzHLRsGvqeQKL4WPsTwRz7t3I2e0qbCvlRXx7oBsf7NCF8gyNWMw6Fl4RwwKebs/mNKc/NfRFo8Ey6f9GrYNhyWNr4P0aRJeZ3WYWsVHqVCblvkwGh3KXYxJ13f8sFLQIvtG45XuS8X9Cs68= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782837976; c=relaxed/simple; bh=tJsTMzKtM2ckujc94qHb7B5O1XskWikXz82K3hR7thA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OstKLlb0LlfSAfqqA/0U8l6hXNq2A70XKcbP9lmZ+7ewLz6NKLj1ZgZiN+B1cTdneARm5JoxoFLfv5t1myUu6jq4SBWdur+FuMBtZqn0qNCPhpLAjW9FrqxoQPXsOo+D8+ZfAD2VPfGwBbLWU7CHnei0EVH7PHR9XkHMWxgKaB0= 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=KK6SMCF0; arc=none smtp.client-ip=209.85.214.175 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="KK6SMCF0" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2c9e8a1d256so25206665ad.1 for ; Tue, 30 Jun 2026 09:46:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782837974; x=1783442774; 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=HHhIFB/lwAV7YlLBcirT3lG64iGvOufo3zoAL+EAuJg=; b=KK6SMCF0CwIRb+ckyL7eUBCT97QNS6TKjrIWFLFFx8jTGHnPqhqmfcTgytkZQHNBwb CU5OxHnFn0iPArmmOH/xtBlIsCNoZKtr4Zms2zfcZhDh1oWsYXLFHdm9ouoGUX6hEPwE 5DqneSj5/nCPXpbB1F0HUckQ58svf+zQaTlqJqcptimu1NeZNVKF+EvO+NiYlq0nmPm7 fPTf+XAaQVJT+9FL9uBWozcG9l6SvI4+Xoj9gKeaG4S3XMxcY6SkXekUuxOEwFQaZ78y Gizcbnzn5qDmn9cbqdq81yVdRihTA9c0ZSu6dN+vECyP5bimsZu/BJp6rHl5edH+Is9j hl5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782837974; x=1783442774; 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=HHhIFB/lwAV7YlLBcirT3lG64iGvOufo3zoAL+EAuJg=; b=XR1B4/RuHtvJlReEwpFE0wfo1LKDJcP9L5185l8ARO4NFSPrbZTX5YpeuPyU1F7AoS XTzcbcC8myHG7hzu87fBFos12f3e89qmRc0OUflcZcL6QBlPGQeTM2+q3ERPy3g977d5 3phjWq3zYsYHRMvGwHVBRAfvn4JmJzgpFn+74iECM1DsFJZP1pKTSLaLCXZfj4kAlJcF W+cY5zr5gm+Fw0R7It763Mh2/A8ocPiySzXOzepLFW6GZGboQlWdieeKN5MkCFF+k6Jn TqCZSszNHS0hA5DVgv2Z5byprZ3zmlSxl4woX4ociTcpjwy7qrDDpBZo19zD1YtnrsZs tp8w== X-Forwarded-Encrypted: i=1; AHgh+RoP3IeIDP117HVQZR7sxhz/iPOclFRmIkXGKyhovEaK/jGBCPoUcTY6AtFiu5DKbxjxDjSwlVSar6I/YWU=@vger.kernel.org X-Gm-Message-State: AOJu0Ywg2zI0Vy+r2CcqE5pFBCkkwLCRr45qsh4jT32zLLxGlp81q8My tlkS4ql0RKDLHHYvyCqmQIcp2AOrDv27nXRl/oUZzIzCAC40eD3dFV14 X-Gm-Gg: AfdE7cnFOzSHhqbnp850s9vWrO7t49YmH7Ez9QxXhRz8JSca1w/YP5ui44Vccg2XSn7 n0q2hWOyQCfw7wypaaEteeKpWGdVJCYou95PjynQZs3wvrXDb1NfULDKopR9IxJ9+l3mmLwuqQ5 ZPWqNJdHFomm+EqNG5ut09/XbiZefviHu1UAGFMwNLI84KZtbpX1qXVit/R9YYWwVd7iU6ywXkC ckx2xHeOmAo9HMEIPQ+6hqYP9G99EehwOnyFzPyw4TiGu5QMuTUsq4GTaZxK7Fz/AGHvf1PO9gc EjCw8MX4nwknC4vn5u/26v6P4ug5f06V8Ccn6CZG4fymZlhxkkNQ+rxYiWIs8lKgJgj7ZMIpNgr HRr75LmWmiQ31Qw6+0xX91AeSPs0jrIZXpNoN17BhedIMx6GkE6/PGRU/62prXe/YW2Hvakwg6A 9bZAoxeRG3QBr0/UTk4mVQ3DjJrJ1r1m54Gv11MZ3L4OP3+72zR/tNuwo= X-Received: by 2002:a17:903:234d:b0:2ca:2073:3119 with SMTP id d9443c01a7336-2ca2ea1d0dfmr32374435ad.32.1782837974269; Tue, 30 Jun 2026 09:46:14 -0700 (PDT) Received: from kernel-dev.multipass ([49.36.101.14]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ca3828b0e7sm17583155ad.47.2026.06.30.09.46.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2026 09:46:13 -0700 (PDT) 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 Subject: [PATCH v2] staging: greybus: audio: split gb_audio_gb_get_topology() Date: Tue, 30 Jun 2026 22:16:02 +0530 Message-ID: <20260630164602.37663-1-adi25charis@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: 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 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 --- 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