From 2273e2dcd97ba79dce4b7881579c3f44fbfebd52 Mon Sep 17 00:00:00 2001 From: Li Jun Date: Tue, 13 Nov 2018 16:37:42 +0800 Subject: [PATCH] MLK-20220 staging: typec: tcpci: fix improper use of negative value Coverity complains CID 3411292: Improper use of negative valure (NEGATIVE_RETURNS), as possibly assign a negative value to unsigned int, fix it by use an int temp value for negative value return. Acked-by: Peter Chen Signed-off-by: Li Jun (cherry picked from commit 9ab72e25fcda73a455a434993c8186663c241f27) --- drivers/staging/typec/tcpci.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/staging/typec/tcpci.c b/drivers/staging/typec/tcpci.c index 20223d380cef..0bd9a2e55c0f 100644 --- a/drivers/staging/typec/tcpci.c +++ b/drivers/staging/typec/tcpci.c @@ -662,13 +662,14 @@ static int tcpci_parse_config(struct tcpci *tcpci) goto sink; /* Check source pdo array size */ - tcfg->nr_src_pdo = device_property_read_u32_array(tcpci->dev, - "src-pdos", NULL, 0); - if (tcfg->nr_src_pdo <= 0) { + ret = device_property_read_u32_array(tcpci->dev, "src-pdos", NULL, 0); + if (ret <= 0) { dev_err(tcpci->dev, "typec source pdo is missing!\n"); return -EINVAL; } + tcfg->nr_src_pdo = ret; + /* Alloc src_pdo based on the array size */ tcfg->src_pdo = devm_kzalloc(tcpci->dev, sizeof(*tcfg->src_pdo) * tcfg->nr_src_pdo, GFP_KERNEL); @@ -728,13 +729,15 @@ static int tcpci_parse_config(struct tcpci *tcpci) sink: /* Check the num of snk pdo */ - tcfg->nr_snk_pdo = device_property_read_u32_array(tcpci->dev, - "snk-pdos", NULL, 0); - if (tcfg->nr_snk_pdo <= 0) { + ret = device_property_read_u32_array(tcpci->dev, + "snk-pdos", NULL, 0); + if (ret <= 0) { dev_err(tcpci->dev, "typec sink pdo is missing!\n"); return -EINVAL; } + tcfg->nr_snk_pdo = ret; + /* alloc snk_pdo based on the array size */ tcfg->snk_pdo = devm_kzalloc(tcpci->dev, sizeof(*tcfg->snk_pdo) * tcfg->nr_snk_pdo, GFP_KERNEL);