mirror of
https://github.com/apache/nuttx.git
synced 2025-12-16 09:45:18 +08:00
Check return from nxsem_wait_initialize()
Resolution of Issue 619 will require multiple steps, this part of the first step in that resolution: Every call to nxsem_wait_uninterruptible() must handle the return value from nxsem_wait_uninterruptible properly. This commit is only for those files under drivers/usbhost.
This commit is contained in:
committed by
Abdelatif Guettouche
parent
2d13ea7477
commit
d9b42cebe7
@@ -2,35 +2,20 @@
|
||||
* drivers/usbhost/usbhost_devaddr.c
|
||||
* Manage USB device addresses
|
||||
*
|
||||
* Copyright (C) 2013, 2015, 2017 Gregory Nutt. All rights reserved.
|
||||
* Authors: Gregory Nutt <gnutt@nuttx.org>
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
@@ -65,9 +50,9 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void usbhost_takesem(FAR struct usbhost_devaddr_s *devgen)
|
||||
static int usbhost_takesem(FAR struct usbhost_devaddr_s *devgen)
|
||||
{
|
||||
nxsem_wait_uninterruptible(&devgen->exclsem);
|
||||
return nxsem_wait_uninterruptible(&devgen->exclsem);
|
||||
}
|
||||
|
||||
#define usbhost_givesem(devgen) nxsem_post(&devgen->exclsem)
|
||||
@@ -183,8 +168,8 @@ usbhost_roothubport(FAR struct usbhost_hubport_s *hport)
|
||||
|
||||
while (hport->parent != NULL)
|
||||
{
|
||||
/* This is not a root hub port. It is a port on a hub. Try the port of
|
||||
* the parent hub that supports this port.
|
||||
/* This is not a root hub port. It is a port on a hub. Try the port
|
||||
* of the parent hub that supports this port.
|
||||
*/
|
||||
|
||||
hport = hport->parent;
|
||||
@@ -269,6 +254,7 @@ int usbhost_devaddr_create(FAR struct usbhost_hubport_s *hport)
|
||||
{
|
||||
FAR struct usbhost_devaddr_s *devgen;
|
||||
int devaddr;
|
||||
int ret;
|
||||
|
||||
/* Get the address generation data from the root hub port */
|
||||
|
||||
@@ -278,7 +264,11 @@ int usbhost_devaddr_create(FAR struct usbhost_hubport_s *hport)
|
||||
|
||||
/* Get exclusive access to the root hub port device address data */
|
||||
|
||||
usbhost_takesem(devgen);
|
||||
ret = usbhost_takesem(devgen);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Allocate a device address */
|
||||
|
||||
@@ -297,7 +287,8 @@ int usbhost_devaddr_create(FAR struct usbhost_hubport_s *hport)
|
||||
* Name: usbhost_devaddr_destroy
|
||||
*
|
||||
* Description:
|
||||
* Release a device address previously assigned by usbhost_devaddr_create().
|
||||
* Release a device address previously assigned by
|
||||
* usbhost_devaddr_create().
|
||||
*
|
||||
* Input Parameters:
|
||||
* hport - A reference to a hub port structure from which a device has been
|
||||
@@ -309,9 +300,11 @@ int usbhost_devaddr_create(FAR struct usbhost_hubport_s *hport)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void usbhost_devaddr_destroy(FAR struct usbhost_hubport_s *hport, uint8_t devaddr)
|
||||
void usbhost_devaddr_destroy(FAR struct usbhost_hubport_s *hport,
|
||||
uint8_t devaddr)
|
||||
{
|
||||
FAR struct usbhost_devaddr_s *devgen;
|
||||
int ret;
|
||||
|
||||
/* Ignore bad device address */
|
||||
|
||||
@@ -325,7 +318,18 @@ void usbhost_devaddr_destroy(FAR struct usbhost_hubport_s *hport, uint8_t devadd
|
||||
|
||||
/* Get exclusive access to the root hub port device address data */
|
||||
|
||||
usbhost_takesem(devgen);
|
||||
do
|
||||
{
|
||||
ret = usbhost_takesem(devgen);
|
||||
|
||||
/* The only expected error would -ECANCELED meaning that the parent
|
||||
* thread has been canceled. We have to continue and free the
|
||||
* device address in this case.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(ret == OK || ret == -ECANCELED);
|
||||
}
|
||||
while (ret < 0);
|
||||
|
||||
/* Free the device address */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user