2024-06-03 19:47:28

by Keith Busch

[permalink] [raw]
Subject: Re: [PATCH v2] null_blk: fix validation of block size

On Mon, Jun 03, 2024 at 09:26:45PM +0200, Andreas Hindborg wrote:
> - dev->blocksize = round_down(dev->blocksize, 512);
> - dev->blocksize = clamp_t(unsigned int, dev->blocksize, 512, 4096);
> + if (blk_validate_block_size(dev->blocksize) != 0) {
> + return -EINVAL;
> + }

No need for the { } brackets for a one-line if.

It also looks like a good idea if this check was just done in
blk_validate_limits() so that each driver doesn't have to do their own
checks. That block function is kind of recent though. Your patch here
looks fine if you want stable back-ports, but I haven't heard any
complaints till recently :)


2024-06-04 07:55:49

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH v2] null_blk: fix validation of block size

On Mon, Jun 03, 2024 at 01:47:17PM -0600, Keith Busch wrote:
> On Mon, Jun 03, 2024 at 09:26:45PM +0200, Andreas Hindborg wrote:
> > - dev->blocksize = round_down(dev->blocksize, 512);
> > - dev->blocksize = clamp_t(unsigned int, dev->blocksize, 512, 4096);
> > + if (blk_validate_block_size(dev->blocksize) != 0) {
> > + return -EINVAL;
> > + }
>
> No need for the { } brackets for a one-line if.

or the != 0.

>
> It also looks like a good idea if this check was just done in
> blk_validate_limits() so that each driver doesn't have to do their own
> checks. That block function is kind of recent though.

Yes. We already discussed this in another thread a few days ago.