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 9BFA8C27C4F for ; Mon, 24 Jun 2024 00:29:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:References:Cc:To:Subject:From:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=oLmnGFODnPObQ8SNLRDoqcDqu7WbjsbbEs2V4iPJ7G8=; b=bLv9FBLD94u7X4E8nprKv1UfbQ Zs0iWbdbNOQ9vMg9Xj1WI+0HePp5Qm0ajQJ1qTKKI5w/Y2Bnuq6RHnYEkEYGMgMBu8jrSIIJSso/G R7Ar+jju0H8kny0+9M3eIuQcpS5CQxUXpZhLsVVwVtir56AjFQ401BVyIUy5lf7aAgxfB3VHvkIYw c7CjSR7V6azsHsWgnM2QCqkT8N1Jt4+bym92N4d/F0I5pHh+7aQhLx2G9bF/hm6Xta0QVz4e02Fvm oX+7lTSiTkZapLqdUyig+VGDda0bfjGw/W3i0kf//yns/kEo+Uebgy43ed3X6TIlRzRth3AWUe+7n nUF1qh8g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sLXa1-0000000F6dx-35Jc; Mon, 24 Jun 2024 00:29:09 +0000 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sLXZw-0000000F6cj-3rp2 for linux-arm-kernel@lists.infradead.org; Mon, 24 Jun 2024 00:29:06 +0000 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1f64ecb1766so27736105ad.1 for ; Sun, 23 Jun 2024 17:29:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719188943; x=1719793743; darn=lists.infradead.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:from:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=oLmnGFODnPObQ8SNLRDoqcDqu7WbjsbbEs2V4iPJ7G8=; b=TdEQxTNTB7ZL7lTeCX41brGMofXAW5V+iTa6PsWFezRcS3Bm05YHlFnEWX+XK9bx4A kUPWMadX0tPnnKIF24q+MSixHJstm/77x1rey/Ns1JtGCCOxUb7/ynKxpzoU6VY5OEAN xGc6533dvgdpvXBrSxTJ/w4Ef12MS0b8ohEAbaMBxf126TtTywAS7BviOfgFZxOQrGFI VpRAbSYf7FZzKWP6QS3KPtQ6LRLr1vRhej9s0cEvCOso0829GwPVu7kBnMaKyf5fgJWU 6KCXBo7Nwu8kUWTkZnX3zCyqyxwyCCas8eQvX4Mtn1exnQTKUOAVrXlfhpdh5Re0iFaR Y4IA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719188943; x=1719793743; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:from:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oLmnGFODnPObQ8SNLRDoqcDqu7WbjsbbEs2V4iPJ7G8=; b=AB69hkedkJ6ZaWiTUI471cYxm6Ew/XXkeh8D6PjlHWS3lzSSR0vPqCE2ulmRU4WXvx Esw+KBmB5ZBrHwVWsPSvVMJc8nJjJSAgd5Ins2gNnnqPhu15NyDpSXnLxStf2//OFV+g akwHQtBW1DrkKZKR8BEkvHWzcT4e2CYXxP96Axv6yY3O121U6ekA6DmwdzRxkS6sOwuc rnj+xFY9bg0R3DQ09/DW4W0Xb/7tOfl+ieLqhqUloL9MiB096Uudq/PiBRni+3wULNwh CXVOlEjnrjT7Ke5PRwf1nvWtHL9JfCJ1c5dfuSESO20gVaCPhcOH1Xa+jymy3fJsaA/z 8lVw== X-Forwarded-Encrypted: i=1; AJvYcCUfxxYgD8h4NfvvQX1cJ99YrRVeXnP8sV7jK0UtSGP/iiVYRq9ybqh+9vhR1j0kmMIYTozWiqYR/iQxB+mwJ9bth4RG5WVYimHVj7aww75l/290fgQ= X-Gm-Message-State: AOJu0Yy/pFaR7Ma6lBNHlFCXMRvto1Vm6xVkGN4U8WZW22jhFAOKOtm3 O/IQ818BjAODnIpBYj8RQfLOYCheXcuSlYTFfoF8DAt8D1dxHNMj X-Google-Smtp-Source: AGHT+IECn2hTtkJjNmvo3hggOFyAa58BXolKo9b0f+I99ahJTLOAAtfdF/uLHCUGuOL9LyZQb8E7Fg== X-Received: by 2002:a17:902:ce82:b0:1f7:3d0d:4cd with SMTP id d9443c01a7336-1fa1d514687mr45274765ad.24.1719188942752; Sun, 23 Jun 2024 17:29:02 -0700 (PDT) Received: from [172.19.1.51] (60-250-192-107.hinet-ip.hinet.net. [60.250.192.107]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f9eb32b9edsm50417225ad.118.2024.06.23.17.28.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 23 Jun 2024 17:29:02 -0700 (PDT) Message-ID: Date: Mon, 24 Jun 2024 08:28:57 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Shan-Chun Hung Subject: Re: [PATCH 2/2] mmc: sdhci-of-ma35d1: Add Novoton MA35D1 SDHCI driver To: Andy Shevchenko Cc: ulf.hansson@linaro.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, adrian.hunter@intel.com, p.zabel@pengutronix.de, pbrobinson@gmail.com, serghox@gmail.com, mcgrof@kernel.org, prabhakar.mahadev-lad.rj@bp.renesas.com, forbidden405@outlook.com, tmaimon77@gmail.com, linux-arm-kernel@lists.infradead.org, linux-mmc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, ychuang3@nuvoton.com, schung@nuvoton.com References: <20240619054641.277062-1-shanchun1218@gmail.com> <20240619054641.277062-3-shanchun1218@gmail.com> <1e249c77-def1-4ffc-bbd6-d64f7e95b0ac@gmail.com> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240623_172905_060074_C2D29FA2 X-CRM114-Status: GOOD ( 32.93 ) 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 Dear Andy, Thanks for you review. On 2024/6/21 下午 07:25, Andy Shevchenko wrote: > On Fri, Jun 21, 2024 at 10:06 AM Shan-Chun Hung wrote: >> On 2024/6/20 上午 03:09, Andy Shevchenko wrote: >>> On Wed, Jun 19, 2024 at 7:47 AM Shan-Chun Hung wrote: > ... > >>> You are missing a lot of header inclusions, please follow IWYU principle. >> I am not familiar with IWYU yet, but I will learn it and use it for >> checks later on. > "Include What You Use". But some of the headers may be omitted as they > are guaranteed to be included by others. It's a bit hard because one > should know and follow the kernel development, currently the headers > in the kernel are a bit of a mess. Absolutely, kernel development needs careful attention to many details, like managing header file > ... > >>>> +#define BOUNDARY_OK(addr, len) \ >>>> + ((addr | (SZ_128M - 1)) == ((addr + len - 1) | (SZ_128M - 1))) >>> Besides sizes.h being missed, this can be done with help of ALIGN() >>> macro (or alike). So, kill this and use the globally defined macro >>> inline. >> I will add sizes.h and directly apply globally defined ALIGN() macro >> instead > Also check what header should be included for that macro, IIRC it's align.h. I will add add "#include " > ... > >>>> + for (idx = 0; idx < ARRAY_SIZE(restore_data); idx++) { >>>> + if (restore_data[idx].width == 32) >>> sizeof(u32) ? >> Your idea is better, I will change it. > You might probably want to use the same in the restore_data array initialiser. I will modify it. >>>> + val[idx] = sdhci_readl(host, restore_data[idx].reg); >>>> + else if (restore_data[idx].width == 8) >>> sizeof(u8) ? >> I will fix it. >>>> + val[idx] = sdhci_readb(host, restore_data[idx].reg); >>>> + } > ... > >>>> + pltfm_host->clk = devm_clk_get(&pdev->dev, NULL); >>>> + if (IS_ERR(pltfm_host->clk)) { >>>> + err = PTR_ERR(pltfm_host->clk); >>>> + dev_err(&pdev->dev, "failed to get clk: %d\n", err); >>> Use >>> >>> return dev_err_probe(...); >> I will use dev_err_probe() instead of dev_err() >>>> + goto free_pltfm; >>> This is wrong. You may not call non-devm before devm ones, otherwise >>> it makes a room for subtle mistakes on remove-probe or unbind-bind >>> cycles. Have you tested that? >> I have tested it, there is no error messages during driver initial process. >> >> My thought is that sdhci_pltfm_init() and sdhci_pltfm_free() are used together. >> >> If there's any error after the successful execution of sdhci_pltfm_init(), >> I'll use sdhci_pltfm_free(). >> >> I am not entirely sure if this answers your question. > Yes, they are, the problem is that freeing resources happens in > non-reversed order (for some of the resources). This might lead to > subtle mistakes as I said above. The rule of thumb is to avoid mixing > devm_*() with non-devm_*() calls. If you have both, they have to be > grouped as all devm_*() followed by all non-devm_*(). > In some cases you might need to wrap existing calls to become managed. > This may be done with the help of devm_add_action_or_reset(). Check > other drivers which are using that. I will add devm_add_action_or_reset() to do sdhci_pltfm_free(). >>>> + } >>>> + err = clk_prepare_enable(pltfm_host->clk); >>>> + if (err) >>>> + goto free_pltfm; >>> Use _enabled variant of devm_clk_get() instead. >> I will use devm_clk_get_optional_enabled() instead. >>>> + } > ... > >>>> +free_pltfm: >>>> + sdhci_pltfm_free(pdev); >>> This should go to be correct in ordering. >> I am not entirely sure if it is similar to the "goto free_pltfm;" issue. > Yes. It's part of the same issue. >>>> + return err; >>>> +} >>>> + >>>> +static int ma35_remove(struct platform_device *pdev) >>> Use remove_new callback. >> I will fix it. >>>> +{ >>>> + struct sdhci_host *host = platform_get_drvdata(pdev); >>>> + struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); >>>> + >>>> + sdhci_remove_host(host, 0); >>>> + clk_disable_unprepare(pltfm_host->clk); >>>> + sdhci_pltfm_free(pdev); >>> At least these two will go away as per probe error path. >> I will use sdhci_pltfm_remove instead of the ma35_remove. > After fixing the ordering issues in ->probe() this might need more > modifications. Understood, I will correct these issues as soon as possible. >>>> + return 0; >>>> +} > -- > With Best Regards, > Andy Shevchenko Best Regards, Shan-Chun