Skip to content

Commit c318af3

Browse files
321lipengdavem330
authored andcommitted
net: hns3: clean up hns3_dbg_cmd_write()
As more commands are added, hns3_dbg_cmd_write() is going to get more bloated, so move the part about command check into a separate function. Signed-off-by: Peng Li <[email protected]> Signed-off-by: Huazhong Tan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 433e280 commit c318af3

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -423,14 +423,38 @@ static ssize_t hns3_dbg_cmd_read(struct file *filp, char __user *buffer,
423423
return (*ppos = len);
424424
}
425425

426+
static int hns3_dbg_check_cmd(struct hnae3_handle *handle, char *cmd_buf)
427+
{
428+
int ret = 0;
429+
430+
if (strncmp(cmd_buf, "help", 4) == 0)
431+
hns3_dbg_help(handle);
432+
else if (strncmp(cmd_buf, "queue info", 10) == 0)
433+
ret = hns3_dbg_queue_info(handle, cmd_buf);
434+
else if (strncmp(cmd_buf, "queue map", 9) == 0)
435+
ret = hns3_dbg_queue_map(handle);
436+
else if (strncmp(cmd_buf, "bd info", 7) == 0)
437+
ret = hns3_dbg_bd_info(handle, cmd_buf);
438+
else if (strncmp(cmd_buf, "dev capability", 14) == 0)
439+
hns3_dbg_dev_caps(handle);
440+
else if (strncmp(cmd_buf, "dev spec", 8) == 0)
441+
hns3_dbg_dev_specs(handle);
442+
else if (handle->ae_algo->ops->dbg_run_cmd)
443+
ret = handle->ae_algo->ops->dbg_run_cmd(handle, cmd_buf);
444+
else
445+
ret = -EOPNOTSUPP;
446+
447+
return ret;
448+
}
449+
426450
static ssize_t hns3_dbg_cmd_write(struct file *filp, const char __user *buffer,
427451
size_t count, loff_t *ppos)
428452
{
429453
struct hnae3_handle *handle = filp->private_data;
430454
struct hns3_nic_priv *priv = handle->priv;
431455
char *cmd_buf, *cmd_buf_tmp;
432456
int uncopied_bytes;
433-
int ret = 0;
457+
int ret;
434458

435459
if (*ppos != 0)
436460
return 0;
@@ -461,23 +485,7 @@ static ssize_t hns3_dbg_cmd_write(struct file *filp, const char __user *buffer,
461485
count = cmd_buf_tmp - cmd_buf + 1;
462486
}
463487

464-
if (strncmp(cmd_buf, "help", 4) == 0)
465-
hns3_dbg_help(handle);
466-
else if (strncmp(cmd_buf, "queue info", 10) == 0)
467-
ret = hns3_dbg_queue_info(handle, cmd_buf);
468-
else if (strncmp(cmd_buf, "queue map", 9) == 0)
469-
ret = hns3_dbg_queue_map(handle);
470-
else if (strncmp(cmd_buf, "bd info", 7) == 0)
471-
ret = hns3_dbg_bd_info(handle, cmd_buf);
472-
else if (strncmp(cmd_buf, "dev capability", 14) == 0)
473-
hns3_dbg_dev_caps(handle);
474-
else if (strncmp(cmd_buf, "dev spec", 8) == 0)
475-
hns3_dbg_dev_specs(handle);
476-
else if (handle->ae_algo->ops->dbg_run_cmd)
477-
ret = handle->ae_algo->ops->dbg_run_cmd(handle, cmd_buf);
478-
else
479-
ret = -EOPNOTSUPP;
480-
488+
ret = hns3_dbg_check_cmd(handle, cmd_buf);
481489
if (ret)
482490
hns3_dbg_help(handle);
483491

0 commit comments

Comments
 (0)