Changeset 5f6e25e in mainline
- Timestamp:
- 2011-08-29T23:00:12Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 58cbb0c8
- Parents:
- c5be39b
- Location:
- uspace
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/pci/pciintel/pci.c
rc5be39b r5f6e25e 215 215 }; 216 216 217 static pci_bus_t *pci_bus_new(void)218 {219 pci_bus_t *bus;220 221 bus = (pci_bus_t *) calloc(1, sizeof(pci_bus_t));222 if (bus == NULL)223 return NULL;224 225 fibril_mutex_initialize(&bus->conf_mutex);226 return bus;227 }228 229 static void pci_bus_delete(pci_bus_t *bus)230 {231 assert(bus != NULL);232 free(bus);233 }234 235 217 static void pci_conf_read(pci_fun_t *fun, int reg, uint8_t *buf, size_t len) 236 218 { … … 584 566 dnode->parent_sess = NULL; 585 567 586 bus = pci_bus_new();568 bus = ddf_dev_data_alloc(dnode, sizeof(pci_bus_t)); 587 569 if (bus == NULL) { 588 570 ddf_msg(LVL_ERROR, "pci_add_device allocation failed."); … … 590 572 goto fail; 591 573 } 574 fibril_mutex_initialize(&bus->conf_mutex); 575 592 576 bus->dnode = dnode; 593 577 dnode->driver_data = bus; … … 655 639 656 640 fail: 657 if (bus != NULL)658 pci_bus_delete(bus);659 660 641 if (dnode->parent_sess) 661 642 async_hangup(dnode->parent_sess); -
uspace/drv/bus/usb/uhci/uhci.c
rc5be39b r5f6e25e 192 192 ddf_fun_destroy(instance->rh_fun); \ 193 193 } \ 194 free(instance); \195 194 device->driver_data = NULL; \ 196 195 usb_log_error(message); \ -
uspace/drv/bus/usb/usbhid/kbd/kbddev.c
rc5be39b r5f6e25e 734 734 int rc = usb_kbd_create_function(hid_dev, kbd_dev); 735 735 if (rc != EOK) { 736 usb_kbd_ free(&kbd_dev);736 usb_kbd_destroy(kbd_dev); 737 737 return rc; 738 738 } … … 779 779 * @param kbd_dev Pointer to the structure to be destroyed. 780 780 */ 781 void usb_kbd_ free(usb_kbd_t **kbd_dev)782 { 783 if (kbd_dev == NULL || *kbd_dev == NULL) {781 void usb_kbd_destroy(usb_kbd_t *kbd_dev) 782 { 783 if (kbd_dev == NULL) { 784 784 return; 785 785 } 786 786 787 787 // hangup phone to the console 788 async_obsolete_hangup( (*kbd_dev)->console_phone);789 790 if ( (*kbd_dev)->repeat_mtx != NULL) {788 async_obsolete_hangup(kbd_dev->console_phone); 789 790 if (kbd_dev->repeat_mtx != NULL) { 791 791 //assert(!fibril_mutex_is_locked((*kbd_dev)->repeat_mtx)); 792 792 // FIXME - the fibril_mutex_is_locked may not cause 793 793 // fibril scheduling 794 while (fibril_mutex_is_locked( (*kbd_dev)->repeat_mtx)) {}795 free( (*kbd_dev)->repeat_mtx);794 while (fibril_mutex_is_locked(kbd_dev->repeat_mtx)) {} 795 free(kbd_dev->repeat_mtx); 796 796 } 797 797 798 798 // free all buffers 799 if ((*kbd_dev)->keys != NULL) { 800 free((*kbd_dev)->keys); 801 } 802 if ((*kbd_dev)->keys_old != NULL) { 803 free((*kbd_dev)->keys_old); 804 } 805 if ((*kbd_dev)->led_data != NULL) { 806 free((*kbd_dev)->led_data); 807 } 808 if ((*kbd_dev)->led_path != NULL) { 809 usb_hid_report_path_free((*kbd_dev)->led_path); 810 } 811 if ((*kbd_dev)->output_buffer != NULL) { 812 usb_hid_report_output_free((*kbd_dev)->output_buffer); 813 } 814 815 free(*kbd_dev); 816 *kbd_dev = NULL; 799 if (kbd_dev->keys != NULL) { 800 free(kbd_dev->keys); 801 } 802 if (kbd_dev->keys_old != NULL) { 803 free(kbd_dev->keys_old); 804 } 805 if (kbd_dev->led_data != NULL) { 806 free(kbd_dev->led_data); 807 } 808 if (kbd_dev->led_path != NULL) { 809 usb_hid_report_path_free(kbd_dev->led_path); 810 } 811 if (kbd_dev->output_buffer != NULL) { 812 usb_hid_report_output_free(kbd_dev->output_buffer); 813 } 817 814 } 818 815 … … 830 827 usb_kbd_mark_unusable(kbd_dev); 831 828 } else { 832 usb_kbd_ free(&kbd_dev);829 usb_kbd_destroy(kbd_dev); 833 830 } 834 831 } -
uspace/drv/bus/usb/usbhid/kbd/kbddev.h
rc5be39b r5f6e25e 131 131 int usb_kbd_is_ready_to_destroy(const usb_kbd_t *kbd_dev); 132 132 133 void usb_kbd_ free(usb_kbd_t **kbd_dev);133 void usb_kbd_destroy(usb_kbd_t *kbd_dev); 134 134 135 135 void usb_kbd_push_ev(struct usb_hid_dev *hid_dev, usb_kbd_t *kbd_dev, -
uspace/drv/bus/usb/usbhid/kbd/kbdrepeat.c
rc5be39b r5f6e25e 80 80 if (!usb_kbd_is_initialized(kbd)) { 81 81 if (usb_kbd_is_ready_to_destroy(kbd)) { 82 usb_kbd_free(&kbd); 83 assert(kbd == NULL); 82 usb_kbd_destroy(kbd); 84 83 } 85 84 return; -
uspace/drv/bus/usb/usbhid/main.c
rc5be39b r5f6e25e 93 93 if (rc != EOK) { 94 94 usb_log_error("Failed to initialize USB/HID device.\n"); 95 usb_hid_ free(&hid_dev);95 usb_hid_destroy(hid_dev); 96 96 return rc; 97 97 } -
uspace/drv/bus/usb/usbhid/mouse/mousedev.c
rc5be39b r5f6e25e 183 183 /*----------------------------------------------------------------------------*/ 184 184 185 static void usb_mouse_ free(usb_mouse_t **mouse_dev)186 { 187 assert(mouse_dev != NULL && *mouse_dev != NULL);185 static void usb_mouse_destroy(usb_mouse_t *mouse_dev) 186 { 187 assert(mouse_dev != NULL); 188 188 189 189 // hangup phone to the console 190 if ((*mouse_dev)->mouse_phone >= 0) { 191 async_obsolete_hangup((*mouse_dev)->mouse_phone); 192 } 193 194 if ((*mouse_dev)->wheel_phone >= 0) { 195 async_obsolete_hangup((*mouse_dev)->wheel_phone); 196 } 197 198 free(*mouse_dev); 199 *mouse_dev = NULL; 190 if (mouse_dev->mouse_phone >= 0) { 191 async_obsolete_hangup(mouse_dev->mouse_phone); 192 } 193 194 if (mouse_dev->wheel_phone >= 0) { 195 async_obsolete_hangup(mouse_dev->wheel_phone); 196 } 200 197 } 201 198 … … 437 434 int rc = usb_mouse_create_function(hid_dev, mouse_dev); 438 435 if (rc != EOK) { 439 usb_mouse_ free(&mouse_dev);436 usb_mouse_destroy(mouse_dev); 440 437 return rc; 441 438 } … … 464 461 { 465 462 if (data != NULL) { 466 usb_mouse_ free((usb_mouse_t **)&data);463 usb_mouse_destroy((usb_mouse_t *)data); 467 464 } 468 465 } -
uspace/drv/bus/usb/usbhid/multimedia/multimedia.c
rc5be39b r5f6e25e 167 167 /*----------------------------------------------------------------------------*/ 168 168 169 static void usb_multimedia_free(usb_multimedia_t **multim_dev)170 {171 if (multim_dev == NULL || *multim_dev == NULL) {172 return;173 }174 175 // hangup phone to the console176 async_obsolete_hangup((*multim_dev)->console_phone);177 178 free(*multim_dev);179 *multim_dev = NULL;180 }181 182 /*----------------------------------------------------------------------------*/183 184 169 static int usb_multimedia_create_function(usb_hid_dev_t *hid_dev, 185 170 usb_multimedia_t *multim_dev) … … 247 232 248 233 int rc = usb_multimedia_create_function(hid_dev, multim_dev); 249 if (rc != EOK) { 250 usb_multimedia_free(&multim_dev); 234 if (rc != EOK) 251 235 return rc; 252 }253 236 254 237 usb_log_debug(NAME " HID/multimedia structure initialized.\n"); … … 267 250 if (data != NULL) { 268 251 usb_multimedia_t *multim_dev = (usb_multimedia_t *)data; 269 usb_multimedia_free(&multim_dev); 252 // hangup phone to the console 253 async_obsolete_hangup(multim_dev->console_phone); 270 254 } 271 255 } -
uspace/drv/bus/usb/usbhid/usbhid.c
rc5be39b r5f6e25e 627 627 } 628 628 629 usb_hid_ free(&hid_dev);629 usb_hid_destroy(hid_dev); 630 630 } 631 631 … … 646 646 /*----------------------------------------------------------------------------*/ 647 647 648 void usb_hid_ free(usb_hid_dev_t **hid_dev)648 void usb_hid_destroy(usb_hid_dev_t *hid_dev) 649 649 { 650 650 int i; 651 651 652 if (hid_dev == NULL || *hid_dev == NULL) {652 if (hid_dev == NULL) { 653 653 return; 654 654 } 655 655 656 656 usb_log_debug("Subdrivers: %p, subdriver count: %d\n", 657 (*hid_dev)->subdrivers, (*hid_dev)->subdriver_count);658 659 assert( (*hid_dev)->subdrivers != NULL660 || (*hid_dev)->subdriver_count == 0);661 662 for (i = 0; i < (*hid_dev)->subdriver_count; ++i) {663 if ( (*hid_dev)->subdrivers[i].deinit != NULL) {664 (*hid_dev)->subdrivers[i].deinit(*hid_dev,665 (*hid_dev)->subdrivers[i].data);657 hid_dev->subdrivers, hid_dev->subdriver_count); 658 659 assert(hid_dev->subdrivers != NULL 660 || hid_dev->subdriver_count == 0); 661 662 for (i = 0; i < hid_dev->subdriver_count; ++i) { 663 if (hid_dev->subdrivers[i].deinit != NULL) { 664 hid_dev->subdrivers[i].deinit(hid_dev, 665 hid_dev->subdrivers[i].data); 666 666 } 667 667 } 668 668 669 669 // free the subdrivers info 670 if ( (*hid_dev)->subdrivers != NULL) {671 free( (*hid_dev)->subdrivers);670 if (hid_dev->subdrivers != NULL) { 671 free(hid_dev->subdrivers); 672 672 } 673 673 674 674 // destroy the parser 675 if ((*hid_dev)->report != NULL) { 676 usb_hid_free_report((*hid_dev)->report); 677 } 678 679 if ((*hid_dev)->report_desc != NULL) { 680 free((*hid_dev)->report_desc); 681 } 682 683 free(*hid_dev); 684 *hid_dev = NULL; 675 if (hid_dev->report != NULL) { 676 usb_hid_free_report(hid_dev->report); 677 } 678 679 if (hid_dev->report_desc != NULL) { 680 free(hid_dev->report_desc); 681 } 685 682 } 686 683 -
uspace/drv/bus/usb/usbhid/usbhid.h
rc5be39b r5f6e25e 158 158 int usb_hid_report_number(usb_hid_dev_t *hid_dev); 159 159 160 void usb_hid_ free(usb_hid_dev_t **hid_dev);160 void usb_hid_destroy(usb_hid_dev_t *hid_dev); 161 161 162 162 #endif /* USB_HID_USBHID_H_ */ -
uspace/drv/bus/usb/usbmast/main.c
rc5be39b r5f6e25e 145 145 usbmast_fun_t *mfun = NULL; 146 146 147 /* Allocate softstate */148 mfun = calloc(1, sizeof(usbmast_fun_t));149 if (mfun == NULL) {150 usb_log_error("Failed allocating softstate.\n");151 rc = ENOMEM;152 goto error;153 }154 155 mfun->mdev = mdev;156 mfun->lun = lun;157 158 147 if (asprintf(&fun_name, "l%u", lun) < 0) { 159 148 usb_log_error("Out of memory.\n"); … … 170 159 171 160 free(fun_name); 161 162 /* Allocate soft state */ 163 mfun = ddf_dev_data_alloc(mdev->ddf_dev, sizeof(usbmast_fun_t)); 164 if (mfun == NULL) { 165 usb_log_error("Failed allocating softstate.\n"); 166 rc = ENOMEM; 167 goto error; 168 } 169 170 mfun->mdev = mdev; 171 mfun->lun = lun; 172 172 173 fun_name = NULL; 173 174 … … 227 228 if (fun_name != NULL) 228 229 free(fun_name); 229 if (mfun != NULL)230 free(mfun);231 230 return rc; 232 231 } -
uspace/drv/char/ns8250/ns8250.c
rc5be39b r5f6e25e 112 112 fibril_mutex_t mutex; 113 113 } ns8250_t; 114 115 /** Create per-device soft-state structure.116 *117 * @return Pointer to soft-state structure.118 */119 static ns8250_t *ns8250_new(void)120 {121 ns8250_t *ns;122 123 ns = (ns8250_t *) calloc(1, sizeof(ns8250_t));124 if (ns == NULL)125 return NULL;126 127 fibril_mutex_initialize(&ns->mutex);128 return ns;129 }130 131 /** Delete soft-state structure.132 *133 * @param ns The driver data structure.134 */135 static void ns8250_delete(ns8250_t *ns)136 {137 assert(ns != NULL);138 free(ns);139 }140 114 141 115 /** Find out if there is some incomming data available on the serial port. … … 721 695 722 696 /* Allocate soft-state for the device */ 723 ns = ns8250_new();697 ns = ddf_dev_data_alloc(dev, sizeof(ns8250_t)); 724 698 if (ns == NULL) { 725 699 rc = ENOMEM; … … 727 701 } 728 702 703 fibril_mutex_initialize(&ns->mutex); 729 704 ns->dev = dev; 730 dev->driver_data = ns;731 705 732 706 rc = ns8250_dev_initialize(ns); … … 792 766 if (need_cleanup) 793 767 ns8250_dev_cleanup(ns); 794 if (ns != NULL)795 ns8250_delete(ns);796 768 return rc; 797 769 } -
uspace/lib/drv/generic/driver.c
rc5be39b r5f6e25e 642 642 static void delete_device(ddf_dev_t *dev) 643 643 { 644 if (dev->driver_data != NULL) 645 free(dev->driver_data); 644 646 free(dev); 645 647 } … … 652 654 { 653 655 clean_match_ids(&fun->match_ids); 656 if (fun->driver_data != NULL) 657 free(fun->driver_data); 654 658 if (fun->name != NULL) 655 659 free(fun->name);
Note:
See TracChangeset
for help on using the changeset viewer.