Message ID | 20190708184711.2984-2-chaitanya.kulkarni@wdc.com (mailing list archive) |
---|---|
State | Not Applicable |
Headers | show |
Series | block: use right accessor to read nr_sects | expand |
Hi Chaitanya, > +static inline sector_t bdev_nr_sects(struct block_device *bdev) > +{ > + return part_nr_sects_read(bdev->bd_part); > +} Can bdev end up being NULL in any of the call sites? Otherwise no objections.
On 7/11/19 6:59 PM, Martin K. Petersen wrote: > Hi Chaitanya, > >> +static inline sector_t bdev_nr_sects(struct block_device *bdev) >> +{ >> + return part_nr_sects_read(bdev->bd_part); >> +} > Can bdev end up being NULL in any of the call sites? > > Otherwise no objections. > Thanks for mentioning that. Initial version which was not posted had that check. This series just replaces the existing accesses without changing anything. So if any of the exiting code has that bug then it will blow up nicely. For future callers I don't mind adding a new check and resend the series. Would you prefer adding a check ?
Chaitanya, > This series just replaces the existing accesses without changing > anything. > > So if any of the exiting code has that bug then it will blow up > nicely. > > For future callers I don't mind adding a new check and resend the > series. > > Would you prefer adding a check ? I checked your call sites and they look fine. Also, I don't think returning a capacity of 0 on error is going to help us much. Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 0c482371c8b3..578383712093 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1464,6 +1464,11 @@ static inline void put_dev_sector(Sector p) put_page(p.v); } +static inline sector_t bdev_nr_sects(struct block_device *bdev) +{ + return part_nr_sects_read(bdev->bd_part); +} + int kblockd_schedule_work(struct work_struct *work); int kblockd_schedule_work_on(int cpu, struct work_struct *work); int kblockd_mod_delayed_work_on(int cpu, struct delayed_work *dwork, unsigned long delay);
This patch introduces helper function to read the number of sectors from struct block_device->bd_part member. For more details Please refer to the comment in the include/linux/genhd.h for part_nr_sects_read(). Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com> --- include/linux/blkdev.h | 5 +++++ 1 file changed, 5 insertions(+)