Skip to contentSkip to conversation

Fixes for issues detected by static analyzers

PATCH New Bart Van Assche 4 participants 7 messages Oct 10, 2018 – Oct 11, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover Fixes for issues detected by static analyzers

Hi Keith, Christoph and Sagi,

This patch series addresses several issues reported by static analyzers like sparse, smatch and Coverity. Please consider these patches for Linux kernel v4.20.

Thanks,

Bart.

Changes compared to v1:
- Left out the patches that have already been queued by Christoph and also patch "nvme-core: Complain if nvme_init_identify() fails".
- Addressed the review feedback that I received for the two patches in v2 of this series.

Bart Van Assche (2):
nvme-core: Make implicit seed truncation explicit
nvmet-fcloop: Suppress a compiler warning

 drivers/nvme/host/core.c     | 2 +-
 drivers/nvme/target/fcloop.c | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
Signature · 1 line
2.19.0.605.g01d371f741-goog
#1 lore raw

PATCH v2 1/2 nvme-core: Make implicit seed truncation explicit

The nvme_user_io.slba field is 64 bits wide. That value is copied into the 32-bit bio_integrity_payload.bip_iter.bi_sector field. Make that truncation explicit to avoid that Coverity complains about implicit truncation. See also Coverity ID 1056486 on http://scan.coverity.com/projects/linux.

Signed-off-by Bart Van Assche <bvanassche at acm.org>
---
 drivers/nvme/host/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/host/core.c +1 -1
index 8cecb36b5af1..65c42448e904 100644
@@ -1132,7 +1132,7 @@ static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio)
 
 	return nvme_submit_user_cmd(ns->queue, &c,
 			(void __user *)(uintptr_t)io.addr, length,
-			metadata, meta_len, io.slba, NULL, 0);
+			metadata, meta_len, lower_32_bits(io.slba), NULL, 0);
 }
 
 static u32 nvme_known_admin_effects(u8 opcode)
Signature · 1 line
2.19.0.605.g01d371f741-goog
#2 lore raw

PATCH v2 1/2 nvme-core: Make implicit seed truncation explicit

Quoted 6 lines · Bart Van Assche

The nvme_user_io.slba field is 64 bits wide. That value is copied into the 32-bit bio_integrity_payload.bip_iter.bi_sector field. Make that truncation explicit to avoid that Coverity complains about implicit truncation. See also Coverity ID 1056486 on http://scan.coverity.com/projects/linux.

Signed-off-by Bart Van Assche <bvanassche at acm.org>

Looks good, thanks for the update.

Reviewed-by Keith Busch <keith.busch at intel.com>
Quoted 19 lines
 drivers/nvme/host/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/host/core.c +1 -1
index 8cecb36b5af1..65c42448e904 100644
@@ -1132,7 +1132,7 @@ static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio)
 
 	return nvme_submit_user_cmd(ns->queue, &c,
 			(void __user *)(uintptr_t)io.addr, length,
-			metadata, meta_len, io.slba, NULL, 0);
+			metadata, meta_len, lower_32_bits(io.slba), NULL, 0);
 }
 
 static u32 nvme_known_admin_effects(u8 opcode)
Signature · 1 line
2.19.0.605.g01d371f741-goog
#3 lore raw

PATCH v2 2/2 nvmet-fcloop: Suppress a compiler warning

In reply to Bart Van Assche

Building with W=1 enables the compiler warning -Wimplicit-fallthrough=3. That option does not recognize the fall-through comment in the fcloop driver. Add a fall-through comment that is recognized for -Wimplicit-fallthrough=3. This patch avoids that the compiler reports the following warning when building with W=1:

drivers/nvme/target/fcloop.c:647:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
if (op == NVMET_FCOP_READDATA)

      ^
Cc James Smart <james.smart at broadcom.com>
Signed-off-by Bart Van Assche <bvanassche at acm.org>
---
 drivers/nvme/target/fcloop.c | 1 +
 1 file changed, 1 insertion(+)
