From: Greg KH <gregkh@linuxfoundation.org>
To: Ganesh Kumar Pittala <ganeshkpittala@gmail.com>
Cc: johan@kernel.org, elder@kernel.org, greybus-dev@lists.linaro.org,
linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
hvaibhav.linux@gmail.com, vaibhav.sr@gmail.com,
mgreer@animalcreek.com, rmfrfs@gmail.com,
pure.logic@nexus-software.ie
Subject: Re: [PATCH v2 3/4] staging: greybus: refactor gb_loopback_fn into smaller helper functions
Date: Thu, 17 Apr 2025 11:09:40 +0200 [thread overview]
Message-ID: <2025041701-purgatory-thievish-3e79@gregkh> (raw)
In-Reply-To: <20250413073220.15931-4-ganeshkpittala@gmail.com>
On Sun, Apr 13, 2025 at 07:32:19AM +0000, Ganesh Kumar Pittala wrote:
> This patch refactors the gb_loopback_fn() function in loopback.c by
> splitting large blocks of logic into well-named static helpers to
> improve clarity, readability, and maintainability.
>
> The control flow remains unchanged. No functional modifications
> are introduced.
>
> This aligns with kernel coding style guidelines for long functions
> and helps future contributors understand and modify loopback behavior
> more easily.
>
> Signed-off-by: Ganesh Kumar Pittala <ganeshkpittala@gmail.com>
> ---
> drivers/staging/greybus/loopback.c | 152 ++++++++++++++++-------------
> 1 file changed, 82 insertions(+), 70 deletions(-)
>
> diff --git a/drivers/staging/greybus/loopback.c b/drivers/staging/greybus/loopback.c
> index c194afea941a..1e3644ede1b6 100644
> --- a/drivers/staging/greybus/loopback.c
> +++ b/drivers/staging/greybus/loopback.c
> @@ -832,105 +832,117 @@ static void gb_loopback_async_wait_to_send(struct gb_loopback *gb)
> kthread_should_stop());
> }
>
> -static int gb_loopback_fn(void *data)
> +static bool gb_loopback_should_stop(struct gb_loopback *gb,
> + struct gb_bundle *bundle)
> +{
> + if (!gb->type) {
> + gb_pm_runtime_put_autosuspend(bundle);
> + wait_event_interruptible(gb->wq,
> + gb->type || kthread_should_stop());
> + if (kthread_should_stop())
> + return true;
> + gb_pm_runtime_get_sync(bundle);
> + }
> + return kthread_should_stop();
> +}
> +
> +static void gb_loopback_handle_completion(struct gb_loopback *gb,
> + struct gb_bundle *bundle)
> +{
> + gb_loopback_async_wait_all(gb);
> +
> + mutex_lock(&gb->mutex);
> + if (gb->iteration_count == gb->iteration_max) {
> + gb->type = 0;
> + gb->send_count = 0;
> + sysfs_notify(&gb->dev->kobj, NULL, "iteration_count");
> + dev_dbg(&bundle->dev, "load test complete\n");
> + } else {
> + dev_dbg(&bundle->dev, "continuing on with new test set\n");
> + }
> + mutex_unlock(&gb->mutex);
> +}
> +
> +static void gb_loopback_dispatch_operation(struct gb_loopback *gb, int type,
> + u32 size)
> {
> int error = 0;
> - int us_wait = 0;
> - int type;
> - int ret;
> - u32 size;
>
> + if (gb->async) {
> + if (type == GB_LOOPBACK_TYPE_PING)
> + error = gb_loopback_async_ping(gb);
> + else if (type == GB_LOOPBACK_TYPE_TRANSFER)
> + error = gb_loopback_async_transfer(gb, size);
> + else if (type == GB_LOOPBACK_TYPE_SINK)
> + error = gb_loopback_async_sink(gb, size);
> +
> + if (error) {
> + gb->error++;
> + gb->iteration_count++;
> + }
> + } else {
> + if (type == GB_LOOPBACK_TYPE_PING)
> + error = gb_loopback_sync_ping(gb);
> + else if (type == GB_LOOPBACK_TYPE_TRANSFER)
> + error = gb_loopback_sync_transfer(gb, size);
> + else if (type == GB_LOOPBACK_TYPE_SINK)
> + error = gb_loopback_sync_sink(gb, size);
> +
> + if (error)
> + gb->error++;
> + gb->iteration_count++;
> + gb_loopback_calculate_stats(gb, !!error);
> + }
> +}
> +
> +static void gb_loopback_delay_if_needed(int us_wait)
> +{
> + if (us_wait) {
> + if (us_wait < 20000)
> + usleep_range(us_wait, us_wait + 100);
> + else
> + msleep(us_wait / 1000);
> + }
> +}
> +
> +static int gb_loopback_fn(void *data)
> +{
> + int us_wait = 0, type;
> + u32 size;
> struct gb_loopback *gb = data;
> struct gb_bundle *bundle = gb->connection->bundle;
>
> - ret = gb_pm_runtime_get_sync(bundle);
> - if (ret)
> - return ret;
> + if (gb_pm_runtime_get_sync(bundle))
> + return -EIO;
>
> while (1) {
> - if (!gb->type) {
> - gb_pm_runtime_put_autosuspend(bundle);
> - wait_event_interruptible(gb->wq, gb->type ||
> - kthread_should_stop());
> - ret = gb_pm_runtime_get_sync(bundle);
> - if (ret)
> - return ret;
> - }
> -
> - if (kthread_should_stop())
> + if (gb_loopback_should_stop(gb, bundle))
> break;
>
> - /* Limit the maximum number of in-flight async operations */
Why is it ok to remove this comment?
And why was this function broken up? Is it confusing such that it now
needs subfunctions that are only called once? Now you have to jump
around to follow the logic of this big while(1) loop, making it harder
to follow.
Remember, we write code for people first, compilers second, and I think
you just made it harder for people to manage this code over time as it
now takes extra work to determine how it all fits together.
thanks,
greg k-h
next prev parent reply other threads:[~2025-04-17 9:09 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-13 7:32 [PATCH v2 0/4] staging: greybus: cleanup, API migration, and refactors Ganesh Kumar Pittala
2025-04-13 7:32 ` [PATCH v2 1/4] staging: greybus: replace deprecated strncpy with strscpy in firmware.c Ganesh Kumar Pittala
2025-04-16 19:54 ` [greybus-dev] " Jeff Johnson
2025-04-13 7:32 ` [PATCH v2 2/4] staging: greybus: replace sprintf with sysfs_emit in sysfs show functions Ganesh Kumar Pittala
2025-04-13 7:32 ` [PATCH v2 3/4] staging: greybus: refactor gb_loopback_fn into smaller helper functions Ganesh Kumar Pittala
2025-04-17 9:09 ` Greg KH [this message]
2025-04-13 7:32 ` [PATCH v2 4/4] staging: greybus: split gb_audio_gb_get_topology into " Ganesh Kumar Pittala
2025-04-17 9:03 ` [PATCH v2 0/4] staging: greybus: cleanup, API migration, and refactors Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2025041701-purgatory-thievish-3e79@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=elder@kernel.org \
--cc=ganeshkpittala@gmail.com \
--cc=greybus-dev@lists.linaro.org \
--cc=hvaibhav.linux@gmail.com \
--cc=johan@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=mgreer@animalcreek.com \
--cc=pure.logic@nexus-software.ie \
--cc=rmfrfs@gmail.com \
--cc=vaibhav.sr@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox