@@ -40,48 +40,6 @@ static struct i40e_vsi *i40e_dbg_find_vsi(struct i40e_pf *pf, int seid)
4040 * setup, adding or removing filters, or other things. Many of
4141 * these will be useful for some forms of unit testing.
4242 **************************************************************/
43- static char i40e_dbg_command_buf [256 ] = "" ;
44-
45- /**
46- * i40e_dbg_command_read - read for command datum
47- * @filp: the opened file
48- * @buffer: where to write the data for the user to read
49- * @count: the size of the user's buffer
50- * @ppos: file position offset
51- **/
52- static ssize_t i40e_dbg_command_read (struct file * filp , char __user * buffer ,
53- size_t count , loff_t * ppos )
54- {
55- struct i40e_pf * pf = filp -> private_data ;
56- struct i40e_vsi * main_vsi ;
57- int bytes_not_copied ;
58- int buf_size = 256 ;
59- char * buf ;
60- int len ;
61-
62- /* don't allow partial reads */
63- if (* ppos != 0 )
64- return 0 ;
65- if (count < buf_size )
66- return - ENOSPC ;
67-
68- buf = kzalloc (buf_size , GFP_KERNEL );
69- if (!buf )
70- return - ENOSPC ;
71-
72- main_vsi = i40e_pf_get_main_vsi (pf );
73- len = snprintf (buf , buf_size , "%s: %s\n" , main_vsi -> netdev -> name ,
74- i40e_dbg_command_buf );
75-
76- bytes_not_copied = copy_to_user (buffer , buf , len );
77- kfree (buf );
78-
79- if (bytes_not_copied )
80- return - EFAULT ;
81-
82- * ppos = len ;
83- return len ;
84- }
8543
8644static char * i40e_filter_state_string [] = {
8745 "INVALID" ,
@@ -1621,7 +1579,6 @@ static ssize_t i40e_dbg_command_write(struct file *filp,
16211579static const struct file_operations i40e_dbg_command_fops = {
16221580 .owner = THIS_MODULE ,
16231581 .open = simple_open ,
1624- .read = i40e_dbg_command_read ,
16251582 .write = i40e_dbg_command_write ,
16261583};
16271584
@@ -1630,48 +1587,6 @@ static const struct file_operations i40e_dbg_command_fops = {
16301587 * The netdev_ops entry in debugfs is for giving the driver commands
16311588 * to be executed from the netdev operations.
16321589 **************************************************************/
1633- static char i40e_dbg_netdev_ops_buf [256 ] = "" ;
1634-
1635- /**
1636- * i40e_dbg_netdev_ops_read - read for netdev_ops datum
1637- * @filp: the opened file
1638- * @buffer: where to write the data for the user to read
1639- * @count: the size of the user's buffer
1640- * @ppos: file position offset
1641- **/
1642- static ssize_t i40e_dbg_netdev_ops_read (struct file * filp , char __user * buffer ,
1643- size_t count , loff_t * ppos )
1644- {
1645- struct i40e_pf * pf = filp -> private_data ;
1646- struct i40e_vsi * main_vsi ;
1647- int bytes_not_copied ;
1648- int buf_size = 256 ;
1649- char * buf ;
1650- int len ;
1651-
1652- /* don't allow partal reads */
1653- if (* ppos != 0 )
1654- return 0 ;
1655- if (count < buf_size )
1656- return - ENOSPC ;
1657-
1658- buf = kzalloc (buf_size , GFP_KERNEL );
1659- if (!buf )
1660- return - ENOSPC ;
1661-
1662- main_vsi = i40e_pf_get_main_vsi (pf );
1663- len = snprintf (buf , buf_size , "%s: %s\n" , main_vsi -> netdev -> name ,
1664- i40e_dbg_netdev_ops_buf );
1665-
1666- bytes_not_copied = copy_to_user (buffer , buf , len );
1667- kfree (buf );
1668-
1669- if (bytes_not_copied )
1670- return - EFAULT ;
1671-
1672- * ppos = len ;
1673- return len ;
1674- }
16751590
16761591/**
16771592 * i40e_dbg_netdev_ops_write - write into netdev_ops datum
@@ -1685,35 +1600,36 @@ static ssize_t i40e_dbg_netdev_ops_write(struct file *filp,
16851600 size_t count , loff_t * ppos )
16861601{
16871602 struct i40e_pf * pf = filp -> private_data ;
1603+ char * cmd_buf , * buf_tmp ;
16881604 int bytes_not_copied ;
16891605 struct i40e_vsi * vsi ;
1690- char * buf_tmp ;
16911606 int vsi_seid ;
16921607 int i , cnt ;
16931608
16941609 /* don't allow partial writes */
16951610 if (* ppos != 0 )
16961611 return 0 ;
1697- if (count >= sizeof (i40e_dbg_netdev_ops_buf ))
1698- return - ENOSPC ;
16991612
1700- memset (i40e_dbg_netdev_ops_buf , 0 , sizeof (i40e_dbg_netdev_ops_buf ));
1701- bytes_not_copied = copy_from_user (i40e_dbg_netdev_ops_buf ,
1702- buffer , count );
1703- if (bytes_not_copied )
1613+ cmd_buf = kzalloc (count + 1 , GFP_KERNEL );
1614+ if (!cmd_buf )
1615+ return count ;
1616+ bytes_not_copied = copy_from_user (cmd_buf , buffer , count );
1617+ if (bytes_not_copied ) {
1618+ kfree (cmd_buf );
17041619 return - EFAULT ;
1705- i40e_dbg_netdev_ops_buf [count ] = '\0' ;
1620+ }
1621+ cmd_buf [count ] = '\0' ;
17061622
1707- buf_tmp = strchr (i40e_dbg_netdev_ops_buf , '\n' );
1623+ buf_tmp = strchr (cmd_buf , '\n' );
17081624 if (buf_tmp ) {
17091625 * buf_tmp = '\0' ;
1710- count = buf_tmp - i40e_dbg_netdev_ops_buf + 1 ;
1626+ count = buf_tmp - cmd_buf + 1 ;
17111627 }
17121628
1713- if (strncmp (i40e_dbg_netdev_ops_buf , "change_mtu" , 10 ) == 0 ) {
1629+ if (strncmp (cmd_buf , "change_mtu" , 10 ) == 0 ) {
17141630 int mtu ;
17151631
1716- cnt = sscanf (& i40e_dbg_netdev_ops_buf [11 ], "%i %i" ,
1632+ cnt = sscanf (& cmd_buf [11 ], "%i %i" ,
17171633 & vsi_seid , & mtu );
17181634 if (cnt != 2 ) {
17191635 dev_info (& pf -> pdev -> dev , "change_mtu <vsi_seid> <mtu>\n" );
@@ -1735,8 +1651,8 @@ static ssize_t i40e_dbg_netdev_ops_write(struct file *filp,
17351651 dev_info (& pf -> pdev -> dev , "Could not acquire RTNL - please try again\n" );
17361652 }
17371653
1738- } else if (strncmp (i40e_dbg_netdev_ops_buf , "set_rx_mode" , 11 ) == 0 ) {
1739- cnt = sscanf (& i40e_dbg_netdev_ops_buf [11 ], "%i" , & vsi_seid );
1654+ } else if (strncmp (cmd_buf , "set_rx_mode" , 11 ) == 0 ) {
1655+ cnt = sscanf (& cmd_buf [11 ], "%i" , & vsi_seid );
17401656 if (cnt != 1 ) {
17411657 dev_info (& pf -> pdev -> dev , "set_rx_mode <vsi_seid>\n" );
17421658 goto netdev_ops_write_done ;
@@ -1756,8 +1672,8 @@ static ssize_t i40e_dbg_netdev_ops_write(struct file *filp,
17561672 dev_info (& pf -> pdev -> dev , "Could not acquire RTNL - please try again\n" );
17571673 }
17581674
1759- } else if (strncmp (i40e_dbg_netdev_ops_buf , "napi" , 4 ) == 0 ) {
1760- cnt = sscanf (& i40e_dbg_netdev_ops_buf [4 ], "%i" , & vsi_seid );
1675+ } else if (strncmp (cmd_buf , "napi" , 4 ) == 0 ) {
1676+ cnt = sscanf (& cmd_buf [4 ], "%i" , & vsi_seid );
17611677 if (cnt != 1 ) {
17621678 dev_info (& pf -> pdev -> dev , "napi <vsi_seid>\n" );
17631679 goto netdev_ops_write_done ;
@@ -1775,21 +1691,20 @@ static ssize_t i40e_dbg_netdev_ops_write(struct file *filp,
17751691 dev_info (& pf -> pdev -> dev , "napi called\n" );
17761692 }
17771693 } else {
1778- dev_info (& pf -> pdev -> dev , "unknown command '%s'\n" ,
1779- i40e_dbg_netdev_ops_buf );
1694+ dev_info (& pf -> pdev -> dev , "unknown command '%s'\n" , cmd_buf );
17801695 dev_info (& pf -> pdev -> dev , "available commands\n" );
17811696 dev_info (& pf -> pdev -> dev , " change_mtu <vsi_seid> <mtu>\n" );
17821697 dev_info (& pf -> pdev -> dev , " set_rx_mode <vsi_seid>\n" );
17831698 dev_info (& pf -> pdev -> dev , " napi <vsi_seid>\n" );
17841699 }
17851700netdev_ops_write_done :
1701+ kfree (cmd_buf );
17861702 return count ;
17871703}
17881704
17891705static const struct file_operations i40e_dbg_netdev_ops_fops = {
17901706 .owner = THIS_MODULE ,
17911707 .open = simple_open ,
1792- .read = i40e_dbg_netdev_ops_read ,
17931708 .write = i40e_dbg_netdev_ops_write ,
17941709};
17951710
0 commit comments