Re: [PATCH v3 1/2] RDMA/hfi1: Fix error return code in parse_platform_config()

From: wangyufen
Date: Mon Nov 28 2022 - 20:30:37 EST




在 2022/11/28 19:57, Leon Romanovsky 写道:
On Sat, Nov 26, 2022 at 09:50:53PM +0800, Wang Yufen wrote:
In the previous while loop, "ret" may be assigned zero, so the error
return code may be incorrectly set to 0 instead of -EINVAL.
Add bail_with_einval goto label and covert all "goto bail;" to "goto
bail_with_einval:" where it's appropriate. Add dropping some duplicative
"ret = -EINVAL;" lines, as Andy suggessted.

Fixes: 97167e813415 ("staging/rdma/hfi1: Tune for unknown channel if configuration file is absent")
Signed-off-by: Wang Yufen <wangyufen@xxxxxxxxxx>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
---
drivers/infiniband/hw/hfi1/firmware.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)

<...>


+bail_with_einval:
+ ret = -EINVAL;

Sorry for being late, but no. It can be seen as anti-pattern as it
causes to the situations where unrelated code changes can potentially
overwrite return value. Please set valid return code before calling to
goto.

OK, will change in v4.
Thanks

Thanks

bail:
memset(pcfgcache, 0, sizeof(struct platform_config_cache));
return ret;
--
1.8.3.1