drivers/nvme/target/fcloop.c +1 -0
index 5251689a1d9a..291f4121f516 100644
@@ -648,6 +648,7 @@ fcloop_fcp_op(struct nvmet_fc_target_port *tgtport,
 			break;
 
 		/* Fall-Thru to RSP handling */
+		/* FALLTHRU */
 
 	case NVMET_FCOP_RSP:
 		if (fcpreq) {
Signature · 1 line
2.19.0.605.g01d371f741-goog
#4 lore raw

PATCH v2 2/2 nvmet-fcloop: Suppress a compiler warning

Quoted 21 lines · Bart Van Assche

Building with W=1 enables the compiler warning -Wimplicit-fallthrough=3. That option does not recognize the fall-through comment in the fcloop driver. Add a fall-through comment that is recognized for -Wimplicit-fallthrough=3. This patch avoids that the compiler reports the following warning when building with W=1:

drivers/nvme/target/fcloop.c:647:6: warning: this statement may fall through [-Wimplicit-fallthrough=]

    if (op == NVMET_FCOP_READDATA)
       ^
Cc James Smart <james.smart at broadcom.com>
Signed-off-by Bart Van Assche <bvanassche at acm.org>
---
  drivers/nvme/target/fcloop.c | 1 +
  1 file changed, 1 insertion(+)
drivers/nvme/target/fcloop.c +0 -0
index 5251689a1d9a..291f4121f516 100644

drivers/nvme/target/fcloop.c fcloop_fcp_op(struct nvmet_fc_target_port *tgtport, · line 654

Quoted 7 lines
drivers/nvme/target/fcloop.c +1 -0
@@ -648,6 +648,7 @@ fcloop_fcp_op(struct nvmet_fc_target_port *tgtport,
  			break;
 
  		/* Fall-Thru to RSP handling */
+		/* FALLTHRU */
 
  	case NVMET_FCOP_RSP:
  		if (fcpreq) {
Reviewed-by James Smart <james.smart at broadcom.com>

I had no idea there was a "standard" way to declare this.

-- james

#5 lore raw

PATCH v2 2/2 nvmet-fcloop: Suppress a compiler warning

Quoted 11 lines · James Smart
Quoted 10 lines · Bart Van Assche
drivers/nvme/target/fcloop.c +1 -0
index 5251689a1d9a..291f4121f516 100644
@@ -648,6 +648,7 @@ fcloop_fcp_op(struct nvmet_fc_target_port *tgtport,
  			break;
 
  		/* Fall-Thru to RSP handling */
+		/* FALLTHRU */
 
Quoted 6 lines

drivers/nvme/target/fcloop.c fcloop_fcp_op(struct nvmet_fc_target_port *tgtport, · line 654

Quoted 2 lines
drivers/nvme/target/fcloop.c +0 -0
  	case NVMET_FCOP_RSP:
  		if (fcpreq) {
Reviewed-by James Smart <james.smart at broadcom.com>

I had no idea there was a "standard" way to declare this.

Thanks James for the review. A detailed description of which comments are recognized by gcc is available on https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#Warning-Options:

The option argument n specifies what kind of comments are accepted:

-Wimplicit-fallthrough=0 disables the warning altogether.
-Wimplicit-fallthrough=1 matches .* regular expression, any comment is used as fallthrough comment. -Wimplicit-fallthrough=2 case insensitively matches .*falls?[ \t-]*thr(ough|u).* regular expression. -Wimplicit-fallthrough=3 case sensitively matches one of the following regular expressions:
-fallthrough
@fallthrough@
lint -fallthrough[ \t]*
[ \t.!]*(ELSE,? |INTENTIONAL(LY)? )?
FALL(S | |-)?THR(OUGH|U)[ \t.!]*(-[^\n\r]*)?
[ \t.!]*(Else,? |Intentional(ly)? )?
Fall((s | |-)[Tt]|t)hr(ough|u)[ \t.!]*(-[^\n\r]*)?
[ \t.!]*([Ee]lse,? |[Ii]ntentional(ly)? )?
fall(s | |-)?thr(ough|u)[ \t.!]*(-[^\n\r]*)?
-Wimplicit-fallthrough=4 case sensitively matches one of the following regular expressions:
-fallthrough
@fallthrough@
lint -fallthrough[ \t]*
[ \t]*FALLTHR(OUGH|U)[ \t]*
-Wimplicit-fallthrough=5 doesn?t recognize any comments as fallthrough comments, only attributes disable the warning.

Bart.