sandbox: cros_ec: Update error handling when reading matrix

At present the return value of ofnode_get_property() is not checked, which
causes a coverity warning. While we are here, use logging for the errors.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reported-by: Coverity (CID: 331157)
This commit is contained in:
Simon Glass 2021-05-13 19:39:26 -06:00 committed by Tom Rini
parent 9dec2c1f03
commit 15dd815c75

View file

@ -5,6 +5,8 @@
* Copyright (c) 2013 The Chromium OS Authors. * Copyright (c) 2013 The Chromium OS Authors.
*/ */
#define LOG_CATEGORY UCLASS_CROS_EC
#include <common.h> #include <common.h>
#include <cros_ec.h> #include <cros_ec.h>
#include <dm.h> #include <dm.h>
@ -221,11 +223,12 @@ static int keyscan_read_fdt_matrix(struct ec_state *ec, ofnode node)
int len; int len;
cell = ofnode_get_property(node, "linux,keymap", &len); cell = ofnode_get_property(node, "linux,keymap", &len);
if (!cell)
return log_msg_ret("prop", -EINVAL);
ec->matrix_count = len / 4; ec->matrix_count = len / 4;
ec->matrix = calloc(ec->matrix_count, sizeof(*ec->matrix)); ec->matrix = calloc(ec->matrix_count, sizeof(*ec->matrix));
if (!ec->matrix) { if (!ec->matrix) {
debug("%s: Out of memory for key matrix\n", __func__); return log_msg_ret("mem", -ENOMEM);
return -1;
} }
/* Now read the data */ /* Now read the data */
@ -243,13 +246,12 @@ static int keyscan_read_fdt_matrix(struct ec_state *ec, ofnode node)
matrix->col >= KEYBOARD_COLS) { matrix->col >= KEYBOARD_COLS) {
debug("%s: Matrix pos out of range (%d,%d)\n", debug("%s: Matrix pos out of range (%d,%d)\n",
__func__, matrix->row, matrix->col); __func__, matrix->row, matrix->col);
return -1; return log_msg_ret("matrix", -ERANGE);
} }
} }
if (upto != ec->matrix_count) { if (upto != ec->matrix_count) {
debug("%s: Read mismatch from key matrix\n", __func__); return log_msg_ret("matrix", -E2BIG);
return -1;
} }
return 0; return 0;