Skip to content

Commit

Permalink
staging: tidspbridge: remove DBC_ENSURE and DBC_REQUIRED
Browse files Browse the repository at this point in the history
The kernel does not use a "Design by Contract" approach, and it is only
activated in the module if CONFIG_TIDSPBRDIGE_DEBUG is enabled, so they are
executed rarely. It is better to remove them: less code to maintain.

Signed-off-by: Víctor Manuel Jáquez Leal <vjaquez@igalia.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Víctor Manuel Jáquez Leal authored and Greg Kroah-Hartman committed Feb 9, 2012
1 parent 8900f00 commit 276cc74
Show file tree
Hide file tree
Showing 24 changed files with 3 additions and 946 deletions.
19 changes: 1 addition & 18 deletions drivers/staging/tidspbridge/core/chnl_sm.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,6 @@ int bridge_chnl_create(struct chnl_mgr **channel_mgr,
struct chnl_mgr *chnl_mgr_obj = NULL;
u8 max_channels;

/* Check DBC requirements: */
DBC_REQUIRE(channel_mgr != NULL);
DBC_REQUIRE(mgr_attrts != NULL);
DBC_REQUIRE(mgr_attrts->max_channels > 0);
DBC_REQUIRE(mgr_attrts->max_channels <= CHNL_MAXCHANNELS);
DBC_REQUIRE(mgr_attrts->word_size != 0);

/* Allocate channel manager object */
chnl_mgr_obj = kzalloc(sizeof(struct chnl_mgr), GFP_KERNEL);
if (chnl_mgr_obj) {
Expand Down Expand Up @@ -491,7 +484,6 @@ int bridge_chnl_flush_io(struct chnl_object *chnl_obj, u32 timeout)
pchnl->state &= ~CHNL_STATECANCEL;
}
}
DBC_ENSURE(status || list_empty(&pchnl->io_requests));
return status;
}

