Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp487840rwb; Fri, 4 Aug 2023 16:45:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IERuNUD8wYNDeuveBr0yXjQYsaDp81B6bF2SRqq7iqGW6i43QbNLT283MTCi32F2vSY5vSS X-Received: by 2002:a05:6a00:21cf:b0:680:d00c:b164 with SMTP id t15-20020a056a0021cf00b00680d00cb164mr3612187pfj.34.1691192723488; Fri, 04 Aug 2023 16:45:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691192723; cv=none; d=google.com; s=arc-20160816; b=WpCMP0vG/pxN2GOnwuhdJL/lbJUix9KbVXSinwvs5vA1T/SAny4DkAXAj48hEOsLgL VhuHGS3haH0i3mMmVIGSte2wj6Oc9/AsXGvF07BQvIL+Sf8RnmwY14SuK2f+M6tCMTrX gb5dToM2qmiV/PYZHWu0vrzxnKtbWBu9Hv9bQ4MfZls8FuoIuhEGVuL/EAPbtbsve8oR zpzCFB+0cT7AkIXxW3TItRQS5ofncF7nXwBf1QUkszRS+XD/dzi+YA5nOX9m60bHGqok 00nxHzauPWVxm73rF1HCUJxxEl1H8vJtYZqET5lH/TjK3Owxlgrbq4MvdA8/SRX7q1gG 6a+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=P2sRXegefcAEl333biQwB8H/OIszvfSG+NNQtF6Df6w=; fh=Is8mJMwgrDQwZ4pQHK3yz048T059Q3HoeG34fyZgXjo=; b=UaCgVS6zLIWJGlOsWF3EDuUZgMWAtNlcZ4t9kVFeZR1dNFw8QakCDJQSa41JBzIAYJ gRyQLXqsYXygLadYbn6rdzs9sbgx27hMLovgQ5YwVSj9TI/u65QgTQ6qelWuP8Pb9p5r GlKOblnC9Ss12BEFgcpsFBjHLcugA/0GYLz9Y9e8HYbFakjoGprTqvT9Cz1OWybNx+FJ 7FQiv9YY2wmP28045/FDMuQQ1mSrisxwoMCoVp/A0mdx24Se6pyTNg0JIWrun2dV8Z06 z+NBA9Vyj+qZe8/ndbZXfwn6RU5osM1d3EBeXOsEGTF9PFdODpRjeb0iLaKz9sCoEGox 7/5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=sJxIClGp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ch6-20020a056a00288600b0068263da2c43si2282317pfb.392.2023.08.04.16.44.53; Fri, 04 Aug 2023 16:45:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=sJxIClGp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229649AbjHDUbl (ORCPT + 99 others); Fri, 4 Aug 2023 16:31:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229534AbjHDUbj (ORCPT ); Fri, 4 Aug 2023 16:31:39 -0400 Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 737044C2D for ; Fri, 4 Aug 2023 13:31:37 -0700 (PDT) Received: by mail-oi1-x233.google.com with SMTP id 5614622812f47-3a5ad4477a7so1880619b6e.1 for ; Fri, 04 Aug 2023 13:31:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691181097; x=1691785897; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=P2sRXegefcAEl333biQwB8H/OIszvfSG+NNQtF6Df6w=; b=sJxIClGpPyW2HMO2BQEMygYCD21+kw9MK5mfE9Jl0bGSq/VBa+BVWlZgjp4vfpCM73 /itVh0mFRBTgD4yixQPHc5rzFzYUi9vH5ip3cSDi5ob+JbpJpA7B2wqzw23fFCr43Jfh K4sJnIIKjz9VqutdxqdXF3ZQRwpbRkVwe8mmNaKz3bZjS7Hg4DWd2sP5Le3PtrcKOATt cSBmau63g/oFdMg+agGgsDep9RcCgwjrZ4Z1PSAuBCsQS6FLKVO/KMAfQZ8mXo+7PaNM qSW3+wKvxkzd/FL0DxSr7mrtqvYRyX8W96NPAfdnJBn8cF++oNNSSv+qjGJ6QbRFHtXX DSfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691181097; x=1691785897; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=P2sRXegefcAEl333biQwB8H/OIszvfSG+NNQtF6Df6w=; b=IElFrVZ8eCvELGsoj+tyH1dHiFTQrE4kYvexeNfgyNb1rKaoBHiMejFFEx7G3l0Z++ 6T+u6LZFNa32pwlZebpXDht3Qr/PeVcK0pd7L68P2zAbdCVhUzku9/HdXaaZQs/R8g70 VWEwPIYLt5mwetJ5rSXbXy21HfjSmbY4iODxLo4/RPYQpPWK6dqLuylEiloHCD/eubWx KpKfA88SUs6gxmpnl/udBBgg8eoRqce6NRqtXkV/L7PUWqWdijEldQ3ILqHdQbBpwmzA d4bqvFmitU3LOryaLPwgsSbIWHYFsXAKu7xFephhevkOnvsn7DTkyAWRRk2sMKhtDUBV DJPA== X-Gm-Message-State: AOJu0Yx65eyplX3NYPYf3/WhjWG3V49IrIw5EQur95XxF3SY7Jk5SiG2 lidk/5wNG9BxknSSZuM7MZ4= X-Received: by 2002:a54:4e02:0:b0:3a4:57a7:b30e with SMTP id a2-20020a544e02000000b003a457a7b30emr2404804oiy.26.1691181096638; Fri, 04 Aug 2023 13:31:36 -0700 (PDT) Received: from madhu-kernel (99-145-207-128.lightspeed.austtx.sbcglobal.net. [99.145.207.128]) by smtp.gmail.com with ESMTPSA id e22-20020a05680809b600b003a75b6cbd38sm1467104oig.45.2023.08.04.13.31.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Aug 2023 13:31:36 -0700 (PDT) Date: Fri, 4 Aug 2023 15:31:34 -0500 From: Madhumitha Prabakaran To: 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 Cc: skhan@linuxfoundation.org, ivan.orlov0322@gmail.com Subject: [PATCH] staging: greybus: Refactor gb_audio_gb_get_topology() into separate calls Message-ID: <20230804203134.GA618419@madhu-kernel> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Refactor gb_audio_gb_get_topology() into separate calls for better modularity. Signed-off-by: Madhumitha Prabakaran --- drivers/staging/greybus/audio_gb.c | 67 +++++++++++++++++++----------- 1 file changed, 42 insertions(+), 25 deletions(-) diff --git a/drivers/staging/greybus/audio_gb.c b/drivers/staging/greybus/audio_gb.c index 9d8994fdb41a..a48ddadd6f1e 100644 --- a/drivers/staging/greybus/audio_gb.c +++ b/drivers/staging/greybus/audio_gb.c @@ -8,39 +8,56 @@ #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; + struct gb_audio_get_topology_size_response size_resp; + int ret; - ret = gb_operation_sync(connection, GB_AUDIO_TYPE_GET_TOPOLOGY_SIZE, - NULL, 0, &size_resp, sizeof(size_resp)); - if (ret) - return ret; + ret = gb_operation_sync(connection, GB_AUDIO_TYPE_GET_TOPOLOGY_SIZE, + NULL, 0, &size_resp, sizeof(size_resp)); + if (ret) + return ret; - size = le16_to_cpu(size_resp.size); - if (size < sizeof(*topo)) - return -ENODATA; + *size = le16_to_cpu(size_resp.size); + return 0; +} - topo = kzalloc(size, GFP_KERNEL); - if (!topo) - return -ENOMEM; +struct gb_audio_topology *gb_audio_gb_alloc_topology(u16 size) +{ + struct gb_audio_topology *topo; - ret = gb_operation_sync(connection, GB_AUDIO_TYPE_GET_TOPOLOGY, NULL, 0, - topo, size); - if (ret) { - kfree(topo); - return ret; - } + if (size < sizeof(struct gb_audio_topology)) + return NULL; - *topology = topo; + topo = kzalloc(size, GFP_KERNEL); + return topo; +} - return 0; +int gb_audio_gb_get_topology(struct gb_connection *connection, + struct gb_audio_topology **topology) +{ + u16 size; + int ret; + + ret = gb_audio_gb_get_topology_size(connection, &size); + if (ret) + return ret; + + *topology = gb_audio_gb_alloc_topology(size); + if (!*topology) + return -ENOMEM; + + ret = gb_operation_sync(connection, GB_AUDIO_TYPE_GET_TOPOLOGY, + NULL, 0, *topology, size); + if (ret) { + kfree(*topology); + *topology = NULL; + return ret; + } + + return 0; } + EXPORT_SYMBOL_GPL(gb_audio_gb_get_topology); int gb_audio_gb_get_control(struct gb_connection *connection, -- 2.25.1