Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rpmsg: char: Migrate to iter versions of read and write

In order to be able to use the aio interface for writing to a rpmsg_char
the write_iter function must be implemented, so migrate to iter version
for read and write functions.

Regular read and write uses the iter methods if present and is as such
unaffected.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>

+16 -11
+16 -11
drivers/rpmsg/rpmsg_char.c
··· 167 167 return 0; 168 168 } 169 169 170 - static ssize_t rpmsg_eptdev_read(struct file *filp, char __user *buf, 171 - size_t len, loff_t *f_pos) 170 + static ssize_t rpmsg_eptdev_read_iter(struct kiocb *iocb, struct iov_iter *to) 172 171 { 172 + struct file *filp = iocb->ki_filp; 173 173 struct rpmsg_eptdev *eptdev = filp->private_data; 174 174 unsigned long flags; 175 175 struct sk_buff *skb; ··· 205 205 if (!skb) 206 206 return -EFAULT; 207 207 208 - use = min_t(size_t, len, skb->len); 209 - if (copy_to_user(buf, skb->data, use)) 208 + use = min_t(size_t, iov_iter_count(to), skb->len); 209 + if (copy_to_iter(skb->data, use, to) != use) 210 210 use = -EFAULT; 211 211 212 212 kfree_skb(skb); ··· 214 214 return use; 215 215 } 216 216 217 - static ssize_t rpmsg_eptdev_write(struct file *filp, const char __user *buf, 218 - size_t len, loff_t *f_pos) 217 + static ssize_t rpmsg_eptdev_write_iter(struct kiocb *iocb, 218 + struct iov_iter *from) 219 219 { 220 + struct file *filp = iocb->ki_filp; 220 221 struct rpmsg_eptdev *eptdev = filp->private_data; 222 + size_t len = iov_iter_count(from); 221 223 void *kbuf; 222 224 int ret; 223 225 224 - kbuf = memdup_user(buf, len); 225 - if (IS_ERR(kbuf)) 226 - return PTR_ERR(kbuf); 226 + kbuf = kzalloc(len, GFP_KERNEL); 227 + if (!kbuf) 228 + return -ENOMEM; 229 + 230 + if (!copy_from_iter_full(kbuf, len, from)) 231 + return -EFAULT; 227 232 228 233 if (mutex_lock_interruptible(&eptdev->ept_lock)) { 229 234 ret = -ERESTARTSYS; ··· 286 281 .owner = THIS_MODULE, 287 282 .open = rpmsg_eptdev_open, 288 283 .release = rpmsg_eptdev_release, 289 - .read = rpmsg_eptdev_read, 290 - .write = rpmsg_eptdev_write, 284 + .read_iter = rpmsg_eptdev_read_iter, 285 + .write_iter = rpmsg_eptdev_write_iter, 291 286 .poll = rpmsg_eptdev_poll, 292 287 .unlocked_ioctl = rpmsg_eptdev_ioctl, 293 288 .compat_ioctl = rpmsg_eptdev_ioctl,