Skip to content

Commit

Permalink
isdn/gigaset: unify function return values
Browse files Browse the repository at this point in the history
Various functions in the Gigaset driver were using different
conventions for the meaning of their int return values.
Align them to the usual negative error numbers convention.

Inspired-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Tilman Schmidt <tilman@imap.cc>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Tilman Schmidt authored and David S. Miller committed May 8, 2012
1 parent 7643ffb commit 81fa7b8
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 81 deletions.
33 changes: 19 additions & 14 deletions drivers/isdn/gigaset/bas-gigaset.c
Original file line number Diff line number Diff line change
Expand Up @@ -2077,16 +2077,14 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
/* Free hardware dependent part of the B channel structure
* parameter:
* bcs B channel structure
* return value:
* !=0 on success
*/
static int gigaset_freebcshw(struct bc_state *bcs)
static void gigaset_freebcshw(struct bc_state *bcs)
{
struct bas_bc_state *ubc = bcs->hw.bas;
int i;

if (!ubc)
return 0;
return;

/* kill URBs and tasklets before freeing - better safe than sorry */
ubc->running = 0;
Expand All @@ -2104,14 +2102,13 @@ static int gigaset_freebcshw(struct bc_state *bcs)
kfree(ubc->isooutbuf);
kfree(ubc);
bcs->hw.bas = NULL;
return 1;
}

/* Initialize hardware dependent part of the B channel structure
* parameter:
* bcs B channel structure
* return value:
* !=0 on success
* 0 on success, error code < 0 on failure
*/
static int gigaset_initbcshw(struct bc_state *bcs)
{
Expand All @@ -2121,7 +2118,7 @@ static int gigaset_initbcshw(struct bc_state *bcs)
bcs->hw.bas = ubc = kmalloc(sizeof(struct bas_bc_state), GFP_KERNEL);
if (!ubc) {
pr_err("out of memory\n");
return 0;
return -ENOMEM;
}

ubc->running = 0;
Expand All @@ -2138,7 +2135,7 @@ static int gigaset_initbcshw(struct bc_state *bcs)
pr_err("out of memory\n");
kfree(ubc);
bcs->hw.bas = NULL;
return 0;
return -ENOMEM;
}
tasklet_init(&ubc->sent_tasklet,
write_iso_tasklet, (unsigned long) bcs);
Expand All @@ -2163,7 +2160,7 @@ static int gigaset_initbcshw(struct bc_state *bcs)
ubc->stolen0s = 0;
tasklet_init(&ubc->rcvd_tasklet,
read_iso_tasklet, (unsigned long) bcs);
return 1;
return 0;
}

static void gigaset_reinitbcshw(struct bc_state *bcs)
Expand All @@ -2186,20 +2183,26 @@ static void gigaset_freecshw(struct cardstate *cs)
cs->hw.bas = NULL;
}

/* Initialize hardware dependent part of the cardstate structure
* parameter:
* cs cardstate structure
* return value:
* 0 on success, error code < 0 on failure
*/
static int gigaset_initcshw(struct cardstate *cs)
{
struct bas_cardstate *ucs;

cs->hw.bas = ucs = kmalloc(sizeof *ucs, GFP_KERNEL);
if (!ucs) {
pr_err("out of memory\n");
return 0;
return -ENOMEM;
}
ucs->int_in_buf = kmalloc(IP_MSGSIZE, GFP_KERNEL);
if (!ucs->int_in_buf) {
kfree(ucs);
pr_err("out of memory\n");
return 0;
return -ENOMEM;
}

ucs->urb_cmd_in = NULL;
Expand All @@ -2218,7 +2221,7 @@ static int gigaset_initcshw(struct cardstate *cs)
init_waitqueue_head(&ucs->waitqueue);
INIT_WORK(&ucs->int_in_wq, int_in_work);

return 1;
return 0;
}

/* freeurbs
Expand Down Expand Up @@ -2378,18 +2381,20 @@ static int gigaset_probe(struct usb_interface *interface,
/* save address of controller structure */
usb_set_intfdata(interface, cs);

if (!gigaset_start(cs))
rc = gigaset_start(cs);
if (rc < 0)
goto error;

return 0;

allocerr:
dev_err(cs->dev, "could not allocate URBs\n");
rc = -ENOMEM;
error:
freeurbs(cs);
usb_set_intfdata(interface, NULL);
gigaset_freecs(cs);
return -ENODEV;
return rc;
}

