From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Stefan Wahren <wahrenst@gmx.net>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Florian Fainelli <florian.fainelli@broadcom.com>,
Umang Jain <umang.jain@ideasonboard.com>,
linux-staging@lists.linux.dev,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 07/11] staging: vchiq_arm: Reduce indentation of service_callback
Date: Wed, 5 Jun 2024 10:07:27 +0300 [thread overview]
Message-ID: <20240605070727.GA3488@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20240604172904.61613-8-wahrenst@gmx.net>
Hi Stefan,
Thank you for the patch.
On Tue, Jun 04, 2024 at 07:29:00PM +0200, Stefan Wahren wrote:
> The service_callback has 5 levels of indentation, which makes it
> hard to read. Reduce this by using a goto for the corner cases
> (no header or VCHI service).
I think the goto isn't very nice. Could you instead try to split code to
a separate function ? That should do a better job at improve
readability.
> Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
> ---
> .../interface/vchiq_arm/vchiq_arm.c | 111 +++++++++---------
> 1 file changed, 57 insertions(+), 54 deletions(-)
>
> diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> index 45acca670bbd..0055c7d7e617 100644
> --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> @@ -1101,71 +1101,74 @@ service_callback(struct vchiq_instance *instance, enum vchiq_reason reason,
> user_service, service->localport, user_service->userdata,
> reason, header, instance, bulk_userdata);
>
> - if (header && user_service->is_vchi) {
> - spin_lock(&service->state->msg_queue_spinlock);
> - while (user_service->msg_insert ==
> - (user_service->msg_remove + MSG_QUEUE_SIZE)) {
> - spin_unlock(&service->state->msg_queue_spinlock);
> - DEBUG_TRACE(SERVICE_CALLBACK_LINE);
> - DEBUG_COUNT(MSG_QUEUE_FULL_COUNT);
> - dev_dbg(service->state->dev, "arm: msg queue full\n");
> - /*
> - * If there is no MESSAGE_AVAILABLE in the completion
> - * queue, add one
> - */
> - if ((user_service->message_available_pos -
> - instance->completion_remove) < 0) {
> - int status;
> -
> - dev_dbg(instance->state->dev,
> - "arm: Inserting extra MESSAGE_AVAILABLE\n");
> - DEBUG_TRACE(SERVICE_CALLBACK_LINE);
> - status = add_completion(instance, reason, NULL, user_service,
> - bulk_userdata);
> - if (status) {
> - DEBUG_TRACE(SERVICE_CALLBACK_LINE);
> - vchiq_service_put(service);
> - return status;
> - }
> - }
> + if (!header || !user_service->is_vchi)
> + goto service_put;
> +
> + spin_lock(&service->state->msg_queue_spinlock);
> + while (user_service->msg_insert ==
> + (user_service->msg_remove + MSG_QUEUE_SIZE)) {
> + spin_unlock(&service->state->msg_queue_spinlock);
> + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
> + DEBUG_COUNT(MSG_QUEUE_FULL_COUNT);
> + dev_dbg(service->state->dev, "arm: msg queue full\n");
> + /*
> + * If there is no MESSAGE_AVAILABLE in the completion
> + * queue, add one
> + */
> + if ((user_service->message_available_pos -
> + instance->completion_remove) < 0) {
> + int status;
>
> + dev_dbg(instance->state->dev,
> + "arm: Inserting extra MESSAGE_AVAILABLE\n");
> DEBUG_TRACE(SERVICE_CALLBACK_LINE);
> - if (wait_for_completion_interruptible(&user_service->remove_event)) {
> - dev_dbg(instance->state->dev, "arm: interrupted\n");
> - DEBUG_TRACE(SERVICE_CALLBACK_LINE);
> - vchiq_service_put(service);
> - return -EAGAIN;
> - } else if (instance->closing) {
> - dev_dbg(instance->state->dev, "arm: closing\n");
> + status = add_completion(instance, reason, NULL, user_service,
> + bulk_userdata);
> + if (status) {
> DEBUG_TRACE(SERVICE_CALLBACK_LINE);
> vchiq_service_put(service);
> - return -EINVAL;
> + return status;
> }
> - DEBUG_TRACE(SERVICE_CALLBACK_LINE);
> - spin_lock(&service->state->msg_queue_spinlock);
> }
>
> - user_service->msg_queue[user_service->msg_insert &
> - (MSG_QUEUE_SIZE - 1)] = header;
> - user_service->msg_insert++;
> -
> - /*
> - * If there is a thread waiting in DEQUEUE_MESSAGE, or if
> - * there is a MESSAGE_AVAILABLE in the completion queue then
> - * bypass the completion queue.
> - */
> - if (((user_service->message_available_pos -
> - instance->completion_remove) >= 0) ||
> - user_service->dequeue_pending) {
> - user_service->dequeue_pending = 0;
> - skip_completion = true;
> + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
> + if (wait_for_completion_interruptible(&user_service->remove_event)) {
> + dev_dbg(instance->state->dev, "arm: interrupted\n");
> + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
> + vchiq_service_put(service);
> + return -EAGAIN;
> + } else if (instance->closing) {
> + dev_dbg(instance->state->dev, "arm: closing\n");
> + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
> + vchiq_service_put(service);
> + return -EINVAL;
> }
> + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
> + spin_lock(&service->state->msg_queue_spinlock);
> + }
>
> - spin_unlock(&service->state->msg_queue_spinlock);
> - complete(&user_service->insert_event);
> + user_service->msg_queue[user_service->msg_insert &
> + (MSG_QUEUE_SIZE - 1)] = header;
> + user_service->msg_insert++;
>
> - header = NULL;
> + /*
> + * If there is a thread waiting in DEQUEUE_MESSAGE, or if
> + * there is a MESSAGE_AVAILABLE in the completion queue then
> + * bypass the completion queue.
> + */
> + if (((user_service->message_available_pos -
> + instance->completion_remove) >= 0) ||
> + user_service->dequeue_pending) {
> + user_service->dequeue_pending = 0;
> + skip_completion = true;
> }
> +
> + spin_unlock(&service->state->msg_queue_spinlock);
> + complete(&user_service->insert_event);
> +
> + header = NULL;
> +
> +service_put:
> DEBUG_TRACE(SERVICE_CALLBACK_LINE);
> vchiq_service_put(service);
>
--
Regards,
Laurent Pinchart
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2024-06-05 7:08 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-04 17:28 [PATCH 00/11] staging: vc04_services: Random cleanups Stefan Wahren
2024-06-04 17:28 ` [PATCH 01/11] staging: vchiq_arm: Replace variable ret with status Stefan Wahren
2024-06-05 6:51 ` Laurent Pinchart
2024-06-05 10:04 ` Stefan Wahren
2024-06-04 17:28 ` [PATCH 02/11] staging: vchiq_arm: Drop obsolete comment Stefan Wahren
2024-06-05 6:52 ` Laurent Pinchart
2024-06-05 10:02 ` Stefan Wahren
2024-06-05 10:32 ` Dan Carpenter
2024-06-04 17:28 ` [PATCH 03/11] staging: vchiq_core: Drop non-functional struct members Stefan Wahren
2024-06-05 7:00 ` Laurent Pinchart
2024-06-04 17:28 ` [PATCH 04/11] staging: vchiq_arm: Drop unnecessary declarations Stefan Wahren
2024-06-05 7:02 ` Laurent Pinchart
2024-06-04 17:28 ` [PATCH 05/11] staging: vchiq_arm: Get the rid off struct vchiq_2835_state Stefan Wahren
2024-06-05 7:11 ` Laurent Pinchart
2024-06-05 10:11 ` Stefan Wahren
2024-06-11 21:22 ` Laurent Pinchart
2024-06-12 5:12 ` Stefan Wahren
2024-06-04 17:28 ` [PATCH 06/11] staging: vchiq_arm: Drop vchiq_arm_init_state Stefan Wahren
2024-06-05 7:08 ` Laurent Pinchart
2024-06-04 17:29 ` [PATCH 07/11] staging: vchiq_arm: Reduce indentation of service_callback Stefan Wahren
2024-06-05 7:07 ` Laurent Pinchart [this message]
2024-06-04 17:29 ` [PATCH 08/11] staging: vchiq_core: Add comments to mutex/spinlocks Stefan Wahren
2024-06-05 7:10 ` Laurent Pinchart
2024-06-04 17:29 ` [PATCH 09/11] staging: vchiq: Move struct vchiq_config to vchiq.h Stefan Wahren
2024-06-05 7:16 ` Laurent Pinchart
2024-06-05 10:15 ` Stefan Wahren
2024-06-04 17:29 ` [PATCH 10/11] staging: vchiq_core: Add hex prefix to debugfs output Stefan Wahren
2024-06-05 7:12 ` Laurent Pinchart
2024-06-04 17:29 ` [PATCH 11/11] staging: vc04_services: Update testing instructions Stefan Wahren
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=20240605070727.GA3488@pendragon.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=florian.fainelli@broadcom.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-staging@lists.linux.dev \
--cc=umang.jain@ideasonboard.com \
--cc=wahrenst@gmx.net \
/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;
as well as URLs for NNTP newsgroup(s).