Skip to content

Commit e9c7218

Browse files
YueHaibingJeff Kirsher
authored andcommitted
ixgbe: introduce a helper to simplify code
ixgbe_dbg_reg_ops_read and ixgbe_dbg_netdev_ops_read copy-pasting the same code except for ixgbe_dbg_netdev_ops_buf/ixgbe_dbg_reg_ops_buf, so introduce a helper ixgbe_dbg_common_ops_read to remove redundant code. Signed-off-by: YueHaibing <[email protected]> Tested-by: Andrew Bowers <[email protected]> Signed-off-by: Jeff Kirsher <[email protected]>
1 parent 7d6446d commit e9c7218

File tree

1 file changed

+21
-36
lines changed

1 file changed

+21
-36
lines changed

drivers/net/ethernet/intel/ixgbe/ixgbe_debugfs.c

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,9 @@ static struct dentry *ixgbe_dbg_root;
1010

1111
static char ixgbe_dbg_reg_ops_buf[256] = "";
1212

13-
/**
14-
* ixgbe_dbg_reg_ops_read - read for reg_ops datum
15-
* @filp: the opened file
16-
* @buffer: where to write the data for the user to read
17-
* @count: the size of the user's buffer
18-
* @ppos: file position offset
19-
**/
20-
static ssize_t ixgbe_dbg_reg_ops_read(struct file *filp, char __user *buffer,
21-
size_t count, loff_t *ppos)
13+
static ssize_t ixgbe_dbg_common_ops_read(struct file *filp, char __user *buffer,
14+
size_t count, loff_t *ppos,
15+
char *dbg_buf)
2216
{
2317
struct ixgbe_adapter *adapter = filp->private_data;
2418
char *buf;
@@ -29,8 +23,7 @@ static ssize_t ixgbe_dbg_reg_ops_read(struct file *filp, char __user *buffer,
2923
return 0;
3024

3125
buf = kasprintf(GFP_KERNEL, "%s: %s\n",
32-
adapter->netdev->name,
33-
ixgbe_dbg_reg_ops_buf);
26+
adapter->netdev->name, dbg_buf);
3427
if (!buf)
3528
return -ENOMEM;
3629

@@ -45,6 +38,20 @@ static ssize_t ixgbe_dbg_reg_ops_read(struct file *filp, char __user *buffer,
4538
return len;
4639
}
4740

41+
/**
42+
* ixgbe_dbg_reg_ops_read - read for reg_ops datum
43+
* @filp: the opened file
44+
* @buffer: where to write the data for the user to read
45+
* @count: the size of the user's buffer
46+
* @ppos: file position offset
47+
**/
48+
static ssize_t ixgbe_dbg_reg_ops_read(struct file *filp, char __user *buffer,
49+
size_t count, loff_t *ppos)
50+
{
51+
return ixgbe_dbg_common_ops_read(filp, buffer, count, ppos,
52+
ixgbe_dbg_reg_ops_buf);
53+
}
54+
4855
/**
4956
* ixgbe_dbg_reg_ops_write - write into reg_ops datum
5057
* @filp: the opened file
@@ -121,33 +128,11 @@ static char ixgbe_dbg_netdev_ops_buf[256] = "";
121128
* @count: the size of the user's buffer
122129
* @ppos: file position offset
123130
**/
124-
static ssize_t ixgbe_dbg_netdev_ops_read(struct file *filp,
125-
char __user *buffer,
131+
static ssize_t ixgbe_dbg_netdev_ops_read(struct file *filp, char __user *buffer,
126132
size_t count, loff_t *ppos)
127133
{
128-
struct ixgbe_adapter *adapter = filp->private_data;
129-
char *buf;
130-
int len;
131-
132-
/* don't allow partial reads */
133-
if (*ppos != 0)
134-
return 0;
135-
136-
buf = kasprintf(GFP_KERNEL, "%s: %s\n",
137-
adapter->netdev->name,
138-
ixgbe_dbg_netdev_ops_buf);
139-
if (!buf)
140-
return -ENOMEM;
141-
142-
if (count < strlen(buf)) {
143-
kfree(buf);
144-
return -ENOSPC;
145-
}
146-
147-
len = simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
148-
149-
kfree(buf);
150-
return len;
134+
return ixgbe_dbg_common_ops_read(filp, buffer, count, ppos,
135+
ixgbe_dbg_netdev_ops_buf);
151136
}
152137

153138
/**

0 commit comments

Comments
 (0)