From patchwork Fri Oct 28 14:08:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Marussi X-Patchwork-Id: 12323 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp859143wru; Fri, 28 Oct 2022 07:20:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5FMqDoG6cKqdA+Vde1iKhE3XktPsoB/bP1T6d54UIyhh+9+cIwdqV9ll7ObI1Eg4HA8opX X-Received: by 2002:a17:902:8491:b0:183:c3d2:2112 with SMTP id c17-20020a170902849100b00183c3d22112mr54824949plo.133.1666966802344; Fri, 28 Oct 2022 07:20:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666966802; cv=none; d=google.com; s=arc-20160816; b=xtSc7HaT8HzyAQKT/coHzNKRWWR7zHcXj/EepH/dDsCP0lhDSldpj8kF1E238kZnxg Mpyj5eMTJFL37mfuDjQaOdIxzffgkG6G3PrX04GRmPrFPjcLNefdJ4BZ+2G3tacFJcbQ kgzIGP51w3ZSPgvBoGprNMFhrNMYT0QYSMCH9fnjxk7fdzD4jmufOWklDJvFu8t64fKV yz9W7olZHckohFl4iCpCQc/mVngVWL02jfpmqcCeQy0bLoiJLl5HmQ9Mq161wxuoytgb thNLtEuA4DTJUzDWHWr3kxmjrXLf+NGwzfO3UFAcK4D27t1QaTmwJx27xvj9NNjnHsHU g/QQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=rZWPEdy/PUXe6IY4C8/HpXYIjo3NSX+Olxmv7xNYExw=; b=aXPjG7xOjdYetdEjZGdwY3cel8LoqlfcH0QKMEcA3Z05JjxaVVEuW+vHxPCEmfNuYY wJF7A/AKSMrE0J2C/gdXgCbOekj7b0j7kELop7usWiV/lgqPIaxtWm9N+tdjzw+VtYEP Ge5aLV4EsC41AacH1HT2Dbxunx/IXWvuZbHqH9tdqBhVI1U9J25lZD7jlRldLf62mU5V odkDACRzx5FCjTHNg4unSH7VlCct36ijVB4X5VuwqYlrFfwPBlRIKbHeB5IYoh6PiIvz Y29i3a761TA9sjxzvCn3k//woEiydLm0oyJN0HY6I54f9vmWsEgY7fcuaXrkdwTQjE7Y Y/QA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ms19-20020a17090b235300b00211e0e9f18csi5103579pjb.40.2022.10.28.07.19.45; Fri, 28 Oct 2022 07:20:02 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231428AbiJ1OJ1 (ORCPT + 99 others); Fri, 28 Oct 2022 10:09:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231472AbiJ1OJL (ORCPT ); Fri, 28 Oct 2022 10:09:11 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 495401E046A for ; Fri, 28 Oct 2022 07:09:10 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 55110113E; Fri, 28 Oct 2022 07:09:16 -0700 (PDT) Received: from e120937-lin.. (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3CAAA3F534; Fri, 28 Oct 2022 07:09:09 -0700 (PDT) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: sudeep.holla@arm.com, cristian.marussi@arm.com, Dan Carpenter Subject: [PATCH 6/8] firmware: arm_scmi: Fix deferred_tx_wq release on error paths Date: Fri, 28 Oct 2022 15:08:31 +0100 Message-Id: <20221028140833.280091-6-cristian.marussi@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221028140833.280091-1-cristian.marussi@arm.com> References: <20221028140833.280091-1-cristian.marussi@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747941381537538377?= X-GMAIL-MSGID: =?utf-8?q?1747941381537538377?= Use devres to allocate the dedicated deferred_tx_wq polling workqueue so as to automatically trigger the proper resource release on error path. Reported-by: Dan Carpenter Fixes: 5a3b7185c47c ("firmware: arm_scmi: Add atomic mode support to virtio transport") Signed-off-by: Cristian Marussi --- drivers/firmware/arm_scmi/virtio.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/firmware/arm_scmi/virtio.c b/drivers/firmware/arm_scmi/virtio.c index 36b7686843a4..33c9b81a55cd 100644 --- a/drivers/firmware/arm_scmi/virtio.c +++ b/drivers/firmware/arm_scmi/virtio.c @@ -148,7 +148,6 @@ static void scmi_vio_channel_cleanup_sync(struct scmi_vio_channel *vioch) { unsigned long flags; DECLARE_COMPLETION_ONSTACK(vioch_shutdown_done); - void *deferred_wq = NULL; /* * Prepare to wait for the last release if not already released @@ -162,16 +161,11 @@ static void scmi_vio_channel_cleanup_sync(struct scmi_vio_channel *vioch) vioch->shutdown_done = &vioch_shutdown_done; virtio_break_device(vioch->vqueue->vdev); - if (!vioch->is_rx && vioch->deferred_tx_wq) { - deferred_wq = vioch->deferred_tx_wq; + if (!vioch->is_rx && vioch->deferred_tx_wq) /* Cannot be kicked anymore after this...*/ vioch->deferred_tx_wq = NULL; - } spin_unlock_irqrestore(&vioch->lock, flags); - if (deferred_wq) - destroy_workqueue(deferred_wq); - scmi_vio_channel_release(vioch); /* Let any possibly concurrent RX path release the channel */ @@ -416,6 +410,11 @@ static bool virtio_chan_available(struct device *dev, int idx) return vioch && !vioch->cinfo; } +static void scmi_destroy_tx_workqueue(void *deferred_tx_wq) +{ + destroy_workqueue(deferred_tx_wq); +} + static int virtio_chan_setup(struct scmi_chan_info *cinfo, struct device *dev, bool tx) { @@ -430,6 +429,8 @@ static int virtio_chan_setup(struct scmi_chan_info *cinfo, struct device *dev, /* Setup a deferred worker for polling. */ if (tx && !vioch->deferred_tx_wq) { + int ret; + vioch->deferred_tx_wq = alloc_workqueue(dev_name(&scmi_vdev->dev), WQ_UNBOUND | WQ_FREEZABLE | WQ_SYSFS, @@ -437,6 +438,11 @@ static int virtio_chan_setup(struct scmi_chan_info *cinfo, struct device *dev, if (!vioch->deferred_tx_wq) return -ENOMEM; + ret = devm_add_action_or_reset(dev, scmi_destroy_tx_workqueue, + vioch->deferred_tx_wq); + if (ret) + return ret; + INIT_WORK(&vioch->deferred_tx_work, scmi_vio_deferred_tx_worker); }