/* gigaset_disconnect
Expand Down
8 changes: 4 additions & 4 deletions drivers/isdn/gigaset/capi.c
Original file line number Diff line number Diff line change
Expand Up @@ -2346,7 +2346,7 @@ static const struct file_operations gigaset_proc_fops = {
* @cs: device descriptor structure.
* @isdnid: device name.
*
* Return value: 1 for success, 0 for failure
* Return value: 0 on success, error code < 0 on failure
*/
int gigaset_isdn_regdev(struct cardstate *cs, const char *isdnid)
{
Expand All @@ -2356,7 +2356,7 @@ int gigaset_isdn_regdev(struct cardstate *cs, const char *isdnid)
iif = kmalloc(sizeof(*iif), GFP_KERNEL);
if (!iif) {
pr_err("%s: out of memory\n", __func__);
return 0;
return -ENOMEM;
}

/* prepare controller structure */
Expand All @@ -2380,12 +2380,12 @@ int gigaset_isdn_regdev(struct cardstate *cs, const char *isdnid)
if (rc) {
pr_err("attach_capi_ctr failed (%d)\n", rc);
kfree(iif);
return 0;
return rc;
}

cs->iif = iif;
cs->hw_hdr_len = CAPI_DATA_B3_REQ_LEN;
return 1;
return 0;
}

