From patchwork Tue Jun 4 17:29:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wahren X-Patchwork-Id: 13685710 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 3CF37C27C53 for ; Tue, 4 Jun 2024 17:29:50 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=vGS2630HcyYGAB9i/u+necjZDUX2GHvY2+IBfYP22us=; b=FWvMuglnQpe5al HnMFVRehG/mgk4wvOM/dgvOHoN1yGhitIxoZ4mQ9z/0xOZclj4zfU4EknS1KfbV2dGYiHIKPW+0yH 9Q1yqDj+//P7BTZRpbnn8Qdwi8YRt1owvSzi92ixBNvCGGKcS/YwrqYh7CdwqGuGeOOMd9LCA1BNW nppJd9iQ0RkrAgFgBd/kYq9aCQFnKFlW995zCUacaAxMNMkJZ6pguBNSQYfeTG0tHd3uze5vJtxLQ vjwFZcnAtakeG4zkED8xhjqicVo4gz9R5bGimeCaiwZurGdc+R1puwbF+it5M0FoTNiHn+oXwJIh1 6monlpeMlpPho3NMHjsA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEXyf-00000003ImZ-1myU; Tue, 04 Jun 2024 17:29:41 +0000 Received: from mout.gmx.net ([212.227.17.20]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEXyS-00000003IeL-1Trt for linux-arm-kernel@lists.infradead.org; Tue, 04 Jun 2024 17:29:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1717522165; x=1718126965; i=wahrenst@gmx.net; bh=J8u0D/gqYRaWIAY1ZLOXtY9R4hmDlnmeyzUMbLiRoSg=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-Id:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=ZnS87CxvJuTpD2oU8uudhKlVgfMl1DUEpWimVjpwkWbeq20JNdtkjQClBCKGQWhA KL95hxQ4SH2N96H6exvZtDFkM4a4MGm+wyEnxs8WEIGvf6PqVh8hKIhb2oxQQwE+a dgNIDHJ98mgNeSsOyx5IZ5cECeK1gux+3prlUEiO+Ymvt1ctsLBFCFiKWDD1Im92x h9ce60x/lcJpPrUcXJRzwSmuTI2oeCZ2TdsKS7z+4gdSR3sDxeEMrre4KFPMWf3+p 2M59in3gfI7vT+uV6eS3lMfl+v4cVT3DUn4ORe3QlDWn86KjrxJbS/Lnjf7rogHPB EhRE5nlPvn9OxfIGPQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from stefanw-SCHENKER ([37.4.248.43]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N1fii-1scq563bA0-011BUz; Tue, 04 Jun 2024 19:29:24 +0200 From: Stefan Wahren To: Greg Kroah-Hartman , Florian Fainelli Cc: Umang Jain , Laurent Pinchart , linux-staging@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Stefan Wahren Subject: [PATCH 07/11] staging: vchiq_arm: Reduce indentation of service_callback Date: Tue, 4 Jun 2024 19:29:00 +0200 Message-Id: <20240604172904.61613-8-wahrenst@gmx.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240604172904.61613-1-wahrenst@gmx.net> References: <20240604172904.61613-1-wahrenst@gmx.net> MIME-Version: 1.0 X-Provags-ID: V03:K1:xh3wPN2mIO7wghK1lfDXv0h4oqXgfc66pt2IdguB11S/DgvPseL 2eAJ8Zdefbow5cJ60vG/LeSMDAiI8JxytPcoTYgeZjwWHVMlm9lLWNp5+KCpvbhkCwvy7TZ q08B7nuF9ezypXro/yjIGsYXvU2jOqifBbadsQjVSskoUUmYt9Z6oKsYa39rmFlkMAz5fje GhDaUWfYeKsyAXCtqTaSQ== UI-OutboundReport: notjunk:1;M01:P0:MfG+iriPnb0=;/GwZxITaXWjLak0kr22F4OTZdb+ CJZL2zKwtv+qxR6CXEJ/XNveBOgWKz4zsctVLHRjml8QikVJDd+4Bw3QkI78u4zCu/Yljvw8s FOilxpBpoO2bcHtXziYaogSpibmBLY3+1Nek8OeGfjlL95u8mU3zH7aK/0cjxp039LSI+I946 zLRuWg7jjjJM3qitGi5o2mWXfEIgTWj9DiUegdjRBs7fC+gDLYYCpfv+2KH/UuhacyMaixALA X7zmES3YuZ1Bv+Uka/fbNgN20ZwyhPJz49oOAuadeRzoapDwS1SXkiiSDwlqz4Ax3KaybbBm5 fI3T7BUnjCTi2AY4s8z9w4tYydGNq8WBkSLKd4eIciR6pP6Qel19N2h9B8PbKfFwzQ5YzyKC7 Zf6cIrQB8gen2iwEIBS3rouHj4fj7G9EVjnWP2QHs5BNHHZKmYtKBkZ0Th42RGPO2V3EhQYzK k3maSher2ix/IiE3336yLZtiZzXcjgj1obwkurkZ1/9FOnX/D41ACbyxTBRGnF0ocKJY0umz/ Nzkjg1Ub+rETXpCZBvkozAPN+wEpwDiKqKpQMfpvfuAQ13p+MW0xHZAsuJOfeCjwXFd7DsRA8 NRbiWkbGsiJs3r8yoSqTEYJmyJBTFar8XYmLeEyuTIv6Bq2WbIMzj8v9jDidqztgYpuAj4VOC iq7Y/VqhheA+ZSjC7Ds7pCd4q6jEEqF1E6yRe3oRaqPjlDWNhWfp3jpDNRKhG6+dMKdKH7qbW E0+zXVVscpLseacKZK2eKnsMr8yjX2hJXcenNqviTlevDo8Q/lod0nd6oQFrE6h6LaXmRVnf1 yfd2bEKEopUM2ZYezvN6mKZP6V1sxDfOhNR82Q6vTYMPs= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240604_102928_752139_FA34760E X-CRM114-Status: GOOD ( 14.66 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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). Signed-off-by: Stefan Wahren --- .../interface/vchiq_arm/vchiq_arm.c | 111 +++++++++--------- 1 file changed, 57 insertions(+), 54 deletions(-) -- 2.34.1 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);