intel-wired-lan.osuosl.org archive mirror
 help / color / mirror / Atom feed
From: Wang Liang <wangliang74@huawei.com>
To: <anthony.l.nguyen@intel.com>, <przemyslaw.kitszel@intel.com>,
	<andrew+netdev@lunn.ch>, <davem@davemloft.net>,
	<edumazet@google.com>, <kuba@kernel.org>, <pabeni@redhat.com>
Cc: <intel-wired-lan@lists.osuosl.org>, <netdev@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <yuehaibing@huawei.com>,
	<zhangchangzhong@huawei.com>, <wangliang74@huawei.com>
Subject: [Intel-wired-lan] [PATCH -next] i40e: Replace sscanf() with kstrtoint() in i40e_dbg_netdev_ops_write()
Date: Sat, 25 Oct 2025 12:07:35 +0800	[thread overview]
Message-ID: <20251025040735.558953-1-wangliang74@huawei.com> (raw)

Commit 9fcdb1c3c4ba ("i40e: remove read access to debugfs files")
introduced some checkpatch warnings like this:

  WARNING: Prefer kstrto<type> to single variable sscanf
  #240: FILE: drivers/net/ethernet/intel/i40e/i40e_debugfs.c:1655:
  +               cnt = sscanf(&cmd_buf[11], "%i", &vsi_seid);

  WARNING: Prefer kstrto<type> to single variable sscanf
  #251: FILE: drivers/net/ethernet/intel/i40e/i40e_debugfs.c:1676:
  +               cnt = sscanf(&cmd_buf[4], "%i", &vsi_seid);

  total: 0 errors, 2 warnings, 0 checks, 194 lines checked

Function kstrtoint() provides better error detection, overflow protection,
and consistent error handling than sscanf(). Replace sscanf() with
kstrtoint() in i40e_dbg_netdev_ops_write() to silence the checkpatch
warnings.

Signed-off-by: Wang Liang <wangliang74@huawei.com>
---
 drivers/net/ethernet/intel/i40e/i40e_debugfs.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/intel/i40e/i40e_debugfs.c b/drivers/net/ethernet/intel/i40e/i40e_debugfs.c
index c17b5d290f0a..2abd12b62509 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_debugfs.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_debugfs.c
@@ -1604,7 +1604,7 @@ static ssize_t i40e_dbg_netdev_ops_write(struct file *filp,
 	int bytes_not_copied;
 	struct i40e_vsi *vsi;
 	int vsi_seid;
-	int i, cnt;
+	int i, ret;
 
 	/* don't allow partial writes */
 	if (*ppos != 0)
@@ -1629,9 +1629,9 @@ static ssize_t i40e_dbg_netdev_ops_write(struct file *filp,
 	if (strncmp(cmd_buf, "change_mtu", 10) == 0) {
 		int mtu;
 
-		cnt = sscanf(&cmd_buf[11], "%i %i",
+		ret = sscanf(&cmd_buf[11], "%i %i",
 			     &vsi_seid, &mtu);
-		if (cnt != 2) {
+		if (ret != 2) {
 			dev_info(&pf->pdev->dev, "change_mtu <vsi_seid> <mtu>\n");
 			goto netdev_ops_write_done;
 		}
@@ -1652,8 +1652,8 @@ static ssize_t i40e_dbg_netdev_ops_write(struct file *filp,
 		}
 
 	} else if (strncmp(cmd_buf, "set_rx_mode", 11) == 0) {
-		cnt = sscanf(&cmd_buf[11], "%i", &vsi_seid);
-		if (cnt != 1) {
+		ret = kstrtoint(&cmd_buf[11], 0, &vsi_seid);
+		if (ret) {
 			dev_info(&pf->pdev->dev, "set_rx_mode <vsi_seid>\n");
 			goto netdev_ops_write_done;
 		}
@@ -1673,8 +1673,8 @@ static ssize_t i40e_dbg_netdev_ops_write(struct file *filp,
 		}
 
 	} else if (strncmp(cmd_buf, "napi", 4) == 0) {
-		cnt = sscanf(&cmd_buf[4], "%i", &vsi_seid);
-		if (cnt != 1) {
+		ret = kstrtoint(&cmd_buf[4], 0, &vsi_seid);
+		if (ret) {
 			dev_info(&pf->pdev->dev, "napi <vsi_seid>\n");
 			goto netdev_ops_write_done;
 		}
-- 
2.34.1


             reply	other threads:[~2025-10-27 15:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-25  4:07 Wang Liang [this message]
2025-10-27  9:40 ` [Intel-wired-lan] [PATCH -next] i40e: Replace sscanf() with kstrtoint() in i40e_dbg_netdev_ops_write() Przemek Kitszel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251025040735.558953-1-wangliang74@huawei.com \
    --to=wangliang74@huawei.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=anthony.l.nguyen@intel.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=przemyslaw.kitszel@intel.com \
    --cc=yuehaibing@huawei.com \
    --cc=zhangchangzhong@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).