2021-04-01 09:19:13

by Srinivas Kandagatla

[permalink] [raw]
Subject: [PATCH] soundwire: qcom: handle return correctly in qcom_swrm_transport_params

Looks like return from reg_write is set but not checked.
Fix this by adding error return path.

Reported-by: coverity-bot <[email protected]>
Addresses-Coverity-ID: 1503591 ("UNUSED_VALUE")
Fixes: 128eaf937adb ("soundwire: qcom: add support to missing transport params")
Signed-off-by: Srinivas Kandagatla <[email protected]>
---
drivers/soundwire/qcom.c | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c
index 5fd4a99cc8ac..348d9a46f850 100644
--- a/drivers/soundwire/qcom.c
+++ b/drivers/soundwire/qcom.c
@@ -731,17 +731,23 @@ static int qcom_swrm_transport_params(struct sdw_bus *bus,
value |= pcfg->si;

ret = ctrl->reg_write(ctrl, reg, value);
+ if (ret)
+ goto err;

if (pcfg->lane_control != SWR_INVALID_PARAM) {
reg = SWRM_DP_PORT_CTRL_2_BANK(params->port_num, bank);
value = pcfg->lane_control;
ret = ctrl->reg_write(ctrl, reg, value);
+ if (ret)
+ goto err;
}

if (pcfg->blk_group_count != SWR_INVALID_PARAM) {
reg = SWRM_DP_BLOCK_CTRL2_BANK(params->port_num, bank);
value = pcfg->blk_group_count;
ret = ctrl->reg_write(ctrl, reg, value);
+ if (ret)
+ goto err;
}

if (pcfg->hstart != SWR_INVALID_PARAM
@@ -755,11 +761,15 @@ static int qcom_swrm_transport_params(struct sdw_bus *bus,
ret = ctrl->reg_write(ctrl, reg, value);
}

+ if (ret)
+ goto err;
+
if (pcfg->bp_mode != SWR_INVALID_PARAM) {
reg = SWRM_DP_BLOCK_CTRL3_BANK(params->port_num, bank);
ret = ctrl->reg_write(ctrl, reg, pcfg->bp_mode);
}

+err:
return ret;
}

--
2.21.0


2021-04-01 20:45:28

by Kees Cook

[permalink] [raw]
Subject: Re: [PATCH] soundwire: qcom: handle return correctly in qcom_swrm_transport_params

On Thu, Apr 01, 2021 at 10:15:02AM +0100, Srinivas Kandagatla wrote:
> Looks like return from reg_write is set but not checked.
> Fix this by adding error return path.
>
> Reported-by: coverity-bot <[email protected]>
> Addresses-Coverity-ID: 1503591 ("UNUSED_VALUE")
> Fixes: 128eaf937adb ("soundwire: qcom: add support to missing transport params")
> Signed-off-by: Srinivas Kandagatla <[email protected]>

Thanks for fixing this!

Reviewed-by: Kees Cook <[email protected]>

-Kees

> ---
> drivers/soundwire/qcom.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c
> index 5fd4a99cc8ac..348d9a46f850 100644
> --- a/drivers/soundwire/qcom.c
> +++ b/drivers/soundwire/qcom.c
> @@ -731,17 +731,23 @@ static int qcom_swrm_transport_params(struct sdw_bus *bus,
> value |= pcfg->si;
>
> ret = ctrl->reg_write(ctrl, reg, value);
> + if (ret)
> + goto err;
>
> if (pcfg->lane_control != SWR_INVALID_PARAM) {
> reg = SWRM_DP_PORT_CTRL_2_BANK(params->port_num, bank);
> value = pcfg->lane_control;
> ret = ctrl->reg_write(ctrl, reg, value);
> + if (ret)
> + goto err;
> }
>
> if (pcfg->blk_group_count != SWR_INVALID_PARAM) {
> reg = SWRM_DP_BLOCK_CTRL2_BANK(params->port_num, bank);
> value = pcfg->blk_group_count;
> ret = ctrl->reg_write(ctrl, reg, value);
> + if (ret)
> + goto err;
> }
>
> if (pcfg->hstart != SWR_INVALID_PARAM
> @@ -755,11 +761,15 @@ static int qcom_swrm_transport_params(struct sdw_bus *bus,
> ret = ctrl->reg_write(ctrl, reg, value);
> }
>
> + if (ret)
> + goto err;
> +
> if (pcfg->bp_mode != SWR_INVALID_PARAM) {
> reg = SWRM_DP_BLOCK_CTRL3_BANK(params->port_num, bank);
> ret = ctrl->reg_write(ctrl, reg, pcfg->bp_mode);
> }
>
> +err:
> return ret;
> }
>
> --
> 2.21.0
>

--
Kees Cook

2021-04-06 15:47:28

by Vinod Koul

[permalink] [raw]
Subject: Re: [PATCH] soundwire: qcom: handle return correctly in qcom_swrm_transport_params

On 01-04-21, 10:15, Srinivas Kandagatla wrote:
> Looks like return from reg_write is set but not checked.
> Fix this by adding error return path.

Applied, thanks

--
~Vinod