Skip to contentSkip to conversation

md: dm-ioctl: drop always-false condition

PATCH In review Sergey Shtylyov 3 participants 4 messages Jan 17, 2023 – Feb 6, 2023 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 md: dm-ioctl: drop always-false condition

The expression 'indata[3] > ULONG_MAX' always evaluates to false since indata[] is declared as an array of *unsigned long* elements and #define ULONG_MAX represents the max value of that exact type...

Note that gcc seems to be able to detect the dead code here and eliminate this check anyway...

Found by Linux Verification Center (linuxtesting.org) with the SVACE static analysis tool.

---
This patch is atop of the 'for-next' branch of the device-mapper repo...

 drivers/md/dm-ioctl.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/md/dm-ioctl.c +1 -2
Index: linux-dm/drivers/md/dm-ioctl.c
===================================================================
@@ -1073,8 +1073,7 @@ static int dev_set_geometry(struct file
 		goto out;
 	}
 
-	if (indata[0] > 65535 || indata[1] > 255 ||
-	    indata[2] > 255 || indata[3] > ULONG_MAX) {
+	if (indata[0] > 65535 || indata[1] > 255 || indata[2] > 255) {
 		DMERR("Geometry exceeds range limits.");
 		goto out;
 	}
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Sergey Shtylyov

The expression 'indata[3] > ULONG_MAX' always evaluates to false since indata[] is declared as an array of *unsigned long* elements and #define ULONG_MAX represents the max value of that exact type...

Note that gcc seems to be able to detect the dead code here and eliminate this check anyway...

Found by Linux Verification Center (linuxtesting.org) with the SVACE static analysis tool.

Quoted 22 lines

---
This patch is atop of the 'for-next' branch of the device-mapper repo...

 drivers/md/dm-ioctl.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Index: linux-dm/drivers/md/dm-ioctl.c
===================================================================

drivers/md/dm-ioctl.c +1 -3
@@ -1073,8 +1073,7 @@ static int dev_set_geometry(struct file
 		goto out;
 	}
 
-	if (indata[0] > 65535 || indata[1] > 255 ||
-	    indata[2] > 255 || indata[3] > ULONG_MAX) {
+	if (indata[0] > 65535 || indata[1] > 255 || indata[2] > 255) {
 		DMERR("Geometry exceeds range limits.");
 		goto out;
 	}
 
--
Quoted 4 lines

dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel

#2 lore raw

On 1/18/23 2:59 PM, Mikulas Patocka wrote:

[...]

Quoted 7 lines
Quoted 7 lines

The expression 'indata[3] > ULONG_MAX' always evaluates to false since indata[] is declared as an array of *unsigned long* elements and #define ULONG_MAX represents the max value of that exact type...

Note that gcc seems to be able to detect the dead code here and eliminate this check anyway...

Quoted 6 lines
Quoted 4 lines

Found by Linux Verification Center (linuxtesting.org) with the SVACE static analysis tool.

Thank you!

Quoted 11 lines

drivers/md/dm-ioctl.c static int dev_set_geometry(struct file

Quoted 11 lines

---
This patch is atop of the 'for-next' branch of the device-mapper repo...

 drivers/md/dm-ioctl.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Index: linux-dm/drivers/md/dm-ioctl.c
===================================================================

drivers/md/dm-ioctl.c +0 -0
@@ -1073,8 +1073,7 @@ static int dev_set_geometry(struct file

Returning to this patch, I think I should've added the name of the function
in question in both the subject and and commit msg... I'll recast...

Quoted 10 lines

drivers/md/dm-ioctl.c static int dev_set_geometry(struct file · line 1079

Quoted 10 lines
drivers/md/dm-ioctl.c +1 -2
 		goto out;
 	}
 
-	if (indata[0] > 65535 || indata[1] > 255 ||
-	    indata[2] > 255 || indata[3] > ULONG_MAX) {
+	if (indata[0] > 65535 || indata[1] > 255 || indata[2] > 255) {
 		DMERR("Geometry exceeds range limits.");
 		goto out;
 	}

MBR, Sergey

maintainer
#3 lore raw
Quoted 26 lines · Sergey Shtylyov

On 1/18/23 2:59 PM, Mikulas Patocka wrote:

[...]

Quoted 7 lines
Quoted 7 lines

The expression 'indata[3] > ULONG_MAX' always evaluates to false since indata[] is declared as an array of *unsigned long* elements and #define ULONG_MAX represents the max value of that exact type...

Note that gcc seems to be able to detect the dead code here and eliminate this check anyway...

Quoted 6 lines
Quoted 4 lines

Found by Linux Verification Center (linuxtesting.org) with the SVACE static analysis tool.

Thank you!

Quoted 6 lines
Quoted 6 lines

---
This patch is atop of the 'for-next' branch of the device-mapper repo...

 drivers/md/dm-ioctl.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Quoted 8 lines
Quoted 5 lines

drivers/md/dm-ioctl.c static int dev_set_geometry(struct file

Quoted 5 lines

Index: linux-dm/drivers/md/dm-ioctl.c
===================================================================

drivers/md/dm-ioctl.c +0 -0
@@ -1073,8 +1073,7 @@ static int dev_set_geometry(struct file

Returning to this patch, I think I should've added the name of the function
in question in both the subject and and commit msg... I'll recast...

Not a big deal, I've already staged it so please don't resend.

See:
https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git/commit/?h=dm-6.3&id=151d812251202aa0dce1fdeabd64794292d40b75

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel