]> www.infradead.org Git - users/sagi/nvme-cli.git/commit
tree: fail on non-negative return values from parse_and_open
authorJeremy Kerr <jk@codeconstruct.com.au>
Wed, 24 Aug 2022 01:20:53 +0000 (09:20 +0800)
committerJeremy Kerr <jk@codeconstruct.com.au>
Wed, 24 Aug 2022 01:44:58 +0000 (09:44 +0800)
commit4b1ebf83582f573cffcf859475187f4dbe1dcc6c
tree69d5c569bedefc0fd6a5224f8937a686fef7764c
parent3e1bc6baf56feef5214554627ed8003037cf3311
tree: fail on non-negative return values from parse_and_open

Currently, we see a warning with specific compilers:

  ../nvme/nvme.c: In function 'ns_rescan':
  ../nvme/nvme.c:4389:19: warning: 'dev' may be used uninitialized in this function [-Wmaybe-uninitialized]

This is due to a theoretical failure path in parse_and_open(), where
argconfig_parse() returns a positive value - this would require the
global errno to be negative.

Even though the unintialised use of dev is only possible with negative
error (which shouldn't happen), we should still consider any non-zero
return value of parse_and_open a failure. This change fixes the
instances of:

    err = parse_and_open(...);
    if (err < 0)

changing to:

    err = parse_and_open(...);
    if (err)

... and also applies this to the single use of open_exclusive().

The positive return values from parse_and_open() were removed in
11542bbd; beforehand, parse_and_open() would return a fd.

Fixes: 11542bbd ("tree: Combine NVMe file descriptor into struct nvme_dev")
Fixes: https://github.com/linux-nvme/nvme-cli/issues/1647
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
20 files changed:
nvme-rpmb.c
nvme.c
plugins/dera/dera-nvme.c
plugins/innogrit/innogrit-nvme.c
plugins/intel/intel-nvme.c
plugins/memblaze/memblaze-nvme.c
plugins/micron/micron-nvme.c
plugins/ocp/ocp-nvme.c
plugins/scaleflux/sfx-nvme.c
plugins/seagate/seagate-nvme.c
plugins/shannon/shannon-nvme.c
plugins/solidigm/solidigm-garbage-collection.c
plugins/solidigm/solidigm-latency-tracking.c
plugins/solidigm/solidigm-smart.c
plugins/toshiba/toshiba-nvme.c
plugins/transcend/transcend-nvme.c
plugins/virtium/virtium-nvme.c
plugins/wdc/wdc-nvme.c
plugins/ymtc/ymtc-nvme.c
plugins/zns/zns.c