Skip to contentSkip to conversation

assorted debugfs stuff

PATCH In review Al Viro 10 participants 36 messages Jul 2, 2025 – Jul 9, 2025 2 messages not in the archive

Subsystems (21)
lore
Share & tools
lore

Al Viro

author maintainer
#0 lore raw

PATCH 1/1 assorted debugfs stuff

A bit more of debugfs work; that stuff sits in
git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs.git #work.debugfs Individual patches in followups. Please, review.

Several removals of pointless debugfs_file_{get,put}():
zynqmp: don't bother with debugfs_file_{get,put}() in proxied fops
hfi1: get rid of redundant debugfs_file_{get,put}()
regmap: get rid of redundant debugfs_file_{get,put}()
resctrl: get rid of pointless debugfs_file_{get,put}()
Getting rid of the last remnants of debugfs_real_fops():
vmscan: don't bother with debugfs_real_fops()
netronome: don't bother with debugfs_real_fops()
debugfs: split short and full proxy wrappers, kill debugfs_real_fops()

Bogosities in drivers/thermal/testing:
fix tt_command_write():
1) unbalanced debugfs_file_get(). Not needed in the first place - file_operations are accessed only via debugfs_create_file(), so debugfs wrappers will take care of that itself.
2) kmalloc() for a buffer used only for duration of a function is not a problem, but for a buffer no longer than 16 bytes?
3) strstr() is for finding substrings; for finding a character there's strchr().

debugfs_get_aux() stuff:
debugfs_get_aux(): allow storing non-const void *
blk-mq-debugfs: use debugfs_aux_data()
lpfc: don't use file->f_path.dentry for comparisons
If you want a home-grown switch, at least use enum for selector...

author maintainer
#1 lore raw

PATCH 1/11 zynqmp: don't bother with debugfs_file_{get,put}() in proxied fops

When debugfs file has been created by debugfs_create_file_unsafe(), we do need the file_operations methods to use debugfs_file_{get,put}() to prevent concurrent removal; for files created by debugfs_create_file() that is done in the wrappers that call underlying methods, so there's no point whatsoever duplicating that in the underlying methods themselves.

---
 drivers/gpu/drm/xlnx/zynqmp_dp.c | 38 ++++----------------------------
 1 file changed, 4 insertions(+), 34 deletions(-)
drivers/gpu/drm/xlnx/zynqmp_dp.c +4 -34
index 238cbb49963e..197defe4f928 100644
@@ -1869,20 +1869,14 @@ static int zynqmp_dp_test_setup(struct zynqmp_dp *dp)
 static ssize_t zynqmp_dp_pattern_read(struct file *file, char __user *user_buf,
 				      size_t count, loff_t *ppos)
 {
-	struct dentry *dentry = file->f_path.dentry;
 	struct zynqmp_dp *dp = file->private_data;
 	char buf[16];
 	ssize_t ret;
 
-	ret = debugfs_file_get(dentry);
-	if (unlikely(ret))
-		return ret;
-
 	scoped_guard(mutex, &dp->lock)
 		ret = snprintf(buf, sizeof(buf), "%s\n",
 			       test_pattern_str[dp->test.pattern]);
 
-	debugfs_file_put(dentry);
 	return simple_read_from_buffer(user_buf, count, ppos, buf, ret);
 }
 
@@ -1890,27 +1884,20 @@ static ssize_t zynqmp_dp_pattern_write(struct file *file,
 				       const char __user *user_buf,
 				       size_t count, loff_t *ppos)
 {
-	struct dentry *dentry = file->f_path.dentry;
 	struct zynqmp_dp *dp = file->private_data;
 	char buf[16];
 	ssize_t ret;
 	int pattern;
 
-	ret = debugfs_file_get(dentry);
-	if (unlikely(ret))
-		return ret;
-
 	ret = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, user_buf,
 				     count);
 	if (ret < 0)
-		goto out;
+		return ret;
 	buf[ret] = '\0';
 
 	pattern = sysfs_match_string(test_pattern_str, buf);
-	if (pattern < 0) {
-		ret = -EINVAL;
-		goto out;
-	}
+	if (pattern < 0)
+		return -EINVAL;
 
 	mutex_lock(&dp->lock);
 	dp->test.pattern = pattern;
@@ -1919,8 +1906,6 @@ static ssize_t zynqmp_dp_pattern_write(struct file *file,
 						 dp->test.custom) ?: ret;
 	mutex_unlock(&dp->lock);
 
-out:
-	debugfs_file_put(dentry);
 	return ret;
 }
 
