On Fri, Jun 21, 2024 at 10:06 AM Shan-Chun Hung<shanchun1218@xxxxxxxxx> wrote:Absolutely, kernel development needs careful attention to many details, like managing header file
On 2024/6/20 上午 03:09, Andy Shevchenko wrote:...
On Wed, Jun 19, 2024 at 7:47 AM Shan-Chun Hung<shanchun1218@xxxxxxxxx> wrote:
"Include What You Use". But some of the headers may be omitted as theyYou 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.
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.
...I will add add "#include <linux/align.h>"
Also check what header should be included for that macro, IIRC it's align.h.I will add sizes.h and directly apply globally defined ALIGN() macro+#define BOUNDARY_OK(addr, len) \Besides sizes.h being missed, this can be done with help of ALIGN()
+ ((addr | (SZ_128M - 1)) == ((addr + len - 1) | (SZ_128M - 1)))
macro (or alike). So, kill this and use the globally defined macro
inline.
instead
...I will modify it.
You might probably want to use the same in the restore_data array initialiser.Your idea is better, I will change it.+ for (idx = 0; idx < ARRAY_SIZE(restore_data); idx++) {sizeof(u32) ?
+ if (restore_data[idx].width == 32)
I will add devm_add_action_or_reset() to do sdhci_pltfm_free()....I will fix it.+ val[idx] = sdhci_readl(host, restore_data[idx].reg);sizeof(u8) ?
+ else if (restore_data[idx].width == 8)
+ val[idx] = sdhci_readb(host, restore_data[idx].reg);
+ }
Yes, they are, the problem is that freeing resources happens inI will use dev_err_probe() instead of dev_err()+ pltfm_host->clk = devm_clk_get(&pdev->dev, NULL);Use
+ if (IS_ERR(pltfm_host->clk)) {
+ err = PTR_ERR(pltfm_host->clk);
+ dev_err(&pdev->dev, "failed to get clk: %d\n", err);
return dev_err_probe(...);
I have tested it, there is no error messages during driver initial process.+ 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?
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.
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.
Understood, I will correct these issues as soon as possible....I will use devm_clk_get_optional_enabled() instead.+ }Use _enabled variant of devm_clk_get() instead.
+ err = clk_prepare_enable(pltfm_host->clk);
+ if (err)
+ goto free_pltfm;
+ }
Yes. It's part of the same issue.I am not entirely sure if it is similar to the "goto free_pltfm;" issue.+free_pltfm:This should go to be correct in ordering.
+ sdhci_pltfm_free(pdev);
After fixing the ordering issues in ->probe() this might need moreI will fix it.+ return err;Use remove_new callback.
+}
+
+static int ma35_remove(struct platform_device *pdev)
I will use sdhci_pltfm_remove instead of the ma35_remove.+{At least these two will go away as per probe error path.
+ 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);
modifications.
--+ return 0;
+}
With Best Regards,
Andy Shevchenko