mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] scsi: scsi_debug: negate wrapped memcmp() result
@ 2026-08-03  9:53 raoxu
  2026-08-03 12:54 ` John Garry
  0 siblings, 1 reply; 2+ messages in thread
From: raoxu @ 2026-08-03  9:53 UTC (permalink / raw)
  To: James.Bottomley; +Cc: martin.petersen, linux-scsi, linux-kernel, raoxu, stable

From: Xu Rao <raoxu@uniontech.com>

comp_write_worker() returns true when the compared data matches.
memcmp() returns zero for equal data and non-zero for different data, so
its result must be negated before it is stored in a bool.

The first segment already uses !memcmp(), but the wrapped segment uses
memcmp() directly, reversing the match result. Use !memcmp() there as
well.

Fixes: 38d5c8336e60 ("scsi_debug: add Report supported opcodes+tmfs; Compare and write")
Cc: stable@vger.kernel.org
Signed-off-by: Xu Rao <raoxu@uniontech.com>
---
 drivers/scsi/scsi_debug.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 9d1c9c41d0f9..a5911482fc44 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -4310,8 +4310,8 @@ static bool comp_write_worker(struct sdeb_store_info *sip, u64 lba, u32 num,
 	if (!res)
 		return res;
 	if (rest)
-		res = memcmp(fsp, arr + ((num - rest) * lb_size),
-			     rest * lb_size);
+		res = !memcmp(fsp, arr + ((num - rest) * lb_size),
+			      rest * lb_size);
 	if (!res)
 		return res;
 	if (compare_only)
--
2.50.1


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

* Re: [PATCH] scsi: scsi_debug: negate wrapped memcmp() result
  2026-08-03  9:53 [PATCH] scsi: scsi_debug: negate wrapped memcmp() result raoxu
@ 2026-08-03 12:54 ` John Garry
  0 siblings, 0 replies; 2+ messages in thread
From: John Garry @ 2026-08-03 12:54 UTC (permalink / raw)
  To: raoxu, James.Bottomley; +Cc: martin.petersen, linux-scsi, linux-kernel, stable

On 03/08/2026 10:53, raoxu wrote:
> From: Xu Rao <raoxu@uniontech.com>
> 
> comp_write_worker() returns true when the compared data matches.
> memcmp() returns zero for equal data and non-zero for different data, so
> its result must be negated before it is stored in a bool.
> 
> The first segment already uses !memcmp(), but the wrapped segment uses
> memcmp() directly, reversing the match result. Use !memcmp() there as
> well.
> 
> Fixes: 38d5c8336e60 ("scsi_debug: add Report supported opcodes+tmfs; Compare and write")
> Cc: stable@vger.kernel.org
> Signed-off-by: Xu Rao <raoxu@uniontech.com>

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

> ---
>   drivers/scsi/scsi_debug.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
> index 9d1c9c41d0f9..a5911482fc44 100644
> --- a/drivers/scsi/scsi_debug.c
> +++ b/drivers/scsi/scsi_debug.c
> @@ -4310,8 +4310,8 @@ static bool comp_write_worker(struct sdeb_store_info *sip, u64 lba, u32 num,
>   	if (!res)
>   		return res;
>   	if (rest)
> -		res = memcmp(fsp, arr + ((num - rest) * lb_size),
> -			     rest * lb_size);
> +		res = !memcmp(fsp, arr + ((num - rest) * lb_size),
> +			      rest * lb_size);
>   	if (!res)
>   		return res;
>   	if (compare_only)
> --
> 2.50.1
> 
> 


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

end of thread, other threads:[~2026-08-03 12:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-03  9:53 [PATCH] scsi: scsi_debug: negate wrapped memcmp() result raoxu
2026-08-03 12:54 ` John Garry

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®