[PATCH 137/437] drm: convert debugfs helpers to be read/write iterator based

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

drivers/gpu/drm/drm_debugfs.c | 28 ++++++++++++++--------------
drivers/gpu/drm/drm_debugfs_crc.c | 26 +++++++++++++-------------
2 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
index 08fcefd804bc..e7d7cbd930ca 100644
--- a/drivers/gpu/drm/drm_debugfs.c
+++ b/drivers/gpu/drm/drm_debugfs.c
@@ -171,7 +171,7 @@ static int drm_debugfs_entry_open(struct inode *inode, struct file *file)
static const struct file_operations drm_debugfs_entry_fops = {
.owner = THIS_MODULE,
.open = drm_debugfs_entry_open,
- .read = seq_read,
+ .read_iter = seq_read_iter,
.llseek = seq_lseek,
.release = single_release,
};
@@ -179,7 +179,7 @@ static const struct file_operations drm_debugfs_entry_fops = {
static const struct file_operations drm_debugfs_fops = {
.owner = THIS_MODULE,
.open = drm_debugfs_open,
- .read = seq_read,
+ .read_iter = seq_read_iter,
.llseek = seq_lseek,
.release = single_release,
};
@@ -403,17 +403,17 @@ static int connector_open(struct inode *inode, struct file *file)
return single_open(file, connector_show, dev);
}

-static ssize_t connector_write(struct file *file, const char __user *ubuf,
- size_t len, loff_t *offp)
+static ssize_t connector_write(struct kiocb *iocb, struct iov_iter *from)
{
- struct seq_file *m = file->private_data;
+ struct seq_file *m = iocb->ki_filp->private_data;
struct drm_connector *connector = m->private;
+ size_t len = iov_iter_count(from);
char buf[12];

if (len > sizeof(buf) - 1)
return -EINVAL;

- if (copy_from_user(buf, ubuf, len))
+ if (!copy_from_iter_full(buf, len, from))
return -EFAULT;

buf[len] = '\0';
@@ -444,15 +444,15 @@ static int edid_open(struct inode *inode, struct file *file)
return single_open(file, edid_show, dev);
}

-static ssize_t edid_write(struct file *file, const char __user *ubuf,
- size_t len, loff_t *offp)
+static ssize_t edid_write(struct kiocb *iocb, struct iov_iter *from)
{
- struct seq_file *m = file->private_data;
+ struct seq_file *m = iocb->ki_filp->private_data;
struct drm_connector *connector = m->private;
+ size_t len = iov_iter_count(from);
char *buf;
int ret;

- buf = memdup_user(ubuf, len);
+ buf = iterdup(from, len);
if (IS_ERR(buf))
return PTR_ERR(buf);

@@ -504,20 +504,20 @@ DEFINE_SHOW_ATTRIBUTE(output_bpc);
static const struct file_operations drm_edid_fops = {
.owner = THIS_MODULE,
.open = edid_open,
- .read = seq_read,
+ .read_iter = seq_read_iter,
.llseek = seq_lseek,
.release = single_release,
- .write = edid_write
+ .write_iter = edid_write
};

static const struct file_operations drm_connector_fops = {
.owner = THIS_MODULE,
.open = connector_open,
- .read = seq_read,
+ .read_iter = seq_read_iter,
.llseek = seq_lseek,
.release = single_release,
- .write = connector_write
+ .write_iter = connector_write
};

void drm_debugfs_connector_add(struct drm_connector *connector)
diff --git a/drivers/gpu/drm/drm_debugfs_crc.c b/drivers/gpu/drm/drm_debugfs_crc.c
index bbc3bc4ba844..85741f3eafee 100644
--- a/drivers/gpu/drm/drm_debugfs_crc.c
+++ b/drivers/gpu/drm/drm_debugfs_crc.c
@@ -117,12 +117,12 @@ static int crc_control_open(struct inode *inode, struct file *file)
return single_open(file, crc_control_show, crtc);
}

-static ssize_t crc_control_write(struct file *file, const char __user *ubuf,
- size_t len, loff_t *offp)
+static ssize_t crc_control_write(struct kiocb *iocb, struct iov_iter *from)
{
- struct seq_file *m = file->private_data;
+ struct seq_file *m = iocb->ki_filp->private_data;
struct drm_crtc *crtc = m->private;
struct drm_crtc_crc *crc = &crtc->crc;
+ size_t len = iov_iter_count(from);
char *source;
size_t values_cnt;
int ret;
@@ -136,7 +136,7 @@ static ssize_t crc_control_write(struct file *file, const char __user *ubuf,
return -E2BIG;
}

- source = memdup_user_nul(ubuf, len);
+ source = iterdup_nul(from, len);
if (IS_ERR(source))
return PTR_ERR(source);

@@ -162,17 +162,17 @@ static ssize_t crc_control_write(struct file *file, const char __user *ubuf,

spin_unlock_irq(&crc->lock);

- *offp += len;
+ iocb->ki_pos += len;
return len;
}

static const struct file_operations drm_crtc_crc_control_fops = {
.owner = THIS_MODULE,
.open = crc_control_open,
- .read = seq_read,
+ .read_iter = seq_read_iter,
.llseek = seq_lseek,
.release = single_release,
- .write = crc_control_write
+ .write_iter = crc_control_write,
};

static int crtc_crc_data_count(struct drm_crtc_crc *crc)
@@ -281,11 +281,11 @@ static int crtc_crc_release(struct inode *inode, struct file *filep)
#define LINE_LEN(values_cnt) (10 + 11 * values_cnt + 1 + 1)
#define MAX_LINE_LEN (LINE_LEN(DRM_MAX_CRC_NR))

-static ssize_t crtc_crc_read(struct file *filep, char __user *user_buf,
- size_t count, loff_t *pos)
+static ssize_t crtc_crc_read(struct kiocb *iocb, struct iov_iter *to)
{
- struct drm_crtc *crtc = filep->f_inode->i_private;
+ struct drm_crtc *crtc = iocb->ki_filp->f_inode->i_private;
struct drm_crtc_crc *crc = &crtc->crc;
+ size_t count = iov_iter_count(to);
struct drm_crtc_crc_entry *entry;
char buf[MAX_LINE_LEN];
int ret, i;
@@ -299,7 +299,7 @@ static ssize_t crtc_crc_read(struct file *filep, char __user *user_buf,

/* Nothing to read? */
while (crtc_crc_data_count(crc) == 0) {
- if (filep->f_flags & O_NONBLOCK) {
+ if (iocb->ki_filp->f_flags & O_NONBLOCK) {
spin_unlock_irq(&crc->lock);
return -EAGAIN;
}
@@ -335,7 +335,7 @@ static ssize_t crtc_crc_read(struct file *filep, char __user *user_buf,
sprintf(buf + 10 + i * 11, " 0x%08x", entry->crcs[i]);
sprintf(buf + 10 + crc->values_cnt * 11, "\n");

- if (copy_to_user(user_buf, buf, LINE_LEN(crc->values_cnt)))
+ if (!copy_to_iter_full(buf, LINE_LEN(crc->values_cnt), to))
return -EFAULT;

return LINE_LEN(crc->values_cnt);
@@ -360,7 +360,7 @@ static __poll_t crtc_crc_poll(struct file *file, poll_table *wait)
static const struct file_operations drm_crtc_crc_data_fops = {
.owner = THIS_MODULE,
.open = crtc_crc_open,
- .read = crtc_crc_read,
+ .read_iter = crtc_crc_read,
.poll = crtc_crc_poll,
.release = crtc_crc_release,
};
--
2.43.0