[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <fa0e9d9d-6362-456b-87f7-990ccf7e8930@kili.mountain>
Date: Fri, 19 May 2023 13:58:10 +0300
From: Dan Carpenter <dan.carpenter@...aro.org>
To: Srinivas Kandagatla <srinivas.kandagatla@...aro.org>
Cc: Sukrut Bellary <sukrut.bellary@...ux.com>,
Abel Vesa <abel.vesa@...aro.org>,
Amol Maheshwari <amahesh@....qualcomm.com>,
Arnd Bergmann <arnd@...db.de>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
linux-arm-msm@...r.kernel.org, linux-kernel@...r.kernel.org,
kernel-janitors@...r.kernel.org,
Shuah Khan <skhan@...uxfoundation.org>
Subject: Re: [PATCH] misc: fastrpc: Fix double free of 'buf' in error path
This is unrelated but I was looking through the driver and I notice
a bunch of code doing:
grep 'return ret ?' drivers/firmware/ -R
return ret ? : res.result[0];
"ret" here is a kernel error code, and res.result[0] is a firmware
error code. Mixing error codes is a dangerous thing. I was reviewing
some of the callers and the firmware error code gets passed quite far
back into the kernel to where we would only expect kernel error codes.
Presumably the firmware is returning positive error codes? To be honest,
I am just guessing. It's better to convert custom error codes to kernel
error codes as soon as possible. I am just guessing. Sukrut, do you
think you could take a look? If the callers do not differentiate
between negative kernel error codes and positive custom error codes then
probably just do:
if (res.result[0])
ret = -EIO; // -EINVAL?
return ret;
Also there are a couple places which do:
return ret ? false : !!res.result[0];
Here true means success and false means failure. So the !! converts
a firmware error code to true when it should be false so that's a bug.
Quadruple negatives are confusing... It should be:
if (ret || res.result[0])
return false;
return true;
regards,
dan carpenter
Powered by blists - more mailing lists