fpga: machxo2-spi: Return an error on failure
authorTom Rix <trix@redhat.com>
Tue, 10 Aug 2021 16:40:36 +0000 (09:40 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 30 Sep 2021 08:11:03 +0000 (10:11 +0200)
[ Upstream commit 34331739e19fd6a293d488add28832ad49c9fc54 ]

Earlier successes leave 'ret' in a non error state, so these errors are
not reported. Set ret to -EINVAL before going to the error handler.

This addresses two issues reported by smatch:
drivers/fpga/machxo2-spi.c:229 machxo2_write_init()
  warn: missing error code 'ret'

drivers/fpga/machxo2-spi.c:316 machxo2_write_complete()
  warn: missing error code 'ret'

[mdf@kernel.org: Reworded commit message]
Fixes: 88fb3a002330 ("fpga: lattice machxo2: Add Lattice MachXO2 support")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Tom Rix <trix@redhat.com>
Signed-off-by: Moritz Fischer <mdf@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/fpga/machxo2-spi.c

index b316369..7688ff3 100644 (file)
@@ -225,8 +225,10 @@ static int machxo2_write_init(struct fpga_manager *mgr,
                goto fail;
 
        get_status(spi, &status);
-       if (test_bit(FAIL, &status))
+       if (test_bit(FAIL, &status)) {
+               ret = -EINVAL;
                goto fail;
+       }
        dump_status_reg(&status);
 
        spi_message_init(&msg);
@@ -313,6 +315,7 @@ static int machxo2_write_complete(struct fpga_manager *mgr,
        dump_status_reg(&status);
        if (!test_bit(DONE, &status)) {
                machxo2_cleanup(mgr);
+               ret = -EINVAL;
                goto fail;
        }