/**
Expand Down
43 changes: 20 additions & 23 deletions drivers/isdn/gigaset/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,13 @@ int gigaset_get_channel(struct bc_state *bcs)
gig_dbg(DEBUG_CHANNEL, "could not allocate channel %d",
bcs->channel);
spin_unlock_irqrestore(&bcs->cs->lock, flags);
return 0;
return -EBUSY;
}
++bcs->use_count;
bcs->busy = 1;
gig_dbg(DEBUG_CHANNEL, "allocated channel %d", bcs->channel);
spin_unlock_irqrestore(&bcs->cs->lock, flags);
return 1;
return 0;
}

struct bc_state *gigaset_get_free_channel(struct cardstate *cs)
Expand Down Expand Up @@ -258,15 +258,15 @@ int gigaset_get_channels(struct cardstate *cs)
spin_unlock_irqrestore(&cs->lock, flags);
gig_dbg(DEBUG_CHANNEL,
"could not allocate all channels");
return 0;
return -EBUSY;
}
for (i = 0; i < cs->channels; ++i)
++cs->bcs[i].use_count;
spin_unlock_irqrestore(&cs->lock, flags);

gig_dbg(DEBUG_CHANNEL, "allocated all channels");

return 1;
return 0;
}

void gigaset_free_channels(struct cardstate *cs)
Expand Down Expand Up @@ -388,8 +388,7 @@ static void gigaset_freebcs(struct bc_state *bcs)
int i;

gig_dbg(DEBUG_INIT, "freeing bcs[%d]->hw", bcs->channel);
if (!bcs->cs->ops->freebcshw(bcs))
gig_dbg(DEBUG_INIT, "failed");
bcs->cs->ops->freebcshw(bcs);

gig_dbg(DEBUG_INIT, "clearing bcs[%d]->at_state", bcs->channel);
clear_at_state(&bcs->at_state);
Expand Down Expand Up @@ -566,6 +565,8 @@ static void gigaset_inbuf_init(struct inbuf_t *inbuf, struct cardstate *cs)
* @inbuf: buffer structure.
* @src: received data.
* @numbytes: number of bytes received.
*
* Return value: !=0 if some data was appended
*/
int gigaset_fill_inbuf(struct inbuf_t *inbuf, const unsigned char *src,
unsigned numbytes)
Expand Down Expand Up @@ -609,8 +610,8 @@ int gigaset_fill_inbuf(struct inbuf_t *inbuf, const unsigned char *src,
EXPORT_SYMBOL_GPL(gigaset_fill_inbuf);

/* Initialize the b-channel structure */
static struct bc_state *gigaset_initbcs(struct bc_state *bcs,
struct cardstate *cs, int channel)
static int gigaset_initbcs(struct bc_state *bcs, struct cardstate *cs,
int channel)
{
int i;

Expand Down Expand Up @@ -649,11 +650,7 @@ static struct bc_state *gigaset_initbcs(struct bc_state *bcs,
bcs->apconnstate = 0;

gig_dbg(DEBUG_INIT, " setting up bcs[%d]->hw", channel);
if (cs->ops->initbcshw(bcs))
return bcs;

gig_dbg(DEBUG_INIT, " failed");
return NULL;
return cs->ops->initbcshw(bcs);
}

/**
Expand Down Expand Up @@ -752,15 +749,15 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
cs->cmdbytes = 0;

gig_dbg(DEBUG_INIT, "setting up iif");
if (!gigaset_isdn_regdev(cs, modulename)) {
if (gigaset_isdn_regdev(cs, modulename) < 0) {
pr_err("error registering ISDN device\n");
goto error;
}

make_valid(cs, VALID_ID);
++cs->cs_init;
gig_dbg(DEBUG_INIT, "setting up hw");
if (!cs->ops->initcshw(cs))
if (cs->ops->initcshw(cs) < 0)
goto error;

++cs->cs_init;
Expand All @@ -774,7 +771,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
/* set up channel data structures */
for (i = 0; i < channels; ++i) {
gig_dbg(DEBUG_INIT, "setting up bcs[%d]", i);
if (!gigaset_initbcs(cs->bcs + i, cs, i)) {
if (gigaset_initbcs(cs->bcs + i, cs, i) < 0) {
pr_err("could not allocate channel %d data\n", i);
goto error;
}
Expand Down Expand Up @@ -869,7 +866,7 @@ static void cleanup_cs(struct cardstate *cs)

for (i = 0; i < cs->channels; ++i) {
gigaset_freebcs(cs->bcs + i);
if (!gigaset_initbcs(cs->bcs + i, cs, i))
if (gigaset_initbcs(cs->bcs + i, cs, i) < 0)
pr_err("could not allocate channel %d data\n", i);
}

Expand All @@ -890,14 +887,14 @@ static void cleanup_cs(struct cardstate *cs)
* waiting for completion of the initialization.
*
* Return value:
* 1 - success, 0 - error
* 0 on success, error code < 0 on failure
*/
int gigaset_start(struct cardstate *cs)
{
unsigned long flags;

if (mutex_lock_interruptible(&cs->mutex))
return 0;
return -EBUSY;

spin_lock_irqsave(&cs->lock, flags);
cs->connected = 1;
Expand All @@ -921,11 +918,11 @@ int gigaset_start(struct cardstate *cs)
wait_event(cs->waitqueue, !cs->waiting);

mutex_unlock(&cs->mutex);
return 1;
return 0;

error:
mutex_unlock(&cs->mutex);
return 0;
return -ENOMEM;
}
EXPORT_SYMBOL_GPL(gigaset_start);

Expand All @@ -937,15 +934,15 @@ EXPORT_SYMBOL_GPL(gigaset_start);
* waiting for completion of the shutdown.
*
* Return value:
* 0 - success, -1 - error (no device associated)
* 0 - success, -ENODEV - error (no device associated)
*/
int gigaset_shutdown(struct cardstate *cs)
{
mutex_lock(&cs->mutex);

if (!(cs->flags & VALID_MINOR)) {
mutex_unlock(&cs->mutex);
return -1;
return -ENODEV;
}

cs->waiting = 1;
Expand Down
2 changes: 1 addition & 1 deletion drivers/isdn/gigaset/dummyll.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void gigaset_isdn_stop(struct cardstate *cs)

int gigaset_isdn_regdev(struct cardstate *cs, const char *isdnid)
{
return 1;
return 0;
}

void gigaset_isdn_unregdev(struct cardstate *cs)
Expand Down
16 changes: 8 additions & 8 deletions drivers/isdn/gigaset/ev-layer.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ static inline struct at_state_t *get_free_channel(struct cardstate *cs,
struct at_state_t *ret;

for (i = 0; i < cs->channels; ++i)
if (gigaset_get_channel(cs->bcs + i)) {
if (gigaset_get_channel(cs->bcs + i) >= 0) {
ret = &cs->bcs[i].at_state;
ret->cid = cid;
return ret;
Expand Down Expand Up @@ -923,18 +923,18 @@ static void do_stop(struct cardstate *cs)
* channel >= 0: getting cid for the channel failed
* channel < 0: entering cid mode failed
*
* returns 0 on failure
* returns 0 on success, <0 on failure
*/
static int reinit_and_retry(struct cardstate *cs, int channel)
{
int i;

if (--cs->retry_count <= 0)
return 0;
return -EFAULT;

for (i = 0; i < cs->channels; ++i)
if (cs->bcs[i].at_state.cid > 0)
return 0;
return -EBUSY;

if (channel < 0)
dev_warn(cs->dev,
Expand All @@ -945,7 +945,7 @@ static int reinit_and_retry(struct cardstate *cs, int channel)
cs->bcs[channel].at_state.pending_commands |= PC_CID;
}
schedule_init(cs, MS_INIT);
return 1;
return 0;
}

static int at_state_invalid(struct cardstate *cs,
Expand Down Expand Up @@ -1016,7 +1016,7 @@ static int do_lock(struct cardstate *cs)
if (cs->bcs[i].at_state.pending_commands)
return -EBUSY;

if (!gigaset_get_channels(cs))
if (gigaset_get_channels(cs) < 0)
return -EBUSY;

break;
Expand Down Expand Up @@ -1125,7 +1125,7 @@ static void do_action(int action, struct cardstate *cs,
init_failed(cs, M_UNKNOWN);
break;
}
if (!reinit_and_retry(cs, -1))
if (reinit_and_retry(cs, -1) < 0)
schedule_init(cs, MS_RECOVER);
break;
case ACT_FAILUMODE:
Expand Down Expand Up @@ -1268,7 +1268,7 @@ static void do_action(int action, struct cardstate *cs,
case ACT_FAILCID:
cs->cur_at_seq = SEQ_NONE;
channel = cs->curchannel;
if (!reinit_and_retry(cs, channel)) {
if (reinit_and_retry(cs, channel) < 0) {
dev_warn(cs->dev,
"Could not get a call ID. Cannot dial.\n");
at_state2 = &cs->bcs[channel].at_state;
Expand Down
Loading

0 comments on commit 81fa7b8

Please sign in to comment.