Re: [PATCH] pci: tegra194: Fix debugfs cleanup for !CONFIG_PCIEASPM

From: Hans Zhang
Date: Sat Apr 05 2025 - 12:42:13 EST




On 2025/4/6 00:14, Christophe JAILLET wrote:
Le 05/04/2025 à 16:54, Hans Zhang a écrit :
When CONFIG_PCIEASPM is disabled, debugfs entries are not created, but
tegra_pcie_dw_remove() and tegra_pcie_dw_shutdown() unconditionally call
debugfs_remove_recursive(), leading to potential NULL pointer operations.

Introduce deinit_debugfs() to wrap debugfs_remove_recursive(), which is
stubbed for !CONFIG_PCIEASPM. Use this function during removal/shutdown to
ensure debugfs cleanup only occurs when entries were initialized.

This prevents kernel warnings and instability when ASPM support is
disabled.


Could you elaborate?


debugfs_remove_recursive() ends either to:

static inline void debugfs_remove(struct dentry *dentry)
{ }
if CONFIG_DEBUG_FS is not set,

or
to a function which starts with:
    if (IS_ERR_OR_NULL(dentry))
        return;
if it is set.


So what does this new deinit_debugfs() add?


Which NULL pointer are you seeing?
Did you actually manage to trigger it?



Hi Christophe,

You're right, and I'm sorry about that.

The following line of code only makes sense if the #if defined(CONFIG_PCIEASPM) condition holds. Do we need to optimize this?

pcie->debugfs = debugfs_create_dir(name, NULL);

Best regards,
Hans