[PATCH 130/437] drivers/i2c: convert to read/write iterators

Jens Axboe
2024-04-11T15:35:20Z

drivers/i2c/i2c-dev.c | 25 ++++++++++++-------------
1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index 8b7e599f1674..4997e70499d5 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -131,14 +131,13 @@ ATTRIBUTE_GROUPS(i2c);
* needed by those system calls and by this SMBus interface.
*/

-static ssize_t i2cdev_read(struct file *file, char __user *buf, size_t count,
- loff_t *offset)
+static ssize_t i2cdev_read(struct kiocb *iocb, struct iov_iter *to)
{
+ struct i2c_client *client = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(to);
char *tmp;
int ret;

- struct i2c_client *client = file->private_data;
-
if (count > 8192)
count = 8192;

@@ -146,31 +145,31 @@ static ssize_t i2cdev_read(struct file *file, char __user *buf, size_t count,
if (tmp == NULL)
return -ENOMEM;

- pr_debug("i2c-%d reading %zu bytes.\n", iminor(file_inode(file)), count);
+ pr_debug("i2c-%d reading %zu bytes.\n", iminor(file_inode(iocb->ki_filp)), count);

ret = i2c_master_recv(client, tmp, count);
if (ret >= 0)
- if (copy_to_user(buf, tmp, ret))
+ if (!copy_to_iter_full(tmp, ret, to))
ret = -EFAULT;
kfree(tmp);
return ret;
}

-static ssize_t i2cdev_write(struct file *file, const char __user *buf,
- size_t count, loff_t *offset)
+static ssize_t i2cdev_write(struct kiocb *iocb, struct iov_iter *from)
{
int ret;
char *tmp;
- struct i2c_client *client = file->private_data;
+ struct i2c_client *client = iocb->ki_filp->private_data;
+ size_t count = iov_iter_count(from);

if (count > 8192)
count = 8192;

- tmp = memdup_user(buf, count);
+ tmp = iterdup(from, count);
if (IS_ERR(tmp))
return PTR_ERR(tmp);

- pr_debug("i2c-%d writing %zu bytes.\n", iminor(file_inode(file)), count);
+ pr_debug("i2c-%d writing %zu bytes.\n", iminor(file_inode(iocb->ki_filp)), count);

ret = i2c_master_send(client, tmp, count);
kfree(tmp);
@@ -626,8 +625,8 @@ static int i2cdev_release(struct inode *inode, struct file *file)
static const struct file_operations i2cdev_fops = {
.owner = THIS_MODULE,
.llseek = no_llseek,
- .read = i2cdev_read,
- .write = i2cdev_write,
+ .read_iter = i2cdev_read,
+ .write_iter = i2cdev_write,
.unlocked_ioctl = i2cdev_ioctl,
.compat_ioctl = compat_i2cdev_ioctl,
.open = i2cdev_open,
--
2.43.0