From nobody Fri Dec 19 17:16:15 2025 Received: from mail-io1-f45.google.com (mail-io1-f45.google.com [209.85.166.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CFBA23DABFF for ; Thu, 11 Apr 2024 15:36:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712849812; cv=none; b=CRv3xw8oeia4+C5bKFwQDU7Qh0w0TMosnJ9ONg4h0eQwq7RG6RAqpTh71H+NbFG93a0ZOwuW4h+hWQiCE3n0y+K/7/rsmtbE1QRy/Fkqtmp/BX8CX9D+2P44CM4tBh/Zk7GHim50YFBHqww2mGw/O1gIK/5Q0oZNBhFISvbBGiE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712849812; c=relaxed/simple; bh=QuK3dpYaFFx2Mh/ClUhCSjDZok6p++AOpN6yprAnvdg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kx/G69Jcxv6iq0tDweZ2KiBY76u1Tv6zVGAqkE6HY6P9sQovRo70th5JDpWLSFvNvcFJRzlXjutLpstUKso5LjCMMooeuWUKFyEiV2N/i6ESc9ZA13BMhfBjr136SQKrwl5OSJmbw2TGAOhAyZ4Vd2xnvsSpUWXcFPQRGMSjpPs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=G0KU6SpF; arc=none smtp.client-ip=209.85.166.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="G0KU6SpF" Received: by mail-io1-f45.google.com with SMTP id ca18e2360f4ac-7d6812b37a6so8960839f.0 for ; Thu, 11 Apr 2024 08:36:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1712849809; x=1713454609; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yjV/Uh3tcbRSrddjd1Z8mJo7f9wXMqNoZNrlnVY07vI=; b=G0KU6SpFggch6VBBuXrDt0Zwo+RLnRPE4emHG3IVi/eRcoPh9wHs2t/JmFtXB94OiC msSM1z1Z9oran3lZxRZMczBgnz/d/ODRmGvfeJ1KCrir585gwjuMxQ8VNh4wAwRUPEEv 4/EjBHynJ3oOnv9hwwdVIY95ytH+yMWQGZD/9uYXl0QTKKqb+CxAkWGyhszqrOjx7QxM IXnUg/Zt+OeyC6Sr+9/tW1qa6zA2y4K+/3F8LL0uvVu/zuzPUj7VWOypcUoEUAJ+FSI0 NjypvPfRNvvd2Mu2ZsrmEQyH3puBG9a+sBn3MUFA2Tf1s9Z3LFRlemUtZv2X28IJMBz4 fi/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712849809; x=1713454609; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yjV/Uh3tcbRSrddjd1Z8mJo7f9wXMqNoZNrlnVY07vI=; b=bP1D8rfTBewiIA3bsL+922xKQN2+9hlTbspUKw66Ui8kgYkNYoEsFaVz3G+TTFA604 sJWybFtfIRqRKPmSotGPcumIVovBxxiPOvaSccNx1P0K44Nc397vJxSIpAXjBZrwBjZP CQRra7Nrq+Y2DwahZ0jTUsHoaMOENTbouEzSP5NZ+h6At7tSENJm9ofZTifzKYPOa8Ns 8MbZIMIRn3Gfsz/nJ+EqVN8fTrn/4rPxB2R9IibrxVa1PWoFzME+KsBRiDyia0LBI+ay HABRB7qUscayOXA4SLvXenYYtrWStRmz26S4g8+6M7LMSU327jEsr/8nDk+1IV2JwhJf NoUQ== X-Gm-Message-State: AOJu0YyjJFumdZpSm6XXcZ0cbjmZQBLHx9wMPY29qpyJJCxdUJM5REQ1 YLNf34S6GC1mIhEEhEmpjELHJqf7oALkqEnrQ5wLOFcI4cnGhKMo2VlGTPRobs8sIeLyCJ4yTay D X-Google-Smtp-Source: AGHT+IEKl7tzo+UNouikvSySi4Sm3yB+IzdkbvPLnw5ufhKakYwKR9ZvaboISqEWVxdgCUbgoaApYQ== X-Received: by 2002:a05:6602:21d7:b0:7d6:9ddf:5095 with SMTP id c23-20020a05660221d700b007d69ddf5095mr17838ioc.1.1712849809229; Thu, 11 Apr 2024 08:36:49 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id jc25-20020a056638891900b0047f14b7f6c0sm457056jab.5.2024.04.11.08.36.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 08:36:47 -0700 (PDT) From: Jens Axboe To: linux-kernel@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 184/437] drivers/mtd: convert to ->read_iter and ->write_iter Date: Thu, 11 Apr 2024 09:15:24 -0600 Message-ID: <20240411153126.16201-185-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240411153126.16201-1-axboe@kernel.dk> References: <20240411153126.16201-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Jens Axboe --- drivers/mtd/mtdchar.c | 52 ++++++++++++++++++------------------ drivers/mtd/ubi/cdev.c | 58 ++++++++++++++++++++--------------------- drivers/mtd/ubi/debug.c | 38 ++++++++++++--------------- drivers/mtd/ubi/ubi.h | 4 +-- drivers/mtd/ubi/upd.c | 24 ++++++++--------- 5 files changed, 83 insertions(+), 93 deletions(-) diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 8dc4f5c493fc..0e3b6674f081 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -124,10 +124,10 @@ static int mtdchar_close(struct inode *inode, struct = file *file) * alignment requirements are not met in the NAND subdriver. */ =20 -static ssize_t mtdchar_read(struct file *file, char __user *buf, size_t co= unt, - loff_t *ppos) +static ssize_t mtdchar_read(struct kiocb *iocb, struct iov_iter *to) { - struct mtd_file_info *mfi =3D file->private_data; + struct mtd_file_info *mfi =3D iocb->ki_filp->private_data; + size_t count =3D iov_iter_count(to); struct mtd_info *mtd =3D mfi->mtd; size_t retlen; size_t total_retlen=3D0; @@ -138,9 +138,9 @@ static ssize_t mtdchar_read(struct file *file, char __u= ser *buf, size_t count, =20 pr_debug("MTD_read\n"); =20 - if (*ppos + count > mtd->size) { - if (*ppos < mtd->size) - count =3D mtd->size - *ppos; + if (iocb->ki_pos + count > mtd->size) { + if (iocb->ki_pos < mtd->size) + count =3D mtd->size - iocb->ki_pos; else count =3D 0; } @@ -157,11 +157,11 @@ static ssize_t mtdchar_read(struct file *file, char _= _user *buf, size_t count, =20 switch (mfi->mode) { case MTD_FILE_MODE_OTP_FACTORY: - ret =3D mtd_read_fact_prot_reg(mtd, *ppos, len, + ret =3D mtd_read_fact_prot_reg(mtd, iocb->ki_pos, len, &retlen, kbuf); break; case MTD_FILE_MODE_OTP_USER: - ret =3D mtd_read_user_prot_reg(mtd, *ppos, len, + ret =3D mtd_read_user_prot_reg(mtd, iocb->ki_pos, len, &retlen, kbuf); break; case MTD_FILE_MODE_RAW: @@ -173,12 +173,12 @@ static ssize_t mtdchar_read(struct file *file, char _= _user *buf, size_t count, ops.oobbuf =3D NULL; ops.len =3D len; =20 - ret =3D mtd_read_oob(mtd, *ppos, &ops); + ret =3D mtd_read_oob(mtd, iocb->ki_pos, &ops); retlen =3D ops.retlen; break; } default: - ret =3D mtd_read(mtd, *ppos, len, &retlen, kbuf); + ret =3D mtd_read(mtd, iocb->ki_pos, len, &retlen, kbuf); } /* Nand returns -EBADMSG on ECC errors, but it returns * the data. For our userspace tools it is important @@ -190,8 +190,8 @@ static ssize_t mtdchar_read(struct file *file, char __u= ser *buf, size_t count, * must be aware of the fact that it deals with NAND */ if (!ret || mtd_is_bitflip_or_eccerr(ret)) { - *ppos +=3D retlen; - if (copy_to_user(buf, kbuf, retlen)) { + iocb->ki_pos +=3D retlen; + if (!copy_to_iter_full(kbuf, retlen, to)) { kfree(kbuf); return -EFAULT; } @@ -199,7 +199,6 @@ static ssize_t mtdchar_read(struct file *file, char __u= ser *buf, size_t count, total_retlen +=3D retlen; =20 count -=3D retlen; - buf +=3D retlen; if (retlen =3D=3D 0) count =3D 0; } @@ -214,10 +213,10 @@ static ssize_t mtdchar_read(struct file *file, char _= _user *buf, size_t count, return total_retlen; } /* mtdchar_read */ =20 -static ssize_t mtdchar_write(struct file *file, const char __user *buf, si= ze_t count, - loff_t *ppos) +static ssize_t mtdchar_write(struct kiocb *iocb, struct iov_iter *from) { - struct mtd_file_info *mfi =3D file->private_data; + struct mtd_file_info *mfi =3D iocb->ki_filp->private_data; + size_t count =3D iov_iter_count(from); struct mtd_info *mtd =3D mfi->mtd; size_t size =3D count; char *kbuf; @@ -228,11 +227,11 @@ static ssize_t mtdchar_write(struct file *file, const= char __user *buf, size_t c =20 pr_debug("MTD_write\n"); =20 - if (*ppos >=3D mtd->size) + if (iocb->ki_pos >=3D mtd->size) return -ENOSPC; =20 - if (*ppos + count > mtd->size) - count =3D mtd->size - *ppos; + if (iocb->ki_pos + count > mtd->size) + count =3D mtd->size - iocb->ki_pos; =20 if (!count) return 0; @@ -244,7 +243,7 @@ static ssize_t mtdchar_write(struct file *file, const c= har __user *buf, size_t c while (count) { len =3D min_t(size_t, count, size); =20 - if (copy_from_user(kbuf, buf, len)) { + if (!copy_from_iter_full(kbuf, len, from)) { kfree(kbuf); return -EFAULT; } @@ -254,7 +253,7 @@ static ssize_t mtdchar_write(struct file *file, const c= har __user *buf, size_t c ret =3D -EROFS; break; case MTD_FILE_MODE_OTP_USER: - ret =3D mtd_write_user_prot_reg(mtd, *ppos, len, + ret =3D mtd_write_user_prot_reg(mtd, iocb->ki_pos, len, &retlen, kbuf); break; =20 @@ -268,13 +267,13 @@ static ssize_t mtdchar_write(struct file *file, const= char __user *buf, size_t c ops.ooboffs =3D 0; ops.len =3D len; =20 - ret =3D mtd_write_oob(mtd, *ppos, &ops); + ret =3D mtd_write_oob(mtd, iocb->ki_pos, &ops); retlen =3D ops.retlen; break; } =20 default: - ret =3D mtd_write(mtd, *ppos, len, &retlen, kbuf); + ret =3D mtd_write(mtd, iocb->ki_pos, len, &retlen, kbuf); } =20 /* @@ -286,10 +285,9 @@ static ssize_t mtdchar_write(struct file *file, const = char __user *buf, size_t c break; =20 if (!ret) { - *ppos +=3D retlen; + iocb->ki_pos +=3D retlen; total_retlen +=3D retlen; count -=3D retlen; - buf +=3D retlen; } else { kfree(kbuf); @@ -1401,8 +1399,8 @@ static int mtdchar_mmap(struct file *file, struct vm_= area_struct *vma) static const struct file_operations mtd_fops =3D { .owner =3D THIS_MODULE, .llseek =3D mtdchar_lseek, - .read =3D mtdchar_read, - .write =3D mtdchar_write, + .read_iter =3D mtdchar_read, + .write_iter =3D mtdchar_write, .unlocked_ioctl =3D mtdchar_unlocked_ioctl, #ifdef CONFIG_COMPAT .compat_ioctl =3D mtdchar_compat_ioctl, diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c index 0d8f04cf03c5..ab99cfff211c 100644 --- a/drivers/mtd/ubi/cdev.c +++ b/drivers/mtd/ubi/cdev.c @@ -168,10 +168,10 @@ static int vol_cdev_fsync(struct file *file, loff_t s= tart, loff_t end, } =20 =20 -static ssize_t vol_cdev_read(struct file *file, __user char *buf, size_t c= ount, - loff_t *offp) +static ssize_t vol_cdev_read(struct kiocb *iocb, struct iov_iter *to) { - struct ubi_volume_desc *desc =3D file->private_data; + struct ubi_volume_desc *desc =3D iocb->ki_filp->private_data; + size_t count =3D iov_iter_count(to); struct ubi_volume *vol =3D desc->vol; struct ubi_device *ubi =3D vol->ubi; int err, lnum, off, len, tbuf_size; @@ -179,7 +179,7 @@ static ssize_t vol_cdev_read(struct file *file, __user = char *buf, size_t count, void *tbuf; =20 dbg_gen("read %zd bytes from offset %lld of volume %d", - count, *offp, vol->vol_id); + count, iocb->ki_pos, vol->vol_id); =20 if (vol->updating) { ubi_err(vol->ubi, "updating"); @@ -189,14 +189,14 @@ static ssize_t vol_cdev_read(struct file *file, __use= r char *buf, size_t count, ubi_err(vol->ubi, "damaged volume, update marker is set"); return -EBADF; } - if (*offp =3D=3D vol->used_bytes || count =3D=3D 0) + if (iocb->ki_pos =3D=3D vol->used_bytes || count =3D=3D 0) return 0; =20 if (vol->corrupted) dbg_gen("read from corrupted volume %d", vol->vol_id); =20 - if (*offp + count > vol->used_bytes) - count_save =3D count =3D vol->used_bytes - *offp; + if (iocb->ki_pos + count > vol->used_bytes) + count_save =3D count =3D vol->used_bytes - iocb->ki_pos; =20 tbuf_size =3D vol->usable_leb_size; if (count < tbuf_size) @@ -206,7 +206,7 @@ static ssize_t vol_cdev_read(struct file *file, __user = char *buf, size_t count, return -ENOMEM; =20 len =3D count > tbuf_size ? tbuf_size : count; - lnum =3D div_u64_rem(*offp, vol->usable_leb_size, &off); + lnum =3D div_u64_rem(iocb->ki_pos, vol->usable_leb_size, &off); =20 do { cond_resched(); @@ -225,15 +225,14 @@ static ssize_t vol_cdev_read(struct file *file, __use= r char *buf, size_t count, } =20 count -=3D len; - *offp +=3D len; + iocb->ki_pos +=3D len; =20 - err =3D copy_to_user(buf, tbuf, len); + err =3D !copy_to_iter_full(tbuf, len, to); if (err) { err =3D -EFAULT; break; } =20 - buf +=3D len; len =3D count > tbuf_size ? tbuf_size : count; } while (count); =20 @@ -245,10 +244,10 @@ static ssize_t vol_cdev_read(struct file *file, __use= r char *buf, size_t count, * This function allows to directly write to dynamic UBI volumes, without * issuing the volume update operation. */ -static ssize_t vol_cdev_direct_write(struct file *file, const char __user = *buf, - size_t count, loff_t *offp) +static ssize_t vol_cdev_direct_write(struct kiocb *iocb, struct iov_iter *= from) { - struct ubi_volume_desc *desc =3D file->private_data; + struct ubi_volume_desc *desc =3D iocb->ki_filp->private_data; + size_t count =3D iov_iter_count(from); struct ubi_volume *vol =3D desc->vol; struct ubi_device *ubi =3D vol->ubi; int lnum, off, len, tbuf_size, err =3D 0; @@ -259,19 +258,19 @@ static ssize_t vol_cdev_direct_write(struct file *fil= e, const char __user *buf, return -EPERM; =20 dbg_gen("requested: write %zd bytes to offset %lld of volume %u", - count, *offp, vol->vol_id); + count, iocb->ki_pos, vol->vol_id); =20 if (vol->vol_type =3D=3D UBI_STATIC_VOLUME) return -EROFS; =20 - lnum =3D div_u64_rem(*offp, vol->usable_leb_size, &off); + lnum =3D div_u64_rem(iocb->ki_pos, vol->usable_leb_size, &off); if (off & (ubi->min_io_size - 1)) { ubi_err(ubi, "unaligned position"); return -EINVAL; } =20 - if (*offp + count > vol->used_bytes) - count_save =3D count =3D vol->used_bytes - *offp; + if (iocb->ki_pos + count > vol->used_bytes) + count_save =3D count =3D vol->used_bytes - iocb->ki_pos; =20 /* We can write only in fractions of the minimum I/O unit */ if (count & (ubi->min_io_size - 1)) { @@ -294,7 +293,7 @@ static ssize_t vol_cdev_direct_write(struct file *file,= const char __user *buf, if (off + len >=3D vol->usable_leb_size) len =3D vol->usable_leb_size - off; =20 - err =3D copy_from_user(tbuf, buf, len); + err =3D !copy_from_iter_full(tbuf, len, from); if (err) { err =3D -EFAULT; break; @@ -311,8 +310,7 @@ static ssize_t vol_cdev_direct_write(struct file *file,= const char __user *buf, } =20 count -=3D len; - *offp +=3D len; - buf +=3D len; + iocb->ki_pos +=3D len; len =3D count > tbuf_size ? tbuf_size : count; } =20 @@ -320,25 +318,25 @@ static ssize_t vol_cdev_direct_write(struct file *fil= e, const char __user *buf, return err ? err : count_save - count; } =20 -static ssize_t vol_cdev_write(struct file *file, const char __user *buf, - size_t count, loff_t *offp) +static ssize_t vol_cdev_write(struct kiocb *iocb, struct iov_iter *from) { int err =3D 0; - struct ubi_volume_desc *desc =3D file->private_data; + struct ubi_volume_desc *desc =3D iocb->ki_filp->private_data; struct ubi_volume *vol =3D desc->vol; struct ubi_device *ubi =3D vol->ubi; + size_t count =3D iov_iter_count(from); =20 if (!vol->updating && !vol->changing_leb) - return vol_cdev_direct_write(file, buf, count, offp); + return vol_cdev_direct_write(iocb, from); =20 if (vol->updating) - err =3D ubi_more_update_data(ubi, vol, buf, count); + err =3D ubi_more_update_data(ubi, vol, from); else - err =3D ubi_more_leb_change_data(ubi, vol, buf, count); + err =3D ubi_more_leb_change_data(ubi, vol, from); =20 if (err < 0) { ubi_err(ubi, "cannot accept more %zd bytes of data, error %d", - count, err); + iov_iter_count(from), err); return err; } =20 @@ -1085,8 +1083,8 @@ const struct file_operations ubi_vol_cdev_operations = =3D { .open =3D vol_cdev_open, .release =3D vol_cdev_release, .llseek =3D vol_cdev_llseek, - .read =3D vol_cdev_read, - .write =3D vol_cdev_write, + .read_iter =3D vol_cdev_read, + .write_iter =3D vol_cdev_write, .fsync =3D vol_cdev_fsync, .unlocked_ioctl =3D vol_cdev_ioctl, .compat_ioctl =3D compat_ptr_ioctl, diff --git a/drivers/mtd/ubi/debug.c b/drivers/mtd/ubi/debug.c index d57f52bd2ff3..2b364dd8e92e 100644 --- a/drivers/mtd/ubi/debug.c +++ b/drivers/mtd/ubi/debug.c @@ -325,11 +325,11 @@ void ubi_debugfs_exit(void) } =20 /* Read an UBI debugfs file */ -static ssize_t dfs_file_read(struct file *file, char __user *user_buf, - size_t count, loff_t *ppos) +static ssize_t dfs_file_read(struct kiocb *iocb, struct iov_iter *to) { - unsigned long ubi_num =3D (unsigned long)file->private_data; - struct dentry *dent =3D file->f_path.dentry; + unsigned long ubi_num =3D (unsigned long)iocb->ki_filp->private_data; + struct dentry *dent =3D iocb->ki_filp->f_path.dentry; + size_t count =3D iov_iter_count(to); struct ubi_device *ubi; struct ubi_debug_info *d; char buf[16]; @@ -354,23 +354,19 @@ static ssize_t dfs_file_read(struct file *file, char = __user *user_buf, val =3D d->emulate_io_failures; else if (dent =3D=3D d->dfs_emulate_failures) { snprintf(buf, sizeof(buf), "0x%04x\n", d->emulate_failures); - count =3D simple_read_from_buffer(user_buf, count, ppos, - buf, strlen(buf)); + count =3D simple_copy_to_iter(buf, &iocb->ki_pos, strlen(buf), to); goto out; } else if (dent =3D=3D d->dfs_emulate_power_cut) { snprintf(buf, sizeof(buf), "%u\n", d->emulate_power_cut); - count =3D simple_read_from_buffer(user_buf, count, ppos, - buf, strlen(buf)); + count =3D simple_copy_to_iter(buf, &iocb->ki_pos, strlen(buf), to); goto out; } else if (dent =3D=3D d->dfs_power_cut_min) { snprintf(buf, sizeof(buf), "%u\n", d->power_cut_min); - count =3D simple_read_from_buffer(user_buf, count, ppos, - buf, strlen(buf)); + count =3D simple_copy_to_iter(buf, &iocb->ki_pos, strlen(buf), to); goto out; } else if (dent =3D=3D d->dfs_power_cut_max) { snprintf(buf, sizeof(buf), "%u\n", d->power_cut_max); - count =3D simple_read_from_buffer(user_buf, count, ppos, - buf, strlen(buf)); + count =3D simple_copy_to_iter(buf, &iocb->ki_pos, strlen(buf), to); goto out; } else { count =3D -EINVAL; @@ -384,7 +380,7 @@ static ssize_t dfs_file_read(struct file *file, char __= user *user_buf, buf[1] =3D '\n'; buf[2] =3D 0x00; =20 - count =3D simple_read_from_buffer(user_buf, count, ppos, buf, 2); + count =3D simple_copy_to_iter(buf, &iocb->ki_pos, 2, to); =20 out: ubi_put_device(ubi); @@ -392,11 +388,11 @@ static ssize_t dfs_file_read(struct file *file, char = __user *user_buf, } =20 /* Write an UBI debugfs file */ -static ssize_t dfs_file_write(struct file *file, const char __user *user_b= uf, - size_t count, loff_t *ppos) +static ssize_t dfs_file_write(struct kiocb *iocb, struct iov_iter *from) { - unsigned long ubi_num =3D (unsigned long)file->private_data; - struct dentry *dent =3D file->f_path.dentry; + unsigned long ubi_num =3D (unsigned long)iocb->ki_filp->private_data; + struct dentry *dent =3D iocb->ki_filp->f_path.dentry; + size_t count =3D iov_iter_count(from); struct ubi_device *ubi; struct ubi_debug_info *d; size_t buf_size; @@ -409,7 +405,7 @@ static ssize_t dfs_file_write(struct file *file, const = char __user *user_buf, d =3D &ubi->dbg; =20 buf_size =3D min_t(size_t, count, (sizeof(buf) - 1)); - if (copy_from_user(buf, user_buf, buf_size)) { + if (!copy_from_iter_full(buf, buf_size, from)) { count =3D -EFAULT; goto out; } @@ -467,8 +463,8 @@ static ssize_t dfs_file_write(struct file *file, const = char __user *user_buf, * detailed_erase_block_info */ static const struct file_operations dfs_fops =3D { - .read =3D dfs_file_read, - .write =3D dfs_file_write, + .read_iter =3D dfs_file_read, + .write_iter =3D dfs_file_write, .open =3D simple_open, .llseek =3D no_llseek, .owner =3D THIS_MODULE, @@ -576,7 +572,7 @@ static int eraseblk_count_release(struct inode *inode, = struct file *f) static const struct file_operations eraseblk_count_fops =3D { .owner =3D THIS_MODULE, .open =3D eraseblk_count_open, - .read =3D seq_read, + .read_iter =3D seq_read_iter, .llseek =3D seq_lseek, .release =3D eraseblk_count_release, }; diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h index 32009a24869e..c932b1d31e6b 100644 --- a/drivers/mtd/ubi/ubi.h +++ b/drivers/mtd/ubi/ubi.h @@ -852,11 +852,11 @@ void ubi_free_volume(struct ubi_device *ubi, struct u= bi_volume *vol); int ubi_start_update(struct ubi_device *ubi, struct ubi_volume *vol, long long bytes); int ubi_more_update_data(struct ubi_device *ubi, struct ubi_volume *vol, - const void __user *buf, int count); + struct iov_iter *from); int ubi_start_leb_change(struct ubi_device *ubi, struct ubi_volume *vol, const struct ubi_leb_change_req *req); int ubi_more_leb_change_data(struct ubi_device *ubi, struct ubi_volume *vo= l, - const void __user *buf, int count); + struct iov_iter *from); =20 /* misc.c */ int ubi_calc_data_len(const struct ubi_device *ubi, const void *buf, diff --git a/drivers/mtd/ubi/upd.c b/drivers/mtd/ubi/upd.c index 962f693cf882..6fa6e5b67631 100644 --- a/drivers/mtd/ubi/upd.c +++ b/drivers/mtd/ubi/upd.c @@ -253,8 +253,7 @@ static int write_leb(struct ubi_device *ubi, struct ubi= _volume *vol, int lnum, * ubi_more_update_data - write more update data. * @ubi: UBI device description object * @vol: volume description object - * @buf: write data (user-space memory buffer) - * @count: how much bytes to write + * @from: write data (user-space memory buffer) * * This function writes more data to the volume which is being updated. It= may * be called arbitrary number of times until all the update data arriveis.= This @@ -263,11 +262,12 @@ static int write_leb(struct ubi_device *ubi, struct u= bi_volume *vol, int lnum, * negative error code in case of failure. */ int ubi_more_update_data(struct ubi_device *ubi, struct ubi_volume *vol, - const void __user *buf, int count) + struct iov_iter *from) { + size_t count =3D iov_iter_count(from); int lnum, offs, err =3D 0, len, to_write =3D count; =20 - dbg_gen("write %d of %lld bytes, %lld already passed", + dbg_gen("write %zd of %lld bytes, %lld already passed", count, vol->upd_bytes, vol->upd_received); =20 if (ubi->ro_mode) @@ -293,7 +293,7 @@ int ubi_more_update_data(struct ubi_device *ubi, struct= ubi_volume *vol, if (len > count) len =3D count; =20 - err =3D copy_from_user(vol->upd_buf + offs, buf, len); + err =3D !copy_from_iter_full(vol->upd_buf + offs, len, from); if (err) return -EFAULT; =20 @@ -314,7 +314,6 @@ int ubi_more_update_data(struct ubi_device *ubi, struct= ubi_volume *vol, =20 vol->upd_received +=3D len; count -=3D len; - buf +=3D len; lnum +=3D 1; } =20 @@ -328,7 +327,7 @@ int ubi_more_update_data(struct ubi_device *ubi, struct= ubi_volume *vol, else len =3D count; =20 - err =3D copy_from_user(vol->upd_buf, buf, len); + err =3D !copy_from_iter_full(vol->upd_buf, len, from); if (err) return -EFAULT; =20 @@ -343,7 +342,6 @@ int ubi_more_update_data(struct ubi_device *ubi, struct= ubi_volume *vol, vol->upd_received +=3D len; count -=3D len; lnum +=3D 1; - buf +=3D len; } =20 ubi_assert(vol->upd_received <=3D vol->upd_bytes); @@ -367,8 +365,7 @@ int ubi_more_update_data(struct ubi_device *ubi, struct= ubi_volume *vol, * ubi_more_leb_change_data - accept more data for atomic LEB change. * @ubi: UBI device description object * @vol: volume description object - * @buf: write data (user-space memory buffer) - * @count: how much bytes to write + * @from: write data (user-space memory buffer) * * This function accepts more data to the volume which is being under the * "atomic LEB change" operation. It may be called arbitrary number of tim= es @@ -378,11 +375,12 @@ int ubi_more_update_data(struct ubi_device *ubi, stru= ct ubi_volume *vol, * of failure. */ int ubi_more_leb_change_data(struct ubi_device *ubi, struct ubi_volume *vo= l, - const void __user *buf, int count) + struct iov_iter *from) { + size_t count =3D iov_iter_count(from); int err; =20 - dbg_gen("write %d of %lld bytes, %lld already passed", + dbg_gen("write %zd of %lld bytes, %lld already passed", count, vol->upd_bytes, vol->upd_received); =20 if (ubi->ro_mode) @@ -391,7 +389,7 @@ int ubi_more_leb_change_data(struct ubi_device *ubi, st= ruct ubi_volume *vol, if (vol->upd_received + count > vol->upd_bytes) count =3D vol->upd_bytes - vol->upd_received; =20 - err =3D copy_from_user(vol->upd_buf + vol->upd_received, buf, count); + err =3D !copy_from_iter_full(vol->upd_buf + vol->upd_received, count, fro= m); if (err) return -EFAULT; =20 --=20 2.43.0