@@ -2026,20 +2011,13 @@ DEFINE_DEBUGFS_ATTRIBUTE(fops_zynqmp_dp_active, zynqmp_dp_active_get,
 static ssize_t zynqmp_dp_custom_read(struct file *file, char __user *user_buf,
 				     size_t count, loff_t *ppos)
 {
-	struct dentry *dentry = file->f_path.dentry;
 	struct zynqmp_dp *dp = file->private_data;
 	ssize_t ret;
 
-	ret = debugfs_file_get(dentry);
-	if (unlikely(ret))
-		return ret;
-
 	mutex_lock(&dp->lock);
 	ret = simple_read_from_buffer(user_buf, count, ppos, &dp->test.custom,
 				      sizeof(dp->test.custom));
 	mutex_unlock(&dp->lock);
-
-	debugfs_file_put(dentry);
 	return ret;
 }
 
@@ -2047,18 +2025,13 @@ static ssize_t zynqmp_dp_custom_write(struct file *file,
 				      const char __user *user_buf,
 				      size_t count, loff_t *ppos)
 {
-	struct dentry *dentry = file->f_path.dentry;
 	struct zynqmp_dp *dp = file->private_data;
 	ssize_t ret;
 	char buf[sizeof(dp->test.custom)];
 
-	ret = debugfs_file_get(dentry);
-	if (unlikely(ret))
-		return ret;
-
 	ret = simple_write_to_buffer(buf, sizeof(buf), ppos, user_buf, count);
 	if (ret < 0)
-		goto out;
+		return ret;
 
 	mutex_lock(&dp->lock);
 	memcpy(dp->test.custom, buf, ret);
@@ -2066,9 +2039,6 @@ static ssize_t zynqmp_dp_custom_write(struct file *file,
 		ret = zynqmp_dp_set_test_pattern(dp, dp->test.pattern,
 						 dp->test.custom) ?: ret;
 	mutex_unlock(&dp->lock);
-
-out:
-	debugfs_file_put(dentry);
 	return ret;
 }
 
Signature · 1 line
2.39.5
author maintainer
#2 lore raw

PATCH 2/11 hfi1: get rid of redundant debugfs_file_{get,put}()

All files in question are created via debugfs_create_file(), so exclusion with removals is provided by debugfs wrappers; as the matter of fact, hfi1-private wrappers had been redundant at least since 2017...

---
 drivers/infiniband/hw/hfi1/debugfs.c | 28 ----------------------------
 drivers/infiniband/hw/hfi1/debugfs.h |  9 ++-------
 drivers/infiniband/hw/hfi1/fault.c   |  9 ---------
 3 files changed, 2 insertions(+), 44 deletions(-)
drivers/infiniband/hw/hfi1/debugfs.c +0 -28
index a1e01b447265..ac37ab7f8995 100644
@@ -22,34 +22,6 @@
 
 static struct dentry *hfi1_dbg_root;
 
-/* wrappers to enforce srcu in seq file */
-ssize_t hfi1_seq_read(struct file *file, char __user *buf, size_t size,
-		      loff_t *ppos)
-{
-	struct dentry *d = file->f_path.dentry;
-	ssize_t r;
-
-	r = debugfs_file_get(d);
-	if (unlikely(r))
-		return r;
-	r = seq_read(file, buf, size, ppos);
-	debugfs_file_put(d);
-	return r;
-}
-
-loff_t hfi1_seq_lseek(struct file *file, loff_t offset, int whence)
-{
-	struct dentry *d = file->f_path.dentry;
-	loff_t r;
-
-	r = debugfs_file_get(d);
-	if (unlikely(r))
-		return r;
-	r = seq_lseek(file, offset, whence);
-	debugfs_file_put(d);
-	return r;
-}
-
 #define private2dd(file) (file_inode(file)->i_private)
 #define private2ppd(file) (file_inode(file)->i_private)
 
drivers/infiniband/hw/hfi1/debugfs.h +2 -7
index 54d952a4016c..65b48839abc6 100644
@@ -33,16 +33,11 @@ static int _##name##_open(struct inode *inode, struct file *s) \
 static const struct file_operations _##name##_file_ops = { \
 	.owner   = THIS_MODULE, \
 	.open    = _##name##_open, \
-	.read    = hfi1_seq_read, \
-	.llseek  = hfi1_seq_lseek, \
+	.read    = seq_read, \
+	.llseek  = seq_lseek, \
 	.release = seq_release \
 }
 
-
-ssize_t hfi1_seq_read(struct file *file, char __user *buf, size_t size,
-		      loff_t *ppos);
-loff_t hfi1_seq_lseek(struct file *file, loff_t offset, int whence);
-
 #ifdef CONFIG_DEBUG_FS
 void hfi1_dbg_ibdev_init(struct hfi1_ibdev *ibd);
 void hfi1_dbg_ibdev_exit(struct hfi1_ibdev *ibd);
drivers/infiniband/hw/hfi1/fault.c +0 -9
index ec9ee59fcf0c..a45cbffd52c7 100644
@@ -104,9 +104,6 @@ static ssize_t fault_opcodes_write(struct file *file, const char __user *buf,
 		goto free_data;
 	}
 
-	ret = debugfs_file_get(file->f_path.dentry);
-	if (unlikely(ret))
-		goto free_data;
 	ptr = data;
 	token = ptr;
 	for (ptr = data; *ptr; ptr = end + 1, token = ptr) {
@@ -154,7 +151,6 @@ static ssize_t fault_opcodes_write(struct file *file, const char __user *buf,
 	}
 	ret = len;
 
-	debugfs_file_put(file->f_path.dentry);
 free_data:
 	kfree(data);
 	return ret;
@@ -173,9 +169,6 @@ static ssize_t fault_opcodes_read(struct file *file, char __user *buf,
 	data = kcalloc(datalen, sizeof(*data), GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
-	ret = debugfs_file_get(file->f_path.dentry);
-	if (unlikely(ret))
-		goto free_data;
 	bit = find_first_bit(fault->opcodes, bitsize);
 	while (bit < bitsize) {
 		zero = find_next_zero_bit(fault->opcodes, bitsize, bit);
@@ -189,11 +182,9 @@ static ssize_t fault_opcodes_read(struct file *file, char __user *buf,
 					 bit);
 		bit = find_next_bit(fault->opcodes, bitsize, zero);
 	}
-	debugfs_file_put(file->f_path.dentry);
 	data[size - 1] = '\n';
 	data[size] = '\0';
 	ret = simple_read_from_buffer(buf, len, pos, data, size);
-free_data:
 	kfree(data);
 	return ret;
 }
Signature · 1 line
2.39.5
author maintainer
#3 lore raw

PATCH 3/11 regmap: get rid of redundant debugfs_file_{get,put}()

In reply to Al Viro

pointless in ->read()/->write() of file_operations used only via debugfs_create_file()

---
 drivers/base/regmap/regmap-debugfs.c | 10 ----------
 1 file changed, 10 deletions(-)
drivers/base/regmap/regmap-debugfs.c +0 -10
index fb84cda92a75..c9b4c04b1cf6 100644
@@ -470,10 +470,6 @@ static ssize_t regmap_cache_only_write_file(struct file *file,
 	if (err)
 		return count;
 
-	err = debugfs_file_get(file->f_path.dentry);
-	if (err)
-		return err;
-
 	map->lock(map->lock_arg);
 
 	if (new_val && !map->cache_only) {
@@ -486,7 +482,6 @@ static ssize_t regmap_cache_only_write_file(struct file *file,
 	map->cache_only = new_val;
 
 	map->unlock(map->lock_arg);
-	debugfs_file_put(file->f_path.dentry);
 
 	if (require_sync) {
 		err = regcache_sync(map);
@@ -517,10 +512,6 @@ static ssize_t regmap_cache_bypass_write_file(struct file *file,
 	if (err)
 		return count;
 
-	err = debugfs_file_get(file->f_path.dentry);
-	if (err)
-		return err;
-
 	map->lock(map->lock_arg);
 
 	if (new_val && !map->cache_bypass) {
@@ -532,7 +523,6 @@ static ssize_t regmap_cache_bypass_write_file(struct file *file,
 	map->cache_bypass = new_val;
 
 	map->unlock(map->lock_arg);
-	debugfs_file_put(file->f_path.dentry);
 
 	return count;
 }
Signature · 1 line
2.39.5
maintainer
#4 lore raw

Re: [PATCH 03/11] regmap: get rid of redundant debugfs_file_{get,put}()

Quoted 2 lines · Al Viro

pointless in ->read()/->write() of file_operations used only via debugfs_create_file()

What's the story with dependencies here - does this need to go with the rest of the series? I don't have the cover letter or the rest of the series.

author maintainer
#5 lore raw

PATCH 4/11 resctrl: get rid of pointless debugfs_file_{get,put}()

In reply to Al Viro

->write() of file_operations that gets used only via debugfs_create_file() is called only under debugfs_file_get()

---
 fs/resctrl/pseudo_lock.c | 4 ----
 1 file changed, 4 deletions(-)
fs/resctrl/pseudo_lock.c +0 -4
index ccc2f9213b4b..87bbc2605de1 100644
@@ -764,13 +764,9 @@ static ssize_t pseudo_lock_measure_trigger(struct file *file,
 	if (ret == 0) {
 		if (sel != 1 && sel != 2 && sel != 3)
 			return -EINVAL;
-		ret = debugfs_file_get(file->f_path.dentry);
-		if (ret)
-			return ret;
 		ret = pseudo_lock_measure_cycles(rdtgrp, sel);
 		if (ret == 0)
 			ret = count;
-		debugfs_file_put(file->f_path.dentry);
 	}
 
 	return ret;
Signature · 1 line
2.39.5
maintainer
#6 lore raw

Re: [PATCH 04/11] resctrl: get rid of pointless debugfs_file_{get,put}()

On Wed, Jul 02, 2025 at 10:16:50PM +0100, Al Viro wrote:

+Reinette

Quoted 29 lines

->write() of file_operations that gets used only via debugfs_create_file() is called only under debugfs_file_get()

---
 fs/resctrl/pseudo_lock.c | 4 ----
 1 file changed, 4 deletions(-)
fs/resctrl/pseudo_lock.c +0 -4
index ccc2f9213b4b..87bbc2605de1 100644
@@ -764,13 +764,9 @@ static ssize_t pseudo_lock_measure_trigger(struct file *file,
 	if (ret == 0) {
 		if (sel != 1 && sel != 2 && sel != 3)
 			return -EINVAL;
-		ret = debugfs_file_get(file->f_path.dentry);
-		if (ret)
-			return ret;
 		ret = pseudo_lock_measure_cycles(rdtgrp, sel);
 		if (ret == 0)
 			ret = count;
-		debugfs_file_put(file->f_path.dentry);
 	}
 
 	return ret;
Signature · 1 line
2.39.5
maintainer Acked-by
#7 lore raw

Re: [PATCH 04/11] resctrl: get rid of pointless debugfs_file_{get,put}()

Quoted 3 lines · Tony

On Wed, Jul 02, 2025 at 10:16:50PM +0100, Al Viro wrote:

+Reinette

Thank you Tony.

Quoted 26 lines
Quoted 26 lines

->write() of file_operations that gets used only via debugfs_create_file() is called only under debugfs_file_get()

---
 fs/resctrl/pseudo_lock.c | 4 ----
 1 file changed, 4 deletions(-)
fs/resctrl/pseudo_lock.c +0 -4
index ccc2f9213b4b..87bbc2605de1 100644
@@ -764,13 +764,9 @@ static ssize_t pseudo_lock_measure_trigger(struct file *file,
 	if (ret == 0) {
 		if (sel != 1 && sel != 2 && sel != 3)
 			return -EINVAL;
-		ret = debugfs_file_get(file->f_path.dentry);
-		if (ret)
-			return ret;
 		ret = pseudo_lock_measure_cycles(rdtgrp, sel);
 		if (ret == 0)
 			ret = count;
-		debugfs_file_put(file->f_path.dentry);
 	}
 
Quoted 4 lines
Quoted 4 lines
fs/resctrl/pseudo_lock.c +0 -0
 	return ret;
Signature · 1 line
2.39.5

Thank you very much for catching and fixing this Al.

How are the patches from this series expected to flow upstream? resctrl changes usually flow upstream via tip. Would you be ok if I pick just this patch and route it via tip or would you prefer to keep it with this series? At this time I do not anticipate any conflicts if this patch goes upstream via other FS changes during this cycle.

Reinette

author maintainer
#8 lore raw

Re: [PATCH 04/11] resctrl: get rid of pointless debugfs_file_{get,put}()

Quoted 10 lines · Reinette Chatre

Thank you very much for catching and fixing this Al.

How are the patches from this series expected to flow upstream? resctrl changes usually flow upstream via tip. Would you be ok if I pick just this patch and route it via tip or would you prefer to keep it with this series? At this time I do not anticipate any conflicts if this patch goes upstream via other FS changes during this cycle.

Up to Greg, really...

#9 lore raw

Re: [PATCH 04/11] resctrl: get rid of pointless debugfs_file_{get,put}()

Quoted 6 lines · Al Viro
Quoted 4 lines · Reinette Chatre

Thank you very much for catching and fixing this Al.

Quoted 8 lines
Quoted 6 lines

How are the patches from this series expected to flow upstream? resctrl changes usually flow upstream via tip. Would you be ok if I pick just this patch and route it via tip or would you prefer to keep it with this series? At this time I do not anticipate any conflicts if this patch goes upstream via other FS changes during this cycle.

Up to Greg, really...

I'll take them all, give me a day or so to catch up with pending reviews, thanks.

greg k-h

maintainer
#10 lore raw

Re: [PATCH 04/11] resctrl: get rid of pointless debugfs_file_{get,put}()

Quoted 14 lines · Greg Kroah-Hartman
Quoted 13 lines · Al Viro
Quoted 10 lines · Reinette Chatre

Thank you very much for catching and fixing this Al.

How are the patches from this series expected to flow upstream? resctrl changes usually flow upstream via tip. Would you be ok if I pick just this patch and route it via tip or would you prefer to keep it with this series? At this time I do not anticipate any conflicts if this patch goes upstream via other FS changes during this cycle.

Quoted 5 lines
Quoted 1 line

Up to Greg, really...

I'll take them all, give me a day or so to catch up with pending reviews, thanks.

Thank you very much Greg.

Reinette

author maintainer
#11 lore raw

PATCH 5/11 vmscan: don't bother with debugfs_real_fops()

In reply to Al Viro

... not when it's used only to check which file is used; debugfs_create_file_aux_num() allows to stash a number into debugfs entry and debugfs_get_aux_num() extracts it.

---
 mm/vmscan.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
mm/vmscan.c +5 -3
index f8dfd2864bbf..0e661672cbb9 100644
@@ -5420,7 +5420,7 @@ static void lru_gen_seq_show_full(struct seq_file *m, struct lruvec *lruvec,
 static int lru_gen_seq_show(struct seq_file *m, void *v)
 {
 	unsigned long seq;
-	bool full = !debugfs_real_fops(m->file)->write;
+	bool full = debugfs_get_aux_num(m->file);
 	struct lruvec *lruvec = v;
 	struct lru_gen_folio *lrugen = &lruvec->lrugen;
 	int nid = lruvec_pgdat(lruvec)->node_id;
@@ -5756,8 +5756,10 @@ static int __init init_lru_gen(void)
 	if (sysfs_create_group(mm_kobj, &lru_gen_attr_group))
 		pr_err("lru_gen: failed to create sysfs group\n");
 
-	debugfs_create_file("lru_gen", 0644, NULL, NULL, &lru_gen_rw_fops);
-	debugfs_create_file("lru_gen_full", 0444, NULL, NULL, &lru_gen_ro_fops);
+	debugfs_create_file_aux_num("lru_gen", 0644, NULL, NULL, 1,
+				    &lru_gen_rw_fops);
+	debugfs_create_file_aux_num("lru_gen_full", 0444, NULL, NULL, 0,
+				    &lru_gen_ro_fops);
 
 	return 0;
 };
Signature · 1 line
2.39.5
#12 lore raw

Re: [PATCH 05/11] vmscan: don't bother with debugfs_real_fops()

mm/vmscan.c static int __init init_lru_gen(void) · line 5762

Quoted 7 lines · Al Viro
mm/vmscan.c +5 -1
-	bool full = !debugfs_real_fops(m->file)->write;
+	bool full = debugfs_get_aux_num(m->file);
 
+	debugfs_create_file_aux_num("lru_gen", 0644, NULL, NULL, 1,
+				    &lru_gen_rw_fops);
+	debugfs_create_file_aux_num("lru_gen_full", 0444, NULL, NULL, 0,
+				    &lru_gen_ro_fops);

Looks like you have the polarity inverted there?

author maintainer
#13 lore raw

Re: [PATCH 05/11] vmscan: don't bother with debugfs_real_fops()

Quoted 10 lines · Matthew Wilcox

Review

Quoted 7 lines · Al Viro
(quoted diff) +5 -1
-	bool full = !debugfs_real_fops(m->file)->write;
+	bool full = debugfs_get_aux_num(m->file);
 
+	debugfs_create_file_aux_num("lru_gen", 0644, NULL, NULL, 1,
+				    &lru_gen_rw_fops);
+	debugfs_create_file_aux_num("lru_gen_full", 0444, NULL, NULL, 0,
+				    &lru_gen_ro_fops);

Looks like you have the polarity inverted there?

Right you are. My apologies... Fixed, force-pushed into the same branch, replacement commit below:

From 51d26db0fd00fbd501f9271550667bab6c5fb107 Mon Sep 17 00:00:00 2001
From: Al Viro <[email protected]>
Date: Wed, 29 Jan 2025 14:43:44 -0500
Subject: [PATCH 05/11] vmscan: don't bother with debugfs_real_fops()

... not when it's used only to check which file is used; debugfs_create_file_aux_num() allows to stash a number into debugfs entry and debugfs_get_aux_num() extracts it.

---
 mm/vmscan.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
mm/vmscan.c +5 -3
index f8dfd2864bbf..27c70848c0a0 100644
@@ -5420,7 +5420,7 @@ static void lru_gen_seq_show_full(struct seq_file *m, struct lruvec *lruvec,
 static int lru_gen_seq_show(struct seq_file *m, void *v)
 {
 	unsigned long seq;
-	bool full = !debugfs_real_fops(m->file)->write;
+	bool full = debugfs_get_aux_num(m->file);
 	struct lruvec *lruvec = v;
 	struct lru_gen_folio *lrugen = &lruvec->lrugen;
 	int nid = lruvec_pgdat(lruvec)->node_id;
@@ -5756,8 +5756,10 @@ static int __init init_lru_gen(void)
 	if (sysfs_create_group(mm_kobj, &lru_gen_attr_group))
 		pr_err("lru_gen: failed to create sysfs group\n");
 
-	debugfs_create_file("lru_gen", 0644, NULL, NULL, &lru_gen_rw_fops);
-	debugfs_create_file("lru_gen_full", 0444, NULL, NULL, &lru_gen_ro_fops);
+	debugfs_create_file_aux_num("lru_gen", 0644, NULL, NULL, false,
+				    &lru_gen_rw_fops);
+	debugfs_create_file_aux_num("lru_gen_full", 0444, NULL, NULL, true,
+				    &lru_gen_ro_fops);
 
 	return 0;
 };
Signature · 1 line
2.39.5
author maintainer
#14 lore raw

PATCH 6/11 netronome: don't bother with debugfs_real_fops()

In reply to Al Viro

Just turn nfp_tx_q_show() into a wrapper for helper that gets told whether it's tx or xdp via an explicit argument and have nfp_xdp_q_show() call the underlying helper instead.

---
 .../net/ethernet/netronome/nfp/nfp_net_debugfs.c  | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/net/ethernet/netronome/nfp/nfp_net_debugfs.c +10 -5
index d8b735ccf899..d843d1e19715 100644
@@ -77,7 +77,7 @@ DEFINE_SHOW_ATTRIBUTE(nfp_rx_q);
 static int nfp_tx_q_show(struct seq_file *file, void *data);
 DEFINE_SHOW_ATTRIBUTE(nfp_tx_q);
 
-static int nfp_tx_q_show(struct seq_file *file, void *data)
+static int __nfp_tx_q_show(struct seq_file *file, void *data, bool is_xdp)
 {
 	struct nfp_net_r_vector *r_vec = file->private;
 	struct nfp_net_tx_ring *tx_ring;
@@ -86,10 +86,10 @@ static int nfp_tx_q_show(struct seq_file *file, void *data)
 
 	rtnl_lock();
 
-	if (debugfs_real_fops(file->file) == &nfp_tx_q_fops)
-		tx_ring = r_vec->tx_ring;
-	else
+	if (is_xdp)
 		tx_ring = r_vec->xdp_ring;
+	else
+		tx_ring = r_vec->tx_ring;
 	if (!r_vec->nfp_net || !tx_ring)
 		goto out;
 	nn = r_vec->nfp_net;
@@ -115,9 +115,14 @@ static int nfp_tx_q_show(struct seq_file *file, void *data)
 	return 0;
 }
 
+static int nfp_tx_q_show(struct seq_file *file, void *data)
+{
+	return __nfp_tx_q_show(file, data, false);
+}
+
 static int nfp_xdp_q_show(struct seq_file *file, void *data)
 {
-	return nfp_tx_q_show(file, data);
+	return __nfp_tx_q_show(file, data, true);
 }
 DEFINE_SHOW_ATTRIBUTE(nfp_xdp_q);
 
Signature · 1 line
2.39.5
Reviewed-by on v1 6/11
#15 lore raw

Re: [PATCH 06/11] netronome: don't bother with debugfs_real_fops()

Quoted 14 lines · Al Viro

Just turn nfp_tx_q_show() into a wrapper for helper that gets told whether it's tx or xdp via an explicit argument and have nfp_xdp_q_show() call the underlying helper instead.

---
 .../net/ethernet/netronome/nfp/nfp_net_debugfs.c  | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/net/ethernet/netronome/nfp/nfp_net_debugfs.c +0 -0
index d8b735ccf899..d843d1e19715 100644

drivers/net/ethernet/netronome/nfp/nfp_net_debugfs.c DEFINE_SHOW_ATTRIBUTE(nfp_rx_q); · line 78

Quoted 2 lines
drivers/net/ethernet/netronome/nfp/nfp_net_debugfs.c +0 -0
@@ -77,7 +77,7 @@ DEFINE_SHOW_ATTRIBUTE(nfp_rx_q);
 static int nfp_tx_q_show(struct seq_file *file, void *data);
 DEFINE_SHOW_ATTRIBUTE(nfp_tx_q);

I could be missing something, but I think this update now allows this DEFINE_SHOW_ATTRIBUTE(nfp_tx_q) to move down to below the function wrapper, and the 'nfp_tx_q_show' declaration here is not needed anymore?

This is just a tiny nit though, I'm also fine if you want to leave it as is. This looks like a nice cleanup to me, thanks!

Quoted 39 lines
drivers/net/ethernet/netronome/nfp/nfp_net_debugfs.c +10 -5
-static int nfp_tx_q_show(struct seq_file *file, void *data)
+static int __nfp_tx_q_show(struct seq_file *file, void *data, bool is_xdp)
 {
 	struct nfp_net_r_vector *r_vec = file->private;
 	struct nfp_net_tx_ring *tx_ring;
@@ -86,10 +86,10 @@ static int nfp_tx_q_show(struct seq_file *file, void *data)
 
 	rtnl_lock();
 
-	if (debugfs_real_fops(file->file) == &nfp_tx_q_fops)
-		tx_ring = r_vec->tx_ring;
-	else
+	if (is_xdp)
 		tx_ring = r_vec->xdp_ring;
+	else
+		tx_ring = r_vec->tx_ring;
 	if (!r_vec->nfp_net || !tx_ring)
 		goto out;
 	nn = r_vec->nfp_net;
@@ -115,9 +115,14 @@ static int nfp_tx_q_show(struct seq_file *file, void *data)
 	return 0;
 }
 
+static int nfp_tx_q_show(struct seq_file *file, void *data)
+{
+	return __nfp_tx_q_show(file, data, false);
+}
+
 static int nfp_xdp_q_show(struct seq_file *file, void *data)
 {
-	return nfp_tx_q_show(file, data);
+	return __nfp_tx_q_show(file, data, true);
 }
 DEFINE_SHOW_ATTRIBUTE(nfp_xdp_q);
 
Signature · 1 line
2.39.5
author maintainer
#16 lore raw

PATCH 7/11 debugfs: split short and full proxy wrappers, kill debugfs_real_fops()

In reply to Al Viro

All users outside of fs/debugfs/file.c are gone, in there we can just fully split the wrappers for full and short cases and be done with that.

---
 fs/debugfs/file.c       | 87 ++++++++++++++++++-----------------------
 include/linux/debugfs.h |  2 -
 2 files changed, 38 insertions(+), 51 deletions(-)
fs/debugfs/file.c +38 -49
index 69e9ddcb113d..77784091a10f 100644
@@ -53,23 +53,6 @@ const void *debugfs_get_aux(const struct file *file)
 }
 EXPORT_SYMBOL_GPL(debugfs_get_aux);
 
-const struct file_operations *debugfs_real_fops(const struct file *filp)
-{
-	struct debugfs_fsdata *fsd = F_DENTRY(filp)->d_fsdata;
-
-	if (!fsd) {
-		/*
-		 * Urgh, we've been called w/o a protecting
-		 * debugfs_file_get().
-		 */
-		WARN_ON(1);
-		return NULL;
-	}
-
-	return fsd->real_fops;
-}
-EXPORT_SYMBOL_GPL(debugfs_real_fops);
-
 enum dbgfs_get_mode {
 	DBGFS_GET_ALREADY,
 	DBGFS_GET_REGULAR,
@@ -302,15 +285,13 @@ static int debugfs_locked_down(struct inode *inode,
 static int open_proxy_open(struct inode *inode, struct file *filp)
 {
 	struct dentry *dentry = F_DENTRY(filp);
-	const struct file_operations *real_fops = NULL;
+	const struct file_operations *real_fops = DEBUGFS_I(inode)->real_fops;
 	int r;
 
 	r = __debugfs_file_get(dentry, DBGFS_GET_REGULAR);
 	if (r)
 		return r == -EIO ? -ENOENT : r;
 
-	real_fops = debugfs_real_fops(filp);
-
 	r = debugfs_locked_down(inode, filp, real_fops);
 	if (r)
 		goto out;
@@ -352,7 +333,6 @@ static ret_type full_proxy_ ## name(proto)				\
 {									\
 	struct dentry *dentry = F_DENTRY(filp);				\
 	struct debugfs_fsdata *fsd = dentry->d_fsdata;			\
-	const struct file_operations *real_fops;			\
 	ret_type r;							\
 									\
 	if (!(fsd->methods & bit))					\
@@ -360,14 +340,13 @@ static ret_type full_proxy_ ## name(proto)				\
 	r = debugfs_file_get(dentry);					\
 	if (unlikely(r))						\
 		return r;						\
-	real_fops = debugfs_real_fops(filp);				\
-	r = real_fops->name(args);					\
+	r = fsd->real_fops->name(args);					\
 	debugfs_file_put(dentry);					\
 	return r;							\
 }
 
-#define FULL_PROXY_FUNC_BOTH(name, ret_type, filp, proto, args, bit, ret)	\
-static ret_type full_proxy_ ## name(proto)				\
+#define SHORT_PROXY_FUNC(name, ret_type, filp, proto, args, bit, ret)	\
+static ret_type short_proxy_ ## name(proto)				\
 {									\
 	struct dentry *dentry = F_DENTRY(filp);				\
 	struct debugfs_fsdata *fsd = dentry->d_fsdata;			\
@@ -378,27 +357,38 @@ static ret_type full_proxy_ ## name(proto)				\
 	r = debugfs_file_get(dentry);					\
 	if (unlikely(r))						\
 		return r;						\
-	if (fsd->real_fops)						\
-		r = fsd->real_fops->name(args);				\
-	else								\
-		r = fsd->short_fops->name(args);			\
+	r = fsd->short_fops->name(args);				\
 	debugfs_file_put(dentry);					\
 	return r;							\
 }
 
-FULL_PROXY_FUNC_BOTH(llseek, loff_t, filp,
-		     PROTO(struct file *filp, loff_t offset, int whence),
-		     ARGS(filp, offset, whence), HAS_LSEEK, -ESPIPE);
+SHORT_PROXY_FUNC(llseek, loff_t, filp,
+		PROTO(struct file *filp, loff_t offset, int whence),
+		ARGS(filp, offset, whence), HAS_LSEEK, -ESPIPE);
 
-FULL_PROXY_FUNC_BOTH(read, ssize_t, filp,
-		     PROTO(struct file *filp, char __user *buf, size_t size,
-			   loff_t *ppos),
-		     ARGS(filp, buf, size, ppos), HAS_READ, -EINVAL);
+FULL_PROXY_FUNC(llseek, loff_t, filp,
+		PROTO(struct file *filp, loff_t offset, int whence),
+		ARGS(filp, offset, whence), HAS_LSEEK, -ESPIPE);
 
-FULL_PROXY_FUNC_BOTH(write, ssize_t, filp,
-		     PROTO(struct file *filp, const char __user *buf,
-			   size_t size, loff_t *ppos),
-		     ARGS(filp, buf, size, ppos), HAS_WRITE, -EINVAL);
+SHORT_PROXY_FUNC(read, ssize_t, filp,
+		PROTO(struct file *filp, char __user *buf, size_t size,
+			loff_t *ppos),
+		ARGS(filp, buf, size, ppos), HAS_READ, -EINVAL);
+
+FULL_PROXY_FUNC(read, ssize_t, filp,
+		PROTO(struct file *filp, char __user *buf, size_t size,
+			loff_t *ppos),
+		ARGS(filp, buf, size, ppos), HAS_READ, -EINVAL);
+
+SHORT_PROXY_FUNC(write, ssize_t, filp,
+		PROTO(struct file *filp, const char __user *buf,
+			size_t size, loff_t *ppos),
+		ARGS(filp, buf, size, ppos), HAS_WRITE, -EINVAL);
+
+FULL_PROXY_FUNC(write, ssize_t, filp,
+		PROTO(struct file *filp, const char __user *buf,
+			size_t size, loff_t *ppos),
+		ARGS(filp, buf, size, ppos), HAS_WRITE, -EINVAL);
 
 FULL_PROXY_FUNC(unlocked_ioctl, long, filp,
 		PROTO(struct file *filp, unsigned int cmd, unsigned long arg),
@@ -410,22 +400,21 @@ static __poll_t full_proxy_poll(struct file *filp,
 	struct dentry *dentry = F_DENTRY(filp);
 	struct debugfs_fsdata *fsd = dentry->d_fsdata;
 	__poll_t r = 0;
-	const struct file_operations *real_fops;
 
 	if (!(fsd->methods & HAS_POLL))
 		return DEFAULT_POLLMASK;
 	if (debugfs_file_get(dentry))
 		return EPOLLHUP;
 
-	real_fops = debugfs_real_fops(filp);
-	r = real_fops->poll(filp, wait);
+	r = fsd->real_fops->poll(filp, wait);
 	debugfs_file_put(dentry);
 	return r;
 }
 
-static int full_proxy_release(struct inode *inode, struct file *filp)
+static int full_proxy_release(struct inode *inode, struct file *file)
 {
-	const struct file_operations *real_fops = debugfs_real_fops(filp);
+	struct debugfs_fsdata *fsd = F_DENTRY(file)->d_fsdata;
+	const struct file_operations *real_fops = fsd->real_fops;
 	int r = 0;
 
 	/*
@@ -435,7 +424,7 @@ static int full_proxy_release(struct inode *inode, struct file *filp)
 	 * ->i_private is still being meaningful here.
 	 */
 	if (real_fops->release)
-		r = real_fops->release(inode, filp);
+		r = real_fops->release(inode, file);
 
 	fops_put(real_fops);
 	return r;
@@ -517,9 +506,9 @@ static int full_proxy_open_short(struct inode *inode, struct file *filp)
 
 const struct file_operations debugfs_full_short_proxy_file_operations = {
 	.open = full_proxy_open_short,
-	.llseek = full_proxy_llseek,
-	.read = full_proxy_read,
-	.write = full_proxy_write,
+	.llseek = short_proxy_llseek,
+	.read = short_proxy_read,
+	.write = short_proxy_write,
 };
 
 ssize_t debugfs_attr_read(struct file *file, char __user *buf,
include/linux/debugfs.h +0 -2
index fa2568b4380d..a420152105d0 100644
@@ -162,7 +162,6 @@ void debugfs_remove(struct dentry *dentry);
 
 void debugfs_lookup_and_remove(const char *name, struct dentry *parent);
 
-const struct file_operations *debugfs_real_fops(const struct file *filp);
 const void *debugfs_get_aux(const struct file *file);
 
 int debugfs_file_get(struct dentry *dentry);
@@ -329,7 +328,6 @@ static inline void debugfs_lookup_and_remove(const char *name,
 					     struct dentry *parent)
 { }
 
-const struct file_operations *debugfs_real_fops(const struct file *filp);
 void *debugfs_get_aux(const struct file *file);
 
 static inline int debugfs_file_get(struct dentry *dentry)
Signature · 1 line
2.39.5
author maintainer
#17 lore raw

PATCH 8/11 fix tt_command_write()

In reply to Al Viro

1) unbalanced debugfs_file_get(). Not needed in the first place - file_operations are accessed only via debugfs_create_file(), so debugfs wrappers will take care of that itself.

2) kmalloc() for a buffer used only for duration of a function is not a problem, but for a buffer no longer than 16 bytes?

3) strstr() is for finding substrings; for finding a character there's strchr().

---
 drivers/thermal/testing/command.c | 30 ++++++++++--------------------
 1 file changed, 10 insertions(+), 20 deletions(-)
drivers/thermal/testing/command.c +10 -20
index ba11d70e8021..1159ecea57e7 100644
@@ -139,31 +139,21 @@ static int tt_command_exec(int index, const char *arg)
 	return ret;
 }
 
-static ssize_t tt_command_process(struct dentry *dentry, const char __user *user_buf,
-				  size_t count)
+static ssize_t tt_command_process(char *s)
 {
-	char *buf __free(kfree);
 	char *arg;
 	int i;
 
-	buf = kmalloc(count + 1, GFP_KERNEL);
-	if (!buf)
-		return -ENOMEM;
+	strim(s);
 
-	if (copy_from_user(buf, user_buf, count))
-		return -EFAULT;
-
-	buf[count] = '\0';
-	strim(buf);
-
-	arg = strstr(buf, ":");
+	arg = strchr(s, ':');
 	if (arg) {
 		*arg = '\0';
 		arg++;
 	}
 
 	for (i = 0; i < ARRAY_SIZE(tt_command_strings); i++) {
-		if (!strcmp(buf, tt_command_strings[i]))
+		if (!strcmp(s, tt_command_strings[i]))
 			return tt_command_exec(i, arg);
 	}
 
@@ -173,20 +163,20 @@ static ssize_t tt_command_process(struct dentry *dentry, const char __user *user
 static ssize_t tt_command_write(struct file *file, const char __user *user_buf,
 				size_t count, loff_t *ppos)
 {
-	struct dentry *dentry = file->f_path.dentry;
+	char buf[TT_COMMAND_SIZE];
 	ssize_t ret;
 
 	if (*ppos)
 		return -EINVAL;
 
-	if (count + 1 > TT_COMMAND_SIZE)
+	if (count > TT_COMMAND_SIZE - 1)
 		return -E2BIG;
 
-	ret = debugfs_file_get(dentry);
-	if (unlikely(ret))
-		return ret;
+	if (copy_from_user(buf, user_buf, count))
+		return -EFAULT;
+	buf[count] = '\0';
 
-	ret = tt_command_process(dentry, user_buf, count);
+	ret = tt_command_process(buf);
 	if (ret)
 		return ret;
 
Signature · 1 line
2.39.5
maintainer Acked-by on v1 8/11
#18 lore raw

Re: [PATCH 08/11] fix tt_command_write()

Quoted 5 lines · Al Viro

1) unbalanced debugfs_file_get(). Not needed in the first place - file_operations are accessed only via debugfs_create_file(), so debugfs wrappers will take care of that itself.

Quoted 7 lines

2) kmalloc() for a buffer used only for duration of a function is not a problem, but for a buffer no longer than 16 bytes?

3) strstr() is for finding substrings; for finding a character there's strchr().

Or do you want me to apply this?

Quoted 75 lines
---
 drivers/thermal/testing/command.c | 30 ++++++++++--------------------
 1 file changed, 10 insertions(+), 20 deletions(-)
drivers/thermal/testing/command.c +10 -21
index ba11d70e8021..1159ecea57e7 100644
@@ -139,31 +139,21 @@ static int tt_command_exec(int index, const char *arg)
        return ret;
 }
 
-static ssize_t tt_command_process(struct dentry *dentry, const char __user *user_buf,
-                                 size_t count)
+static ssize_t tt_command_process(char *s)
 {
-       char *buf __free(kfree);
        char *arg;
        int i;
 
-       buf = kmalloc(count + 1, GFP_KERNEL);
-       if (!buf)
-               return -ENOMEM;
+       strim(s);
 
-       if (copy_from_user(buf, user_buf, count))
-               return -EFAULT;
-
-       buf[count] = '\0';
-       strim(buf);
-
-       arg = strstr(buf, ":");
+       arg = strchr(s, ':');
        if (arg) {
                *arg = '\0';
                arg++;
        }
 
        for (i = 0; i < ARRAY_SIZE(tt_command_strings); i++) {
-               if (!strcmp(buf, tt_command_strings[i]))
+               if (!strcmp(s, tt_command_strings[i]))
                        return tt_command_exec(i, arg);
        }
 
@@ -173,20 +163,20 @@ static ssize_t tt_command_process(struct dentry *dentry, const char __user *user
 static ssize_t tt_command_write(struct file *file, const char __user *user_buf,
                                size_t count, loff_t *ppos)
 {
-       struct dentry *dentry = file->f_path.dentry;
+       char buf[TT_COMMAND_SIZE];
        ssize_t ret;
 
        if (*ppos)
                return -EINVAL;
 
-       if (count + 1 > TT_COMMAND_SIZE)
+       if (count > TT_COMMAND_SIZE - 1)
                return -E2BIG;
 
-       ret = debugfs_file_get(dentry);
-       if (unlikely(ret))
-               return ret;
+       if (copy_from_user(buf, user_buf, count))
+               return -EFAULT;
+       buf[count] = '\0';
 
-       ret = tt_command_process(dentry, user_buf, count);
+       ret = tt_command_process(buf);
        if (ret)
                return ret;
 
--

2.39.5

author maintainer
#19 lore raw

PATCH 9/11 debugfs_get_aux(): allow storing non-const void *

In reply to Al Viro

typechecking is up to users, anyway...

---
 drivers/staging/greybus/camera.c | 2 +-
 fs/debugfs/file.c                | 2 +-
 fs/debugfs/inode.c               | 2 +-
 fs/debugfs/internal.h            | 2 +-
 include/linux/debugfs.h          | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)
drivers/staging/greybus/camera.c +1 -1
index ec9fddfc0b14..5ac19c0055d9 100644
@@ -1128,7 +1128,7 @@ static ssize_t gb_camera_debugfs_write(struct file *file,
 
 static int gb_camera_debugfs_open(struct inode *inode, struct file *file)
 {
-	file->private_data = (void *)debugfs_get_aux(file);
+	file->private_data = debugfs_get_aux(file);
 	return 0;
 }
 
fs/debugfs/file.c +1 -1
index 77784091a10f..3ec3324c2060 100644
@@ -47,7 +47,7 @@ const struct file_operations debugfs_noop_file_operations = {
 
 #define F_DENTRY(filp) ((filp)->f_path.dentry)
 
-const void *debugfs_get_aux(const struct file *file)
+void *debugfs_get_aux(const struct file *file)
 {
 	return DEBUGFS_I(file_inode(file))->aux;
 }
fs/debugfs/inode.c +1 -1
index 30c4944e1862..43e5d1bf1f32 100644
@@ -459,7 +459,7 @@ static struct dentry *__debugfs_create_file(const char *name, umode_t mode,
 		proxy_fops = &debugfs_noop_file_operations;
 	inode->i_fop = proxy_fops;
 	DEBUGFS_I(inode)->raw = real_fops;
-	DEBUGFS_I(inode)->aux = aux;
+	DEBUGFS_I(inode)->aux = (void *)aux;
 
 	d_instantiate(dentry, inode);
 	fsnotify_create(d_inode(dentry->d_parent), dentry);
fs/debugfs/internal.h +1 -1
index 93483fe84425..427987f81571 100644
@@ -19,7 +19,7 @@ struct debugfs_inode_info {
 		const struct debugfs_short_fops *short_fops;
 		debugfs_automount_t automount;
 	};
-	const void *aux;
+	void *aux;
 };
 
 static inline struct debugfs_inode_info *DEBUGFS_I(struct inode *inode)
include/linux/debugfs.h +1 -1
index a420152105d0..7cecda29447e 100644
@@ -162,7 +162,7 @@ void debugfs_remove(struct dentry *dentry);
 
 void debugfs_lookup_and_remove(const char *name, struct dentry *parent);
 
-const void *debugfs_get_aux(const struct file *file);
+void *debugfs_get_aux(const struct file *file);
 
 int debugfs_file_get(struct dentry *dentry);
 void debugfs_file_put(struct dentry *dentry);
Signature · 1 line
2.39.5
author maintainer
#20 lore raw

PATCH 10/11 blk-mq-debugfs: use debugfs_get_aux()

In reply to Al Viro

instead of manually stashing the data pointer into parent directory inode's ->i_private, just pass it to debugfs_create_file_aux() so that it can be extracted without that insane chasing through ->d_parent.

---
 block/blk-mq-debugfs.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
block/blk-mq-debugfs.c +5 -7
index 29b3540dd180..7ed3e71f2fc0 100644
@@ -521,7 +521,7 @@ CTX_RQ_SEQ_OPS(poll, HCTX_TYPE_POLL);
 static int blk_mq_debugfs_show(struct seq_file *m, void *v)
 {
 	const struct blk_mq_debugfs_attr *attr = m->private;
-	void *data = d_inode(m->file->f_path.dentry->d_parent)->i_private;
+	void *data = debugfs_get_aux(m->file);
 
 	return attr->show(data, m);
 }
@@ -531,7 +531,7 @@ static ssize_t blk_mq_debugfs_write(struct file *file, const char __user *buf,
 {
 	struct seq_file *m = file->private_data;
 	const struct blk_mq_debugfs_attr *attr = m->private;
-	void *data = d_inode(file->f_path.dentry->d_parent)->i_private;
+	void *data = debugfs_get_aux(file);
 
 	/*
 	 * Attributes that only implement .seq_ops are read-only and 'attr' is
@@ -546,7 +546,7 @@ static ssize_t blk_mq_debugfs_write(struct file *file, const char __user *buf,
 static int blk_mq_debugfs_open(struct inode *inode, struct file *file)
 {
 	const struct blk_mq_debugfs_attr *attr = inode->i_private;
-	void *data = d_inode(file->f_path.dentry->d_parent)->i_private;
+	void *data = debugfs_get_aux(file);
 	struct seq_file *m;
 	int ret;
 
@@ -612,11 +612,9 @@ static void debugfs_create_files(struct dentry *parent, void *data,
 	if (IS_ERR_OR_NULL(parent))
 		return;
 
-	d_inode(parent)->i_private = data;
-
 	for (; attr->name; attr++)
-		debugfs_create_file(attr->name, attr->mode, parent,
-				    (void *)attr, &blk_mq_debugfs_fops);
+		debugfs_create_file_aux(attr->name, attr->mode, parent,
+				    (void *)attr, data, &blk_mq_debugfs_fops);
 }
 
 void blk_mq_debugfs_register(struct request_queue *q)
Signature · 1 line
2.39.5
author maintainer
#21 lore raw

PATCH 11/11 lpfc: don't use file->f_path.dentry for comparisons

In reply to Al Viro

If you want a home-grown switch, at least use enum for selector...

---
 drivers/scsi/lpfc/lpfc_debugfs.c | 99 ++++++++++++++++----------------
 1 file changed, 51 insertions(+), 48 deletions(-)
drivers/scsi/lpfc/lpfc_debugfs.c +51 -48
index 3fd1aa5cc78c..55ff030ca6cd 100644
@@ -2371,36 +2371,48 @@ lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file)
 	return rc;
 }
 
+enum {
+	writeGuard = 1,
+	writeApp,
+	writeRef,
+	readGuard,
+	readApp,
+	readRef,
+	InjErrLBA,
+	InjErrNPortID,
+	InjErrWWPN,
+};
+
 static ssize_t
 lpfc_debugfs_dif_err_read(struct file *file, char __user *buf,
 	size_t nbytes, loff_t *ppos)
 {
-	struct dentry *dent = file->f_path.dentry;
 	struct lpfc_hba *phba = file->private_data;
+	int kind = debugfs_get_aux_num(file);
 	char cbuf[32];
 	uint64_t tmp = 0;
 	int cnt = 0;
 
-	if (dent == phba->debug_writeGuard)
+	if (kind == writeGuard)
 		cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wgrd_cnt);
-	else if (dent == phba->debug_writeApp)
+	else if (kind == writeApp)
 		cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wapp_cnt);
-	else if (dent == phba->debug_writeRef)
+	else if (kind == writeRef)
 		cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wref_cnt);
-	else if (dent == phba->debug_readGuard)
+	else if (kind == readGuard)
 		cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rgrd_cnt);
-	else if (dent == phba->debug_readApp)
+	else if (kind == readApp)
 		cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rapp_cnt);
-	else if (dent == phba->debug_readRef)
+	else if (kind == readRef)
 		cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rref_cnt);
-	else if (dent == phba->debug_InjErrNPortID)
+	else if (kind == InjErrNPortID)
 		cnt = scnprintf(cbuf, 32, "0x%06x\n",
 				phba->lpfc_injerr_nportid);
-	else if (dent == phba->debug_InjErrWWPN) {
+	else if (kind == InjErrWWPN) {
 		memcpy(&tmp, &phba->lpfc_injerr_wwpn, sizeof(struct lpfc_name));
 		tmp = cpu_to_be64(tmp);
 		cnt = scnprintf(cbuf, 32, "0x%016llx\n", tmp);
-	} else if (dent == phba->debug_InjErrLBA) {
+	} else if (kind == InjErrLBA) {
 		if (phba->lpfc_injerr_lba == (sector_t)(-1))
 			cnt = scnprintf(cbuf, 32, "off\n");
 		else
@@ -2417,8 +2429,8 @@ static ssize_t
 lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
 	size_t nbytes, loff_t *ppos)
 {
-	struct dentry *dent = file->f_path.dentry;
 	struct lpfc_hba *phba = file->private_data;
+	int kind = debugfs_get_aux_num(file);
 	char dstbuf[33];
 	uint64_t tmp = 0;
 	int size;
@@ -2428,7 +2440,7 @@ lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
 	if (copy_from_user(dstbuf, buf, size))
 		return -EFAULT;
 
-	if (dent == phba->debug_InjErrLBA) {
+	if (kind == InjErrLBA) {
 		if ((dstbuf[0] == 'o') && (dstbuf[1] == 'f') &&
 		    (dstbuf[2] == 'f'))
 			tmp = (uint64_t)(-1);
@@ -2437,23 +2449,23 @@ lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
 	if ((tmp == 0) && (kstrtoull(dstbuf, 0, &tmp)))
 		return -EINVAL;
 
-	if (dent == phba->debug_writeGuard)
+	if (kind == writeGuard)
 		phba->lpfc_injerr_wgrd_cnt = (uint32_t)tmp;
-	else if (dent == phba->debug_writeApp)
+	else if (kind == writeApp)
 		phba->lpfc_injerr_wapp_cnt = (uint32_t)tmp;
-	else if (dent == phba->debug_writeRef)
+	else if (kind == writeRef)
 		phba->lpfc_injerr_wref_cnt = (uint32_t)tmp;
-	else if (dent == phba->debug_readGuard)
+	else if (kind == readGuard)
 		phba->lpfc_injerr_rgrd_cnt = (uint32_t)tmp;
-	else if (dent == phba->debug_readApp)
+	else if (kind == readApp)
 		phba->lpfc_injerr_rapp_cnt = (uint32_t)tmp;
-	else if (dent == phba->debug_readRef)
+	else if (kind == readRef)
 		phba->lpfc_injerr_rref_cnt = (uint32_t)tmp;
-	else if (dent == phba->debug_InjErrLBA)
+	else if (kind == InjErrLBA)
 		phba->lpfc_injerr_lba = (sector_t)tmp;
-	else if (dent == phba->debug_InjErrNPortID)
+	else if (kind == InjErrNPortID)
 		phba->lpfc_injerr_nportid = (uint32_t)(tmp & Mask_DID);
-	else if (dent == phba->debug_InjErrWWPN) {
+	else if (kind == InjErrWWPN) {
 		tmp = cpu_to_be64(tmp);
 		memcpy(&phba->lpfc_injerr_wwpn, &tmp, sizeof(struct lpfc_name));
 	} else
@@ -6160,60 +6172,51 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
 			phba->debug_dumpHostSlim = NULL;
 
 		/* Setup DIF Error Injections */
-		snprintf(name, sizeof(name), "InjErrLBA");
 		phba->debug_InjErrLBA =
-			debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+			debugfs_create_file_aux_num("InjErrLBA", 0644,
 			phba->hba_debugfs_root,
-			phba, &lpfc_debugfs_op_dif_err);
+			phba, InjErrLBA, &lpfc_debugfs_op_dif_err);
 		phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
 
-		snprintf(name, sizeof(name), "InjErrNPortID");
 		phba->debug_InjErrNPortID =
-			debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+			debugfs_create_file_aux_num("InjErrNPortID", 0644,
 			phba->hba_debugfs_root,
-			phba, &lpfc_debugfs_op_dif_err);
+			phba, InjErrNPortID, &lpfc_debugfs_op_dif_err);
 
-		snprintf(name, sizeof(name), "InjErrWWPN");
 		phba->debug_InjErrWWPN =
-			debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+			debugfs_create_file_aux_num("InjErrWWPN", 0644,
 			phba->hba_debugfs_root,
-			phba, &lpfc_debugfs_op_dif_err);
+			phba, InjErrWWPN, &lpfc_debugfs_op_dif_err);
 
-		snprintf(name, sizeof(name), "writeGuardInjErr");
 		phba->debug_writeGuard =
-			debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+			debugfs_create_file_aux_num("writeGuardInjErr", 0644,
 			phba->hba_debugfs_root,
-			phba, &lpfc_debugfs_op_dif_err);
+			phba, writeGuard, &lpfc_debugfs_op_dif_err);
 
-		snprintf(name, sizeof(name), "writeAppInjErr");
 		phba->debug_writeApp =
-			debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+			debugfs_create_file_aux_num("writeAppInjErr", 0644,
 			phba->hba_debugfs_root,
-			phba, &lpfc_debugfs_op_dif_err);
+			phba, writeApp, &lpfc_debugfs_op_dif_err);
 
-		snprintf(name, sizeof(name), "writeRefInjErr");
 		phba->debug_writeRef =
-			debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+			debugfs_create_file_aux_num("writeRefInjErr", 0644,
 			phba->hba_debugfs_root,
-			phba, &lpfc_debugfs_op_dif_err);
+			phba, writeRef, &lpfc_debugfs_op_dif_err);
 
-		snprintf(name, sizeof(name), "readGuardInjErr");
 		phba->debug_readGuard =
-			debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+			debugfs_create_file_aux_num("readGuardInjErr", 0644,
 			phba->hba_debugfs_root,
-			phba, &lpfc_debugfs_op_dif_err);
+			phba, readGuard, &lpfc_debugfs_op_dif_err);
 
-		snprintf(name, sizeof(name), "readAppInjErr");
 		phba->debug_readApp =
-			debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+			debugfs_create_file_aux_num("readAppInjErr", 0644,
 			phba->hba_debugfs_root,
-			phba, &lpfc_debugfs_op_dif_err);
+			phba, readApp, &lpfc_debugfs_op_dif_err);
 
-		snprintf(name, sizeof(name), "readRefInjErr");
 		phba->debug_readRef =
-			debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+			debugfs_create_file_aux_num("readRefInjErr", 0644,
 			phba->hba_debugfs_root,
-			phba, &lpfc_debugfs_op_dif_err);
+			phba, readRef, &lpfc_debugfs_op_dif_err);
 
 		/* Setup slow ring trace */
 		if (lpfc_debugfs_max_slow_ring_trc) {
Signature · 1 line
2.39.5

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): CAAmqgVMmgW4PWy289P4a8N0FSZA+cHybNkKbLzFx_qBQtu8ZHA@mail.gmail.com

#24 lore raw

Re: [PATCH 11/11] lpfc: don't use file->f_path.dentry for comparisons

Hi Al,

I’m good with the use of enum. For the if and else if blocks, would it be possible to help us out and convert those to switch case statements?

For example,

switch (kind) {
case writeGuard :

    cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wgrd_cnt);
    break;
case writeApp:
    cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wapp_cnt);
    break;
…
default:
    lpfc_printf_log(...);
}

Thanks,
Justin

author maintainer
#25 lore raw

Re: [PATCH 11/11] lpfc: don't use file->f_path.dentry for comparisons

Quoted 10 lines · Justin Tee

Hi Al,

I’m good with the use of enum. For the if and else if blocks, would it be possible to help us out and convert those to switch case statements?

For example,

switch (kind) {
case writeGuard :

Quoted 9 lines
    cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wgrd_cnt);
    break;
case writeApp:
    cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wapp_cnt);
    break;
…
default:
    lpfc_printf_log(...);
}

Sure, but I'd rather do that as a followup. Speaking of other fun followups in the same area: no point storing most of those dentries; debugfs_remove() takes the entire subtree out, no need to remove them one-by-one and that was the only use they were left... Something along the lines of diff below:

drivers/scsi/lpfc/lpfc.h +1 -29
index fe4fb67eb50c..230f0377c1db 100644
@@ -744,12 +744,6 @@ struct lpfc_vport {
 	struct lpfc_vmid_priority_info vmid_priority;
 
 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
-	struct dentry *debug_disc_trc;
-	struct dentry *debug_nodelist;
-	struct dentry *debug_nvmestat;
-	struct dentry *debug_scsistat;
-	struct dentry *debug_ioktime;
-	struct dentry *debug_hdwqstat;
 	struct dentry *vport_debugfs_root;
 	struct lpfc_debugfs_trc *disc_trc;
 	atomic_t disc_trc_cnt;
@@ -1349,29 +1343,8 @@ struct lpfc_hba {
 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
 	struct dentry *hba_debugfs_root;
 	atomic_t debugfs_vport_count;
-	struct dentry *debug_multixri_pools;
-	struct dentry *debug_hbqinfo;
-	struct dentry *debug_dumpHostSlim;
-	struct dentry *debug_dumpHBASlim;
-	struct dentry *debug_InjErrLBA;  /* LBA to inject errors at */
-	struct dentry *debug_InjErrNPortID;  /* NPortID to inject errors at */
-	struct dentry *debug_InjErrWWPN;  /* WWPN to inject errors at */
-	struct dentry *debug_writeGuard; /* inject write guard_tag errors */
-	struct dentry *debug_writeApp;   /* inject write app_tag errors */
-	struct dentry *debug_writeRef;   /* inject write ref_tag errors */
-	struct dentry *debug_readGuard;  /* inject read guard_tag errors */
-	struct dentry *debug_readApp;    /* inject read app_tag errors */
-	struct dentry *debug_readRef;    /* inject read ref_tag errors */
-
-	struct dentry *debug_nvmeio_trc;
+
 	struct lpfc_debugfs_nvmeio_trc *nvmeio_trc;
-	struct dentry *debug_hdwqinfo;
-#ifdef LPFC_HDWQ_LOCK_STAT
-	struct dentry *debug_lockstat;
-#endif
-	struct dentry *debug_cgn_buffer;
-	struct dentry *debug_rx_monitor;
-	struct dentry *debug_ras_log;
 	atomic_t nvmeio_trc_cnt;
 	uint32_t nvmeio_trc_size;
 	uint32_t nvmeio_trc_output_idx;
@@ -1388,7 +1361,6 @@ struct lpfc_hba {
 	sector_t lpfc_injerr_lba;
 #define LPFC_INJERR_LBA_OFF	(sector_t)(-1)
 
-	struct dentry *debug_slow_ring_trc;
 	struct lpfc_debugfs_trc *slow_ring_trc;
 	atomic_t slow_ring_trc_cnt;
 	/* iDiag debugfs sub-directory */
drivers/scsi/lpfc/lpfc_debugfs.c +46 -184

391 lines not on this page · raw message

#26 lore raw

Re: [PATCH 11/11] lpfc: don't use file->f_path.dentry for comparisons

Quoted 1 line

Sure, but I'd rather do that as a followup.

Yeup, that’s fine.

Quoted 5 lines

Speaking of other fun followups
in the same area: no point storing most of those dentries; debugfs_remove() takes the entire subtree out, no need to remove them one-by-one and that was the only use they were left... Something along the lines of diff below:

Very cool, thanks! We’ll take that diff too (:

Also, may we actually move this enum declaration to lpfc_debugfs.h instead of lpfc_debugfs.c?
enum {
writeGuard = 1,
writeApp,
writeRef,
readGuard,
readApp,
readRef,
InjErrLBA,
InjErrNPortID,
InjErrWWPN,
};

author maintainer
#27 lore raw

Re: [PATCH 11/11] lpfc: don't use file->f_path.dentry for comparisons

Quoted 10 lines · Justin Tee
Quoted 1 line

Sure, but I'd rather do that as a followup.

Yeup, that’s fine.

Quoted 5 lines

Speaking of other fun followups
in the same area: no point storing most of those dentries; debugfs_remove() takes the entire subtree out, no need to remove them one-by-one and that was the only use they were left... Something along the lines of diff below:

Very cool, thanks! We’ll take that diff too (:

Quoted 13 lines

Also, may we actually move this enum declaration to lpfc_debugfs.h instead of lpfc_debugfs.c?
enum {
writeGuard = 1,
writeApp,
writeRef,
readGuard,
readApp,
readRef,
InjErrLBA,
InjErrNPortID,
InjErrWWPN,
};

Sure, no problem... Your driver, your preferences - it's not as if that had any impact outside.

While we are at it, handling of debugfs_vport_count looks fishy - it's easier to spot with aforementioned delta applied.

        if (vport->vport_debugfs_root) {
                debugfs_remove(vport->vport_debugfs_root); /* vportX */
                vport->vport_debugfs_root = NULL;
                atomic_dec(&phba->debugfs_vport_count);
        }

        if (atomic_read(&phba->debugfs_vport_count) == 0) {
		...
	}
	return;

is OK only if all updates of that thing are externally serialized. If they are, we don't need atomic; if they are not, this separation of decrement and test is racy.

Note that if you do *not* have external serialization, there might be another problem if you have the last vport removal overlap with addition of another vport. Or, for that matter, if removal of the last vport on the last HBA overlaps with addition of a new HBA...

Unless something has drastically changed, binding/unbinding of a device to driver should be serialized by drivers/base/* logics; no idea about the vports side of things...

#28 lore raw

Re: [PATCH 11/11] lpfc: don't use file->f_path.dentry for comparisons

Quoted 3 lines

is OK only if all updates of that thing are externally serialized. If they are, we don't need atomic; if they are not, this separation of decrement and test is racy.

Agreed with this too. Vport creation and deletion is serialized, so we do not need to declare debugfs_vport_count as atomic.

At this point, cleaning up the lpfc_debugfs_terminate routine may be a little more involved. If it’s alright with you, Broadcom will take up the responsibility to clean up the lpfc_debugfs_terminate routine during our next driver version update, and we will of course state your authorship in that particular clean up patch.

Regarding this thread’s enum selector patch, I can provide the signed off by after we see that the enum declaration is moved to lpfc_debugfs.h.

Regards,
Justin

author maintainer
#29 lore raw

Re: [PATCH 11/11] lpfc: don't use file->f_path.dentry for comparisons

Quoted 12 lines · Justin Tee
Quoted 3 lines

is OK only if all updates of that thing are externally serialized. If they are, we don't need atomic; if they are not, this separation of decrement and test is racy.

Agreed with this too. Vport creation and deletion is serialized, so we do not need to declare debugfs_vport_count as atomic.

At this point, cleaning up the lpfc_debugfs_terminate routine may be a little more involved. If it’s alright with you, Broadcom will take up the responsibility to clean up the lpfc_debugfs_terminate routine during our next driver version update, and we will of course state your authorship in that particular clean up patch.

Quoted 3 lines

Regarding this thread’s enum selector patch, I can provide the signed off by after we see that the enum declaration is moved to lpfc_debugfs.h.

Would this do?

[PATCH v2] lpfc: don't use file->f_path.dentry for comparisons

If you want a home-grown switch, at least use enum for selector...

---

drivers/scsi/lpfc/lpfc_debugfs.c +39 -48
index 3fd1aa5cc78c..42d138ec11b4 100644
@@ -2375,32 +2375,32 @@ static ssize_t
 lpfc_debugfs_dif_err_read(struct file *file, char __user *buf,
 	size_t nbytes, loff_t *ppos)
 {
-	struct dentry *dent = file->f_path.dentry;
 	struct lpfc_hba *phba = file->private_data;
+	int kind = debugfs_get_aux_num(file);
 	char cbuf[32];
 	uint64_t tmp = 0;
 	int cnt = 0;
 
-	if (dent == phba->debug_writeGuard)
+	if (kind == writeGuard)
 		cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wgrd_cnt);
-	else if (dent == phba->debug_writeApp)
+	else if (kind == writeApp)
 		cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wapp_cnt);
-	else if (dent == phba->debug_writeRef)
+	else if (kind == writeRef)
 		cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wref_cnt);
-	else if (dent == phba->debug_readGuard)
+	else if (kind == readGuard)
 		cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rgrd_cnt);
-	else if (dent == phba->debug_readApp)
+	else if (kind == readApp)
 		cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rapp_cnt);
-	else if (dent == phba->debug_readRef)
+	else if (kind == readRef)
 		cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rref_cnt);
-	else if (dent == phba->debug_InjErrNPortID)
+	else if (kind == InjErrNPortID)
 		cnt = scnprintf(cbuf, 32, "0x%06x\n",
 				phba->lpfc_injerr_nportid);
-	else if (dent == phba->debug_InjErrWWPN) {
+	else if (kind == InjErrWWPN) {
 		memcpy(&tmp, &phba->lpfc_injerr_wwpn, sizeof(struct lpfc_name));
 		tmp = cpu_to_be64(tmp);
 		cnt = scnprintf(cbuf, 32, "0x%016llx\n", tmp);
-	} else if (dent == phba->debug_InjErrLBA) {
+	} else if (kind == InjErrLBA) {
 		if (phba->lpfc_injerr_lba == (sector_t)(-1))
 			cnt = scnprintf(cbuf, 32, "off\n");
 		else
@@ -2417,8 +2417,8 @@ static ssize_t
 lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
 	size_t nbytes, loff_t *ppos)
 {
-	struct dentry *dent = file->f_path.dentry;
 	struct lpfc_hba *phba = file->private_data;
+	int kind = debugfs_get_aux_num(file);
 	char dstbuf[33];
 	uint64_t tmp = 0;
 	int size;
@@ -2428,7 +2428,7 @@ lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
 	if (copy_from_user(dstbuf, buf, size))
 		return -EFAULT;
 
-	if (dent == phba->debug_InjErrLBA) {
+	if (kind == InjErrLBA) {
 		if ((dstbuf[0] == 'o') && (dstbuf[1] == 'f') &&
 		    (dstbuf[2] == 'f'))
 			tmp = (uint64_t)(-1);
@@ -2437,23 +2437,23 @@ lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
 	if ((tmp == 0) && (kstrtoull(dstbuf, 0, &tmp)))
 		return -EINVAL;
 
-	if (dent == phba->debug_writeGuard)
+	if (kind == writeGuard)
 		phba->lpfc_injerr_wgrd_cnt = (uint32_t)tmp;
-	else if (dent == phba->debug_writeApp)
+	else if (kind == writeApp)
 		phba->lpfc_injerr_wapp_cnt = (uint32_t)tmp;
-	else if (dent == phba->debug_writeRef)
+	else if (kind == writeRef)
 		phba->lpfc_injerr_wref_cnt = (uint32_t)tmp;
-	else if (dent == phba->debug_readGuard)
+	else if (kind == readGuard)
 		phba->lpfc_injerr_rgrd_cnt = (uint32_t)tmp;
-	else if (dent == phba->debug_readApp)
+	else if (kind == readApp)
 		phba->lpfc_injerr_rapp_cnt = (uint32_t)tmp;
-	else if (dent == phba->debug_readRef)
+	else if (kind == readRef)
 		phba->lpfc_injerr_rref_cnt = (uint32_t)tmp;
-	else if (dent == phba->debug_InjErrLBA)
+	else if (kind == InjErrLBA)
 		phba->lpfc_injerr_lba = (sector_t)tmp;
-	else if (dent == phba->debug_InjErrNPortID)
+	else if (kind == InjErrNPortID)
 		phba->lpfc_injerr_nportid = (uint32_t)(tmp & Mask_DID);
-	else if (dent == phba->debug_InjErrWWPN) {
+	else if (kind == InjErrWWPN) {
 		tmp = cpu_to_be64(tmp);
 		memcpy(&phba->lpfc_injerr_wwpn, &tmp, sizeof(struct lpfc_name));
 	} else
@@ -6160,60 +6160,51 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
 			phba->debug_dumpHostSlim = NULL;
 
 		/* Setup DIF Error Injections */
-		snprintf(name, sizeof(name), "InjErrLBA");
 		phba->debug_InjErrLBA =
-			debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+			debugfs_create_file_aux_num("InjErrLBA", 0644,
 			phba->hba_debugfs_root,
-			phba, &lpfc_debugfs_op_dif_err);
+			phba, InjErrLBA, &lpfc_debugfs_op_dif_err);
 		phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
 
-		snprintf(name, sizeof(name), "InjErrNPortID");
 		phba->debug_InjErrNPortID =
-			debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+			debugfs_create_file_aux_num("InjErrNPortID", 0644,
 			phba->hba_debugfs_root,
-			phba, &lpfc_debugfs_op_dif_err);
+			phba, InjErrNPortID, &lpfc_debugfs_op_dif_err);
 
-		snprintf(name, sizeof(name), "InjErrWWPN");
 		phba->debug_InjErrWWPN =
-			debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+			debugfs_create_file_aux_num("InjErrWWPN", 0644,
 			phba->hba_debugfs_root,
-			phba, &lpfc_debugfs_op_dif_err);
+			phba, InjErrWWPN, &lpfc_debugfs_op_dif_err);
 
-		snprintf(name, sizeof(name), "writeGuardInjErr");
 		phba->debug_writeGuard =
-			debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+			debugfs_create_file_aux_num("writeGuardInjErr", 0644,
 			phba->hba_debugfs_root,
-			phba, &lpfc_debugfs_op_dif_err);
+			phba, writeGuard, &lpfc_debugfs_op_dif_err);
 
-		snprintf(name, sizeof(name), "writeAppInjErr");
 		phba->debug_writeApp =
-			debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+			debugfs_create_file_aux_num("writeAppInjErr", 0644,
 			phba->hba_debugfs_root,
-			phba, &lpfc_debugfs_op_dif_err);
+			phba, writeApp, &lpfc_debugfs_op_dif_err);
 
-		snprintf(name, sizeof(name), "writeRefInjErr");
 		phba->debug_writeRef =
-			debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+			debugfs_create_file_aux_num("writeRefInjErr", 0644,
 			phba->hba_debugfs_root,
-			phba, &lpfc_debugfs_op_dif_err);
+			phba, writeRef, &lpfc_debugfs_op_dif_err);
 
-		snprintf(name, sizeof(name), "readGuardInjErr");
 		phba->debug_readGuard =
-			debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+			debugfs_create_file_aux_num("readGuardInjErr", 0644,
 			phba->hba_debugfs_root,
-			phba, &lpfc_debugfs_op_dif_err);
+			phba, readGuard, &lpfc_debugfs_op_dif_err);
 
-		snprintf(name, sizeof(name), "readAppInjErr");
 		phba->debug_readApp =
-			debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+			debugfs_create_file_aux_num("readAppInjErr", 0644,
 			phba->hba_debugfs_root,
-			phba, &lpfc_debugfs_op_dif_err);
+			phba, readApp, &lpfc_debugfs_op_dif_err);
 
-		snprintf(name, sizeof(name), "readRefInjErr");
 		phba->debug_readRef =
-			debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+			debugfs_create_file_aux_num("readRefInjErr", 0644,
 			phba->hba_debugfs_root,
-			phba, &lpfc_debugfs_op_dif_err);
+			phba, readRef, &lpfc_debugfs_op_dif_err);
 
 		/* Setup slow ring trace */
 		if (lpfc_debugfs_max_slow_ring_trc) {
drivers/scsi/lpfc/lpfc_debugfs.h +11 -0
index 8d2e8d05bbc0..f319f3af0400 100644
@@ -322,6 +322,17 @@ enum {
 						 * discovery */
 #endif /* H_LPFC_DEBUG_FS */
 
+enum {
+	writeGuard = 1,
+	writeApp,
+	writeRef,
+	readGuard,
+	readApp,
+	readRef,
+	InjErrLBA,
+	InjErrNPortID,
+	InjErrWWPN,
+};
 
 /*
  * Driver debug utility routines outside of debugfs. The debug utility
Reviewed-by
#30 lore raw

Re: [PATCH 11/11] lpfc: don't use file->f_path.dentry for comparisons

Quoted 196 lines

[PATCH v2] lpfc: don't use file->f_path.dentry for comparisons

If you want a home-grown switch, at least use enum for selector...

---

drivers/scsi/lpfc/lpfc_debugfs.c +39 -48
index 3fd1aa5cc78c..42d138ec11b4 100644
@@ -2375,32 +2375,32 @@ static ssize_t
 lpfc_debugfs_dif_err_read(struct file *file, char __user *buf,
        size_t nbytes, loff_t *ppos)
 {
-       struct dentry *dent = file->f_path.dentry;
        struct lpfc_hba *phba = file->private_data;
+       int kind = debugfs_get_aux_num(file);
        char cbuf[32];
        uint64_t tmp = 0;
        int cnt = 0;
 
-       if (dent == phba->debug_writeGuard)
+       if (kind == writeGuard)
                cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wgrd_cnt);
-       else if (dent == phba->debug_writeApp)
+       else if (kind == writeApp)
                cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wapp_cnt);
-       else if (dent == phba->debug_writeRef)
+       else if (kind == writeRef)
                cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wref_cnt);
-       else if (dent == phba->debug_readGuard)
+       else if (kind == readGuard)
                cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rgrd_cnt);
-       else if (dent == phba->debug_readApp)
+       else if (kind == readApp)
                cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rapp_cnt);
-       else if (dent == phba->debug_readRef)
+       else if (kind == readRef)
                cnt = scnprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rref_cnt);
-       else if (dent == phba->debug_InjErrNPortID)
+       else if (kind == InjErrNPortID)
                cnt = scnprintf(cbuf, 32, "0x%06x\n",
                                phba->lpfc_injerr_nportid);
-       else if (dent == phba->debug_InjErrWWPN) {
+       else if (kind == InjErrWWPN) {
                memcpy(&tmp, &phba->lpfc_injerr_wwpn, sizeof(struct lpfc_name));
                tmp = cpu_to_be64(tmp);
                cnt = scnprintf(cbuf, 32, "0x%016llx\n", tmp);
-       } else if (dent == phba->debug_InjErrLBA) {
+       } else if (kind == InjErrLBA) {
                if (phba->lpfc_injerr_lba == (sector_t)(-1))
                        cnt = scnprintf(cbuf, 32, "off\n");
                else
@@ -2417,8 +2417,8 @@ static ssize_t
 lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
        size_t nbytes, loff_t *ppos)
 {
-       struct dentry *dent = file->f_path.dentry;
        struct lpfc_hba *phba = file->private_data;
+       int kind = debugfs_get_aux_num(file);
        char dstbuf[33];
        uint64_t tmp = 0;
        int size;
@@ -2428,7 +2428,7 @@ lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
        if (copy_from_user(dstbuf, buf, size))
                return -EFAULT;
 
-       if (dent == phba->debug_InjErrLBA) {
+       if (kind == InjErrLBA) {
                if ((dstbuf[0] == 'o') && (dstbuf[1] == 'f') &&
                    (dstbuf[2] == 'f'))
                        tmp = (uint64_t)(-1);
@@ -2437,23 +2437,23 @@ lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf,
        if ((tmp == 0) && (kstrtoull(dstbuf, 0, &tmp)))
                return -EINVAL;
 
-       if (dent == phba->debug_writeGuard)
+       if (kind == writeGuard)
                phba->lpfc_injerr_wgrd_cnt = (uint32_t)tmp;
-       else if (dent == phba->debug_writeApp)
+       else if (kind == writeApp)
                phba->lpfc_injerr_wapp_cnt = (uint32_t)tmp;
-       else if (dent == phba->debug_writeRef)
+       else if (kind == writeRef)
                phba->lpfc_injerr_wref_cnt = (uint32_t)tmp;
-       else if (dent == phba->debug_readGuard)
+       else if (kind == readGuard)
                phba->lpfc_injerr_rgrd_cnt = (uint32_t)tmp;
-       else if (dent == phba->debug_readApp)
+       else if (kind == readApp)
                phba->lpfc_injerr_rapp_cnt = (uint32_t)tmp;
-       else if (dent == phba->debug_readRef)
+       else if (kind == readRef)
                phba->lpfc_injerr_rref_cnt = (uint32_t)tmp;
-       else if (dent == phba->debug_InjErrLBA)
+       else if (kind == InjErrLBA)
                phba->lpfc_injerr_lba = (sector_t)tmp;
-       else if (dent == phba->debug_InjErrNPortID)
+       else if (kind == InjErrNPortID)
                phba->lpfc_injerr_nportid = (uint32_t)(tmp & Mask_DID);
-       else if (dent == phba->debug_InjErrWWPN) {
+       else if (kind == InjErrWWPN) {
                tmp = cpu_to_be64(tmp);
                memcpy(&phba->lpfc_injerr_wwpn, &tmp, sizeof(struct lpfc_name));
        } else
@@ -6160,60 +6160,51 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
                        phba->debug_dumpHostSlim = NULL;
 
                /* Setup DIF Error Injections */
-               snprintf(name, sizeof(name), "InjErrLBA");
                phba->debug_InjErrLBA =
-                       debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+                       debugfs_create_file_aux_num("InjErrLBA", 0644,
                        phba->hba_debugfs_root,
-                       phba, &lpfc_debugfs_op_dif_err);
+                       phba, InjErrLBA, &lpfc_debugfs_op_dif_err);
                phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF;
 
-               snprintf(name, sizeof(name), "InjErrNPortID");
                phba->debug_InjErrNPortID =
-                       debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+                       debugfs_create_file_aux_num("InjErrNPortID", 0644,
                        phba->hba_debugfs_root,
-                       phba, &lpfc_debugfs_op_dif_err);
+                       phba, InjErrNPortID, &lpfc_debugfs_op_dif_err);
 
-               snprintf(name, sizeof(name), "InjErrWWPN");
                phba->debug_InjErrWWPN =
-                       debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+                       debugfs_create_file_aux_num("InjErrWWPN", 0644,
                        phba->hba_debugfs_root,
-                       phba, &lpfc_debugfs_op_dif_err);
+                       phba, InjErrWWPN, &lpfc_debugfs_op_dif_err);
 
-               snprintf(name, sizeof(name), "writeGuardInjErr");
                phba->debug_writeGuard =
-                       debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+                       debugfs_create_file_aux_num("writeGuardInjErr", 0644,
                        phba->hba_debugfs_root,
-                       phba, &lpfc_debugfs_op_dif_err);
+                       phba, writeGuard, &lpfc_debugfs_op_dif_err);
 
-               snprintf(name, sizeof(name), "writeAppInjErr");
                phba->debug_writeApp =
-                       debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+                       debugfs_create_file_aux_num("writeAppInjErr", 0644,
                        phba->hba_debugfs_root,
-                       phba, &lpfc_debugfs_op_dif_err);
+                       phba, writeApp, &lpfc_debugfs_op_dif_err);
 