Expand Down Expand Up @@ -705,8 +697,6 @@ int bridge_chnl_idle(struct chnl_object *chnl_obj, u32 timeout,
struct chnl_mgr *chnl_mgr_obj;
int status = 0;

DBC_REQUIRE(chnl_obj);

chnl_mode = chnl_obj->chnl_mode;
chnl_mgr_obj = chnl_obj->chnl_mgr_obj;

Expand Down Expand Up @@ -736,10 +726,7 @@ int bridge_chnl_open(struct chnl_object **chnl,
struct chnl_mgr *chnl_mgr_obj = hchnl_mgr;
struct chnl_object *pchnl = NULL;
struct sync_object *sync_event = NULL;
/* Ensure DBC requirements: */
DBC_REQUIRE(chnl != NULL);
DBC_REQUIRE(pattrs != NULL);
DBC_REQUIRE(hchnl_mgr != NULL);

*chnl = NULL;

/* Validate Args: */
Expand Down Expand Up @@ -906,8 +893,6 @@ static void free_chirp_list(struct list_head *chirp_list)
{
struct chnl_irp *chirp, *tmp;

DBC_REQUIRE(chirp_list != NULL);

list_for_each_entry_safe(chirp, tmp, chirp_list, link) {
list_del(&chirp->link);
kfree(chirp);
Expand All @@ -924,8 +909,6 @@ static int search_free_channel(struct chnl_mgr *chnl_mgr_obj,
int status = -ENOSR;
u32 i;

DBC_REQUIRE(chnl_mgr_obj);

for (i = 0; i < chnl_mgr_obj->max_channels; i++) {
if (chnl_mgr_obj->channels[i] == NULL) {
status = 0;
Expand Down
3 changes: 0 additions & 3 deletions drivers/staging/tidspbridge/core/tiomap3430.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,6 @@ static void bad_page_dump(u32 pa, struct page *pg)
void bridge_drv_entry(struct bridge_drv_interface **drv_intf,
const char *driver_file_name)
{

DBC_REQUIRE(driver_file_name != NULL);

if (strcmp(driver_file_name, "UMA") == 0)
*drv_intf = &drv_interface_fxns;
else
Expand Down
4 changes: 0 additions & 4 deletions drivers/staging/tidspbridge/gen/uuidutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,13 @@ void uuid_uuid_to_string(struct dsp_uuid *uuid_obj, char *sz_uuid,
{
s32 i; /* return result from snprintf. */

DBC_REQUIRE(uuid_obj && sz_uuid);

i = snprintf(sz_uuid, size,
"%.8X_%.4X_%.4X_%.2X%.2X_%.2X%.2X%.2X%.2X%.2X%.2X",
uuid_obj->data1, uuid_obj->data2, uuid_obj->data3,
uuid_obj->data4, uuid_obj->data5,
uuid_obj->data6[0], uuid_obj->data6[1],
uuid_obj->data6[2], uuid_obj->data6[3],
uuid_obj->data6[4], uuid_obj->data6[5]);

DBC_ENSURE(i != -1);
}

static s32 uuid_hex_to_bin(char *buf, s32 len)
Expand Down
7 changes: 0 additions & 7 deletions drivers/staging/tidspbridge/include/dspbridge/dbc.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,8 @@
if (!(exp)) \
pr_err("%s, line %d: Assertion (" #exp ") failed.\n", \
__FILE__, __LINE__)
#define DBC_REQUIRE DBC_ASSERT /* Function Precondition. */
#define DBC_ENSURE DBC_ASSERT /* Function Postcondition. */

#else

#define DBC_ASSERT(exp) {}
#define DBC_REQUIRE(exp) {}
#define DBC_ENSURE(exp) {}

#endif /* DEBUG */

#endif /* DBC_ */
16 changes: 0 additions & 16 deletions drivers/staging/tidspbridge/pmgr/chnl.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ int chnl_create(struct chnl_mgr **channel_mgr,
struct chnl_mgr *hchnl_mgr;
struct chnl_mgr_ *chnl_mgr_obj = NULL;

DBC_REQUIRE(refs > 0);
DBC_REQUIRE(channel_mgr != NULL);
DBC_REQUIRE(mgr_attrts != NULL);

*channel_mgr = NULL;

/* Validate args: */
Expand Down Expand Up @@ -99,8 +95,6 @@ int chnl_create(struct chnl_mgr **channel_mgr,
}
}

DBC_ENSURE(status || chnl_mgr_obj);

return status;
}

Expand All @@ -115,8 +109,6 @@ int chnl_destroy(struct chnl_mgr *hchnl_mgr)
struct bridge_drv_interface *intf_fxns;
int status;

DBC_REQUIRE(refs > 0);

if (chnl_mgr_obj) {
intf_fxns = chnl_mgr_obj->intf_fxns;
/* Let Bridge channel module destroy the chnl_mgr: */
Expand All @@ -135,11 +127,7 @@ int chnl_destroy(struct chnl_mgr *hchnl_mgr)
*/
void chnl_exit(void)
{
DBC_REQUIRE(refs > 0);

refs--;

DBC_ENSURE(refs >= 0);
}

/*
Expand All @@ -151,12 +139,8 @@ bool chnl_init(void)
{
bool ret = true;

DBC_REQUIRE(refs >= 0);

if (ret)
refs++;

DBC_ENSURE((ret && (refs > 0)) || (!ret && (refs >= 0)));

return ret;
}
59 changes: 0 additions & 59 deletions drivers/staging/tidspbridge/pmgr/cmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,6 @@ int cmm_create(struct cmm_object **ph_cmm_mgr,
struct cmm_object *cmm_obj = NULL;
int status = 0;

DBC_REQUIRE(refs > 0);
DBC_REQUIRE(ph_cmm_mgr != NULL);

*ph_cmm_mgr = NULL;
/* create, zero, and tag a cmm mgr object */
cmm_obj = kzalloc(sizeof(struct cmm_object), GFP_KERNEL);
Expand Down Expand Up @@ -283,7 +280,6 @@ int cmm_destroy(struct cmm_object *hcmm_mgr, bool force)
s32 slot_seg;
struct cmm_mnode *node, *tmp;

DBC_REQUIRE(refs > 0);
if (!hcmm_mgr) {
status = -EFAULT;
return status;
Expand Down Expand Up @@ -333,8 +329,6 @@ int cmm_destroy(struct cmm_object *hcmm_mgr, bool force)
*/
void cmm_exit(void)
{
DBC_REQUIRE(refs > 0);

refs--;
}

Expand All @@ -351,9 +345,6 @@ int cmm_free_buf(struct cmm_object *hcmm_mgr, void *buf_pa, u32 ul_seg_id)
struct cmm_allocator *allocator;
struct cmm_attrs *pattrs;

DBC_REQUIRE(refs > 0);
DBC_REQUIRE(buf_pa != NULL);

if (ul_seg_id == 0) {
pattrs = &cmm_dfltalctattrs;
ul_seg_id = pattrs->seg_id;
Expand Down Expand Up @@ -392,8 +383,6 @@ int cmm_get_handle(void *hprocessor, struct cmm_object ** ph_cmm_mgr)
int status = 0;
struct dev_object *hdev_obj;

DBC_REQUIRE(refs > 0);
DBC_REQUIRE(ph_cmm_mgr != NULL);
if (hprocessor != NULL)
status = proc_get_dev_object(hprocessor, &hdev_obj);
else
Expand All @@ -419,8 +408,6 @@ int cmm_get_info(struct cmm_object *hcmm_mgr,
struct cmm_allocator *altr;
struct cmm_mnode *curr;

DBC_REQUIRE(cmm_info_obj != NULL);

if (!hcmm_mgr) {
status = -EFAULT;
return status;
Expand Down Expand Up @@ -472,12 +459,9 @@ bool cmm_init(void)
{
bool ret = true;

DBC_REQUIRE(refs >= 0);
if (ret)
refs++;

DBC_ENSURE((ret && (refs > 0)) || (!ret && (refs >= 0)));

return ret;
}

Expand All @@ -499,13 +483,6 @@ int cmm_register_gppsm_seg(struct cmm_object *hcmm_mgr,
struct cmm_mnode *new_node;
s32 slot_seg;

DBC_REQUIRE(ul_size > 0);
DBC_REQUIRE(sgmt_id != NULL);
DBC_REQUIRE(dw_gpp_base_pa != 0);
DBC_REQUIRE(gpp_base_va != 0);
DBC_REQUIRE((c_factor <= CMM_ADDTODSPPA) &&
(c_factor >= CMM_SUBFROMDSPPA));

dev_dbg(bridge, "%s: dw_gpp_base_pa %x ul_size %x dsp_addr_offset %x "
"dw_dsp_base %x ul_dsp_size %x gpp_base_va %x\n",
__func__, dw_gpp_base_pa, ul_size, dsp_addr_offset,
Expand Down Expand Up @@ -589,7 +566,6 @@ int cmm_un_register_gppsm_seg(struct cmm_object *hcmm_mgr,
struct cmm_allocator *psma;
u32 ul_id = ul_seg_id;

DBC_REQUIRE(ul_seg_id > 0);
if (!hcmm_mgr)
return -EFAULT;

Expand Down Expand Up @@ -635,8 +611,6 @@ static void un_register_gppsm_seg(struct cmm_allocator *psma)
{
struct cmm_mnode *curr, *tmp;

DBC_REQUIRE(psma != NULL);

/* free nodes on free list */
list_for_each_entry_safe(curr, tmp, &psma->free_list, link) {
list_del(&curr->link);
Expand Down Expand Up @@ -664,7 +638,6 @@ static void un_register_gppsm_seg(struct cmm_allocator *psma)
static s32 get_slot(struct cmm_object *cmm_mgr_obj)
{
s32 slot_seg = -1; /* neg on failure */
DBC_REQUIRE(cmm_mgr_obj != NULL);
/* get first available slot in cmm mgr SMSegTab[] */
for (slot_seg = 0; slot_seg < CMM_MAXGPPSEGS; slot_seg++) {
if (cmm_mgr_obj->pa_gppsm_seg_tab[slot_seg] == NULL)
Expand All @@ -687,11 +660,6 @@ static struct cmm_mnode *get_node(struct cmm_object *cmm_mgr_obj, u32 dw_pa,
{
struct cmm_mnode *pnode;

DBC_REQUIRE(cmm_mgr_obj != NULL);
DBC_REQUIRE(dw_pa != 0);
DBC_REQUIRE(dw_va != 0);
DBC_REQUIRE(ul_size != 0);

/* Check cmm mgr's node freelist */
if (list_empty(&cmm_mgr_obj->node_free_list)) {
pnode = kzalloc(sizeof(struct cmm_mnode), GFP_KERNEL);
Expand Down Expand Up @@ -719,7 +687,6 @@ static struct cmm_mnode *get_node(struct cmm_object *cmm_mgr_obj, u32 dw_pa,
*/
static void delete_node(struct cmm_object *cmm_mgr_obj, struct cmm_mnode *pnode)
{
DBC_REQUIRE(pnode != NULL);
list_add_tail(&pnode->link, &cmm_mgr_obj->node_free_list);
}

Expand Down Expand Up @@ -794,9 +761,6 @@ static void add_to_free_list(struct cmm_allocator *allocator,
static struct cmm_allocator *get_allocator(struct cmm_object *cmm_mgr_obj,
u32 ul_seg_id)
{
DBC_REQUIRE(cmm_mgr_obj != NULL);
DBC_REQUIRE((ul_seg_id > 0) && (ul_seg_id <= CMM_MAXGPPSEGS));

return cmm_mgr_obj->pa_gppsm_seg_tab[ul_seg_id - 1];
}

Expand All @@ -818,10 +782,6 @@ int cmm_xlator_create(struct cmm_xlatorobject **xlator,
struct cmm_xlator *xlator_object = NULL;
int status = 0;

DBC_REQUIRE(refs > 0);
DBC_REQUIRE(xlator != NULL);
DBC_REQUIRE(hcmm_mgr != NULL);

*xlator = NULL;
if (xlator_attrs == NULL)
xlator_attrs = &cmm_dfltxlatorattrs; /* set defaults */
Expand Down Expand Up @@ -851,13 +811,6 @@ void *cmm_xlator_alloc_buf(struct cmm_xlatorobject *xlator, void *va_buf,
void *tmp_va_buff;
struct cmm_attrs attrs;

DBC_REQUIRE(refs > 0);
DBC_REQUIRE(xlator != NULL);
DBC_REQUIRE(xlator_obj->cmm_mgr != NULL);
DBC_REQUIRE(va_buf != NULL);
DBC_REQUIRE(pa_size > 0);
DBC_REQUIRE(xlator_obj->seg_id > 0);

if (xlator_obj) {
attrs.seg_id = xlator_obj->seg_id;
__raw_writel(0, va_buf);
Expand Down Expand Up @@ -887,10 +840,6 @@ int cmm_xlator_free_buf(struct cmm_xlatorobject *xlator, void *buf_va)
int status = -EPERM;
void *buf_pa = NULL;

DBC_REQUIRE(refs > 0);
DBC_REQUIRE(buf_va != NULL);
DBC_REQUIRE(xlator_obj->seg_id > 0);

if (xlator_obj) {
/* convert Va to Pa so we can free it. */
buf_pa = cmm_xlator_translate(xlator, buf_va, CMM_VA2PA);
Expand Down Expand Up @@ -918,10 +867,6 @@ int cmm_xlator_info(struct cmm_xlatorobject *xlator, u8 ** paddr,
struct cmm_xlator *xlator_obj = (struct cmm_xlator *)xlator;
int status = 0;

DBC_REQUIRE(refs > 0);
DBC_REQUIRE(paddr != NULL);
DBC_REQUIRE((segm_id > 0) && (segm_id <= CMM_MAXGPPSEGS));

if (xlator_obj) {
if (set_info) {
/* set translators virtual address range */
Expand All @@ -948,10 +893,6 @@ void *cmm_xlator_translate(struct cmm_xlatorobject *xlator, void *paddr,
struct cmm_allocator *allocator = NULL;
u32 dw_offset = 0;

DBC_REQUIRE(refs > 0);
DBC_REQUIRE(paddr != NULL);
DBC_REQUIRE((xtype >= CMM_VA2PA) && (xtype <= CMM_DSPPA2PA));

if (!xlator_obj)
goto loop_cont;

Expand Down
Loading

0 comments on commit 276cc74

Please sign in to comment.