2020-11-25 06:48:36

by Qinglang Miao

[permalink] [raw]
Subject: [PATCH] soundwire: Fix error return code in sdw_compute_port_params

Fix to return the error code -EINVAL in sdw_compute_port_params
instead of 0.

Fixes: 9026118f20e2 ("soundwire: Add generic bandwidth allocation algorithm")
Reported-by: Hulk Robot <[email protected]>
Signed-off-by: Qinglang Miao <[email protected]>
---
drivers/soundwire/generic_bandwidth_allocation.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/soundwire/generic_bandwidth_allocation.c b/drivers/soundwire/generic_bandwidth_allocation.c
index 0bdef38c9..ad857ac62 100644
--- a/drivers/soundwire/generic_bandwidth_allocation.c
+++ b/drivers/soundwire/generic_bandwidth_allocation.c
@@ -283,8 +283,10 @@ static int sdw_compute_port_params(struct sdw_bus *bus)
if (ret < 0)
return ret;

- if (group.count == 0)
+ if (group.count == 0) {
+ ret = -EINVAL;
goto out;
+ }

params = kcalloc(group.count, sizeof(*params), GFP_KERNEL);
if (!params) {
--
2.23.0


2020-11-30 20:54:49

by Pierre-Louis Bossart

[permalink] [raw]
Subject: Re: [PATCH] soundwire: Fix error return code in sdw_compute_port_params



On 11/25/20 12:50 AM, Qinglang Miao wrote:
> Fix to return the error code -EINVAL in sdw_compute_port_params
> instead of 0.
>
> Fixes: 9026118f20e2 ("soundwire: Add generic bandwidth allocation algorithm")
> Reported-by: Hulk Robot <[email protected]>
> Signed-off-by: Qinglang Miao <[email protected]>

Thanks for the patch.
The test covers a very unlikely error scenario but nevertheless not a
zero probability so the suggested fix makes sense to me.

Reviewed-by: Pierre-Louis Bossart <[email protected]>

> ---
> drivers/soundwire/generic_bandwidth_allocation.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/soundwire/generic_bandwidth_allocation.c b/drivers/soundwire/generic_bandwidth_allocation.c
> index 0bdef38c9..ad857ac62 100644
> --- a/drivers/soundwire/generic_bandwidth_allocation.c
> +++ b/drivers/soundwire/generic_bandwidth_allocation.c
> @@ -283,8 +283,10 @@ static int sdw_compute_port_params(struct sdw_bus *bus)
> if (ret < 0)
> return ret;
>
> - if (group.count == 0)
> + if (group.count == 0) {
> + ret = -EINVAL;
> goto out;
> + }
>
> params = kcalloc(group.count, sizeof(*params), GFP_KERNEL);
> if (!params) {
>