lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240411153126.16201-328-axboe@kernel.dk>
Date: Thu, 11 Apr 2024 09:17:47 -0600
From: Jens Axboe <axboe@...nel.dk>
To: linux-kernel@...r.kernel.org
Cc: Bui Quang Minh <minhquangbui99@...il.com>,
	Jens Axboe <axboe@...nel.dk>
Subject: [PATCH 327/437] drivers/net/ethernet/amd-xgbe: convert to read/write iterators

From: Bui Quang Minh <minhquangbui99@...il.com>

Signed-off-by: Bui Quang Minh <minhquangbui99@...il.com>
[axboe: fix typo in xi2c_reg_value_read_iter]
Signed-off-by: Jens Axboe <axboe@...nel.dk>
---
 drivers/net/ethernet/amd/xgbe/xgbe-debugfs.c | 233 +++++++++----------
 1 file changed, 112 insertions(+), 121 deletions(-)

diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-debugfs.c b/drivers/net/ethernet/amd/xgbe/xgbe-debugfs.c
index b0a6c96b6ef4..5dfd4fc8618e 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-debugfs.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-debugfs.c
@@ -121,36 +121,30 @@
 #include "xgbe.h"
 #include "xgbe-common.h"
 
-static ssize_t xgbe_common_read(char __user *buffer, size_t count,
-				loff_t *ppos, unsigned int value)
+static ssize_t xgbe_common_read_iter(struct iov_iter *to, loff_t *ppos,
+				     unsigned int value)
 {
-	char *buf;
-	ssize_t len;
+	char buf[16];
+	int len;
+	size_t count = iov_iter_count(to);
 
 	if (*ppos != 0)
 		return 0;
 
-	buf = kasprintf(GFP_KERNEL, "0x%08x\n", value);
-	if (!buf)
-		return -ENOMEM;
-
-	if (count < strlen(buf)) {
-		kfree(buf);
+	len = sprintf(buf, "0x%08x\n", value);
+	if (count < len)
 		return -ENOSPC;
-	}
-
-	len = simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
-	kfree(buf);
 
-	return len;
+	return simple_copy_to_iter(buf, ppos, len, to);
 }
 