-               snprintf(name, sizeof(name), "writeRefInjErr");
                phba->debug_writeRef =
-                       debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+                       debugfs_create_file_aux_num("writeRefInjErr", 0644,
                        phba->hba_debugfs_root,
-                       phba, &lpfc_debugfs_op_dif_err);
+                       phba, writeRef, &lpfc_debugfs_op_dif_err);
 
-               snprintf(name, sizeof(name), "readGuardInjErr");
                phba->debug_readGuard =
-                       debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+                       debugfs_create_file_aux_num("readGuardInjErr", 0644,
                        phba->hba_debugfs_root,
-                       phba, &lpfc_debugfs_op_dif_err);
+                       phba, readGuard, &lpfc_debugfs_op_dif_err);
 
-               snprintf(name, sizeof(name), "readAppInjErr");
                phba->debug_readApp =
-                       debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+                       debugfs_create_file_aux_num("readAppInjErr", 0644,
                        phba->hba_debugfs_root,
-                       phba, &lpfc_debugfs_op_dif_err);
+                       phba, readApp, &lpfc_debugfs_op_dif_err);
 
-               snprintf(name, sizeof(name), "readRefInjErr");
                phba->debug_readRef =
-                       debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR,
+                       debugfs_create_file_aux_num("readRefInjErr", 0644,
                        phba->hba_debugfs_root,
-                       phba, &lpfc_debugfs_op_dif_err);
+                       phba, readRef, &lpfc_debugfs_op_dif_err);
 
                /* Setup slow ring trace */
                if (lpfc_debugfs_max_slow_ring_trc) {
drivers/scsi/lpfc/lpfc_debugfs.h +4 -0
index 8d2e8d05bbc0..f319f3af0400 100644
@@ -322,6 +322,17 @@ enum {
                                                 * discovery */
 #endif /* H_LPFC_DEBUG_FS */
 
+enum {
+       writeGuard = 1,
+       writeApp,
+       writeRef,

drivers/scsi/lpfc/lpfc_debugfs.h enum { · line 338

Quoted 10 lines
drivers/scsi/lpfc/lpfc_debugfs.h +7 -0
+       readGuard,
+       readApp,
+       readRef,
+       InjErrLBA,
+       InjErrNPortID,
+       InjErrWWPN,
+};
 
 /*
  * Driver debug utility routines outside of debugfs. The debug utility

Regards,
Justin

maintainer Applied
#31 lore raw

Re: (subset) [PATCH 01/11] zynqmp: don't bother with debugfs_file_{get,put}() in proxied fops

In reply to Al Viro
Quoted 8 lines · Al Viro

When debugfs file has been created by debugfs_create_file_unsafe(), we do need the file_operations methods to use debugfs_file_{get,put}() to prevent concurrent removal; for files created by debugfs_create_file() that is done in the wrappers that call underlying methods, so there's no point whatsoever duplicating that in the underlying methods themselves.

[...]

Applied, thanks!

[10/11] blk-mq-debugfs: use debugfs_get_aux()

        commit: c25885fc939f29200cccb58ffdb920a91ec62647

Best regards,

Signature · 1 line
Jens Axboe
author maintainer
#32 lore raw

Re: (subset) [PATCH 01/11] zynqmp: don't bother with debugfs_file_{get,put}() in proxied fops

Quoted 9 lines · Jens Axboe
Quoted 7 lines · Al Viro

When debugfs file has been created by debugfs_create_file_unsafe(), we do need the file_operations methods to use debugfs_file_{get,put}() to prevent concurrent removal; for files created by debugfs_create_file() that is done in the wrappers that call underlying methods, so there's no point whatsoever duplicating that in the underlying methods themselves.

Quoted 6 lines
Quoted 1 line

[...]

Applied, thanks!

[10/11] blk-mq-debugfs: use debugfs_get_aux()

        commit: c25885fc939f29200cccb58ffdb920a91ec62647

Umm... That sucker depends upon the previous commit - you'll need to cast debugfs_get_aux() result to void * without that...

maintainer
#33 lore raw

Re: (subset) [PATCH 01/11] zynqmp: don't bother with debugfs_file_{get,put}() in proxied fops

Quoted 12 lines · Al Viro
Quoted 11 lines · Jens Axboe
Quoted 8 lines · Al Viro

When debugfs file has been created by debugfs_create_file_unsafe(), we do need the file_operations methods to use debugfs_file_{get,put}() to prevent concurrent removal; for files created by debugfs_create_file() that is done in the wrappers that call underlying methods, so there's no point whatsoever duplicating that in the underlying methods themselves.

[...]

Quoted 7 lines
Quoted 4 lines

Applied, thanks!

[10/11] blk-mq-debugfs: use debugfs_get_aux()

        commit: c25885fc939f29200cccb58ffdb920a91ec62647

Umm... That sucker depends upon the previous commit - you'll need to cast debugfs_get_aux() result to void * without that...

Gah ok - wasn't cleear since I wasn't CC'ed on the series, just the single patch. If it's a single patch, I'm assuming it's good to go if it looks good.

I'll just drop it.

Signature · 1 line
Jens Axboe
#34 lore raw

Re: (subset) [PATCH 01/11] zynqmp: don't bother with debugfs_file_{get,put}() in proxied fops

In reply to Al Viro
Quoted 12 lines · Al Viro
Quoted 11 lines · Jens Axboe
Quoted 8 lines · Al Viro

When debugfs file has been created by debugfs_create_file_unsafe(), we do need the file_operations methods to use debugfs_file_{get,put}() to prevent concurrent removal; for files created by debugfs_create_file() that is done in the wrappers that call underlying methods, so there's no point whatsoever duplicating that in the underlying methods themselves.

[...]

Quoted 7 lines
Quoted 4 lines

Applied, thanks!

[10/11] blk-mq-debugfs: use debugfs_get_aux()

        commit: c25885fc939f29200cccb58ffdb920a91ec62647

Umm... That sucker depends upon the previous commit - you'll need to cast debugfs_get_aux() result to void * without that...

Wait, what "previous commit" this is patch 01/11 of the series?

I'm all for you just taking this through your trees if it depends on something else that is there, but that wasn't obvious, sorry.

greg k-h

author maintainer
#35 lore raw

Re: (subset) [PATCH 01/11] zynqmp: don't bother with debugfs_file_{get,put}() in proxied fops

Quoted 11 lines · Greg Kroah-Hartman
Quoted 10 lines · Al Viro
Quoted 9 lines · Jens Axboe
Quoted 7 lines · Al Viro

When debugfs file has been created by debugfs_create_file_unsafe(), we do need the file_operations methods to use debugfs_file_{get,put}() to prevent concurrent removal; for files created by debugfs_create_file() that is done in the wrappers that call underlying methods, so there's no point whatsoever duplicating that in the underlying methods themselves.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line

[...]

Applied, thanks!

[10/11] blk-mq-debugfs: use debugfs_get_aux()

       ^^^^^
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
        commit: c25885fc939f29200cccb58ffdb920a91ec62647

Umm... That sucker depends upon the previous commit - you'll need to cast debugfs_get_aux() result to void * without that...

Wait, what "previous commit" this is patch 01/11 of the series?

Jens replied to 01/11 saying that he'd grabbed 10/11, unfortunately without 09/11...

maintainer
#36 lore raw

Re: (subset) [PATCH 01/11] zynqmp: don't bother with debugfs_file_{get,put}() in proxied fops

In reply to Al Viro
Quoted 8 lines · Al Viro

When debugfs file has been created by debugfs_create_file_unsafe(), we do need the file_operations methods to use debugfs_file_{get,put}() to prevent concurrent removal; for files created by debugfs_create_file() that is done in the wrappers that call underlying methods, so there's no point whatsoever duplicating that in the underlying methods themselves.

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git for-next

Thanks!

[03/11] regmap: get rid of redundant debugfs_file_{get,put}()

        commit: 9f711c9321cffe3e03709176873c277fa911c366

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

#37 lore raw
In reply to Al Viro
Quoted 24 lines · Al Viro

A bit more of debugfs work; that stuff sits in
git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs.git #work.debugfs Individual patches in followups. Please, review.

Several removals of pointless debugfs_file_{get,put}():
zynqmp: don't bother with debugfs_file_{get,put}() in proxied fops
hfi1: get rid of redundant debugfs_file_{get,put}()
regmap: get rid of redundant debugfs_file_{get,put}()
resctrl: get rid of pointless debugfs_file_{get,put}()
Getting rid of the last remnants of debugfs_real_fops():
vmscan: don't bother with debugfs_real_fops()
netronome: don't bother with debugfs_real_fops()
debugfs: split short and full proxy wrappers, kill debugfs_real_fops()

Bogosities in drivers/thermal/testing:
fix tt_command_write():
1) unbalanced debugfs_file_get(). Not needed in the first place - file_operations are accessed only via debugfs_create_file(), so debugfs wrappers will take care of that itself.
2) kmalloc() for a buffer used only for duration of a function is not a problem, but for a buffer no longer than 16 bytes?
3) strstr() is for finding substrings; for finding a character there's strchr().

Quoted 5 lines

debugfs_get_aux() stuff:
debugfs_get_aux(): allow storing non-const void *
blk-mq-debugfs: use debugfs_aux_data()
lpfc: don't use file->f_path.dentry for comparisons
If you want a home-grown switch, at least use enum for selector...

All now queued up for testing, thanks.

greg k-h