From patchwork Thu Aug 24 10:40:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fei Shao X-Patchwork-Id: 13363977 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 45101C7113B for ; Thu, 24 Aug 2023 10:42: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:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:To:From:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=LEJf1Ko1BMCyWS/D/rsWBp+WuGpyKGTRzMpr52lamRc=; b=m19VTwU7XpfOWE enxNGG9BDkU4OXPf8hmr1FHJGXg/au8Ca/tzU+lJunnk6gvnCmFid/6sFkNRrkvQ15k0c3F3us9AG SaACkAQfN/KVkEGCJDz4YbiNUR3VLRuW0pyGBxOWxjKLZ1mEjVzsBZp223CizuUp2rMPGSRCECp1t 98lQhqSAX1lCMqt6iy1SNPJw+k/EK8TGL+0vcb+tvAg9iksJPFYFXMisEzueqF3olbhRW8ucYadKk pdLCMKlVhvWPVYtfwNEZ6ObBFEgC4FqbeAK6O96OK45Z3rpgxyok6S31ji3XPSd+EJMWzuPQ44Rpw 4yF8cVTUbFrTeaF9SU6A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qZ7mq-002tlM-3A; Thu, 24 Aug 2023 10:42:00 +0000 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qZ7mo-002ti5-0F for linux-mediatek@lists.infradead.org; Thu, 24 Aug 2023 10:41:59 +0000 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1bdca7cc28dso52417295ad.1 for ; Thu, 24 Aug 2023 03:41:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1692873714; x=1693478514; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LEJf1Ko1BMCyWS/D/rsWBp+WuGpyKGTRzMpr52lamRc=; b=oaZO0U9EnOZE/Os+8hmlmogE4YwN515J72FCRMHS0mo31BHgkDUfNVslhtRyvz2atI shXHfduCWhdeyg1WmMDN3GzTmCG3gc52LI5GIU/tRzvvRW9AdZ2FI87Phb2icityItBZ LyCOsvzyLqM0ivkRo4XPSXJCLzdyOURzpKDls= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692873714; x=1693478514; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LEJf1Ko1BMCyWS/D/rsWBp+WuGpyKGTRzMpr52lamRc=; b=fn+T96NgsiOgywoM1VzpL8fFc8Nil1rLzUqggBKSEE8UKu+zRPm3biU6UKPA8596+2 P3JBnckV4rkhGDPt5WLmS9CGnzI2DyoCPOSZBtof5hlC5tJ5tOuCvhsyK/nIL8H3dVHv 9EfJ5qpB9jpBCefUSARlFyEJFI4SBw+o4VWCJUUS1D1FxnqVibpj40DAsy+uVPFct0+5 BF09mtLPo4meEglesL6riX8kYweCxemXGZMfdO/VLUmxwZkwM62GVMMKI9oZAHLssPxO tItUYIPd8sLEujSj6zXi3qNwPXt7D4Ge1obclqpD0bX9Vygud3Kr/NGjSKypVL0+c6+L SLjQ== X-Gm-Message-State: AOJu0YwtHtG8d50spSyMPdBfM7bRWnCN3P0v9NMATHAzGd4BvkHRVQpK lvtRNhXsUVWHihZ1IpE87fH1mA== X-Google-Smtp-Source: AGHT+IF+kf7WstGJzoE6CoHxmnzcwn+x6Is3sSPEaLcz4wnfFtA6FShvnq99VJEDPmziWkv/tJ0woQ== X-Received: by 2002:a17:902:da88:b0:1bc:203f:3b3c with SMTP id j8-20020a170902da8800b001bc203f3b3cmr17586042plx.24.1692873714369; Thu, 24 Aug 2023 03:41:54 -0700 (PDT) Received: from fshao-p620.tpe.corp.google.com ([2401:fa00:1:10:ed6d:42e3:a23:8316]) by smtp.gmail.com with ESMTPSA id q2-20020a170902dac200b001b5247cac3dsm12524645plx.110.2023.08.24.03.41.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Aug 2023 03:41:54 -0700 (PDT) From: Fei Shao To: Stephen Boyd , Chen-Yu Tsai Subject: [PATCH 1/5] spmi: Introduce device-managed functions Date: Thu, 24 Aug 2023 18:40:08 +0800 Message-ID: <20230824104101.4083400-2-fshao@chromium.org> X-Mailer: git-send-email 2.42.0.rc1.204.g551eb34607-goog In-Reply-To: <20230824104101.4083400-1-fshao@chromium.org> References: <20230824104101.4083400-1-fshao@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230824_034158_116451_291D3339 X-CRM114-Status: GOOD ( 15.68 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Utilize the managed resource (devres) framework and add the following devm_* helpers for the SPMI driver: - devm_spmi_controller_alloc() - devm_spmi_controller_add() Signed-off-by: Fei Shao Reviewed-by: AngeloGioacchino Del Regno --- drivers/spmi/Makefile | 2 +- drivers/spmi/devres.c | 61 +++++++++++++++++++++++++++++++++++++++++++ include/linux/spmi.h | 3 +++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 drivers/spmi/devres.c diff --git a/drivers/spmi/Makefile b/drivers/spmi/Makefile index 9d974424c8c1..02d917f4df34 100644 --- a/drivers/spmi/Makefile +++ b/drivers/spmi/Makefile @@ -2,7 +2,7 @@ # # Makefile for kernel SPMI framework. # -obj-$(CONFIG_SPMI) += spmi.o +obj-$(CONFIG_SPMI) += spmi.o devres.o obj-$(CONFIG_SPMI_HISI3670) += hisi-spmi-controller.o obj-$(CONFIG_SPMI_MSM_PMIC_ARB) += spmi-pmic-arb.o diff --git a/drivers/spmi/devres.c b/drivers/spmi/devres.c new file mode 100644 index 000000000000..f18cbbe28812 --- /dev/null +++ b/drivers/spmi/devres.c @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2023 Google LLC. + */ + +#include +#include + +static void devm_spmi_controller_release(struct device *parent, void *res) +{ + spmi_controller_put(*(struct spmi_controller **)res); +} + +struct spmi_controller *devm_spmi_controller_alloc(struct device *parent, size_t size) +{ + struct spmi_controller **ptr, *ctrl; + + ptr = devres_alloc(devm_spmi_controller_release, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return ERR_PTR(-ENOMEM); + + ctrl = spmi_controller_alloc(parent, size); + if (!ctrl) { + devres_free(ptr); + return ERR_PTR(-ENOMEM); + } + + *ptr = ctrl; + devres_add(parent, ptr); + + return ctrl; +} +EXPORT_SYMBOL_GPL(devm_spmi_controller_alloc); + +static void devm_spmi_controller_remove(struct device *parent, void *res) +{ + spmi_controller_remove(*(struct spmi_controller **)res); +} + +int devm_spmi_controller_add(struct device *parent, struct spmi_controller *ctrl) +{ + struct spmi_controller **ptr; + int ret; + + ptr = devres_alloc(devm_spmi_controller_remove, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return -ENOMEM; + + ret = spmi_controller_add(ctrl); + if (ret) { + devres_free(ptr); + return ret; + } + + *ptr = ctrl; + devres_add(parent, ptr); + + return 0; + +} +EXPORT_SYMBOL_GPL(devm_spmi_controller_add); diff --git a/include/linux/spmi.h b/include/linux/spmi.h index eac1956a8727..14597708fdbc 100644 --- a/include/linux/spmi.h +++ b/include/linux/spmi.h @@ -120,6 +120,9 @@ static inline void spmi_controller_put(struct spmi_controller *ctrl) int spmi_controller_add(struct spmi_controller *ctrl); void spmi_controller_remove(struct spmi_controller *ctrl); +struct spmi_controller *devm_spmi_controller_alloc(struct device *parent, size_t size); +int devm_spmi_controller_add(struct device *parent, struct spmi_controller *ctrl); + /** * struct spmi_driver - SPMI slave device driver * @driver: SPMI device drivers should initialize name and owner field of From patchwork Thu Aug 24 10:40:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fei Shao X-Patchwork-Id: 13363980 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 23531C27C40 for ; Thu, 24 Aug 2023 10:42:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:To:From:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=a7ehnQUGg3AKORpAuWZQKuhgBidrmQAa7Q4v6MvPOrg=; b=pRYneBGZ/p1dsc vYuSm7dHsq0S8Wvvk9fDJyIDqpw5z9qkOJrsM5lnXzsFywpFoCkcPG4DVUx6J+bDxZadpxgec3TzL pviUT7froYv88DsAoJX2GQ2nfOYcad4lsV2sD0Nt8fHe04ksel5F3Y/LKyZbfNd29oO1zehdnafkJ DBx0vaa8ELNYZBxJ+2g2bEjtcypfqJNaa8dEcwfWvi+WOLQi1U0BSdymNNZbcx548UIGSgnGKn5Fg 4GSyT7ipKdiiCHhwm9AjyhiMhfInaIiFKmhcXoaD0v1X+2gWzWVheVUyfJEE00uuFQhYZ4nd47SAB dgmJatTzQiPQPx1giUtg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qZ7n1-002tpw-0T; Thu, 24 Aug 2023 10:42:11 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qZ7mp-002tj4-3A for linux-mediatek@lists.infradead.org; Thu, 24 Aug 2023 10:42:03 +0000 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1bf7a6509deso28890405ad.3 for ; Thu, 24 Aug 2023 03:41:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1692873717; x=1693478517; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=a7ehnQUGg3AKORpAuWZQKuhgBidrmQAa7Q4v6MvPOrg=; b=GGkazUlFNAPtpUy021BsGhwjV4kl0TZaOHnxO5hTMMZ7jN4oxl/ZGX63JCXaCN3kRI wqujm3hGuqh7Pv17N2fF7meF3cBy8afMW/3OTTCiSQ1LCkwQ9Xgwd5vqoK2MbZNC9ipN 3zymGy8wrhUon01M1eAueKxCbnxFh+xguSlWY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692873717; x=1693478517; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=a7ehnQUGg3AKORpAuWZQKuhgBidrmQAa7Q4v6MvPOrg=; b=W1uilVI2i3qZEMdlkbmcTqzWSZvNEZBTGiT1miNgiR7AY9g50LJ3vmy3zcvRkEskA/ 21i/x2/IXxCFVqxmgjIJKumgOS4MDKX9dLsKHQuAEmjw9oygLoRUVHiNxq6wkbAXEkOA +udUlGX5Ftk8kGFgWDqR0CSw/k28Szus7CBvJzCvFsdNgkTAI0HroqR53J4FJrdW5Cwj s7DIbNNoM3X313vz/lRBew9x/dZOwr+P7f3eywnYVsq7DDrl8Yu/J3jthLfK+EVkFQ55 CtLOtwAkywtdCKm1CChjzRANbAuRgmTv5dxoP1czBK9sacSDI8JC89KA2KVhXYRjyQIq UhZQ== X-Gm-Message-State: AOJu0Ywn8G157WhlK9LNjgnHFZJGA6GigqrLg3mYC2NBOcIDddt3+S9J yNy0N9vaCio9SJYc0tfswu45Lg== X-Google-Smtp-Source: AGHT+IHVMrdwEtZBx83tpEboYUtEK7EO5abihTGfCj+KqNS/3F8eD0JIrOXuuysFoORhdmvs9PS0PA== X-Received: by 2002:a17:902:d511:b0:1bc:5e50:9345 with SMTP id b17-20020a170902d51100b001bc5e509345mr14923808plg.50.1692873717041; Thu, 24 Aug 2023 03:41:57 -0700 (PDT) Received: from fshao-p620.tpe.corp.google.com ([2401:fa00:1:10:ed6d:42e3:a23:8316]) by smtp.gmail.com with ESMTPSA id q2-20020a170902dac200b001b5247cac3dsm12524645plx.110.2023.08.24.03.41.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Aug 2023 03:41:56 -0700 (PDT) From: Fei Shao To: Stephen Boyd , Chen-Yu Tsai Subject: [PATCH 2/5] spmi: Use devm_spmi_controller_alloc() Date: Thu, 24 Aug 2023 18:40:09 +0800 Message-ID: <20230824104101.4083400-3-fshao@chromium.org> X-Mailer: git-send-email 2.42.0.rc1.204.g551eb34607-goog In-Reply-To: <20230824104101.4083400-1-fshao@chromium.org> References: <20230824104101.4083400-1-fshao@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230824_034200_033538_630970A4 X-CRM114-Status: GOOD ( 17.67 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mauro Carvalho Chehab , linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Matthias Brugger , linux-arm-kernel@lists.infradead.org, AngeloGioacchino Del Regno Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Convert to the device-managed version of spmi_controller_alloc() and simplify the excess error handling code. Signed-off-by: Fei Shao Reviewed-by: AngeloGioacchino Del Regno --- drivers/spmi/hisi-spmi-controller.c | 22 +++----- drivers/spmi/spmi-mtk-pmif.c | 26 +++------ drivers/spmi/spmi-pmic-arb.c | 87 ++++++++++------------------- 3 files changed, 46 insertions(+), 89 deletions(-) diff --git a/drivers/spmi/hisi-spmi-controller.c b/drivers/spmi/hisi-spmi-controller.c index 9cbd473487cb..a5525902656a 100644 --- a/drivers/spmi/hisi-spmi-controller.c +++ b/drivers/spmi/hisi-spmi-controller.c @@ -267,10 +267,10 @@ static int spmi_controller_probe(struct platform_device *pdev) struct resource *iores; int ret; - ctrl = spmi_controller_alloc(&pdev->dev, sizeof(*spmi_controller)); - if (!ctrl) { + ctrl = devm_spmi_controller_alloc(&pdev->dev, sizeof(*spmi_controller)); + if (IS_ERR(ctrl)) { dev_err(&pdev->dev, "can not allocate spmi_controller data\n"); - return -ENOMEM; + return PTR_ERR(ctrl); } spmi_controller = spmi_controller_get_drvdata(ctrl); spmi_controller->controller = ctrl; @@ -278,24 +278,21 @@ static int spmi_controller_probe(struct platform_device *pdev) iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!iores) { dev_err(&pdev->dev, "can not get resource!\n"); - ret = -EINVAL; - goto err_put_controller; + return -EINVAL; } spmi_controller->base = devm_ioremap(&pdev->dev, iores->start, resource_size(iores)); if (!spmi_controller->base) { dev_err(&pdev->dev, "can not remap base addr!\n"); - ret = -EADDRNOTAVAIL; - goto err_put_controller; + return -EADDRNOTAVAIL; } ret = of_property_read_u32(pdev->dev.of_node, "hisilicon,spmi-channel", &spmi_controller->channel); if (ret) { dev_err(&pdev->dev, "can not get channel\n"); - ret = -ENODEV; - goto err_put_controller; + return -ENODEV; } platform_set_drvdata(pdev, spmi_controller); @@ -314,14 +311,10 @@ static int spmi_controller_probe(struct platform_device *pdev) ret = spmi_controller_add(ctrl); if (ret) { dev_err(&pdev->dev, "spmi_controller_add failed with error %d!\n", ret); - goto err_put_controller; + return ret; } return 0; - -err_put_controller: - spmi_controller_put(ctrl); - return ret; } static void spmi_del_controller(struct platform_device *pdev) @@ -329,7 +322,6 @@ static void spmi_del_controller(struct platform_device *pdev) struct spmi_controller *ctrl = platform_get_drvdata(pdev); spmi_controller_remove(ctrl); - spmi_controller_put(ctrl); } static const struct of_device_id spmi_controller_match_table[] = { diff --git a/drivers/spmi/spmi-mtk-pmif.c b/drivers/spmi/spmi-mtk-pmif.c index 74b73f9bc222..eb909a6e3b9e 100644 --- a/drivers/spmi/spmi-mtk-pmif.c +++ b/drivers/spmi/spmi-mtk-pmif.c @@ -437,29 +437,24 @@ static int mtk_spmi_probe(struct platform_device *pdev) int err, i; u32 chan_offset; - ctrl = spmi_controller_alloc(&pdev->dev, sizeof(*arb)); - if (!ctrl) - return -ENOMEM; + ctrl = devm_spmi_controller_alloc(&pdev->dev, sizeof(*arb)); + if (IS_ERR(ctrl)) + return PTR_ERR(ctrl); arb = spmi_controller_get_drvdata(ctrl); arb->data = device_get_match_data(&pdev->dev); if (!arb->data) { - err = -EINVAL; dev_err(&pdev->dev, "Cannot get drv_data\n"); - goto err_put_ctrl; + return -EINVAL; } arb->base = devm_platform_ioremap_resource_byname(pdev, "pmif"); - if (IS_ERR(arb->base)) { - err = PTR_ERR(arb->base); - goto err_put_ctrl; - } + if (IS_ERR(arb->base)) + return PTR_ERR(arb->base); arb->spmimst_base = devm_platform_ioremap_resource_byname(pdev, "spmimst"); - if (IS_ERR(arb->spmimst_base)) { - err = PTR_ERR(arb->spmimst_base); - goto err_put_ctrl; - } + if (IS_ERR(arb->spmimst_base)) + return PTR_ERR(arb->spmimst_base); arb->nclks = ARRAY_SIZE(pmif_clock_names); for (i = 0; i < arb->nclks; i++) @@ -468,7 +463,7 @@ static int mtk_spmi_probe(struct platform_device *pdev) err = clk_bulk_get(&pdev->dev, arb->nclks, arb->clks); if (err) { dev_err(&pdev->dev, "Failed to get clocks: %d\n", err); - goto err_put_ctrl; + return err; } err = clk_bulk_prepare_enable(arb->nclks, arb->clks); @@ -500,8 +495,6 @@ static int mtk_spmi_probe(struct platform_device *pdev) clk_bulk_disable_unprepare(arb->nclks, arb->clks); err_put_clks: clk_bulk_put(arb->nclks, arb->clks); -err_put_ctrl: - spmi_controller_put(ctrl); return err; } @@ -513,7 +506,6 @@ static void mtk_spmi_remove(struct platform_device *pdev) clk_bulk_disable_unprepare(arb->nclks, arb->clks); clk_bulk_put(arb->nclks, arb->clks); spmi_controller_remove(ctrl); - spmi_controller_put(ctrl); } static const struct of_device_id mtk_spmi_match_table[] = { diff --git a/drivers/spmi/spmi-pmic-arb.c b/drivers/spmi/spmi-pmic-arb.c index dcb675d980d4..9ed1180fe31f 100644 --- a/drivers/spmi/spmi-pmic-arb.c +++ b/drivers/spmi/spmi-pmic-arb.c @@ -1443,9 +1443,9 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev) u32 channel, ee, hw_ver; int err; - ctrl = spmi_controller_alloc(&pdev->dev, sizeof(*pmic_arb)); - if (!ctrl) - return -ENOMEM; + ctrl = devm_spmi_controller_alloc(&pdev->dev, sizeof(*pmic_arb)); + if (IS_ERR(ctrl)) + return PTR_ERR(ctrl); pmic_arb = spmi_controller_get_drvdata(ctrl); pmic_arb->spmic = ctrl; @@ -1462,20 +1462,16 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev) */ res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "core"); core = devm_ioremap(&ctrl->dev, res->start, resource_size(res)); - if (IS_ERR(core)) { - err = PTR_ERR(core); - goto err_put_ctrl; - } + if (IS_ERR(core)) + return PTR_ERR(core); pmic_arb->core_size = resource_size(res); pmic_arb->ppid_to_apid = devm_kcalloc(&ctrl->dev, PMIC_ARB_MAX_PPID, sizeof(*pmic_arb->ppid_to_apid), GFP_KERNEL); - if (!pmic_arb->ppid_to_apid) { - err = -ENOMEM; - goto err_put_ctrl; - } + if (!pmic_arb->ppid_to_apid) + return -ENOMEM; hw_ver = readl_relaxed(core + PMIC_ARB_VERSION); @@ -1499,19 +1495,15 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev) "obsrvr"); pmic_arb->rd_base = devm_ioremap(&ctrl->dev, res->start, resource_size(res)); - if (IS_ERR(pmic_arb->rd_base)) { - err = PTR_ERR(pmic_arb->rd_base); - goto err_put_ctrl; - } + if (IS_ERR(pmic_arb->rd_base)) + return PTR_ERR(pmic_arb->rd_base); res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "chnls"); pmic_arb->wr_base = devm_ioremap(&ctrl->dev, res->start, resource_size(res)); - if (IS_ERR(pmic_arb->wr_base)) { - err = PTR_ERR(pmic_arb->wr_base); - goto err_put_ctrl; - } + if (IS_ERR(pmic_arb->wr_base)) + return PTR_ERR(pmic_arb->wr_base); } pmic_arb->max_periphs = PMIC_ARB_MAX_PERIPHS; @@ -1522,10 +1514,9 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev) of_property_read_u32(pdev->dev.of_node, "qcom,bus-id", &pmic_arb->bus_instance); if (pmic_arb->bus_instance > 1) { - err = -EINVAL; dev_err(&pdev->dev, "invalid bus instance (%u) specified\n", pmic_arb->bus_instance); - goto err_put_ctrl; + return -EINVAL; } if (pmic_arb->bus_instance == 0) { @@ -1543,10 +1534,9 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev) } if (pmic_arb->base_apid + pmic_arb->apid_count > pmic_arb->max_periphs) { - err = -EINVAL; dev_err(&pdev->dev, "Unsupported APID count %d detected\n", pmic_arb->base_apid + pmic_arb->apid_count); - goto err_put_ctrl; + return -EINVAL; } } else if (hw_ver >= PMIC_ARB_VERSION_V5_MIN) { pmic_arb->base_apid = 0; @@ -1554,55 +1544,45 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev) PMIC_ARB_FEATURES_PERIPH_MASK; if (pmic_arb->apid_count > pmic_arb->max_periphs) { - err = -EINVAL; dev_err(&pdev->dev, "Unsupported APID count %d detected\n", pmic_arb->apid_count); - goto err_put_ctrl; + return -EINVAL; } } pmic_arb->apid_data = devm_kcalloc(&ctrl->dev, pmic_arb->max_periphs, sizeof(*pmic_arb->apid_data), GFP_KERNEL); - if (!pmic_arb->apid_data) { - err = -ENOMEM; - goto err_put_ctrl; - } + if (!pmic_arb->apid_data) + return -ENOMEM; dev_info(&ctrl->dev, "PMIC arbiter version %s (0x%x)\n", pmic_arb->ver_ops->ver_str, hw_ver); res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "intr"); pmic_arb->intr = devm_ioremap_resource(&ctrl->dev, res); - if (IS_ERR(pmic_arb->intr)) { - err = PTR_ERR(pmic_arb->intr); - goto err_put_ctrl; - } + if (IS_ERR(pmic_arb->intr)) + return PTR_ERR(pmic_arb->intr); res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "cnfg"); pmic_arb->cnfg = devm_ioremap_resource(&ctrl->dev, res); - if (IS_ERR(pmic_arb->cnfg)) { - err = PTR_ERR(pmic_arb->cnfg); - goto err_put_ctrl; - } + if (IS_ERR(pmic_arb->cnfg)) + return PTR_ERR(pmic_arb->cnfg); pmic_arb->irq = platform_get_irq_byname(pdev, "periph_irq"); - if (pmic_arb->irq < 0) { - err = pmic_arb->irq; - goto err_put_ctrl; - } + if (pmic_arb->irq < 0) + return pmic_arb->irq; err = of_property_read_u32(pdev->dev.of_node, "qcom,channel", &channel); if (err) { dev_err(&pdev->dev, "channel unspecified.\n"); - goto err_put_ctrl; + return err; } if (channel > 5) { dev_err(&pdev->dev, "invalid channel (%u) specified.\n", channel); - err = -EINVAL; - goto err_put_ctrl; + return -EINVAL; } pmic_arb->channel = channel; @@ -1610,22 +1590,19 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev) err = of_property_read_u32(pdev->dev.of_node, "qcom,ee", &ee); if (err) { dev_err(&pdev->dev, "EE unspecified.\n"); - goto err_put_ctrl; + return err; } if (ee > 5) { dev_err(&pdev->dev, "invalid EE (%u) specified\n", ee); - err = -EINVAL; - goto err_put_ctrl; + return -EINVAL; } pmic_arb->ee = ee; mapping_table = devm_kcalloc(&ctrl->dev, pmic_arb->max_periphs, sizeof(*mapping_table), GFP_KERNEL); - if (!mapping_table) { - err = -ENOMEM; - goto err_put_ctrl; - } + if (!mapping_table) + return -ENOMEM; pmic_arb->mapping_table = mapping_table; /* Initialize max_apid/min_apid to the opposite bounds, during @@ -1645,7 +1622,7 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev) if (err) { dev_err(&pdev->dev, "could not read APID->PPID mapping table, rc= %d\n", err); - goto err_put_ctrl; + return err; } } @@ -1654,8 +1631,7 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev) &pmic_arb_irq_domain_ops, pmic_arb); if (!pmic_arb->domain) { dev_err(&pdev->dev, "unable to create irq_domain\n"); - err = -ENOMEM; - goto err_put_ctrl; + return -ENOMEM; } irq_set_chained_handler_and_data(pmic_arb->irq, pmic_arb_chained_irq, @@ -1669,8 +1645,6 @@ static int spmi_pmic_arb_probe(struct platform_device *pdev) err_domain_remove: irq_set_chained_handler_and_data(pmic_arb->irq, NULL, NULL); irq_domain_remove(pmic_arb->domain); -err_put_ctrl: - spmi_controller_put(ctrl); return err; } @@ -1681,7 +1655,6 @@ static void spmi_pmic_arb_remove(struct platform_device *pdev) spmi_controller_remove(ctrl); irq_set_chained_handler_and_data(pmic_arb->irq, NULL, NULL); irq_domain_remove(pmic_arb->domain); - spmi_controller_put(ctrl); } static const struct of_device_id spmi_pmic_arb_match_table[] = { From patchwork Thu Aug 24 10:40:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fei Shao X-Patchwork-Id: 13363978 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 6EEA0C27C40 for ; Thu, 24 Aug 2023 10:42:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:To:From:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=11OMDqVoPHj88ZJ2JJBotRCN1O2u/mKSOXzwJ5mYolk=; b=m/DMoaM+mX650q 86J8AsknKKNM31l4PuGA4orGlappXloAR8js/VTgk/4+HRCyThYCosOKhTYhwO8dDiCS8EMHuK57N b9Wvsp6j7BHqEX7b8+4nbg7P1is7CjwYrKYohtN2g8yL47OmpV0cUemftip3H7bGC/aV6Juv13DOg ecyKDsnz7JJ1p0yQNM1crsm5KUM0VTJNtzkvODY6KFo2oviatsGHi+jKO3Tfsze1KjnsRXpEtksMg xGTkgiO3rnGwFzYrpOaZj6NH1U8Y4zN9y8qZJDaVVcVJ7CS/bpAJbUM4ZVIAFApUkdACbx4+algOL SyCQmqrgmsbiXjiW/hmQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qZ7ms-002tmB-1b; Thu, 24 Aug 2023 10:42:02 +0000 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qZ7mp-002tkH-2E for linux-mediatek@lists.infradead.org; Thu, 24 Aug 2023 10:42:00 +0000 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1bdb7b0c8afso41201625ad.3 for ; Thu, 24 Aug 2023 03:41:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1692873719; x=1693478519; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=11OMDqVoPHj88ZJ2JJBotRCN1O2u/mKSOXzwJ5mYolk=; b=TLRyytcCKZ5pvPqDgKQrJygb5/3SMgG9GDYdNw6z2HnL81D20CEDAFstplAijFbP4k bxJu/nxU4QI51JcqgWn43/7+qNZd/RWjEAJgvnKSJyZDLYhX0C6TLk9CFt4gHcJiokv8 /EnejQ+0+FfhONT74+rGUVytbINgjc8WfJPD0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692873719; x=1693478519; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=11OMDqVoPHj88ZJ2JJBotRCN1O2u/mKSOXzwJ5mYolk=; b=HbO5m8dwzWmCPGxBSrEOK3Y333sGf7r8H6F9R5ZKwBWCt7jNsHVGjPBBgXUF7b9xQc C/EIjcuvLxj9MCt4sfgS1ty1VcMpHMIwMZ2gHQEfERiIA8WHYo9JsWXDRlRp99gWW0wh TqK8R5jeW8kfCz4ni0z7jmJLJmUByMmpqubOgsLhT2eIOHQlZyvsfo2NepNuziaNjcm1 Eu/T58JBuGnA15mi3PSsqQ3v52cTK+neIRDqCQ0DRvcGCmvgJ1BJoy1iT7X/cuuvQ/KX bZ3LUjESvxj8Wq8aWw7v1qcC3ejspsaALPulDdU7vqJN2ZWjVHqATAa+ZQMoHr3Kfeo8 Z4/g== X-Gm-Message-State: AOJu0YxlKLKoTEzoePEPX1IcmhK2dFoAt77XKVXoJBvmwDa2LWQ+hBko U1qt9yyZrHa96ljvz0fn9XEsPw== X-Google-Smtp-Source: AGHT+IEjXqoNHLwL9K3+kgYdZSexg1MmfuqiBw8xGh1DzEWiwriMgsY3wjC8rJhHLSB9/+0if9QOXA== X-Received: by 2002:a17:903:1c4:b0:1bb:b91b:2b3c with SMTP id e4-20020a17090301c400b001bbb91b2b3cmr14732522plh.34.1692873719205; Thu, 24 Aug 2023 03:41:59 -0700 (PDT) Received: from fshao-p620.tpe.corp.google.com ([2401:fa00:1:10:ed6d:42e3:a23:8316]) by smtp.gmail.com with ESMTPSA id q2-20020a170902dac200b001b5247cac3dsm12524645plx.110.2023.08.24.03.41.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Aug 2023 03:41:58 -0700 (PDT) From: Fei Shao To: Stephen Boyd , Chen-Yu Tsai Subject: [PATCH 3/5] spmi: mtk-pmif: Reorder driver remove sequence Date: Thu, 24 Aug 2023 18:40:10 +0800 Message-ID: <20230824104101.4083400-4-fshao@chromium.org> X-Mailer: git-send-email 2.42.0.rc1.204.g551eb34607-goog In-Reply-To: <20230824104101.4083400-1-fshao@chromium.org> References: <20230824104101.4083400-1-fshao@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230824_034159_743524_4CC56648 X-CRM114-Status: GOOD ( 12.05 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Matthias Brugger , linux-arm-kernel@lists.infradead.org, AngeloGioacchino Del Regno Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org This driver enables clocks and then adds SPMI controller in probing, so we expect the reversed sequence in removal. Fix the order in the remove callback. Signed-off-by: Fei Shao Reviewed-by: AngeloGioacchino Del Regno --- drivers/spmi/spmi-mtk-pmif.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/spmi/spmi-mtk-pmif.c b/drivers/spmi/spmi-mtk-pmif.c index eb909a6e3b9e..2127bbd2f856 100644 --- a/drivers/spmi/spmi-mtk-pmif.c +++ b/drivers/spmi/spmi-mtk-pmif.c @@ -503,9 +503,9 @@ static void mtk_spmi_remove(struct platform_device *pdev) struct spmi_controller *ctrl = platform_get_drvdata(pdev); struct pmif *arb = spmi_controller_get_drvdata(ctrl); + spmi_controller_remove(ctrl); clk_bulk_disable_unprepare(arb->nclks, arb->clks); clk_bulk_put(arb->nclks, arb->clks); - spmi_controller_remove(ctrl); } static const struct of_device_id mtk_spmi_match_table[] = { From patchwork Thu Aug 24 10:40:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fei Shao X-Patchwork-Id: 13363979 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 E8724C6FA8F for ; Thu, 24 Aug 2023 10:42:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:To:From:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ydoYhmo/zUvr/Z1jqPRUS4uEIJI8i2ctDqfsePibZ0M=; b=RqisC4a8XcR0XO Dae1isov/m2c4EpdZvzowloV1PYKb3sKrYat4P5f8HiiM+490fBph5aOxB27qc7U39sclE+iYQtb+ hIseKO83zgPHrWLORdXj4arPjO6NC0slAtfFFLTbX7Z9TVRNYh4xU2zd6m8/oHnr3tgw5DY6TxTUp J2EDtnFCepZYUWgKsZbcxcW6zgl9oW2PJtipS9rUFA7dqBIA5GIVI6Xrc+FtkrXQMeA2o9+chwM8C VVF0VbEbIR4t6o+bdpp6WxieBxadylkIKBB25soad33EZIapZerNuVcxorck5QeeZKJnvIy3aVJ9B /RnNTIkCxiBrJ8Cd5RGw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qZ7n0-002tpi-2k; Thu, 24 Aug 2023 10:42:10 +0000 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qZ7mr-002tli-1j for linux-mediatek@lists.infradead.org; Thu, 24 Aug 2023 10:42:02 +0000 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1bda9207132so52474055ad.0 for ; Thu, 24 Aug 2023 03:42:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1692873721; x=1693478521; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ydoYhmo/zUvr/Z1jqPRUS4uEIJI8i2ctDqfsePibZ0M=; b=j+dJGmOnwFeanBncZxVZvZXDdOANE32WW+vw/iNPUL0ILVzlBSEFppcBXzFD+4nHDw WDZkcvHZrG2lDUkUEqCtDbaDjj6P9RZXLwL+Q2iQl3XehAvnZ06VtCkoHYMZvb1UfJSm XQj5mgQokXWMgcLNvVRQ4s3flUWFlQ95iUaPU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692873721; x=1693478521; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ydoYhmo/zUvr/Z1jqPRUS4uEIJI8i2ctDqfsePibZ0M=; b=f7z85kyEoRdraR4DvTyg9psqylfV7LmWsd/nC8tN29TCe8bsIxe+hjeqXNfYCRAQTV eNHL7Nfgtna1PE3Z1Cj4ybBCyZ9SF/dpE29KbnF7e8V7ksgqo2eaeZ3hE5qqpGrRrcSQ 9edp8PhBv7SA3R3TiV9o1HWiygt59xlv8JkkSSY8v8lnJKLT1lAjlpuVvUSxJVfhe/fq PTz0xdJKnzPAa6WtQfxhOU+Ce/S5XB0UA/Itds3ad0dVo73qADDjKOr2cYNpeieub6If EYe/1u92RNH18omry0ojDjhZj6+Ght9Dm/Uq49ce0VIQKk2/vFXfvEu8zoqlEg/e3h+N C/UA== X-Gm-Message-State: AOJu0YynTl/rxrR7m4oABhzCXWnv2uSzhqY/3UKG8+kFNZ2a/wXunQGo +RQMK7/pPXhJEj1/IN9daWkPxg== X-Google-Smtp-Source: AGHT+IElZ1QAwdCYRCRyL6bvp8lbkZPrWVHjamIivTYTyzrIfMNAh7MSIJqXviqpBH4X+ld/2/CnDg== X-Received: by 2002:a17:903:2446:b0:1b1:9233:bbf5 with SMTP id l6-20020a170903244600b001b19233bbf5mr17338652pls.57.1692873721059; Thu, 24 Aug 2023 03:42:01 -0700 (PDT) Received: from fshao-p620.tpe.corp.google.com ([2401:fa00:1:10:ed6d:42e3:a23:8316]) by smtp.gmail.com with ESMTPSA id q2-20020a170902dac200b001b5247cac3dsm12524645plx.110.2023.08.24.03.41.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Aug 2023 03:42:00 -0700 (PDT) From: Fei Shao To: Stephen Boyd , Chen-Yu Tsai Subject: [PATCH 4/5] spmi: hisi-spmi-controller: Use devm_spmi_controller_add() Date: Thu, 24 Aug 2023 18:40:11 +0800 Message-ID: <20230824104101.4083400-5-fshao@chromium.org> X-Mailer: git-send-email 2.42.0.rc1.204.g551eb34607-goog In-Reply-To: <20230824104101.4083400-1-fshao@chromium.org> References: <20230824104101.4083400-1-fshao@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230824_034201_590313_322423CD X-CRM114-Status: GOOD ( 14.72 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mauro Carvalho Chehab , linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Convert to the device-managed version of spmi_controller_add() and delete the unnecessary driver remove callback. Signed-off-by: Fei Shao --- Note that I skipped the conversions in spmi-mtk-pmif.c and spmi-pmic-arb.c because the driver remove sequence would have been changed, as using the devm version will postpone spmi_controller_remove() to where after remove callback is executed. So it turns out only hisi-spmi-controller.c is updated. drivers/spmi/hisi-spmi-controller.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/drivers/spmi/hisi-spmi-controller.c b/drivers/spmi/hisi-spmi-controller.c index a5525902656a..674a350cc676 100644 --- a/drivers/spmi/hisi-spmi-controller.c +++ b/drivers/spmi/hisi-spmi-controller.c @@ -308,7 +308,7 @@ static int spmi_controller_probe(struct platform_device *pdev) ctrl->read_cmd = spmi_read_cmd; ctrl->write_cmd = spmi_write_cmd; - ret = spmi_controller_add(ctrl); + ret = devm_spmi_controller_add(&pdev->dev, ctrl); if (ret) { dev_err(&pdev->dev, "spmi_controller_add failed with error %d!\n", ret); return ret; @@ -317,13 +317,6 @@ static int spmi_controller_probe(struct platform_device *pdev) return 0; } -static void spmi_del_controller(struct platform_device *pdev) -{ - struct spmi_controller *ctrl = platform_get_drvdata(pdev); - - spmi_controller_remove(ctrl); -} - static const struct of_device_id spmi_controller_match_table[] = { { .compatible = "hisilicon,kirin970-spmi-controller", @@ -334,7 +327,6 @@ MODULE_DEVICE_TABLE(of, spmi_controller_match_table); static struct platform_driver spmi_controller_driver = { .probe = spmi_controller_probe, - .remove_new = spmi_del_controller, .driver = { .name = "hisi_spmi_controller", .of_match_table = spmi_controller_match_table, From patchwork Thu Aug 24 10:40:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fei Shao X-Patchwork-Id: 13363981 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 69D63C7113B for ; Thu, 24 Aug 2023 10:42:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:To:From:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=R5Mj2qxwRu6ImbCbgKZB2mTmZc1sJ7FaGws4X/FyAcE=; b=h8mZCYd72qQ+J3 5loFWhht6Q6bTvhOZ9Dgok0twZiPJgaQD6JZgVcxGCFzzGDV8IUePXdK+OlEdg/X6mxVya2RhjKa0 dZMYYaMwbTrulJiBJk8ZFgOOTHOY9pov+eTC835ptb7ps42wXKSmAIMQBAcuBPowjY3LFiWyauZa/ AgPQBxbPvES6ABA7lYnNNvvEi/LlTgcMa6GTW6I7sjbsGDkUnXwG0xwW1VRxk6itdbT4ZNkqjPNta QAcjTkp/fz0zdlu0R2onQ9Qn5CaWUdRWIDlcG8yEfUTVhprCQZE8KReQJra0uHLjD0OsW8CC6p1HV 4dcgEEOFBr53O2B/euSQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qZ7n1-002tqC-1W; Thu, 24 Aug 2023 10:42:11 +0000 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qZ7mv-002tmf-2k for linux-mediatek@lists.infradead.org; Thu, 24 Aug 2023 10:42:07 +0000 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1bdca7cc28dso52418215ad.1 for ; Thu, 24 Aug 2023 03:42:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1692873723; x=1693478523; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=R5Mj2qxwRu6ImbCbgKZB2mTmZc1sJ7FaGws4X/FyAcE=; b=hZcQz83MuTgtVUHEdO3LOPIFB0JNUEtBmCMJCDx9VL+8o4UxqsI1LRU5qOk/EXIyhZ 96mdg+nhN+nkSlIDrvQ9tWxN32QvRpmMl2z70EA4VSyUSViZZ1Zz/K9JfTVjQ3fkYxaF gw+rR/aaoD2Q5MAoxZQg20nwNEbqER36/p6cE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692873723; x=1693478523; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=R5Mj2qxwRu6ImbCbgKZB2mTmZc1sJ7FaGws4X/FyAcE=; b=NeOqomUrTmkm8iaP7e9G6rP3BYqJDS6I9Kpn9vBdiaq972Lp5dzEC/9XIjwv25HZ8u 8wy4BfKBb19jtbL1n8IYBzW4+DE/5GNKxO/pywj2jhxOrl2JEFe3CRSr1x6ln6uFoYcJ hTqMfet+3jWpG//z6vqqHhUpMw48pEnOp5tcGqPxQh8w7UtxmHl4h7RUyI0SdRXJyGJy DywVMrKG+tqkJ6d70LiR81zFxpMneM/CVP3t9SFfh3b4yPTDQGfoac/iM1p0NxbpWTtm kKU+HzhcPpU0YPk59KcmM1n5VzbA07FxkCtpTcHgiT5mx+aIxLtlLmv4JBEftdjUazI+ hviw== X-Gm-Message-State: AOJu0YzF1gdPKhVn81/uVZRRyAvDLQb7rt1qwryblh4OsBxgj920G54v ToDLEkk7Xi+1FRJqyWzFxV3oiw== X-Google-Smtp-Source: AGHT+IGao9Th9qVXpav06rwJB33LMdKfO90d0/0YX0Nw2S957J/ZS1b/jA6DEO74HGdi3p7m7JgSFw== X-Received: by 2002:a17:903:264d:b0:1bf:364:f013 with SMTP id je13-20020a170903264d00b001bf0364f013mr13653715plb.45.1692873722931; Thu, 24 Aug 2023 03:42:02 -0700 (PDT) Received: from fshao-p620.tpe.corp.google.com ([2401:fa00:1:10:ed6d:42e3:a23:8316]) by smtp.gmail.com with ESMTPSA id q2-20020a170902dac200b001b5247cac3dsm12524645plx.110.2023.08.24.03.42.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Aug 2023 03:42:02 -0700 (PDT) From: Fei Shao To: Stephen Boyd , Chen-Yu Tsai Subject: [PATCH 5/5] spmi: Return meaningful errors in spmi_controller_alloc() Date: Thu, 24 Aug 2023 18:40:12 +0800 Message-ID: <20230824104101.4083400-6-fshao@chromium.org> X-Mailer: git-send-email 2.42.0.rc1.204.g551eb34607-goog In-Reply-To: <20230824104101.4083400-1-fshao@chromium.org> References: <20230824104101.4083400-1-fshao@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230824_034205_889742_A05E93D5 X-CRM114-Status: GOOD ( 11.89 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org spmi_controller_alloc() currently returns NULL to all types of errors, which can be improved. Use appropriate error code in returns and pass the errors from used functions where possible. Signed-off-by: Fei Shao --- drivers/spmi/devres.c | 4 ++-- drivers/spmi/spmi.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/spmi/devres.c b/drivers/spmi/devres.c index f18cbbe28812..c19f09243bc3 100644 --- a/drivers/spmi/devres.c +++ b/drivers/spmi/devres.c @@ -20,9 +20,9 @@ struct spmi_controller *devm_spmi_controller_alloc(struct device *parent, size_t return ERR_PTR(-ENOMEM); ctrl = spmi_controller_alloc(parent, size); - if (!ctrl) { + if (IS_ERR(ctrl)) { devres_free(ptr); - return ERR_PTR(-ENOMEM); + return ctrl; } *ptr = ctrl; diff --git a/drivers/spmi/spmi.c b/drivers/spmi/spmi.c index 7313d4c18a04..5f11ced3f8b9 100644 --- a/drivers/spmi/spmi.c +++ b/drivers/spmi/spmi.c @@ -445,11 +445,11 @@ struct spmi_controller *spmi_controller_alloc(struct device *parent, int id; if (WARN_ON(!parent)) - return NULL; + return ERR_PTR(-EINVAL); ctrl = kzalloc(sizeof(*ctrl) + size, GFP_KERNEL); if (!ctrl) - return NULL; + return ERR_PTR(-ENOMEM); device_initialize(&ctrl->dev); ctrl->dev.type = &spmi_ctrl_type; @@ -463,7 +463,7 @@ struct spmi_controller *spmi_controller_alloc(struct device *parent, dev_err(parent, "unable to allocate SPMI controller identifier.\n"); spmi_controller_put(ctrl); - return NULL; + return ERR_PTR(id); } ctrl->nr = id;