diff mbox series

firmware: arm_scmi: check return value of idr_find

Message ID 20190325204823.5428-1-kjlu@umn.edu (mailing list archive)
State New, archived
Headers show
Series firmware: arm_scmi: check return value of idr_find | expand

Commit Message

Kangjie Lu March 25, 2019, 8:48 p.m. UTC
Thanks for Steven Price's review of this patch. In the current code,
idr_find won't return NULL because the SCMI_PROTOCOL_BASE id must 
exist. However, it might return NULL in the future code if the check
is on another node while processing the children in subsequent calls 
to scmi_mbox_chan_setup().
Therefore, the patch conservatively checks the return value and 
returns -EINVAL when it indeed failed.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
Reviewed-by: Steven Price <steven.price@arm.com>
---
 drivers/firmware/arm_scmi/driver.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Steven Price March 26, 2019, 11:34 a.m. UTC | #1
On 25/03/2019 20:48, Kangjie Lu wrote:
> Thanks for Steven Price's review of this patch. In the current code,

There's no need to include a "thanks" message in the commit message -
the "Reviewed-by" tag is sufficient. Please also remember to include an
appropriate version tag in the subject - this should be "v2".

Thanks,

Steve

> idr_find won't return NULL because the SCMI_PROTOCOL_BASE id must 
> exist. However, it might return NULL in the future code if the check
> is on another node while processing the children in subsequent calls 
> to scmi_mbox_chan_setup().
> Therefore, the patch conservatively checks the return value and 
> returns -EINVAL when it indeed failed.
> 
> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
> Reviewed-by: Steven Price <steven.price@arm.com>
> ---
>  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;
>  	}
>  
>
Sudeep Holla April 10, 2019, 4:31 p.m. UTC | #2
On Mon, Mar 25, 2019 at 03:48:22PM -0500, Kangjie Lu wrote:

You should mark this v2 id you changed any code or commit message or
added any tags. Just FYI for future.

> Thanks for Steven Price's review of this patch. In the current code,
> idr_find won't return NULL because the SCMI_PROTOCOL_BASE id must 
> exist. However, it might return NULL in the future code if the check
> is on another node while processing the children in subsequent calls 
> to scmi_mbox_chan_setup().

I don't understand the reference here to future code here. If you have
out of tree code that results in such a scenario, please share or
provide the details on that.

As I mentioned in previous mail, I would bail out much earlier if
SCMI_PROTOCOL_BASE is not allocated IDR and not reach to this point.
We continue even if scmi_create_protocol_device fails for few child
devices.

--
Regards,
Sudeep
diff mbox series

Patch

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;
 	}