iwlwifi: mvm: no need to check return value of debugfs_create functions
Subsystems (2)
Greg Kroah-Hartman
maintainerPATCH 1/1 iwlwifi: mvm: no need to check return value of debugfs_create functions
When calling debugfs functions, there is no need to ever check the return value. The function can work or not, but the code logic should never do something different based on this.
--- .../wireless/intel/iwlwifi/mvm/debugfs-vif.c | 17 +--- .../net/wireless/intel/iwlwifi/mvm/debugfs.c | 84 +++++++------------ drivers/net/wireless/intel/iwlwifi/mvm/mvm.h | 7 +- drivers/net/wireless/intel/iwlwifi/mvm/ops.c | 12 +-- drivers/net/wireless/intel/iwlwifi/mvm/rs.c | 8 +- 5 files changed, 36 insertions(+), 92 deletions(-)
drivers/net/wireless/intel/iwlwifi/mvm/debugfs-vif.c +2 -15
@@ -1446,9 +1446,8 @@ static ssize_t iwl_dbgfs_quota_min_read(struct file *file,#define MVM_DEBUGFS_READ_WRITE_FILE_OPS (name, bufsz) \ _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)#define MVM_DEBUGFS_ADD_FILE_VIF (name, parent, mode) do { \ - if (!debugfs_create_file(#name, mode, parent, vif, \ - &iwl_dbgfs_##name##_ops)) \ - goto err; \ + debugfs_create_file(#name, mode, parent, vif, \ + &iwl_dbgfs_##name##_ops); \ } while (0)MVM_DEBUGFS_READ_FILE_OPS (mac_params);
@@ -1483,12 +1482,6 @@ void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif) mvmvif->dbgfs_dir =debugfs_create_dir ("iwlmvm" , dbgfs_dir); -if (!mvmvif->dbgfs_dir) { -IWL_ERR (mvm,"Failed to create debugfs directory under %pd\n" , - dbgfs_dir); -return ; - } -if (iwlmvm_mod_params.power_scheme !=IWL_POWER_SCHEME_CAM && ((vif->type ==NL80211_IFTYPE_STATION && !vif->p2p) || (vif->type ==NL80211_IFTYPE_STATION && vif->p2p)))
@@ -1537,12 +1530,6 @@ void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif) mvmvif->dbgfs_slink =debugfs_create_symlink (dbgfs_dir->d_name.name, mvm->debugfs_dir, buf); -if (!mvmvif->dbgfs_slink) -IWL_ERR (mvm,"Can't create debugfs symbolic link under %pd\n" , - dbgfs_dir); -return ; -err: -IWL_ERR (mvm,"Can't create debugfs entity\n" ); }void iwl_mvm_vif_dbgfs_clean (struct iwl_mvm *mvm,struct ieee80211_vif *vif)
drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c +28 -56
129 lines not on this page · raw message
drivers/net/wireless/intel/iwlwifi/mvm/mvm.h +3 -4
@@ -1682,14 +1682,13 @@ void iwl_mvm_rx_umac_scan_iter_complete_notif(struct iwl_mvm *mvm,/* MVM debugfs */ #ifdef CONFIG_IWLWIFI_DEBUGFS -int iwl_mvm_dbgfs_register (struct iwl_mvm *mvm,struct dentry *dbgfs_dir); +void iwl_mvm_dbgfs_register (struct iwl_mvm *mvm,struct dentry *dbgfs_dir);void iwl_mvm_vif_dbgfs_register (struct iwl_mvm *mvm,struct ieee80211_vif *vif);void iwl_mvm_vif_dbgfs_clean (struct iwl_mvm *mvm,struct ieee80211_vif *vif);#else -static inline int iwl_mvm_dbgfs_register (struct iwl_mvm *mvm, -struct dentry *dbgfs_dir) +static inline void iwl_mvm_dbgfs_register (struct iwl_mvm *mvm, +struct dentry *dbgfs_dir) { -return 0 ; }static inline void iwl_mvm_vif_dbgfs_register (struct iwl_mvm *mvm,struct ieee80211_vif *vif)
drivers/net/wireless/intel/iwlwifi/mvm/ops.c +1 -11
@@ -827,9 +827,7 @@ iwl_op_mode_mvm_start(struct iwl_trans *trans, const struct iwl_cfg *cfg, min_backoff =iwl_mvm_min_backoff (mvm);iwl_mvm_thermal_initialize (mvm, min_backoff); - err =iwl_mvm_dbgfs_register (mvm, dbgfs_dir); -if (err) - goto out_unregister; +iwl_mvm_dbgfs_register (mvm, dbgfs_dir);if (!iwl_mvm_has_new_rx_stats_api (mvm)) memset(&mvm->rx_stats_v3, 0,
@@ -848,14 +846,6 @@ iwl_op_mode_mvm_start(struct iwl_trans *trans, const struct iwl_cfg *cfg,return op_mode; - out_unregister: -if (iwlmvm_mod_params.init_dbg) -return op_mode; - -ieee80211_unregister_hw (mvm->hw); - mvm->hw_registered = false; -iwl_mvm_leds_exit (mvm); -iwl_mvm_thermal_exit (mvm); out_free:iwl_fw_flush_dump (&mvm->fwrt);iwl_fw_runtime_free (&mvm->fwrt);
drivers/net/wireless/intel/iwlwifi/mvm/rs.c +2 -6
@@ -4041,9 +4041,8 @@ static ssize_t iwl_dbgfs_ss_force_write(struct iwl_lq_sta *lq_sta, char *buf,#define MVM_DEBUGFS_READ_WRITE_FILE_OPS (name, bufsz) \ _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct iwl_lq_sta)#define MVM_DEBUGFS_ADD_FILE_RS (name, parent, mode) do { \ - if (!debugfs_create_file(#name, mode, parent, lq_sta, \ - &iwl_dbgfs_##name##_ops)) \ - goto err; \ + debugfs_create_file(#name, mode, parent, lq_sta, \ + &iwl_dbgfs_##name##_ops); \ } while (0)MVM_DEBUGFS_READ_WRITE_FILE_OPS (ss_force,32 );
@@ -4071,9 +4070,6 @@ static void rs_drv_add_sta_debugfs(void *mvm, void *priv_sta, &lq_sta->pers.dbg_fixed_txp_reduction);MVM_DEBUGFS_ADD_FILE_RS (ss_force, dir,0600 ); -return ; -err: -IWL_ERR ((struct iwl_mvm *)mvm,"Can't create debugfs entity\n" ); }void rs_remove_sta_debugfs (void *mvm,void *mvm_sta)
Signature · 1 line
2.20.1
Quoted 5 lines · Greg Kroah-Hartman
When calling debugfs functions, there is no need to ever check the return value. The function can work or not, but the code logic should
never do something different based on this.
Quoted 8 lines
Cc Johannes Berg <[email protected]>Cc Emmanuel Grumbach <[email protected]>Cc Luca Coelho <[email protected]>Cc Intel Linux Wireless <[email protected]>Cc Kalle Valo <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>---
Thanks, Greg! I applied this in our internal tree and it will reach upstream following our normal upstreaming process.
--
Cheers,
Luca.
Quoted 31 lines · Greg Kroah-Hartman
drivers/net/wireless/intel/iwlwifi/mvm/debugfs-vif.c +2
-9@@ -1446,9 +1446,8 @@ static ssize_t iwl_dbgfs_quota_min_read(struct file *file,#define MVM_DEBUGFS_READ_WRITE_FILE_OPS (name, bufsz) \ _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)#define MVM_DEBUGFS_ADD_FILE_VIF (name, parent, mode) do { \ - if (!debugfs_create_file(#name, mode, parent, vif, \ - &iwl_dbgfs_##name##_ops)) \ - goto err; \ + debugfs_create_file(#name, mode, parent, vif, \ + &iwl_dbgfs_##name##_ops); \ } while (0)MVM_DEBUGFS_READ_FILE_OPS (mac_params);@@ -1483,12 +1482,6 @@ void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif) mvmvif->dbgfs_dir =debugfs_create_dir ("iwlmvm" , dbgfs_dir); -if (!mvmvif->dbgfs_dir) { -IWL_ERR (mvm,"Failed to create debugfs directory under %pd\n" , - dbgfs_dir); -return ; - } -if (iwlmvm_mod_params.power_scheme !=IWL_POWER_SCHEME_CAM && ((vif->type ==NL80211_IFTYPE_STATION && !vif->p2p) || (vif->type ==NL80211_IFTYPE_STATION && vif->p2p)))@@ -1537,12 +1530,6 @@ void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
drivers/net/wireless/intel/iwlwifi/mvm/debugfs-vif.c void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif) · line 1534
Quoted 10 lines
drivers/net/wireless/intel/iwlwifi/mvm/debugfs-vif.c +0
-6mvmvif->dbgfs_slink =debugfs_create_symlink (dbgfs_dir->d_name.name, mvm->debugfs_dir, buf); -if (!mvmvif->dbgfs_slink) -IWL_ERR (mvm,"Can't create debugfs symbolic link under %pd\n" , - dbgfs_dir); -return ; -err: -IWL_ERR (mvm,"Can't create debugfs entity\n" ); }
Fedora got a bug report https://bugzilla.redhat.com/show_bug.cgi?id=1691034
of a crash with 5.0 and the user did a bisect which pointed to ff9fb72bc077 ("debugfs: return error values, not NULL") because the error checking is no longer correct in this driver.
Based on https://patchwork.kernel.org/patch/10865839/, it looks like this is supposed to go in for 5.2 but this needs to go in now as the error checking is currently broken without it. Can this get queued for Linus so we can get it in 5.0 stable?
Thanks,
Laura
Greg Kroah-Hartman
maintainerQuoted 43 lines · Laura Abbott
Quoted 27 lines · Greg Kroah-Hartman
drivers/net/wireless/intel/iwlwifi/mvm/debugfs-vif.c +2
-9@@ -1446,9 +1446,8 @@ static ssize_t iwl_dbgfs_quota_min_read(struct file *file,#define MVM_DEBUGFS_READ_WRITE_FILE_OPS (name, bufsz) \ _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)#define MVM_DEBUGFS_ADD_FILE_VIF (name, parent, mode) do { \ - if (!debugfs_create_file(#name, mode, parent, vif, \ - &iwl_dbgfs_##name##_ops)) \ - goto err; \ + debugfs_create_file(#name, mode, parent, vif, \ + &iwl_dbgfs_##name##_ops); \ } while (0)MVM_DEBUGFS_READ_FILE_OPS (mac_params);@@ -1483,12 +1482,6 @@ void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif) mvmvif->dbgfs_dir =debugfs_create_dir ("iwlmvm" , dbgfs_dir); -if (!mvmvif->dbgfs_dir) { -IWL_ERR (mvm,"Failed to create debugfs directory under %pd\n" , - dbgfs_dir); -return ; - } -if (iwlmvm_mod_params.power_scheme !=IWL_POWER_SCHEME_CAM && ((vif->type ==NL80211_IFTYPE_STATION && !vif->p2p) || (vif->type ==NL80211_IFTYPE_STATION && vif->p2p)))drivers/net/wireless/intel/iwlwifi/mvm/debugfs-vif.c void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif) · line 1532
Quoted 9 lines
drivers/net/wireless/intel/iwlwifi/mvm/debugfs-vif.c +0
-6@@ -1537,12 +1530,6 @@ void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif) mvmvif->dbgfs_slink =debugfs_create_symlink (dbgfs_dir->d_name.name, mvm->debugfs_dir, buf); -if (!mvmvif->dbgfs_slink) -IWL_ERR (mvm,"Can't create debugfs symbolic link under %pd\n" , - dbgfs_dir); -return ; -err: -IWL_ERR (mvm,"Can't create debugfs entity\n" ); }Fedora got a bug report https://bugzilla.redhat.com/show_bug.cgi?id=1691034
of a crash with 5.0 and the user did a bisect which pointed toff9fb72bc077("debugfs: return error values, not NULL") because the error checking is no longer correct in this driver.
Quoted 4 lines
Based on https://patchwork.kernel.org/patch/10865839/, it looks like this is supposed to go in for 5.2 but this needs to go in now as the error checking is currently broken without it. Can this get queued for Linus so we can get it in 5.0 stable?
That's odd, I can't see how the error checking is wrong here. If the directory is not created, an error will be returned, which should be able to be handled by debugfs_create_file().
So with this patch does the error go away?
strange,
greg k-h
Quoted 49 lines · Greg Kroah-Hartman
Quoted 43 lines · Laura Abbott
Quoted 27 lines · Greg Kroah-Hartman
drivers/net/wireless/intel/iwlwifi/mvm/debugfs-vif.c +2
-9@@ -1446,9 +1446,8 @@ static ssize_t iwl_dbgfs_quota_min_read(struct file *file,#define MVM_DEBUGFS_READ_WRITE_FILE_OPS (name, bufsz) \ _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)#define MVM_DEBUGFS_ADD_FILE_VIF (name, parent, mode) do { \ - if (!debugfs_create_file(#name, mode, parent, vif, \ - &iwl_dbgfs_##name##_ops)) \ - goto err; \ + debugfs_create_file(#name, mode, parent, vif, \ + &iwl_dbgfs_##name##_ops); \ } while (0)MVM_DEBUGFS_READ_FILE_OPS (mac_params);@@ -1483,12 +1482,6 @@ void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif) mvmvif->dbgfs_dir =debugfs_create_dir ("iwlmvm" , dbgfs_dir); -if (!mvmvif->dbgfs_dir) { -IWL_ERR (mvm,"Failed to create debugfs directory under %pd\n" , - dbgfs_dir); -return ; - } -if (iwlmvm_mod_params.power_scheme !=IWL_POWER_SCHEME_CAM && ((vif->type ==NL80211_IFTYPE_STATION && !vif->p2p) || (vif->type ==NL80211_IFTYPE_STATION && vif->p2p)))drivers/net/wireless/intel/iwlwifi/mvm/debugfs-vif.c void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif) · line 1532
Quoted 9 lines
drivers/net/wireless/intel/iwlwifi/mvm/debugfs-vif.c +0
-6@@ -1537,12 +1530,6 @@ void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif) mvmvif->dbgfs_slink =debugfs_create_symlink (dbgfs_dir->d_name.name, mvm->debugfs_dir, buf); -if (!mvmvif->dbgfs_slink) -IWL_ERR (mvm,"Can't create debugfs symbolic link under %pd\n" , - dbgfs_dir); -return ; -err: -IWL_ERR (mvm,"Can't create debugfs entity\n" ); }Fedora got a bug report https://bugzilla.redhat.com/show_bug.cgi?id=1691034
of a crash with 5.0 and the user did a bisect which pointed toff9fb72bc077("debugfs: return error values, not NULL") because the error checking is no longer correct in this driver.Quoted 4 lines
Based on https://patchwork.kernel.org/patch/10865839/, it looks like this is supposed to go in for 5.2 but this needs to go in now as the error checking is currently broken without it. Can this get queued for Linus so we can get it in 5.0 stable?
Quoted 6 lines
That's odd, I can't see how the error checking is wrong here. If the directory is not created, an error will be returned, which should be able to be handled by
debugfs_create_file().So with this patch does the error go away?
The full patch didn't apply cleanly and I didn't try to backport it for the reporter to test. I was going off of the theory that if the patch was there it would fix the problem.
What I _think_ is going wrong is dbgfs_dir is actually an errno value:
struct dentry *dbgfs_dir = vif->debugfs_dir;
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
char buf[100];
/*
* Check if debugfs directory already exist before creating it.
* This may happen when, for example, resetting hw or suspend-resume
*/
if (!dbgfs_dir || mvmvif->dbgfs_dir)
return;so this blows up in the snprintf
snprintf(buf, 100, "../../../%pd3/%pd",
dbgfs_dir,
mvmvif->dbgfs_dir);Unless I misunderstood what the debugfs error change did. I think this also means the if check needs to look for IS_ERR and not just !dbgfs_dir.
Thanks,
Laura
Quoted 4 lines
strange,
greg k-h
Greg Kroah-Hartman
maintainerQuoted 76 lines · Laura Abbott
Quoted 49 lines · Greg Kroah-Hartman
Quoted 43 lines · Laura Abbott
Quoted 27 lines · Greg Kroah-Hartman
drivers/net/wireless/intel/iwlwifi/mvm/debugfs-vif.c +2
-9@@ -1446,9 +1446,8 @@ static ssize_t iwl_dbgfs_quota_min_read(struct file *file,#define MVM_DEBUGFS_READ_WRITE_FILE_OPS (name, bufsz) \ _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)#define MVM_DEBUGFS_ADD_FILE_VIF (name, parent, mode) do { \ - if (!debugfs_create_file(#name, mode, parent, vif, \ - &iwl_dbgfs_##name##_ops)) \ - goto err; \ + debugfs_create_file(#name, mode, parent, vif, \ + &iwl_dbgfs_##name##_ops); \ } while (0)MVM_DEBUGFS_READ_FILE_OPS (mac_params);@@ -1483,12 +1482,6 @@ void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif) mvmvif->dbgfs_dir =debugfs_create_dir ("iwlmvm" , dbgfs_dir); -if (!mvmvif->dbgfs_dir) { -IWL_ERR (mvm,"Failed to create debugfs directory under %pd\n" , - dbgfs_dir); -return ; - } -if (iwlmvm_mod_params.power_scheme !=IWL_POWER_SCHEME_CAM && ((vif->type ==NL80211_IFTYPE_STATION && !vif->p2p) || (vif->type ==NL80211_IFTYPE_STATION && vif->p2p)))drivers/net/wireless/intel/iwlwifi/mvm/debugfs-vif.c void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif) · line 1532
Quoted 9 lines
drivers/net/wireless/intel/iwlwifi/mvm/debugfs-vif.c +0
-6@@ -1537,12 +1530,6 @@ void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif) mvmvif->dbgfs_slink =debugfs_create_symlink (dbgfs_dir->d_name.name, mvm->debugfs_dir, buf); -if (!mvmvif->dbgfs_slink) -IWL_ERR (mvm,"Can't create debugfs symbolic link under %pd\n" , - dbgfs_dir); -return ; -err: -IWL_ERR (mvm,"Can't create debugfs entity\n" ); }Fedora got a bug report https://bugzilla.redhat.com/show_bug.cgi?id=1691034
of a crash with 5.0 and the user did a bisect which pointed toff9fb72bc077("debugfs: return error values, not NULL") because the error checking is no longer correct in this driver.Quoted 4 lines
Based on https://patchwork.kernel.org/patch/10865839/, it looks like this is supposed to go in for 5.2 but this needs to go in now as the error checking is currently broken without it. Can this get queued for Linus so we can get it in 5.0 stable?
Quoted 6 lines
That's odd, I can't see how the error checking is wrong here. If the directory is not created, an error will be returned, which should be able to be handled by
debugfs_create_file().So with this patch does the error go away?
The full patch didn't apply cleanly and I didn't try to backport it for the reporter to test. I was going off of the theory that if the patch was there it would fix the problem.
What I _think_ is going wrong is
dbgfs_diris actually an errno value:struct dentry *dbgfs_dir = vif->debugfs_dir; struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); char buf[100]; /* * Check if debugfs directory already exist before creating it. * This may happen when, for example, resetting hw or suspend-resume */ if (!dbgfs_dir || mvmvif->dbgfs_dir) return;
Quoted 5 lines
so this blows up in the snprintf
snprintf(buf, 100, "../../../%pd3/%pd", dbgfs_dir, mvmvif->dbgfs_dir);
Ah, yeah, that's horrible. They had the name before, why pull it out of the dentry again? That will blow up hard, but maybe printk should check to see if the pointer really is a pointer first.
Quoted 2 lines
Unless I misunderstood what the debugfs error change did. I think this also means the if check needs to look for
IS_ERRand not just !dbgfs_dir.
Yes, that is correct.
thanks,
greg k-h
Quoted 79 lines · Greg Kroah-Hartman
Quoted 78 lines · Laura Abbott
Quoted 49 lines · Greg Kroah-Hartman
Quoted 43 lines · Laura Abbott
Quoted 27 lines · Greg Kroah-Hartman
drivers/net/wireless/intel/iwlwifi/mvm/debugfs-vif.c +2
-9@@ -1446,9 +1446,8 @@ static ssize_t iwl_dbgfs_quota_min_read(struct file *file,#define MVM_DEBUGFS_READ_WRITE_FILE_OPS (name, bufsz) \ _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)#define MVM_DEBUGFS_ADD_FILE_VIF (name, parent, mode) do { \ - if (!debugfs_create_file(#name, mode, parent, vif, \ - &iwl_dbgfs_##name##_ops)) \ - goto err; \ + debugfs_create_file(#name, mode, parent, vif, \ + &iwl_dbgfs_##name##_ops); \ } while (0)MVM_DEBUGFS_READ_FILE_OPS (mac_params);@@ -1483,12 +1482,6 @@ void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif) mvmvif->dbgfs_dir =debugfs_create_dir ("iwlmvm" , dbgfs_dir); -if (!mvmvif->dbgfs_dir) { -IWL_ERR (mvm,"Failed to create debugfs directory under %pd\n" , - dbgfs_dir); -return ; - } -if (iwlmvm_mod_params.power_scheme !=IWL_POWER_SCHEME_CAM && ((vif->type ==NL80211_IFTYPE_STATION && !vif->p2p) || (vif->type ==NL80211_IFTYPE_STATION && vif->p2p)))drivers/net/wireless/intel/iwlwifi/mvm/debugfs-vif.c void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif) · line 1532
Quoted 9 lines
drivers/net/wireless/intel/iwlwifi/mvm/debugfs-vif.c +0
-6@@ -1537,12 +1530,6 @@ void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif) mvmvif->dbgfs_slink =debugfs_create_symlink (dbgfs_dir->d_name.name, mvm->debugfs_dir, buf); -if (!mvmvif->dbgfs_slink) -IWL_ERR (mvm,"Can't create debugfs symbolic link under %pd\n" , - dbgfs_dir); -return ; -err: -IWL_ERR (mvm,"Can't create debugfs entity\n" ); }Fedora got a bug report https://bugzilla.redhat.com/show_bug.cgi?id=1691034
of a crash with 5.0 and the user did a bisect which pointed toff9fb72bc077("debugfs: return error values, not NULL") because the error checking is no longer correct in this driver.Quoted 4 lines
Based on https://patchwork.kernel.org/patch/10865839/, it looks like this is supposed to go in for 5.2 but this needs to go in now as the error checking is currently broken without it. Can this get queued for Linus so we can get it in 5.0 stable?
Quoted 6 lines
That's odd, I can't see how the error checking is wrong here. If the directory is not created, an error will be returned, which should be able to be handled by
debugfs_create_file().So with this patch does the error go away?
The full patch didn't apply cleanly and I didn't try to backport it for the reporter to test. I was going off of the theory that if the patch was there it would fix the problem.
What I _think_ is going wrong is
dbgfs_diris actually an errno value:struct dentry *dbgfs_dir = vif->debugfs_dir; struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); char buf[100]; /* * Check if debugfs directory already exist before creating it. * This may happen when, for example, resetting hw or suspend-resume */ if (!dbgfs_dir || mvmvif->dbgfs_dir) return;so this blows up in the snprintf
Quoted 7 lines
Quoted 3 lines
snprintf(buf, 100, "../../../%pd3/%pd", dbgfs_dir, mvmvif->dbgfs_dir);Ah, yeah, that's horrible. They had the name before, why pull it out of the dentry again? That will blow up hard, but maybe printk should check to see if the pointer really is a pointer first.
I agree this is ugly. But do you mean we could use ("../../../%pd3/%s", dbgfs_dir, "iwlmvm")? Or how did we have the name?
Also, this would solve the sprintf() problem, but still wouldn't solve the real issue, which is not check for ERR in dbgfs_dir.
Quoted 4 lines
Quoted 2 lines
Unless I misunderstood what the debugfs error change did. I think this also means the if check needs to look for
IS_ERRand not just !dbgfs_dir.Yes, that is correct.
Yeah, we can do that. So this patch doesn't need to be sent for v5.1-rc* and v5.0, right? At least I don't see how it would fix the issue. What we need is a new patch with the IS_ERR check.
--
Cheers,
Luca.
Greg Kroah-Hartman
maintainerQuoted 84 lines · Luca Coelho
Quoted 83 lines · Greg Kroah-Hartman
Quoted 81 lines · Laura Abbott
Quoted 49 lines · Greg Kroah-Hartman
Quoted 43 lines · Laura Abbott
Quoted 27 lines · Greg Kroah-Hartman
drivers/net/wireless/intel/iwlwifi/mvm/debugfs-vif.c +2
-9@@ -1446,9 +1446,8 @@ static ssize_t iwl_dbgfs_quota_min_read(struct file *file,#define MVM_DEBUGFS_READ_WRITE_FILE_OPS (name, bufsz) \ _MVM_DEBUGFS_READ_WRITE_FILE_OPS(name, bufsz, struct ieee80211_vif)#define MVM_DEBUGFS_ADD_FILE_VIF (name, parent, mode) do { \ - if (!debugfs_create_file(#name, mode, parent, vif, \ - &iwl_dbgfs_##name##_ops)) \ - goto err; \ + debugfs_create_file(#name, mode, parent, vif, \ + &iwl_dbgfs_##name##_ops); \ } while (0)MVM_DEBUGFS_READ_FILE_OPS (mac_params);@@ -1483,12 +1482,6 @@ void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif) mvmvif->dbgfs_dir =debugfs_create_dir ("iwlmvm" , dbgfs_dir); -if (!mvmvif->dbgfs_dir) { -IWL_ERR (mvm,"Failed to create debugfs directory under %pd\n" , - dbgfs_dir); -return ; - } -if (iwlmvm_mod_params.power_scheme !=IWL_POWER_SCHEME_CAM && ((vif->type ==NL80211_IFTYPE_STATION && !vif->p2p) || (vif->type ==NL80211_IFTYPE_STATION && vif->p2p)))drivers/net/wireless/intel/iwlwifi/mvm/debugfs-vif.c void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif) · line 1532
Quoted 9 lines
drivers/net/wireless/intel/iwlwifi/mvm/debugfs-vif.c +0
-6@@ -1537,12 +1530,6 @@ void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif) mvmvif->dbgfs_slink =debugfs_create_symlink (dbgfs_dir->d_name.name, mvm->debugfs_dir, buf); -if (!mvmvif->dbgfs_slink) -IWL_ERR (mvm,"Can't create debugfs symbolic link under %pd\n" , - dbgfs_dir); -return ; -err: -IWL_ERR (mvm,"Can't create debugfs entity\n" ); }Fedora got a bug report https://bugzilla.redhat.com/show_bug.cgi?id=1691034
of a crash with 5.0 and the user did a bisect which pointed toff9fb72bc077("debugfs: return error values, not NULL") because the error checking is no longer correct in this driver.Quoted 4 lines
Based on https://patchwork.kernel.org/patch/10865839/, it looks like this is supposed to go in for 5.2 but this needs to go in now as the error checking is currently broken without it. Can this get queued for Linus so we can get it in 5.0 stable?
Quoted 6 lines
That's odd, I can't see how the error checking is wrong here. If the directory is not created, an error will be returned, which should be able to be handled by
debugfs_create_file().So with this patch does the error go away?
The full patch didn't apply cleanly and I didn't try to backport it for the reporter to test. I was going off of the theory that if the patch was there it would fix the problem.
What I _think_ is going wrong is
dbgfs_diris actually an errno value:struct dentry *dbgfs_dir = vif->debugfs_dir; struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); char buf[100]; /* * Check if debugfs directory already exist before creating it. * This may happen when, for example, resetting hw or suspend-resume */ if (!dbgfs_dir || mvmvif->dbgfs_dir) return;so this blows up in the snprintf
snprintf(buf, 100, "../../../%pd3/%pd", dbgfs_dir, mvmvif->dbgfs_dir);
Quoted 6 lines
Quoted 3 lines
Ah, yeah, that's horrible. They had the name before, why pull it out of the dentry again? That will blow up hard, but maybe printk should check to see if the pointer really is a pointer first.
I agree this is ugly. But do you mean we could use ("../../../%pd3/%s",
dbgfs_dir, "iwlmvm")? Or how did we have the name?
You "had" the name because you created this directory and name previously :)
Quoted 2 lines
Also, this would solve the
sprintf()problem, but still wouldn't solve the real issue, which is not check for ERR indbgfs_dir.
True.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Unless I misunderstood what the debugfs error change did. I think this also means the if check needs to look for
IS_ERRand not just !dbgfs_dir.Yes, that is correct.
Yeah, we can do that. So this patch doesn't need to be sent for v5.1-rc* and v5.0, right? At least I don't see how it would fix the issue. What we need is a new patch with the
IS_ERRcheck.
Ok, let me go create that right now...
thanks,
greg k-h
Greg Kroah-Hartman
maintainerPATCH 1/1 iwlwifi: properly check debugfs dentry before using it
debugfs can now report an error code if something went wrong instead of just NULL. So if the return value is to be used as a "real" dentry, it needs to be checked if it is an error before dereferencing it.
This is now happening because of ff9fb72bc077 ("debugfs: return error values, not NULL"). If multiple iwlwifi devices are in the system, this can cause problems when the driver attempts to create the main debugfs directory again. Later on in the code we fail horribly by trying to dereference a pointer that is an error value.
drivers/net/wireless/intel/iwlwifi/mvm/debugfs-vif.c +1 -2
@@ -774,8 +774,7 @@ void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif)return ; mvmvif->dbgfs_dir =debugfs_create_dir ("iwlmvm" , dbgfs_dir); - -if (!mvmvif->dbgfs_dir) { +if (IS_ERR_OR_NULL (mvmvif->dbgfs_dir)) {IWL_ERR (mvm,"Failed to create debugfs directory under %pd\n" , dbgfs_dir);return ;
Re: [PATCH] iwlwifi: properly check debugfs dentry before using it
Quoted 11 lines · Greg Kroah-Hartman
debugfs can now report an error code if something went wrong instead of just NULL. So if the return value is to be used as a "real" dentry, it needs to be checked if it is an error before dereferencing it.
This is now happening because of
ff9fb72bc077("debugfs: return error values, not NULL"). If multiple iwlwifi devices are in the system, this can cause problems when the driver attempts to create the main debugfs directory again. Later on in the code we fail horribly by trying to dereference a pointer that is an error value.Reported-by Laura Abbott <[email protected]>
Can you add
for the bugzilla reporter who took the time to do the bisect? I'll ask for testing as well.
Quoted 24 lines
Cc Johannes Berg <[email protected]>Cc Emmanuel Grumbach <[email protected]>Cc Luca Coelho <[email protected]>Cc Intel Linux Wireless <[email protected]>Cc Kalle Valo <[email protected]>Cc stable <[email protected]> # 5.0Signed-off-by Greg Kroah-Hartman <[email protected]>drivers/net/wireless/intel/iwlwifi/mvm/debugfs-vif.c +1
-2@@ -774,8 +774,7 @@ void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif)return ; mvmvif->dbgfs_dir =debugfs_create_dir ("iwlmvm" , dbgfs_dir); - -if (!mvmvif->dbgfs_dir) { +if (IS_ERR_OR_NULL (mvmvif->dbgfs_dir)) {IWL_ERR (mvm,"Failed to create debugfs directory under %pd\n" , dbgfs_dir);return ;
Re: [PATCH] iwlwifi: properly check debugfs dentry before using it
In reply to Greg Kroah-HartmanQuoted 39 lines · Greg Kroah-Hartman
debugfs can now report an error code if something went wrong instead of
just NULL. So if the return value is to be used as a "real" dentry, it
needs to be checked if it is an error before dereferencing it.This is now happening because of
ff9fb72bc077("debugfs: return error values, not NULL"). If multiple iwlwifi devices are in the system, this
can cause problems when the driver attempts to create the main debugfs
directory again. Later on in the code we fail horribly by trying to dereference a pointer that is an error value.Reported-by Laura Abbott <[email protected]>Cc Johannes Berg <[email protected]>Cc Emmanuel Grumbach <[email protected]>Cc Luca Coelho <[email protected]>Cc Intel Linux Wireless <[email protected]>Cc Kalle Valo <[email protected]>Cc stable <[email protected]> # 5.0Signed-off-by Greg Kroah-Hartman <[email protected]>drivers/net/wireless/intel/iwlwifi/mvm/debugfs-vif.c +1
-2@@ -774,8 +774,7 @@ void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif)return ; mvmvif->dbgfs_dir =debugfs_create_dir ("iwlmvm" , dbgfs_dir); - - if (!mvmvif->dbgfs_dir) { + if (IS_ERR_OR_NULL(mvmvif->dbgfs_dir)) { IWL_ERR(mvm, "Failed to create debugfs directory under %pd\n",
drivers/net/wireless/intel/iwlwifi/mvm/debugfs-vif.c void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif) · line 780
Quoted 2 lines
drivers/net/wireless/intel/iwlwifi/mvm/debugfs-vif.c +0
-0dbgfs_dir);return ;
Thanks! I've applied this internally and will send upstream for v5.1- rc* following our normal upstreaming process.
I added the other Reported-by that Laura asked for and added "mvm:" to the subject.
--
Cheers,
Luca.