Changeset e27c2476 in mainline


Ignore:
Timestamp:
2011-10-29T20:37:48Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
96ec0a9
Parents:
c44a5f1
Message:

usbhub: Fix double free in error paths.

Remove redundant usb_hub_dev_create.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbhub/usbhub.c

    rc44a5f1 re27c2476  
    6868
    6969static int usb_set_first_configuration(usb_device_t *usb_device);
    70 static usb_hub_dev_t * usb_hub_dev_create(usb_device_t *usb_dev);
    7170static int usb_hub_process_hub_specific_info(usb_hub_dev_t *hub_dev);
    7271static void usb_hub_over_current(const usb_hub_dev_t *hub_dev,
     
    133132        assert(usb_dev);
    134133        /* Create driver soft-state structure */
    135         usb_hub_dev_t *hub_dev = usb_hub_dev_create(usb_dev);
     134        usb_hub_dev_t *hub_dev =
     135            usb_device_data_alloc(usb_dev, sizeof(usb_hub_dev_t));
    136136        if (hub_dev == NULL) {
    137137                usb_log_error("Failed to create hun driver structure.\n");
    138138                return ENOMEM;
    139139        }
     140        hub_dev->usb_device = usb_dev;
     141        hub_dev->pending_ops_count = 0;
     142        hub_dev->running = false;
     143        fibril_mutex_initialize(&hub_dev->pending_ops_mutex);
     144        fibril_condvar_initialize(&hub_dev->pending_ops_cv);
    140145
    141146        /* Create hc connection */
     
    146151                usb_log_error("Could not initialize connection to device: %s\n",
    147152                    str_error(opResult));
    148                 free(hub_dev);
    149153                return opResult;
    150154        }
     
    155159                usb_log_error("Could not set hub configuration: %s\n",
    156160                    str_error(opResult));
    157                 free(hub_dev);
    158161                return opResult;
    159162        }
     
    164167                usb_log_error("Could process hub specific info, %s\n",
    165168                    str_error(opResult));
    166                 free(hub_dev);
    167169                return opResult;
    168170        }
     
    173175        if (hub_dev->hub_fun == NULL) {
    174176                usb_log_error("Failed to create hub function.\n");
    175                 free(hub_dev);
    176177                return ENOMEM;
    177178        }
     
    181182                usb_log_error("Failed to bind hub function: %s.\n",
    182183                   str_error(opResult));
    183                 free(hub_dev);
    184184                ddf_fun_destroy(hub_dev->hub_fun);
    185185                return opResult;
     
    193193                ddf_fun_unbind(hub_dev->hub_fun);
    194194                ddf_fun_destroy(hub_dev->hub_fun);
    195                 free(hub_dev);
    196195                usb_log_error("Failed to create polling fibril: %s.\n",
    197196                    str_error(opResult));
     
    240239        }
    241240        return true;
    242 }
    243 /*----------------------------------------------------------------------------*/
    244 /**
    245  * create usb_hub_dev_t structure
    246  *
    247  * Does only basic copying of known information into new structure.
    248  * @param usb_dev usb device structure
    249  * @return basic usb_hub_dev_t structure
    250  */
    251 static usb_hub_dev_t * usb_hub_dev_create(usb_device_t *usb_dev)
    252 {
    253         assert(usb_dev);
    254         usb_hub_dev_t *hub_dev =
    255             usb_device_data_alloc(usb_dev, sizeof(usb_hub_dev_t));
    256         if (!hub_dev)
    257             return NULL;
    258 
    259         hub_dev->usb_device = usb_dev;
    260         hub_dev->ports = NULL;
    261         hub_dev->port_count = 0;
    262         hub_dev->pending_ops_count = 0;
    263         hub_dev->running = false;
    264         fibril_mutex_initialize(&hub_dev->pending_ops_mutex);
    265         fibril_condvar_initialize(&hub_dev->pending_ops_cv);
    266 
    267         return hub_dev;
    268241}
    269242/*----------------------------------------------------------------------------*/
Note: See TracChangeset for help on using the changeset viewer.