From patchwork Fri Feb 3 23:53:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 13128533 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 157A0C05027 for ; Fri, 3 Feb 2023 23:55:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230042AbjBCXzC (ORCPT ); Fri, 3 Feb 2023 18:55:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229626AbjBCXzB (ORCPT ); Fri, 3 Feb 2023 18:55:01 -0500 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DBEC68AF3 for ; Fri, 3 Feb 2023 15:55:00 -0800 (PST) Received: by mail-ed1-x535.google.com with SMTP id cw4so6589466edb.13 for ; Fri, 03 Feb 2023 15:55:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=IjF+AyumbkCroYCpRQKcqM9cxRCnUovfKnLOGpRIN+s=; b=FKCCAVUddag1opHQeKvMv4wdWqCwre69SRK8n27XialLZjd8H6hUcOfTvJG1KXcUaA tXR6HisbAoAlPxxz2fS6sm2qwptrTYIzVe4K/PVUBSPFHIkrH2P2ASQvlTDxxE4xM5Uy Qrx1XfN11zQb0leJtFcptPQYZCHVH1FB4Za8si9DZpFu/S7yOfloqRey3MT7FgMMgiQS oci9TUCK2JRiS6IA8gQZDv87KzAhiY7U4kjtAvN4xrkQXybNHqFpWsU/QTPNGwPsgbAd G1xUZyDFlms2Sg1jr01BH18ADmhQ2TPgr/9nKkltCMHUKOk1syS7Z9+Fc+Nl+B8eFIOM 2riQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IjF+AyumbkCroYCpRQKcqM9cxRCnUovfKnLOGpRIN+s=; b=6NChGQQhQt0a1jUBRMri8cMAcsoJ25yX7wKuV+mcifsxeiG4zk8l1/OTHEWyPH3oxV JaY1MRhuP+SH/58xzc7LxHLBBE+947dyAq+l9N59DStOsddNgbwNq9hWGiQ/hnqWk2zj U18M54EyJ+gf77Wmr74r3Xg9FaPtvWQXAVC1x5GAr1PeiBdBCit0QjRBL6qzWCRxdNbM 4ilJELOYrD4lHqhHiMj/Oi4c29wpAYKQlBIUknsXUD6DfUbVVDjeFAMyDoh4Ge1+Se3E SdhenE+AUA3/wLdvu5ty+4u9Fl++rF3mdSS0DFoWb+HTTzDN1QU+23Veu7zCHCJsjJKt FEow== X-Gm-Message-State: AO0yUKWeK7mEPtli3mqWu3N1DC5ZBcdE3Xha1gXvscUQRkTyfTuh8E2o b2Z72MpaDSIlY1Z7HSObPjE= X-Google-Smtp-Source: AK7set/8EtO/rSBe+ssFcgZE1P/ihXSBguQMxtMY5jcbuGFFuR8NJaiNvM//B+KsvSsAkT7LfrU9FA== X-Received: by 2002:a50:aacf:0:b0:49c:fdd2:a47d with SMTP id r15-20020a50aacf000000b0049cfdd2a47dmr12624790edc.37.1675468498814; Fri, 03 Feb 2023 15:54:58 -0800 (PST) Received: from ?IPV6:2a01:c23:b81c:5800:95fd:ccbf:6c44:23f7? (dynamic-2a01-0c23-b81c-5800-95fd-ccbf-6c44-23f7.c23.pool.telefonica.de. [2a01:c23:b81c:5800:95fd:ccbf:6c44:23f7]) by smtp.googlemail.com with ESMTPSA id r17-20020a05640251d100b0046c7c3755a7sm1792895edd.17.2023.02.03.15.54.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Feb 2023 15:54:58 -0800 (PST) Message-ID: <6d8f9fdc-7c9e-8e4f-e6ef-5470b971c74e@gmail.com> Date: Sat, 4 Feb 2023 00:53:35 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: [PATCH 1/2] mmc: core: add devm_mmc_alloc_host Content-Language: en-US From: Heiner Kallweit To: Ulf Hansson , Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl Cc: "linux-mmc@vger.kernel.org" , "open list:ARM/Amlogic Meson..." , "linux-arm-kernel@lists.infradead.org" References: In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Add a device-managed version of mmc_alloc_host(). The argument order is reversed compared to mmc_alloc_host() because device-managed functions typically have the device argument first. Signed-off-by: Heiner Kallweit --- drivers/mmc/core/host.c | 26 ++++++++++++++++++++++++++ include/linux/mmc/host.h | 1 + 2 files changed, 27 insertions(+) diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c index d17eda753..6a7475ad7 100644 --- a/drivers/mmc/core/host.c +++ b/drivers/mmc/core/host.c @@ -588,6 +588,32 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev) EXPORT_SYMBOL(mmc_alloc_host); +static void devm_mmc_host_release(struct device *dev, void *res) +{ + mmc_free_host(*(struct mmc_host **)res); +} + +struct mmc_host *devm_mmc_alloc_host(struct device *dev, int extra) +{ + struct mmc_host **dr, *host; + + dr = devres_alloc(devm_mmc_host_release, sizeof(*dr), GFP_KERNEL); + if (!dr) + return ERR_PTR(-ENOMEM); + + host = mmc_alloc_host(extra, dev); + if (IS_ERR(host)) { + devres_free(dr); + return host; + } + + *dr = host; + devres_add(dev, dr); + + return host; +} +EXPORT_SYMBOL(devm_mmc_alloc_host); + static int mmc_validate_host_caps(struct mmc_host *host) { struct device *dev = host->parent; diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index 8fdd3cf97..812e6b583 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -527,6 +527,7 @@ struct mmc_host { struct device_node; struct mmc_host *mmc_alloc_host(int extra, struct device *); +struct mmc_host *devm_mmc_alloc_host(struct device *dev, int extra); int mmc_add_host(struct mmc_host *); void mmc_remove_host(struct mmc_host *); void mmc_free_host(struct mmc_host *); From patchwork Fri Feb 3 23:54:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 13128534 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9EFD3C61DA4 for ; Fri, 3 Feb 2023 23:55:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231614AbjBCXzD (ORCPT ); Fri, 3 Feb 2023 18:55:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229626AbjBCXzD (ORCPT ); Fri, 3 Feb 2023 18:55:03 -0500 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FD6C69503 for ; Fri, 3 Feb 2023 15:55:01 -0800 (PST) Received: by mail-ej1-x629.google.com with SMTP id me3so19657850ejb.7 for ; Fri, 03 Feb 2023 15:55:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=B5szyujuXXZvpHfx5ixivTtqq4kbda1YQiNvs6P56sM=; b=V/yndW6G5Khi4mY4pY9vfL6FkgwaJ4UMRnSXIJM678O4jSMDXJCLF+txfC3zq0+7ZQ TT8Ujb3OIUTL+G7NHMBDlQ1nkFU6jeGyizeMMxVW5/m7SN8MIrMb4SKsw4gx+Ndhssw6 z/EGjjPppap7hj/nKpRCvgd0C28zAAHqKyikh/3w2Bu+6Qc7vZwIfgXI6DCfXzYTH4l2 MI0LjYb9WmRy+uvcooR/5ThKtGjX0wnfEjvE1hRxwgefxuMgIGAR5BvoTHmu6kBthmwJ GUea+Ul5gbsnPVzHvMEV/D7EuUP61DQQ8k8M8C7ja8xfuyqUBVc9X0svEWv7eEvxqElK +Oow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=B5szyujuXXZvpHfx5ixivTtqq4kbda1YQiNvs6P56sM=; b=DkDMxvnhaXcLkW7lDMd5KBJ5rmn9tlEDk6WHx/6xhnoIJgl1ac4TnaNocfoGs3JlVz aPtwojpIVLL6JNO66CIofBTKolxqfee82hdPc9WTd6DDPA9NrM5Yjm+ks1OBaQrbtNJ3 +NZ9FISFu3B727VnI5i9gYYEslQG8GgTLkqvC2ulqtkDAsWs8ZNuD3WM51/xkjeYAiSe URohQaoy35YENDjRqQSLWvZ/8IpW2cpDSQYykKzcxYJfNUxF4qOIYbTHNiVeJcaMvGFp Wq0HFsiYaoaWQ8se7zDnPXD2SnPOqBLmzhChepQWLmqVNj3iWz6wMM1XnojXJUeMctnl VqVw== X-Gm-Message-State: AO0yUKX0XkCDv4VwwPzoVNgtka5WrQkZy4jOHKDMDvQ7VkpSYZRIwhJE LiRoiXk8TtV8I+7YEjtuKjyhZLRuzpE= X-Google-Smtp-Source: AK7set+US4/Wmk03TuWdp+ujn1Hpoc7KrqhYQdTBXn8/qmtcZAFC8XTsWlzfbF8uqODk2+pvjHTZsA== X-Received: by 2002:a17:907:c20c:b0:883:3661:97e5 with SMTP id ti12-20020a170907c20c00b00883366197e5mr11825031ejc.50.1675468500022; Fri, 03 Feb 2023 15:55:00 -0800 (PST) Received: from ?IPV6:2a01:c23:b81c:5800:95fd:ccbf:6c44:23f7? (dynamic-2a01-0c23-b81c-5800-95fd-ccbf-6c44-23f7.c23.pool.telefonica.de. [2a01:c23:b81c:5800:95fd:ccbf:6c44:23f7]) by smtp.googlemail.com with ESMTPSA id v21-20020a509555000000b004a9cb25d1eesm1139909eda.87.2023.02.03.15.54.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Feb 2023 15:54:59 -0800 (PST) Message-ID: <728f159b-885f-c78a-1a3d-f55c245250e1@gmail.com> Date: Sat, 4 Feb 2023 00:54:48 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: [PATCH 2/2] mmc: meson-gx: use devm_mmc_alloc_host Content-Language: en-US From: Heiner Kallweit To: Ulf Hansson , Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl Cc: "linux-mmc@vger.kernel.org" , "open list:ARM/Amlogic Meson..." , "linux-arm-kernel@lists.infradead.org" References: In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Use new function devm_mmc_alloc_host() to simplify the code. Signed-off-by: Heiner Kallweit --- drivers/mmc/host/meson-gx-mmc.c | 52 +++++++++++---------------------- 1 file changed, 17 insertions(+), 35 deletions(-) diff --git a/drivers/mmc/host/meson-gx-mmc.c b/drivers/mmc/host/meson-gx-mmc.c index be1a972c2..a2fc25467 100644 --- a/drivers/mmc/host/meson-gx-mmc.c +++ b/drivers/mmc/host/meson-gx-mmc.c @@ -1185,7 +1185,7 @@ static int meson_mmc_probe(struct platform_device *pdev) struct mmc_host *mmc; int ret; - mmc = mmc_alloc_host(sizeof(struct meson_host), &pdev->dev); + mmc = devm_mmc_alloc_host(&pdev->dev, sizeof(struct meson_host)); if (!mmc) return -ENOMEM; host = mmc_priv(mmc); @@ -1201,46 +1201,33 @@ static int meson_mmc_probe(struct platform_device *pdev) host->vqmmc_enabled = false; ret = mmc_regulator_get_supply(mmc); if (ret) - goto free_host; + return ret; ret = mmc_of_parse(mmc); - if (ret) { - if (ret != -EPROBE_DEFER) - dev_warn(&pdev->dev, "error parsing DT: %d\n", ret); - goto free_host; - } + if (ret) + return dev_err_probe(&pdev->dev, ret, "error parsing DT\n"); host->data = (struct meson_mmc_data *) of_device_get_match_data(&pdev->dev); - if (!host->data) { - ret = -EINVAL; - goto free_host; - } + if (!host->data) + return -EINVAL; ret = device_reset_optional(&pdev->dev); - if (ret) { - dev_err_probe(&pdev->dev, ret, "device reset failed\n"); - goto free_host; - } + if (ret) + return dev_err_probe(&pdev->dev, ret, "device reset failed\n"); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); host->regs = devm_ioremap_resource(&pdev->dev, res); - if (IS_ERR(host->regs)) { - ret = PTR_ERR(host->regs); - goto free_host; - } + if (IS_ERR(host->regs)) + return PTR_ERR(host->regs); host->irq = platform_get_irq(pdev, 0); - if (host->irq <= 0) { - ret = -EINVAL; - goto free_host; - } + if (host->irq <= 0) + return -EINVAL; host->pinctrl = devm_pinctrl_get(&pdev->dev); - if (IS_ERR(host->pinctrl)) { - ret = PTR_ERR(host->pinctrl); - goto free_host; - } + if (IS_ERR(host->pinctrl)) + return PTR_ERR(host->pinctrl); host->pins_clk_gate = pinctrl_lookup_state(host->pinctrl, "clk-gate"); @@ -1251,14 +1238,12 @@ static int meson_mmc_probe(struct platform_device *pdev) } host->core_clk = devm_clk_get(&pdev->dev, "core"); - if (IS_ERR(host->core_clk)) { - ret = PTR_ERR(host->core_clk); - goto free_host; - } + if (IS_ERR(host->core_clk)) + return PTR_ERR(host->core_clk); ret = clk_prepare_enable(host->core_clk); if (ret) - goto free_host; + return ret; ret = meson_mmc_clk_init(host); if (ret) @@ -1353,8 +1338,6 @@ static int meson_mmc_probe(struct platform_device *pdev) clk_disable_unprepare(host->mmc_clk); err_core_clk: clk_disable_unprepare(host->core_clk); -free_host: - mmc_free_host(mmc); return ret; } @@ -1371,7 +1354,6 @@ static int meson_mmc_remove(struct platform_device *pdev) clk_disable_unprepare(host->mmc_clk); clk_disable_unprepare(host->core_clk); - mmc_free_host(host->mmc); return 0; }