[V2,1/7] block: add a helper function to read nr_setcs
diff mbox series

Message ID 20190617012832.4311-2-chaitanya.kulkarni@wdc.com
State New
Headers show
Series
  • block: use right accessor to read nr_setcs
Related show

Commit Message

Chaitanya Kulkarni June 17, 2019, 1:28 a.m. UTC
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 | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Bart Van Assche June 17, 2019, 3:47 p.m. UTC | #1
On 6/16/19 6:28 PM, Chaitanya Kulkarni wrote:
> 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 | 10 ++++++++++
>   1 file changed, 10 insertions(+)
> 
> diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
> index 592669bcc536..2ef1de20fd22 100644
> --- a/include/linux/blkdev.h
> +++ b/include/linux/blkdev.h
> @@ -1475,6 +1475,16 @@ static inline void put_dev_sector(Sector p)
>   	put_page(p.v);
>   }
>   
> +/* Helper function to read the bdev->bd_part->nr_sects */
> +static inline sector_t bdev_nr_sects(struct block_device *bdev)
> +{
> +	sector_t nr_sects;
> +
> +	nr_sects = part_nr_sects_read(bdev->bd_part);
> +
> +	return nr_sects;
> +}

Although this looks fine to me, is there any reason why the body of that 
function has not been written as follows?

static inline sector_t bdev_nr_sects(struct block_device *bdev)
{
	return part_nr_sects_read(bdev->bd_part);
}

Thanks,

Bart.
Chaitanya Kulkarni June 17, 2019, 4:55 p.m. UTC | #2
On 06/17/2019 08:47 AM, Bart Van Assche wrote:
> On 6/16/19 6:28 PM, Chaitanya Kulkarni wrote:
>> 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 | 10 ++++++++++
>>    1 file changed, 10 insertions(+)
>>
>> diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
>> index 592669bcc536..2ef1de20fd22 100644
>> --- a/include/linux/blkdev.h
>> +++ b/include/linux/blkdev.h
>> @@ -1475,6 +1475,16 @@ static inline void put_dev_sector(Sector p)
>>    	put_page(p.v);
>>    }
>>
>> +/* Helper function to read the bdev->bd_part->nr_sects */
>> +static inline sector_t bdev_nr_sects(struct block_device *bdev)
>> +{
>> +	sector_t nr_sects;
>> +
>> +	nr_sects = part_nr_sects_read(bdev->bd_part);
>> +
>> +	return nr_sects;
>> +}
>
> Although this looks fine to me, is there any reason why the body of that
> function has not been written as follows?
>
> static inline sector_t bdev_nr_sects(struct block_device *bdev)
> {
> 	return part_nr_sects_read(bdev->bd_part);
> }
This perfectly make sense, thanks for the suggestion, will add it in a 
next version.
>
> Thanks,
>
> Bart.
>

Patch
diff mbox series

diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 592669bcc536..2ef1de20fd22 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1475,6 +1475,16 @@  static inline void put_dev_sector(Sector p)
 	put_page(p.v);
 }
 
+/* Helper function to read the bdev->bd_part->nr_sects */
+static inline sector_t bdev_nr_sects(struct block_device *bdev)
+{
+	sector_t nr_sects;
+
+	nr_sects = part_nr_sects_read(bdev->bd_part);
+
+	return nr_sects;
+}
+
 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);