[U-Boot] [PATCH 1/1] dm: usb: ehci: avoid possible NULL dereference
Marek Vasut
marex at denx.de
Mon Nov 20 14:42:08 UTC 2017
On 11/20/2017 03:39 PM, Heinrich Schuchardt wrote:
>
>
> On 11/20/2017 01:47 AM, Marek Vasut wrote:
>> On 11/19/2017 11:42 PM, Heinrich Schuchardt wrote:
>>> It is unwise to first dereference a pointer and
>>> afterwards to check if it was NULL.
>>
>> The check is still incomplete, the hccr is not checked.
>
> Thanks for reviewing.
>
> Depending on CONFIG_DM_USB ctrl->hccr is set in ehci_register or in
> usb_lowlevel_init.
>
> There are other functions (ehci_get_portsc_register, ehci_submit_root,
> ehci_common_init) on ctrl->hccr != NULL too.
>
> Shouldn't we check(!ctrl || !ctrl->hcor || !ctrl->hccr) in ehci_register
> and usb_lowlevel_init instead of checking it in ehci_shutdown?
Sounds good
> Best regards
>
> Heinrich
>
>>
>>> Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
>>> ---
>>> drivers/usb/host/ehci-hcd.c | 4 +++-
>>> 1 file changed, 3 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
>>> index be3e842dcc..80bc8219af 100644
>>> --- a/drivers/usb/host/ehci-hcd.c
>>> +++ b/drivers/usb/host/ehci-hcd.c
>>> @@ -208,11 +208,13 @@ static int ehci_shutdown(struct ehci_ctrl *ctrl)
>>> {
>>> int i, ret = 0;
>>> uint32_t cmd, reg;
>>> - int max_ports = HCS_N_PORTS(ehci_readl(&ctrl->hccr->cr_hcsparams));
>>> + int max_ports;
>>> if (!ctrl || !ctrl->hcor)
>>> return -EINVAL;
>>> + max_ports = HCS_N_PORTS(ehci_readl(&ctrl->hccr->cr_hcsparams));
>>> +
>>> cmd = ehci_readl(&ctrl->hcor->or_usbcmd);
>>> /* If not run, directly return */
>>> if (!(cmd & CMD_RUN))
>>>
>>
>>
--
Best regards,
Marek Vasut
More information about the U-Boot
mailing list