Changeset 5823525e in mainline for uspace/drv/bus/usb/usbmid/main.c


Ignore:
Timestamp:
2018-01-12T11:01:38Z (6 years ago)
Author:
Petr Manek <petr.manek@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
46c5dc2
Parents:
bb1e968
git-author:
Petr Manek <petr.manek@…> (2018-01-12 11:01:33)
git-committer:
Petr Manek <petr.manek@…> (2018-01-12 11:01:38)
Message:

usbmid: refactoring

Redistributed code between device_remove(), _removed() and _gone() in
order to minimize redundancy and improve efficient design.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbmid/main.c

    rbb1e968 r5823525e  
    7777
    7878        /* Remove all children */
     79        list_foreach(usb_mid->interface_list, link, usbmid_interface_t, iface) {
     80                usb_log_info("Removing child `%s'.\n",
     81                    ddf_fun_get_name(iface->fun));
     82
     83                /* Tell the child to go offline. */
     84                int pret = ddf_fun_offline(iface->fun);
     85                if (pret != EOK) {
     86                        usb_log_warning("Failed to turn off child `%s': %s\n",
     87                            ddf_fun_get_name(iface->fun), str_error(pret));
     88                        ret = pret;
     89                }
     90        }
     91
     92        return ret;
     93}
     94
     95static int destroy_interfaces(usb_mid_t *usb_mid)
     96{
     97        int ret = EOK;
     98
    7999        while (!list_empty(&usb_mid->interface_list)) {
    80100                link_t *item = list_first(&usb_mid->interface_list);
     
    83103                usbmid_interface_t *iface = usbmid_interface_from_link(item);
    84104
    85                 usb_log_info("Removing child `%s'.\n",
    86                     ddf_fun_get_name(iface->fun));
    87 
    88                 /* Tell the child to go off-line. */
    89                 int pret = ddf_fun_offline(iface->fun);
     105                const int pret = usbmid_interface_destroy(iface);
    90106                if (pret != EOK) {
    91                         usb_log_warning("Failed to turn off child `%s': %s\n",
    92                             ddf_fun_get_name(iface->fun), str_error(pret));
    93                         ret = pret;
    94                 }
    95 
    96                 /* Now remove the child. */
    97                 pret = usbmid_interface_destroy(iface);
    98                 if (pret != EOK) {
    99                         usb_log_error("Failed to destroy child `%s': %s\n",
     107                        usb_log_error("Failed to remove child `%s': %s\n",
    100108                            ddf_fun_get_name(iface->fun), str_error(pret));
    101109                        ret = pret;
    102110                }
    103111        }
     112
    104113        return ret;
    105114}
     
    107116static int usbmid_device_removed(usb_device_t *dev)
    108117{
    109         // TODO: Implement me!
    110         return EOK;
     118        assert(dev);
     119        usb_mid_t *usb_mid = usb_device_data_get(dev);
     120        assert(usb_mid);
     121
     122        /* Children are offline. Destroy them now. */
     123        return destroy_interfaces(usb_mid);
    111124}
    112125
     
    133146        ddf_fun_destroy(usb_mid->ctl_fun);
    134147
    135         /* Now remove all other functions */
    136         while (!list_empty(&usb_mid->interface_list)) {
    137                 link_t *item = list_first(&usb_mid->interface_list);
    138                 list_remove(item);
    139 
    140                 usbmid_interface_t *iface = usbmid_interface_from_link(item);
    141 
    142                 usb_log_info("Child `%s' is gone.\n",
    143                     ddf_fun_get_name(iface->fun));
    144 
    145                 const int pret = usbmid_interface_destroy(iface);
    146                 if (pret != EOK) {
    147                         usb_log_error("Failed to remove child `%s': %s\n",
    148                             ddf_fun_get_name(iface->fun), str_error(pret));
    149                         ret = pret;
    150                 }
    151         }
    152         return ret;
     148        /* Destroy children and tell their drivers they are gone. */
     149        return destroy_interfaces(usb_mid);
    153150}
    154151
Note: See TracChangeset for help on using the changeset viewer.