[PATCH 429/437] sbus: envctrl: convert to read/write iterators
From: Jens Axboe
Date: Thu Apr 11 2024 - 13:19:41 EST
Signed-off-by: Jens Axboe <axboe@xxxxxxxxx>
---
drivers/sbus/char/envctrl.c | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/drivers/sbus/char/envctrl.c b/drivers/sbus/char/envctrl.c
index 491cc6c0b3f9..ceebe708647d 100644
--- a/drivers/sbus/char/envctrl.c
+++ b/drivers/sbus/char/envctrl.c
@@ -533,8 +533,7 @@ static unsigned char envctrl_i2c_voltage_status(struct i2c_child_t *pchild,
/* Function Description: Read a byte from /dev/envctrl. Mapped to user read().
* Return: Number of read bytes. 0 for error.
*/
-static ssize_t
-envctrl_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
+static ssize_t envctrl_read(struct kiocb *iocb, struct iov_iter *to)
{
struct i2c_child_t *pchild;
unsigned char data[10];
@@ -545,14 +544,14 @@ envctrl_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
* Get the data and put back to the user buffer.
*/
- switch ((int)(long)file->private_data) {
+ switch ((int)(long)iocb->ki_filp->private_data) {
case ENVCTRL_RD_WARNING_TEMPERATURE:
if (warning_temperature == 0)
return 0;
data[0] = (unsigned char)(warning_temperature);
ret = 1;
- if (copy_to_user(buf, data, ret))
+ if (!copy_to_iter_full(data, ret, to))
ret = -EFAULT;
break;
@@ -562,7 +561,7 @@ envctrl_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
data[0] = (unsigned char)(shutdown_temperature);
ret = 1;
- if (copy_to_user(buf, data, ret))
+ if (!copy_to_iter_full(data, ret, to))
ret = -EFAULT;
break;
@@ -570,7 +569,7 @@ envctrl_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
if (!(pchild = envctrl_get_i2c_child(ENVCTRL_MTHRBDTEMP_MON)))
return 0;
ret = envctrl_read_noncpu_info(pchild, ENVCTRL_MTHRBDTEMP_MON, data);
- if (copy_to_user(buf, data, ret))
+ if (!copy_to_iter_full(data, ret, to))
ret = -EFAULT;
break;
@@ -580,7 +579,7 @@ envctrl_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
ret = envctrl_read_cpu_info(read_cpu, pchild, ENVCTRL_CPUTEMP_MON, data);
/* Reset cpu to the default cpu0. */
- if (copy_to_user(buf, data, ret))
+ if (!copy_to_iter_full(data, ret, to))
ret = -EFAULT;
break;
@@ -590,7 +589,7 @@ envctrl_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
ret = envctrl_read_cpu_info(read_cpu, pchild, ENVCTRL_CPUVOLTAGE_MON, data);
/* Reset cpu to the default cpu0. */
- if (copy_to_user(buf, data, ret))
+ if (!copy_to_iter_full(data, ret, to))
ret = -EFAULT;
break;
@@ -598,7 +597,7 @@ envctrl_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
if (!(pchild = envctrl_get_i2c_child(ENVCTRL_SCSITEMP_MON)))
return 0;
ret = envctrl_read_noncpu_info(pchild, ENVCTRL_SCSITEMP_MON, data);
- if (copy_to_user(buf, data, ret))
+ if (!copy_to_iter_full(data, ret, to))
ret = -EFAULT;
break;
@@ -606,7 +605,7 @@ envctrl_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
if (!(pchild = envctrl_get_i2c_child(ENVCTRL_ETHERTEMP_MON)))
return 0;
ret = envctrl_read_noncpu_info(pchild, ENVCTRL_ETHERTEMP_MON, data);
- if (copy_to_user(buf, data, ret))
+ if (!copy_to_iter_full(data, ret, to))
ret = -EFAULT;
break;
@@ -615,7 +614,7 @@ envctrl_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
return 0;
data[0] = envctrl_i2c_read_8574(pchild->addr);
ret = envctrl_i2c_fan_status(pchild,data[0], data);
- if (copy_to_user(buf, data, ret))
+ if (!copy_to_iter_full(data, ret, to))
ret = -EFAULT;
break;
@@ -624,7 +623,7 @@ envctrl_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
return 0;
data[0] = envctrl_i2c_read_8574(pchild->addr);
ret = envctrl_i2c_globaladdr(pchild, data[0], data);
- if (copy_to_user(buf, data, ret))
+ if (!copy_to_iter_full(data, ret, to))
ret = -EFAULT;
break;
@@ -635,7 +634,7 @@ envctrl_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
return 0;
data[0] = envctrl_i2c_read_8574(pchild->addr);
ret = envctrl_i2c_voltage_status(pchild, data[0], data);
- if (copy_to_user(buf, data, ret))
+ if (!copy_to_iter_full(data, ret, to))
ret = -EFAULT;
break;
@@ -711,7 +710,7 @@ envctrl_release(struct inode *inode, struct file *file)
static const struct file_operations envctrl_fops = {
.owner = THIS_MODULE,
- .read = envctrl_read,
+ .read_iter = envctrl_read,
.unlocked_ioctl = envctrl_ioctl,
.compat_ioctl = compat_ptr_ioctl,
.open = envctrl_open,
--
2.43.0