Changeset eadaeae8 in mainline for kernel/generic/src/cap/cap.c


Ignore:
Timestamp:
2018-03-21T20:58:49Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3be9d10
Parents:
874381a
Message:

Make capability handles type-safe

Define distinct pointer types for the handles of the supported
capability types and use them instead of integer handles. This makes it
virtually impossible to pass a non-handle or a handle of different type
instead of the proper handle. Also turn cap_handle_t into an "untyped"
capability handle that can be assigned to and from the "typed" handles.

This commit also fixes a bug in msim-con driver, which wrongly used the
IRQ number instead of the IRQ capability handle to unregister the IRQ.

This commit also fixes the wrong use of the capability handle instead
of error code in libusbhost.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/cap/cap.c

    r874381a readaeae8  
    9292{
    9393        cap_t *cap = hash_table_get_inst(item, cap_t, caps_link);
    94         return hash_mix(cap->handle);
     94        return hash_mix(CAP_HANDLE_RAW(cap->handle));
    9595}
    9696
     
    9898{
    9999        cap_handle_t *handle = (cap_handle_t *) key;
    100         return hash_mix(*handle);
     100        return hash_mix(CAP_HANDLE_RAW(*handle));
    101101}
    102102
     
    224224        assert(mutex_locked(&task->cap_info->lock));
    225225
    226         if ((handle < CAPS_START) || (handle > CAPS_LAST))
     226        if ((CAP_HANDLE_RAW(handle) < CAPS_START) ||
     227            (CAP_HANDLE_RAW(handle) > CAPS_LAST))
    227228                return NULL;
    228229        ht_link_t *link = hash_table_find(&task->cap_info->caps, &handle);
     
    329330void cap_free(task_t *task, cap_handle_t handle)
    330331{
    331         assert(handle >= CAPS_START);
    332         assert(handle <= CAPS_LAST);
     332        assert(CAP_HANDLE_RAW(handle) >= CAPS_START);
     333        assert(CAP_HANDLE_RAW(handle) <= CAPS_LAST);
    333334
    334335        mutex_lock(&task->cap_info->lock);
     
    338339
    339340        hash_table_remove_item(&task->cap_info->caps, &cap->caps_link);
    340         ra_free(task->cap_info->handles, handle, 1);
     341        ra_free(task->cap_info->handles, CAP_HANDLE_RAW(handle), 1);
    341342        slab_free(cap_cache, cap);
    342343        mutex_unlock(&task->cap_info->lock);
Note: See TracChangeset for help on using the changeset viewer.