Re: [PATCH v2] block: add check that partition length needs to be aligned with block size

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jun 27, 2023 at 01:39:26PM +0900, Damien Le Moal wrote:
> > diff --git a/block/ioctl.c b/block/ioctl.c
> > index 3be11941fb2d..c40b382dd58f 100644
> > --- a/block/ioctl.c
> > +++ b/block/ioctl.c
> > @@ -33,14 +33,18 @@ static int blkpg_do_ioctl(struct block_device *bdev,
> >  	if (op == BLKPG_DEL_PARTITION)
> >  		return bdev_del_partition(disk, p.pno);
> >  
> > +	/* check if partition is aligned to blocksize */
> > +	if (p.start & (bdev_logical_block_size(bdev) - 1))
> > +		return -EINVAL;
> > +	/* check if length is aligned to blocksize */
> > +	if (p.length & (bdev_logical_block_size(bdev) - 1))
> > +		return -EINVAL;
> 
> 	long long blksz_mask = bdev_logical_block_size(bdev) - 1;
> 
> 	/* Check that the partition is aligned to the block size */
> 	if ((p.start & blksz_mask) || (p.length & blksz_mask))
> 		return -EINVAL;

A Minor nit on top of your comment:

 	unsigned int blksz = bdev_logical_block_size(bdev);
 
 	/* Check that the partition is aligned to the block size */
 	if (!IS_ALIGNED(p.start, blksz) || !IS_ALIGNED(p.length, blksz))
 		return -EINVAL;

> 
> would be cleaner and avoid the rather redundant comments.
> 



[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux