@@ -242,13 +242,7 @@ static ssize_t kernfs_fop_read_iter(struct kiocb *iocb, struct iov_iter *iter)
242242 return kernfs_file_read_iter (iocb , iter );
243243}
244244
245- /**
246- * kernfs_fop_write - kernfs vfs write callback
247- * @file: file pointer
248- * @user_buf: data to write
249- * @count: number of bytes
250- * @ppos: starting offset
251- *
245+ /*
252246 * Copy data in from userland and pass it to the matching kernfs write
253247 * operation.
254248 *
@@ -258,20 +252,18 @@ static ssize_t kernfs_fop_read_iter(struct kiocb *iocb, struct iov_iter *iter)
258252 * modify only the the value you're changing, then write entire buffer
259253 * back.
260254 */
261- static ssize_t kernfs_fop_write (struct file * file , const char __user * user_buf ,
262- size_t count , loff_t * ppos )
255+ static ssize_t kernfs_fop_write_iter (struct kiocb * iocb , struct iov_iter * iter )
263256{
264- struct kernfs_open_file * of = kernfs_of (file );
257+ struct kernfs_open_file * of = kernfs_of (iocb -> ki_filp );
258+ ssize_t len = iov_iter_count (iter );
265259 const struct kernfs_ops * ops ;
266- ssize_t len ;
267260 char * buf ;
268261
269262 if (of -> atomic_write_len ) {
270- len = count ;
271263 if (len > of -> atomic_write_len )
272264 return - E2BIG ;
273265 } else {
274- len = min_t (size_t , count , PAGE_SIZE );
266+ len = min_t (size_t , len , PAGE_SIZE );
275267 }
276268
277269 buf = of -> prealloc_buf ;
@@ -282,7 +274,7 @@ static ssize_t kernfs_fop_write(struct file *file, const char __user *user_buf,
282274 if (!buf )
283275 return - ENOMEM ;
284276
285- if (copy_from_user (buf , user_buf , len ) ) {
277+ if (copy_from_iter (buf , len , iter ) != len ) {
286278 len = - EFAULT ;
287279 goto out_free ;
288280 }
@@ -301,15 +293,15 @@ static ssize_t kernfs_fop_write(struct file *file, const char __user *user_buf,
301293
302294 ops = kernfs_ops (of -> kn );
303295 if (ops -> write )
304- len = ops -> write (of , buf , len , * ppos );
296+ len = ops -> write (of , buf , len , iocb -> ki_pos );
305297 else
306298 len = - EINVAL ;
307299
308300 kernfs_put_active (of -> kn );
309301 mutex_unlock (& of -> mutex );
310302
311303 if (len > 0 )
312- * ppos += len ;
304+ iocb -> ki_pos += len ;
313305
314306out_free :
315307 if (buf == of -> prealloc_buf )
@@ -662,7 +654,7 @@ static int kernfs_fop_open(struct inode *inode, struct file *file)
662654
663655 /*
664656 * Write path needs to atomic_write_len outside active reference.
665- * Cache it in open_file. See kernfs_fop_write () for details.
657+ * Cache it in open_file. See kernfs_fop_write_iter () for details.
666658 */
667659 of -> atomic_write_len = ops -> atomic_write_len ;
668660
@@ -950,7 +942,7 @@ EXPORT_SYMBOL_GPL(kernfs_notify);
950942
951943const struct file_operations kernfs_file_fops = {
952944 .read_iter = kernfs_fop_read_iter ,
953- .write = kernfs_fop_write ,
945+ .write_iter = kernfs_fop_write_iter ,
954946 .llseek = generic_file_llseek ,
955947 .mmap = kernfs_fop_mmap ,
956948 .open = kernfs_fop_open ,
0 commit comments