Skip to content

Commit 89443a9

Browse files
ovpanaitgregkh
authored andcommitted
staging: axis-fifo: drop redundant read/write_flags from axis_fifo
The driver stores file flags (read_flags/write_flags) in the axis_fifo struct, duplicating information already available in struct file. Switch to using f->f_flags directly in read/write paths and open(), removing the unnecessary fields. Signed-off-by: Ovidiu Panait <ovidiu.panait.oss@gmail.com> Link: https://lore.kernel.org/r/20250919195400.3180039-5-ovidiu.panait.oss@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4497288 commit 89443a9

1 file changed

Lines changed: 8 additions & 22 deletions

File tree

drivers/staging/axis-fifo/axis-fifo.c

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ struct axis_fifo {
128128
struct mutex read_lock; /* lock for reading */
129129
wait_queue_head_t write_queue; /* wait queue for asynchronos write */
130130
struct mutex write_lock; /* lock for writing */
131-
unsigned int write_flags; /* write file flags */
132-
unsigned int read_flags; /* read file flags */
133131

134132
struct device *dt_device; /* device created from the device tree */
135133
struct miscdevice miscdev;
@@ -186,7 +184,7 @@ static ssize_t axis_fifo_read(struct file *f, char __user *buf,
186184
int ret;
187185
u32 tmp_buf[READ_BUF_SIZE];
188186

189-
if (fifo->read_flags & O_NONBLOCK) {
187+
if (f->f_flags & O_NONBLOCK) {
190188
/*
191189
* Device opened in non-blocking mode. Try to lock it and then
192190
* check if any packet is available.
@@ -328,7 +326,7 @@ static ssize_t axis_fifo_write(struct file *f, const char __user *buf,
328326
if (words_to_write > (fifo->tx_fifo_depth - 4))
329327
return -EINVAL;
330328

331-
if (fifo->write_flags & O_NONBLOCK) {
329+
if (f->f_flags & O_NONBLOCK) {
332330
/*
333331
* Device opened in non-blocking mode. Try to lock it and then
334332
* check if there is any room to write the given buffer.
@@ -425,27 +423,15 @@ static int axis_fifo_open(struct inode *inod, struct file *f)
425423
{
426424
struct axis_fifo *fifo = container_of(f->private_data,
427425
struct axis_fifo, miscdev);
426+
unsigned int flags = f->f_flags & O_ACCMODE;
427+
428428
f->private_data = fifo;
429429

430-
if (((f->f_flags & O_ACCMODE) == O_WRONLY) ||
431-
((f->f_flags & O_ACCMODE) == O_RDWR)) {
432-
if (fifo->has_tx_fifo) {
433-
fifo->write_flags = f->f_flags;
434-
} else {
435-
dev_err(fifo->dt_device, "tried to open device for write but the transmit fifo is disabled\n");
436-
return -EPERM;
437-
}
438-
}
430+
if ((flags == O_WRONLY || flags == O_RDWR) && !fifo->has_tx_fifo)
431+
return -EPERM;
439432

440-
if (((f->f_flags & O_ACCMODE) == O_RDONLY) ||
441-
((f->f_flags & O_ACCMODE) == O_RDWR)) {
442-
if (fifo->has_rx_fifo) {
443-
fifo->read_flags = f->f_flags;
444-
} else {
445-
dev_err(fifo->dt_device, "tried to open device for read but the receive fifo is disabled\n");
446-
return -EPERM;
447-
}
448-
}
433+
if ((flags == O_RDONLY || flags == O_RDWR) && !fifo->has_rx_fifo)
434+
return -EPERM;
449435

450436
return 0;
451437
}

0 commit comments

Comments
 (0)