On 09/03/2019 04:02, Kangjie Lu wrote:
> idr_find may return NULL, so check its return value and return an
> error code.
> 
> Signed-off-by: Kangjie Lu <[email protected]>
> ---
>  drivers/firmware/arm_scmi/driver.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/firmware/arm_scmi/driver.c 
> b/drivers/firmware/arm_scmi/driver.c
> index 8f952f2f1a29..35faa203d549 100644
> --- a/drivers/firmware/arm_scmi/driver.c
> +++ b/drivers/firmware/arm_scmi/driver.c
> @@ -709,6 +709,8 @@ scmi_mbox_chan_setup(struct scmi_info *info, struct 
> device *dev, int prot_id)
>  
>       if (scmi_mailbox_check(np)) {
>               cinfo = idr_find(&info->tx_idr, SCMI_PROTOCOL_BASE);
> +             if (!cinfo)
> +                     return -EINVAL;
>               goto idr_alloc;
>       }
>  
> 

I don't believe this situation can ever actually occur. The
SCMI_PROTOCOL_BASE id is reserved just after the IDR is created in
scmi_probe() in the first call to scmi_mbox_chan_setup(). That first
call can't enter the above if() block because the scmi_mailbox_check()
call has already been checked in scmi_probe(). It is only when
processing the children in subsequent calls to scmi_mbox_chan_setup()
that the check is on another node and so might fail. But by this time
the SCMI_PROTOCOL_BASE id must exist.

So there shouldn't be any way of reaching the situation where the IDR
doesn't contain SCMI_PROTOCOL_BASE and idr_find() returns NULL.

Having said that it did take me a while to understand the code well
enough to reason that, and the above return should be handled
appropriately, so you can add my Reviewed-by. But it would be worth
expanding the commit message pointing out that there isn't actually a
bug (yet).

Steve

Reply via email to