Changeset 6e6dc7d in mainline


Ignore:
Timestamp:
2011-02-20T17:31:21Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
51f0e410
Parents:
c723b772
Message:

Refactoring of match id creation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/src/recognise.c

    rc723b772 r6e6dc7d  
    112112}
    113113
     114#define ADD_MATCHID_OR_RETURN(match_ids, score, format, ...) \
     115        do { \
     116                int __rc = usb_add_match_id((match_ids), (score), \
     117                    format, ##__VA_ARGS__); \
     118                if (__rc != EOK) { \
     119                        return __rc; \
     120                } \
     121        } while (0)
     122
    114123/** Create device match ids based on its interface.
    115124 *
     
    131140        }
    132141
    133         int rc;
    134 
    135142        if (descriptor->interface_class == USB_CLASS_USE_INTERFACE) {
    136143                return ENOENT;
     
    140147        assert(classname != NULL);
    141148
    142         rc = usb_add_match_id(matches, 50,
     149        ADD_MATCHID_OR_RETURN(matches, 50,
    143150            "usb&interface&class=%s",
    144151            classname);
    145         if (rc != EOK) {
    146                 return rc;
    147         }
    148 
    149         rc = usb_add_match_id(matches, 70,
     152        ADD_MATCHID_OR_RETURN(matches, 70,
    150153            "usb&interface&class=%s&subclass=0x%02x",
    151154            classname, descriptor->interface_subclass);
    152         if (rc != EOK) {
    153                 return rc;
    154         }
    155 
    156         rc = usb_add_match_id(matches, 100,
     155        ADD_MATCHID_OR_RETURN(matches, 100,
    157156            "usb&interface&class=%s&subclass=0x%02x&protocol=0x%02x",
    158157            classname, descriptor->interface_subclass,
    159158            descriptor->interface_protocol);
    160159
    161         return rc;
     160        return EOK;
    162161}
    163162
     
    172171    const usb_standard_device_descriptor_t *device_descriptor)
    173172{
    174         int rc;
    175        
    176173        /*
    177174         * Unless the vendor id is 0, the pair idVendor-idProduct
     
    180177        if (device_descriptor->vendor_id != 0) {
    181178                /* First, with release number. */
    182                 rc = usb_add_match_id(matches, 100,
     179                ADD_MATCHID_OR_RETURN(matches, 100,
    183180                    "usb&vendor=0x%04x&product=0x%04x&release=" BCD_FMT,
    184181                    (int) device_descriptor->vendor_id,
    185182                    (int) device_descriptor->product_id,
    186183                    BCD_ARGS(device_descriptor->device_version));
    187                 if (rc != EOK) {
    188                         return rc;
    189                 }
    190184               
    191185                /* Next, without release number. */
    192                 rc = usb_add_match_id(matches, 90,
     186                ADD_MATCHID_OR_RETURN(matches, 90,
    193187                    "usb&vendor=0x%04x&product=0x%04x",
    194188                    (int) device_descriptor->vendor_id,
    195189                    (int) device_descriptor->product_id);
    196                 if (rc != EOK) {
    197                         return rc;
    198                 }
    199190        }       
    200191
     
    204195         */
    205196        if (device_descriptor->device_class != USB_CLASS_USE_INTERFACE) {
    206                 rc = usb_add_match_id(matches, 50, "usb&class=%s",
     197                ADD_MATCHID_OR_RETURN(matches, 50, "usb&class=%s",
    207198                    usb_str_class(device_descriptor->device_class));
    208                 if (rc != EOK) {
    209                         return rc;
    210                 }
    211199        } else {
    212                 rc = usb_add_match_id(matches, 50, "usb&mid");
    213                 if (rc != EOK) {
    214                         return rc;
    215                 }
     200                ADD_MATCHID_OR_RETURN(matches, 50, "usb&mid");
    216201        }
    217202       
     
    260245                    current_descriptor;
    261246               
    262                 int rc = usb_add_match_id(matches, 50,
     247                ADD_MATCHID_OR_RETURN(matches, 50,
    263248                    "usb&interface&class=%s",
    264249                    usb_str_class(interface->interface_class));
    265                 if (rc != EOK) {
    266                         return rc;
    267                 }
    268250        }
    269251       
     
    367349         * As a fallback, provide the simplest match id possible.
    368350         */
    369         rc = usb_add_match_id(matches, 1, "usb&fallback");
    370         if (rc != EOK) {
    371                 return rc;
    372         }
     351        ADD_MATCHID_OR_RETURN(matches, 1, "usb&fallback");
    373352
    374353        return EOK;
Note: See TracChangeset for help on using the changeset viewer.