-static ssize_t xgbe_common_write(const char __user *buffer, size_t count,
-				 loff_t *ppos, unsigned int *value)
+static ssize_t xgbe_common_write_iter(struct iov_iter *from, loff_t *ppos,
+				      unsigned int *value)
 {
 	char workarea[32];
 	ssize_t len;
 	int ret;
+	size_t count = iov_iter_count(from);
 
 	if (*ppos != 0)
 		return -EINVAL;
@@ -158,8 +152,8 @@ static ssize_t xgbe_common_write(const char __user *buffer, size_t count,
 	if (count >= sizeof(workarea))
 		return -ENOSPC;
 
-	len = simple_write_to_buffer(workarea, sizeof(workarea) - 1, ppos,
-				     buffer, count);
+	len = simple_copy_from_iter(workarea, ppos, sizeof(workarea) - 1,
+				    from);
 	if (len < 0)
 		return len;
 
@@ -171,44 +165,43 @@ static ssize_t xgbe_common_write(const char __user *buffer, size_t count,
 	return len;
 }
 
-static ssize_t xgmac_reg_addr_read(struct file *filp, char __user *buffer,
-				   size_t count, loff_t *ppos)
+static ssize_t xgmac_reg_addr_read_iter(struct kiocb *iocb,
+					struct iov_iter *to)
 {
-	struct xgbe_prv_data *pdata = filp->private_data;
+	struct xgbe_prv_data *pdata = iocb->ki_filp->private_data;
 
-	return xgbe_common_read(buffer, count, ppos, pdata->debugfs_xgmac_reg);
+	return xgbe_common_read_iter(to, &iocb->ki_pos,
+				     pdata->debugfs_xgmac_reg);
 }
 
-static ssize_t xgmac_reg_addr_write(struct file *filp,
-				    const char __user *buffer,
-				    size_t count, loff_t *ppos)
+static ssize_t xgmac_reg_addr_write_iter(struct kiocb *iocb,
+					 struct iov_iter *from)
 {
-	struct xgbe_prv_data *pdata = filp->private_data;
+	struct xgbe_prv_data *pdata = iocb->ki_filp->private_data;
 
-	return xgbe_common_write(buffer, count, ppos,
-				 &pdata->debugfs_xgmac_reg);
+	return xgbe_common_write_iter(from, &iocb->ki_pos,
+				      &pdata->debugfs_xgmac_reg);
 }
 
-static ssize_t xgmac_reg_value_read(struct file *filp, char __user *buffer,
-				    size_t count, loff_t *ppos)
+static ssize_t xgmac_reg_value_read_iter(struct kiocb *iocb,
+					 struct iov_iter *to)
 {
-	struct xgbe_prv_data *pdata = filp->private_data;
+	struct xgbe_prv_data *pdata = iocb->ki_filp->private_data;
 	unsigned int value;
 
 	value = XGMAC_IOREAD(pdata, pdata->debugfs_xgmac_reg);
 
-	return xgbe_common_read(buffer, count, ppos, value);
+	return xgbe_common_read_iter(to, &iocb->ki_pos, value);
 }
 
-static ssize_t xgmac_reg_value_write(struct file *filp,
-				     const char __user *buffer,
-				     size_t count, loff_t *ppos)
+static ssize_t xgmac_reg_value_write_iter(struct kiocb *iocb,
+					  struct iov_iter *from)
 {
-	struct xgbe_prv_data *pdata = filp->private_data;
+	struct xgbe_prv_data *pdata = iocb->ki_filp->private_data;
 	unsigned int value;
 	ssize_t len;
 
-	len = xgbe_common_write(buffer, count, ppos, &value);
+	len = xgbe_common_write_iter(from, &iocb->ki_pos, &value);
 	if (len < 0)
 		return len;
 
@@ -220,72 +213,73 @@ static ssize_t xgmac_reg_value_write(struct file *filp,
 static const struct file_operations xgmac_reg_addr_fops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.read =  xgmac_reg_addr_read,
-	.write = xgmac_reg_addr_write,
+	.read_iter =  xgmac_reg_addr_read_iter,
+	.write_iter = xgmac_reg_addr_write_iter,
 };
 
 static const struct file_operations xgmac_reg_value_fops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.read =  xgmac_reg_value_read,
-	.write = xgmac_reg_value_write,
+	.read_iter =  xgmac_reg_value_read_iter,
+	.write_iter = xgmac_reg_value_write_iter,
 };
 
-static ssize_t xpcs_mmd_read(struct file *filp, char __user *buffer,
-			     size_t count, loff_t *ppos)
+static ssize_t xpcs_mmd_read_iter(struct kiocb *iocb,
+				  struct iov_iter *to)
 {
-	struct xgbe_prv_data *pdata = filp->private_data;
+	struct xgbe_prv_data *pdata = iocb->ki_filp->private_data;
 
-	return xgbe_common_read(buffer, count, ppos, pdata->debugfs_xpcs_mmd);
+	return xgbe_common_read_iter(to, &iocb->ki_pos,
+				     pdata->debugfs_xpcs_mmd);
 }
 
-static ssize_t xpcs_mmd_write(struct file *filp, const char __user *buffer,
-			      size_t count, loff_t *ppos)
+static ssize_t xpcs_mmd_write_iter(struct kiocb *iocb,
+				   struct iov_iter *from)
 {
-	struct xgbe_prv_data *pdata = filp->private_data;
+	struct xgbe_prv_data *pdata = iocb->ki_filp->private_data;
 
-	return xgbe_common_write(buffer, count, ppos,
-				 &pdata->debugfs_xpcs_mmd);
+	return xgbe_common_write_iter(from, &iocb->ki_pos,
+				      &pdata->debugfs_xpcs_mmd);
 }
 
-static ssize_t xpcs_reg_addr_read(struct file *filp, char __user *buffer,
-				  size_t count, loff_t *ppos)
+static ssize_t xpcs_reg_addr_read_iter(struct kiocb *iocb,
+				       struct iov_iter *to)
 {
-	struct xgbe_prv_data *pdata = filp->private_data;
+	struct xgbe_prv_data *pdata = iocb->ki_filp->private_data;
 
-	return xgbe_common_read(buffer, count, ppos, pdata->debugfs_xpcs_reg);
+	return xgbe_common_read_iter(to, &iocb->ki_pos,
+				     pdata->debugfs_xpcs_reg);
 }
 
-static ssize_t xpcs_reg_addr_write(struct file *filp, const char __user *buffer,
-				   size_t count, loff_t *ppos)
+static ssize_t xpcs_reg_addr_write_iter(struct kiocb *iocb,
+					struct iov_iter *from)
 {
-	struct xgbe_prv_data *pdata = filp->private_data;
+	struct xgbe_prv_data *pdata = iocb->ki_filp->private_data;
 
-	return xgbe_common_write(buffer, count, ppos,
-				 &pdata->debugfs_xpcs_reg);
+	return xgbe_common_write_iter(from, &iocb->ki_pos,
+				      &pdata->debugfs_xpcs_reg);
 }
 
-static ssize_t xpcs_reg_value_read(struct file *filp, char __user *buffer,
-				   size_t count, loff_t *ppos)
+static ssize_t xpcs_reg_value_read_iter(struct kiocb *iocb,
+					struct iov_iter *to)
 {
-	struct xgbe_prv_data *pdata = filp->private_data;
+	struct xgbe_prv_data *pdata = iocb->ki_filp->private_data;
 	unsigned int value;
 
 	value = XMDIO_READ(pdata, pdata->debugfs_xpcs_mmd,
 			   pdata->debugfs_xpcs_reg);
 
-	return xgbe_common_read(buffer, count, ppos, value);
+	return xgbe_common_read_iter(to, &iocb->ki_pos, value);
 }
 
-static ssize_t xpcs_reg_value_write(struct file *filp,
-				    const char __user *buffer,
-				    size_t count, loff_t *ppos)
+static ssize_t xpcs_reg_value_write_iter(struct kiocb *iocb,
+					 struct iov_iter *from)
 {
-	struct xgbe_prv_data *pdata = filp->private_data;
+	struct xgbe_prv_data *pdata = iocb->ki_filp->private_data;
 	unsigned int value;
 	ssize_t len;
 
-	len = xgbe_common_write(buffer, count, ppos, &value);
+	len = xgbe_common_write_iter(from, &iocb->ki_pos, &value);
 	if (len < 0)
 		return len;
 
@@ -298,62 +292,61 @@ static ssize_t xpcs_reg_value_write(struct file *filp,
 static const struct file_operations xpcs_mmd_fops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.read =  xpcs_mmd_read,
-	.write = xpcs_mmd_write,
+	.read_iter =  xpcs_mmd_read_iter,
+	.write_iter = xpcs_mmd_write_iter,
 };
 
 static const struct file_operations xpcs_reg_addr_fops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.read =  xpcs_reg_addr_read,
-	.write = xpcs_reg_addr_write,
+	.read_iter =  xpcs_reg_addr_read_iter,
+	.write_iter = xpcs_reg_addr_write_iter,
 };
 
 static const struct file_operations xpcs_reg_value_fops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.read =  xpcs_reg_value_read,
-	.write = xpcs_reg_value_write,
+	.read_iter =  xpcs_reg_value_read_iter,
+	.write_iter = xpcs_reg_value_write_iter,
 };
 
-static ssize_t xprop_reg_addr_read(struct file *filp, char __user *buffer,
-				   size_t count, loff_t *ppos)
+static ssize_t xprop_reg_addr_read_iter(struct kiocb *iocb,
+					struct iov_iter *to)
 {
-	struct xgbe_prv_data *pdata = filp->private_data;
+	struct xgbe_prv_data *pdata = iocb->ki_filp->private_data;
 
-	return xgbe_common_read(buffer, count, ppos, pdata->debugfs_xprop_reg);
+	return xgbe_common_read_iter(to, &iocb->ki_pos,
+				     pdata->debugfs_xprop_reg);
 }
 
-static ssize_t xprop_reg_addr_write(struct file *filp,
-				    const char __user *buffer,
-				    size_t count, loff_t *ppos)
+static ssize_t xprop_reg_addr_write_iter(struct kiocb *iocb,
+					 struct iov_iter *from)
 {
-	struct xgbe_prv_data *pdata = filp->private_data;
+	struct xgbe_prv_data *pdata = iocb->ki_filp->private_data;
 
-	return xgbe_common_write(buffer, count, ppos,
-				 &pdata->debugfs_xprop_reg);
+	return xgbe_common_write_iter(from, &iocb->ki_pos,
+				      &pdata->debugfs_xprop_reg);
 }
 
-static ssize_t xprop_reg_value_read(struct file *filp, char __user *buffer,
-				    size_t count, loff_t *ppos)
+static ssize_t xprop_reg_value_read_iter(struct kiocb *iocb,
+					 struct iov_iter *to)
 {
-	struct xgbe_prv_data *pdata = filp->private_data;
+	struct xgbe_prv_data *pdata = iocb->ki_filp->private_data;
 	unsigned int value;
 
 	value = XP_IOREAD(pdata, pdata->debugfs_xprop_reg);
 
-	return xgbe_common_read(buffer, count, ppos, value);
+	return xgbe_common_read_iter(to, &iocb->ki_pos, value);
 }
 
-static ssize_t xprop_reg_value_write(struct file *filp,
-				     const char __user *buffer,
-				     size_t count, loff_t *ppos)
+static ssize_t xprop_reg_value_write_iter(struct kiocb *iocb,
+					  struct iov_iter *from)
 {
-	struct xgbe_prv_data *pdata = filp->private_data;
+	struct xgbe_prv_data *pdata = iocb->ki_filp->private_data;
 	unsigned int value;
 	ssize_t len;
 
-	len = xgbe_common_write(buffer, count, ppos, &value);
+	len = xgbe_common_write_iter(from, &iocb->ki_pos, &value);
 	if (len < 0)
 		return len;
 
@@ -365,55 +358,53 @@ static ssize_t xprop_reg_value_write(struct file *filp,
 static const struct file_operations xprop_reg_addr_fops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.read =  xprop_reg_addr_read,
-	.write = xprop_reg_addr_write,
+	.read_iter =  xprop_reg_addr_read_iter,
+	.write_iter = xprop_reg_addr_write_iter,
 };
 
 static const struct file_operations xprop_reg_value_fops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.read =  xprop_reg_value_read,
-	.write = xprop_reg_value_write,
+	.read_iter =  xprop_reg_value_read_iter,
+	.write_iter = xprop_reg_value_write_iter,
 };
 
-static ssize_t xi2c_reg_addr_read(struct file *filp, char __user *buffer,
-				  size_t count, loff_t *ppos)
+static ssize_t xi2c_reg_addr_read_iter(struct kiocb *iocb, struct iov_iter *to)
 {
-	struct xgbe_prv_data *pdata = filp->private_data;
+	struct xgbe_prv_data *pdata = iocb->ki_filp->private_data;
 
-	return xgbe_common_read(buffer, count, ppos, pdata->debugfs_xi2c_reg);
+	return xgbe_common_read_iter(to, &iocb->ki_pos,
+				     pdata->debugfs_xi2c_reg);
 }
 
-static ssize_t xi2c_reg_addr_write(struct file *filp,
-				   const char __user *buffer,
-				   size_t count, loff_t *ppos)
+static ssize_t xi2c_reg_addr_write_iter(struct kiocb *iocb,
+					struct iov_iter *from)
 {
-	struct xgbe_prv_data *pdata = filp->private_data;
+	struct xgbe_prv_data *pdata = iocb->ki_filp->private_data;
 
-	return xgbe_common_write(buffer, count, ppos,
-				 &pdata->debugfs_xi2c_reg);
+	return xgbe_common_write_iter(from, &iocb->ki_pos,
+				      &pdata->debugfs_xi2c_reg);
 }
 
-static ssize_t xi2c_reg_value_read(struct file *filp, char __user *buffer,
-				   size_t count, loff_t *ppos)
+static ssize_t xi2c_reg_value_read_iter(struct kiocb *iocb,
+					struct iov_iter *to)
 {
-	struct xgbe_prv_data *pdata = filp->private_data;
+	struct xgbe_prv_data *pdata = iocb->ki_filp->private_data;
 	unsigned int value;
 
 	value = XI2C_IOREAD(pdata, pdata->debugfs_xi2c_reg);
 
-	return xgbe_common_read(buffer, count, ppos, value);
+	return xgbe_common_read_iter(to, &iocb->ki_pos, value);
 }
 
-static ssize_t xi2c_reg_value_write(struct file *filp,
-				    const char __user *buffer,
-				    size_t count, loff_t *ppos)
+static ssize_t xi2c_reg_value_write_iter(struct kiocb *iocb,
+					 struct iov_iter *from)
 {
-	struct xgbe_prv_data *pdata = filp->private_data;
+	struct xgbe_prv_data *pdata = iocb->ki_filp->private_data;
 	unsigned int value;
 	ssize_t len;
 
-	len = xgbe_common_write(buffer, count, ppos, &value);
+	len = xgbe_common_write_iter(from, &iocb->ki_pos, &value);
 	if (len < 0)
 		return len;
 
@@ -425,15 +416,15 @@ static ssize_t xi2c_reg_value_write(struct file *filp,
 static const struct file_operations xi2c_reg_addr_fops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.read =  xi2c_reg_addr_read,
-	.write = xi2c_reg_addr_write,
+	.read_iter =  xi2c_reg_addr_read_iter,
+	.write_iter = xi2c_reg_addr_write_iter,
 };
 
 static const struct file_operations xi2c_reg_value_fops = {
 	.owner = THIS_MODULE,
 	.open = simple_open,
-	.read =  xi2c_reg_value_read,
-	.write = xi2c_reg_value_write,
+	.read_iter =  xi2c_reg_value_read_iter,
+	.write_iter = xi2c_reg_value_write_iter,
 };
 
 void xgbe_debugfs_init(struct xgbe_prv_data *pdata)
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