From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 60314C25B76 for ; Wed, 5 Jun 2024 07:08:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=oGER6BcYCnPnltB4m6MrKGx2MGAoBXu32W23tGVvG9w=; b=nFsFrFzmi0x+Us /sBQMHIYftGJtvXSg3hrR73wlDHibodUC1EFpbxhY8/4yAYY6zIJtEzOkqV78txTaQj1Oeeiqv0NV Lcu8Yit72iy5diXC32RHORh9ShdCPA83PPdAyrU9HKjftX0Kqp5omJvESsk0TyLU0AkckYfjuJSs5 bgwHDvM6boK6UrFZQODCnVxbv0UCcLaY79FZ5DCA+Skg+ZHw17p66xk/msj121yf8pAAZy/VRD3YN 2RvjQ/WN7lGCpzlXtbYpl4XPz4dZNsqlkWVVrkWegM/wYoD/VD62ju4xHuGAtpnQ12vZxx9Oo4mzj KWpcBzcyUdgz2qQeSsgA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEkkP-00000004vQ7-09qI; Wed, 05 Jun 2024 07:07:49 +0000 Received: from perceval.ideasonboard.com ([213.167.242.64]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEkkL-00000004vPA-1uS0 for linux-arm-kernel@lists.infradead.org; Wed, 05 Jun 2024 07:07:46 +0000 Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 74EB8BEB; Wed, 5 Jun 2024 09:07:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1717571255; bh=s4lo2D5CYmFDoqgh8iknfXx2tNx870WfNaMcRm1qgTk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=fEHVc98GdE4/9890K1uDlywybXNfBxTgWyfR5pXYdFNhG2hg1ISQ49UXpF7h9cQPr 9ngtLLLIeL08QzWWMVa+nyySy16JA42ZQWtYcXGbEhX9bWLekjCfTyolKrLM7FRcUF cBxiz4ZzkMUxBp9z5uvH6oqMRS/A5LRQMzCn3E2A= Date: Wed, 5 Jun 2024 10:07:27 +0300 From: Laurent Pinchart To: Stefan Wahren Cc: Greg Kroah-Hartman , Florian Fainelli , Umang Jain , linux-staging@lists.linux.dev, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH 07/11] staging: vchiq_arm: Reduce indentation of service_callback Message-ID: <20240605070727.GA3488@pendragon.ideasonboard.com> References: <20240604172904.61613-1-wahrenst@gmx.net> <20240604172904.61613-8-wahrenst@gmx.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240604172904.61613-8-wahrenst@gmx.net> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240605_000745_664973_1E6EC0C6 X-CRM114-Status: GOOD ( 23.05 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 > --- > .../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