linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Steven Price <steven.price@arm.com>
To: Kangjie Lu <kjlu@umn.edu>
Cc: pakki001@umn.edu, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	Sudeep Holla <sudeep.holla@arm.com>
Subject: Re: [PATCH] firmware: arm_scmi: check return value of idr_find
Date: Mon, 25 Mar 2019 11:54:58 +0000	[thread overview]
Message-ID: <225abd6e-4551-213d-367b-93d938789188@arm.com> (raw)
In-Reply-To: <20190309040239.32431-1-kjlu@umn.edu>

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 <kjlu@umn.edu>
> ---
>  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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2019-03-25 11:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-09  4:02 [PATCH] firmware: arm_scmi: check return value of idr_find Kangjie Lu
2019-03-23  2:18 ` Kangjie Lu
2019-03-25 11:54 ` Steven Price [this message]
2019-03-25 20:48   ` Kangjie Lu
2019-03-26 11:34     ` Steven Price
2019-04-10 16:31     ` Sudeep Holla
2019-04-10 16:25 ` Sudeep Holla

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=225abd6e-4551-213d-367b-93d938789188@arm.com \
    --to=steven.price@arm.com \
    --cc=kjlu@umn.edu \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pakki001@umn.edu \
    --cc=sudeep.holla@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).