Re: [PATCH] loop: Add sanity check for read/write_iter
From: Lizhi Xu
Date: Fri Apr 25 2025 - 00:20:07 EST
On Fri, 25 Apr 2025 06:06:51 +0200, Zhu Yanjun wrote:
> > diff --git a/drivers/block/loop.c b/drivers/block/loop.c
> > index 674527d770dc..4f968e3071ed 100644
> > --- a/drivers/block/loop.c
> > +++ b/drivers/block/loop.c
> > @@ -449,10 +449,15 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
> > cmd->iocb.ki_flags = IOCB_DIRECT;
> > cmd->iocb.ki_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 0);
> >
> > - if (rw == ITER_SOURCE)
> > - ret = file->f_op->write_iter(&cmd->iocb, &iter);
> > - else
> > - ret = file->f_op->read_iter(&cmd->iocb, &iter);
> > + ret = 0;
> > + if (rw == ITER_SOURCE) {
> > + if (likely(file->f_op->write_iter))
> > + ret = file->f_op->write_iter(&cmd->iocb, &iter);
> > + }
> > + else {
> > + if (likely(file->f_op->read_iter))
>
> "else if" is better?
There is nothing wrong with writing it this way logically, but it will
destroy the clarity of the original context regarding the read/write logical
relationship.