linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] block: use int type to store negative value
@ 2025-09-02 13:09 Qianfeng Rong
  2025-09-02 16:03 ` Bart Van Assche
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Qianfeng Rong @ 2025-09-02 13:09 UTC (permalink / raw)
  To: Jens Axboe, linux-block, linux-kernel; +Cc: Qianfeng Rong

Change the 'ret' variable in blk_stack_limits() from unsigned int to int,
as it needs to store negative value -1.

Storing the negative error codes in unsigned type, or performing equality
comparisons (e.g., ret == -1), doesn't cause an issue at runtime [1] but
can be confusing.  Additionally, assigning negative error codes to unsigned
type may trigger a GCC warning when the -Wsign-conversion flag is enabled.

No effect on runtime.

Link: https://lore.kernel.org/all/x3wogjf6vgpkisdhg3abzrx7v7zktmdnfmqeih5kosszmagqfs@oh3qxrgzkikf/ #1
Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
---
 block/blk-settings.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/block/blk-settings.c b/block/blk-settings.c
index d6438e6c276d..693bc8d20acf 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -763,7 +763,8 @@ static void blk_stack_atomic_writes_limits(struct queue_limits *t,
 int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
 		     sector_t start)
 {
-	unsigned int top, bottom, alignment, ret = 0;
+	unsigned int top, bottom, alignment;
+	int ret = 0;
 
 	t->features |= (b->features & BLK_FEAT_INHERIT_MASK);
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] block: use int type to store negative value
  2025-09-02 13:09 [PATCH] block: use int type to store negative value Qianfeng Rong
@ 2025-09-02 16:03 ` Bart Van Assche
  2025-09-02 16:11 ` John Garry
  2025-09-03  1:21 ` Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Bart Van Assche @ 2025-09-02 16:03 UTC (permalink / raw)
  To: Qianfeng Rong, Jens Axboe, linux-block, linux-kernel,
	Martin K . Petersen

On 9/2/25 6:09 AM, Qianfeng Rong wrote:
> Change the 'ret' variable in blk_stack_limits() from unsigned int to int,
> as it needs to store negative value -1.
> 
> Storing the negative error codes in unsigned type, or performing equality
> comparisons (e.g., ret == -1), doesn't cause an issue at runtime [1] but
> can be confusing.  Additionally, assigning negative error codes to unsigned
> type may trigger a GCC warning when the -Wsign-conversion flag is enabled.
> 
> No effect on runtime.
> 
> Link: https://lore.kernel.org/all/x3wogjf6vgpkisdhg3abzrx7v7zktmdnfmqeih5kosszmagqfs@oh3qxrgzkikf/ #1
> Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
> ---
>   block/blk-settings.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/block/blk-settings.c b/block/blk-settings.c
> index d6438e6c276d..693bc8d20acf 100644
> --- a/block/blk-settings.c
> +++ b/block/blk-settings.c
> @@ -763,7 +763,8 @@ static void blk_stack_atomic_writes_limits(struct queue_limits *t,
>   int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
>   		     sector_t start)
>   {
> -	unsigned int top, bottom, alignment, ret = 0;
> +	unsigned int top, bottom, alignment;
> +	int ret = 0;
>   
>   	t->features |= (b->features & BLK_FEAT_INHERIT_MASK);

Has it been considered to add a Fixes tag, e.g. this tag?

Fixes: fe0b393f2c0a ("block: Correct handling of bottom device misaligment")

With or without that tag:

Reviewed-by: Bart Van Assche <bvanassche@acm.org>





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] block: use int type to store negative value
  2025-09-02 13:09 [PATCH] block: use int type to store negative value Qianfeng Rong
  2025-09-02 16:03 ` Bart Van Assche
@ 2025-09-02 16:11 ` John Garry
  2025-09-03  1:21 ` Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: John Garry @ 2025-09-02 16:11 UTC (permalink / raw)
  To: Qianfeng Rong, Jens Axboe, linux-block, linux-kernel

On 02/09/2025 14:09, Qianfeng Rong wrote:

maybe be more exact in the subject, like "block: use int to store 
blk_stack_limits() return value"

> Change the 'ret' variable in blk_stack_limits() from unsigned int to int,
> as it needs to store negative value -1.
> 
> Storing the negative error codes in unsigned type, or performing equality
> comparisons (e.g., ret == -1), doesn't cause an issue at runtime [1] but
> can be confusing.  Additionally, assigning negative error codes to unsigned
> type may trigger a GCC warning when the -Wsign-conversion flag is enabled.
> 
> No effect on runtime.
> 
> Link: https://urldefense.com/v3/__https://lore.kernel.org/all/x3wogjf6vgpkisdhg3abzrx7v7zktmdnfmqeih5kosszmagqfs@oh3qxrgzkikf/__;!!ACWV5N9M2RV99hQ!JfWLPo_X7bYZL3xujNcmSob_sFzfvnOmFwzTQ-buSgEyxB4Rx04CZsZmcwf8CSAME6ySlTkSsgsc2EWpNVX-LC_C$  #1
> Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>

Reviewed-by: John Garry <john.g.garry@oracle.com>

> ---
>   block/blk-settings.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/block/blk-settings.c b/block/blk-settings.c
> index d6438e6c276d..693bc8d20acf 100644
> --- a/block/blk-settings.c
> +++ b/block/blk-settings.c
> @@ -763,7 +763,8 @@ static void blk_stack_atomic_writes_limits(struct queue_limits *t,
>   int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
>   		     sector_t start)
>   {
> -	unsigned int top, bottom, alignment, ret = 0;
> +	unsigned int top, bottom, alignment;
> +	int ret = 0;
>   
>   	t->features |= (b->features & BLK_FEAT_INHERIT_MASK);
>   


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] block: use int type to store negative value
  2025-09-02 13:09 [PATCH] block: use int type to store negative value Qianfeng Rong
  2025-09-02 16:03 ` Bart Van Assche
  2025-09-02 16:11 ` John Garry
@ 2025-09-03  1:21 ` Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2025-09-03  1:21 UTC (permalink / raw)
  To: linux-block, linux-kernel, Qianfeng Rong


On Tue, 02 Sep 2025 21:09:30 +0800, Qianfeng Rong wrote:
> Change the 'ret' variable in blk_stack_limits() from unsigned int to int,
> as it needs to store negative value -1.
> 
> Storing the negative error codes in unsigned type, or performing equality
> comparisons (e.g., ret == -1), doesn't cause an issue at runtime [1] but
> can be confusing.  Additionally, assigning negative error codes to unsigned
> type may trigger a GCC warning when the -Wsign-conversion flag is enabled.
> 
> [...]

Applied, thanks!

[1/1] block: use int type to store negative value
      commit: b0b4518c992eb5f316c6e40ff186cbb7a5009518

Best regards,
-- 
Jens Axboe




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-09-03  1:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-02 13:09 [PATCH] block: use int type to store negative value Qianfeng Rong
2025-09-02 16:03 ` Bart Van Assche
2025-09-02 16:11 ` John Garry
2025-09-03  1:21 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).