diff mbox

[for-4.17,20/20] bcache: Fix a compiler warning in bcache_device_init()

Message ID 20180319003633.27225-21-mlyle@lyle.org (mailing list archive)
State New, archived
Headers show

Commit Message

Michael Lyle March 19, 2018, 12:36 a.m. UTC
From: Bart Van Assche <bart.vanassche@wdc.com>

Avoid that building with W=1 triggers the following compiler warning:

drivers/md/bcache/super.c:776:20: warning: comparison is always false due to limited range of data type [-Wtype-limits]
      d->nr_stripes > SIZE_MAX / sizeof(atomic_t)) {
                    ^

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Reviewed-by: Michael Lyle <mlyle@lyle.org>
---
 drivers/md/bcache/super.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Coly Li March 19, 2018, 1:32 a.m. UTC | #1
On 19/03/2018 8:36 AM, Michael Lyle wrote:
> From: Bart Van Assche <bart.vanassche@wdc.com>
> 
> Avoid that building with W=1 triggers the following compiler warning:
> 
> drivers/md/bcache/super.c:776:20: warning: comparison is always false due to limited range of data type [-Wtype-limits]
>       d->nr_stripes > SIZE_MAX / sizeof(atomic_t)) {
>                     ^
> 
> Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
> Reviewed-by: Michael Lyle <mlyle@lyle.org>

There is a missing Reviewed-by: Coly Li <colyli@suse.de> from me :-)

Thanks.

Coly Li

> ---
>  drivers/md/bcache/super.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
> index 640ff8072ed8..d90d9e59ca00 100644
> --- a/drivers/md/bcache/super.c
> +++ b/drivers/md/bcache/super.c
> @@ -778,6 +778,8 @@ static int bcache_device_init(struct bcache_device *d, unsigned block_size,
>  			      sector_t sectors)
>  {
>  	struct request_queue *q;
> +	const size_t max_stripes = min_t(size_t, INT_MAX,
> +					 SIZE_MAX / sizeof(atomic_t));
>  	size_t n;
>  	int idx;
>  
> @@ -786,9 +788,7 @@ static int bcache_device_init(struct bcache_device *d, unsigned block_size,
>  
>  	d->nr_stripes = DIV_ROUND_UP_ULL(sectors, d->stripe_size);
>  
> -	if (!d->nr_stripes ||
> -	    d->nr_stripes > INT_MAX ||
> -	    d->nr_stripes > SIZE_MAX / sizeof(atomic_t)) {
> +	if (!d->nr_stripes || d->nr_stripes > max_stripes) {
>  		pr_err("nr_stripes too large or invalid: %u (start sector beyond end of disk?)",
>  			(unsigned)d->nr_stripes);
>  		return -ENOMEM;
>
Michael Lyle March 21, 2018, 6:38 p.m. UTC | #2
On 03/18/2018 06:32 PM, Coly Li wrote:
> On 19/03/2018 8:36 AM, Michael Lyle wrote:
>> From: Bart Van Assche <bart.vanassche@wdc.com>
>>
>> Avoid that building with W=1 triggers the following compiler warning:
>>
>> drivers/md/bcache/super.c:776:20: warning: comparison is always false due to limited range of data type [-Wtype-limits]
>>       d->nr_stripes > SIZE_MAX / sizeof(atomic_t)) {
>>                     ^
>>
>> Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
>> Reviewed-by: Michael Lyle <mlyle@lyle.org>
> 
> There is a missing Reviewed-by: Coly Li <colyli@suse.de> from me :-)

Hi Coly--- sorry that I lost these.

Mike
Coly Li March 22, 2018, 4:17 a.m. UTC | #3
On 22/03/2018 2:38 AM, Michael Lyle wrote:
> On 03/18/2018 06:32 PM, Coly Li wrote:
>> On 19/03/2018 8:36 AM, Michael Lyle wrote:
>>> From: Bart Van Assche <bart.vanassche@wdc.com>
>>>
>>> Avoid that building with W=1 triggers the following compiler warning:
>>>
>>> drivers/md/bcache/super.c:776:20: warning: comparison is always false due to limited range of data type [-Wtype-limits]
>>>       d->nr_stripes > SIZE_MAX / sizeof(atomic_t)) {
>>>                     ^
>>>
>>> Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
>>> Reviewed-by: Michael Lyle <mlyle@lyle.org>
>>
>> There is a missing Reviewed-by: Coly Li <colyli@suse.de> from me :-)
> 
> Hi Coly--- sorry that I lost these.

The major motivation is just making my employer know where they pay for
my time :-)

Thanks.

Coly Li
diff mbox

Patch

diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index 640ff8072ed8..d90d9e59ca00 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -778,6 +778,8 @@  static int bcache_device_init(struct bcache_device *d, unsigned block_size,
 			      sector_t sectors)
 {
 	struct request_queue *q;
+	const size_t max_stripes = min_t(size_t, INT_MAX,
+					 SIZE_MAX / sizeof(atomic_t));
 	size_t n;
 	int idx;
 
@@ -786,9 +788,7 @@  static int bcache_device_init(struct bcache_device *d, unsigned block_size,
 
 	d->nr_stripes = DIV_ROUND_UP_ULL(sectors, d->stripe_size);
 
-	if (!d->nr_stripes ||
-	    d->nr_stripes > INT_MAX ||
-	    d->nr_stripes > SIZE_MAX / sizeof(atomic_t)) {
+	if (!d->nr_stripes || d->nr_stripes > max_stripes) {
 		pr_err("nr_stripes too large or invalid: %u (start sector beyond end of disk?)",
 			(unsigned)d->nr_stripes);
 		return -ENOMEM;