From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kees Cook Subject: Re: [PATCH 08/30] target/iblock: use bdev_nr_bytes instead of open coding it Date: Fri, 15 Oct 2021 08:57:59 -0700 Message-ID: <202110150857.A7E96DAE@keescook> References: <20211015132643.1621913-1-hch@lst.de> <20211015132643.1621913-9-hch@lst.de> Mime-Version: 1.0 Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=rgGaYmDb8aNvCIAME7GO0birqL1mkWt7ydTyP9O/cKE=; b=kIRUc5W9BEwRakFXurh5nloSfV/GZ6KodZpU7B1gErDYA9VUyCtogTyGs+Y5G+H20i dnc1ZbM+E5Bs4xUGAtigRUSltSsKM9wVuaq9ndK9JOr2Z68iGubgRtUXKZR8iuFZIw97 IrBdRqOJrF7Mv/zRwmHVkacPzOteyiW6Cc+yE= Content-Disposition: inline In-Reply-To: <20211015132643.1621913-9-hch-jcswGhMUV9g@public.gmane.org> List-ID: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Christoph Hellwig Cc: Jens Axboe , Coly Li , Mike Snitzer , Song Liu , David Sterba , Josef Bacik , Theodore Ts'o , OGAWA Hirofumi , Dave Kleikamp , Ryusuke Konishi , Anton Altaparmakov , Konstantin Komarov , Phillip Lougher , Jan Kara , linux-block-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, dm-devel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org, drbd-dev-cunTk1MwBs8qoQakbn7OcQ@public.gmane.org, linux-bcache-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-raid-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-nvme-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, linux-scsi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, target-devel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org On Fri, Oct 15, 2021 at 03:26:21PM +0200, Christoph Hellwig wrote: > Use the proper helper to read the block device size. > > Signed-off-by: Christoph Hellwig > Reviewed-by: Chaitanya Kulkarni Is this basically an open-coded non-sb version of sb_bdev_nr_blocks()? Reviewed-by: Kees Cook > --- > drivers/target/target_core_iblock.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/target/target_core_iblock.c b/drivers/target/target_core_iblock.c > index 31df20abe141f..b1ef041cacd81 100644 > --- a/drivers/target/target_core_iblock.c > +++ b/drivers/target/target_core_iblock.c > @@ -232,9 +232,9 @@ static unsigned long long iblock_emulate_read_cap_with_block_size( > struct block_device *bd, > struct request_queue *q) > { > - unsigned long long blocks_long = (div_u64(i_size_read(bd->bd_inode), > - bdev_logical_block_size(bd)) - 1); > u32 block_size = bdev_logical_block_size(bd); > + unsigned long long blocks_long = > + div_u64(bdev_nr_bytes(bd), block_size) - 1; > > if (block_size == dev->dev_attrib.block_size) > return blocks_long; > -- > 2.30.2 > -- Kees Cook