Re: [PATCH] misc: fastrpc: Fix double free of 'buf' in error path

From: Dan Carpenter
Date: Fri May 19 2023 - 06:58:24 EST


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