codingstyle/cleanup - error code propagation and single point of exit for misc functions; - caught an INIT_LIST_HEAD() in disguise; - remove a lonely, unneeded, (void *) cast. Yell if you do not like it or if you want more. Signed-off-by: Francois Romieu <romieu@xxxxxxxxxxxxx> diff -puN drivers/media/dvb/dvb-core/dvb_demux.c~dvb-220 drivers/media/dvb/dvb-core/dvb_demux.c --- a/drivers/media/dvb/dvb-core/dvb_demux.c~dvb-220 2005-05-20 19:38:27.198542787 +0200 +++ b/drivers/media/dvb/dvb-core/dvb_demux.c 2005-05-20 19:38:27.226538215 +0200 @@ -548,7 +548,7 @@ static struct dvb_demux_filter * dvb_dmx return &demux->filter[i]; } -static struct dvb_demux_feed * dvb_dmx_feed_alloc(struct dvb_demux *demux) +static struct dvb_demux_feed *dvb_dmx_feed_alloc(struct dvb_demux *demux) { int i; @@ -557,7 +557,7 @@ static struct dvb_demux_feed * dvb_dmx_f break; if (i == demux->feednum) - return NULL; + return ERR_PTR(-EBUSY); demux->feed[i].state = DMX_STATE_ALLOCATED; @@ -673,31 +673,35 @@ static int dmx_ts_feed_start_filtering(s struct dvb_demux *demux = feed->demux; int ret; - if (down_interruptible (&demux->mutex)) - return -ERESTARTSYS; + ret = down_interruptible(&demux->mutex); + if (ret < 0) + goto out; if (feed->state != DMX_STATE_READY || feed->type != DMX_TYPE_TS) { - up(&demux->mutex); - return -EINVAL; + ret = -EINVAL; + goto out_mutex_up; } if (!demux->start_feed) { - up(&demux->mutex); - return -ENODEV; + ret = -ENODEV; + goto out_mutex_up; } - if ((ret = demux->start_feed(feed)) < 0) { - up(&demux->mutex); - return ret; - } + ret = demux->start_feed(feed); + if (ret < 0) + goto out_mutex_up; spin_lock_irq(&demux->lock); ts_feed->is_filtering = 1; feed->state = DMX_STATE_GO; spin_unlock_irq(&demux->lock); - up(&demux->mutex); - return 0; + ret = 0; + +out_mutex_up: + up(&demux->mutex); +out: + return ret; } static int dmx_ts_feed_stop_filtering(struct dmx_ts_feed* ts_feed) @@ -706,17 +710,18 @@ static int dmx_ts_feed_stop_filtering(st struct dvb_demux *demux = feed->demux; int ret; - if (down_interruptible (&demux->mutex)) - return -ERESTARTSYS; + ret = down_interruptible(&demux->mutex); + if (ret < 0) + goto out; if (feed->state < DMX_STATE_GO) { - up(&demux->mutex); - return -EINVAL; + ret = -EINVAL; + goto out_mutex_up; } if (!demux->stop_feed) { - up(&demux->mutex); - return -ENODEV; + ret = -ENODEV; + goto out_mutex_up; } ret = demux->stop_feed(feed); @@ -727,6 +732,9 @@ static int dmx_ts_feed_stop_filtering(st spin_unlock_irq(&demux->lock); up(&demux->mutex); +out_mutex_up: + up(&demux->mutex); +out: return ret; } @@ -735,13 +743,16 @@ static int dvbdmx_allocate_ts_feed (stru { struct dvb_demux *demux = (struct dvb_demux *) dmx; struct dvb_demux_feed *feed; + int ret; - if (down_interruptible (&demux->mutex)) - return -ERESTARTSYS; + ret = down_interruptible(&demux->mutex); + if (ret < 0) + goto out; - if (!(feed = dvb_dmx_feed_alloc(demux))) { - up(&demux->mutex); - return -EBUSY; + feed = dvb_dmx_feed_alloc(demux); + if (IS_ERR(feed)) { + ret = PTR_ERR(feed); + goto out_mutex_up; } feed->type = DMX_TYPE_TS; @@ -760,19 +771,22 @@ static int dvbdmx_allocate_ts_feed (stru (*ts_feed)->set = dmx_ts_feed_set; - if (!(feed->filter = dvb_dmx_filter_alloc(demux))) { + feed->filter = dvb_dmx_filter_alloc(demux); + if (!feed->filter) { feed->state = DMX_STATE_FREE; - up(&demux->mutex); - return -EBUSY; + goto out_mutex_up; } feed->filter->type = DMX_TYPE_TS; feed->filter->feed = feed; feed->filter->state = DMX_STATE_READY; - up(&demux->mutex); + ret = 0; - return 0; +out_mutex_up: + up(&demux->mutex); +out: + return ret; } static int dvbdmx_release_ts_feed(struct dmx_demux *dmx, struct dmx_ts_feed *ts_feed) @@ -1021,13 +1035,16 @@ static int dvbdmx_allocate_section_feed( { struct dvb_demux *dvbdmx = (struct dvb_demux *) demux; struct dvb_demux_feed *dvbdmxfeed; + int ret; - if (down_interruptible (&dvbdmx->mutex)) - return -ERESTARTSYS; + ret = down_interruptible(&dvbdmx->mutex); + if (ret < 0) + goto out; - if (!(dvbdmxfeed = dvb_dmx_feed_alloc(dvbdmx))) { - up(&dvbdmx->mutex); - return -EBUSY; + dvbdmxfeed = dvb_dmx_feed_alloc(dvbdmx); + if (IS_ERR(dvbdmxfeed)) { + ret = PTR_ERR(dvbdmxfeed); + goto out_mutex_up; } dvbdmxfeed->type = DMX_TYPE_SEC; @@ -1051,8 +1068,10 @@ static int dvbdmx_allocate_section_feed( (*feed)->stop_filtering = dmx_section_feed_stop_filtering; (*feed)->release_filter = dmx_section_feed_release_filter; +out_mutex_up: up(&dvbdmx->mutex); - return 0; +out: + return ret; } static int dvbdmx_release_section_feed(struct dmx_demux *demux, @@ -1229,9 +1248,9 @@ int dvb_dmx_init(struct dvb_demux *dvbde dvbdemux->feed[i].state = DMX_STATE_FREE; dvbdemux->feed[i].index = i; } - dvbdemux->frontend_list.next= - dvbdemux->frontend_list.prev= - &dvbdemux->frontend_list; + + INIT_LIST_HEAD(&dvbdemux->frontend_list); + for (i=0; i<DMX_TS_PES_OTHER; i++) { dvbdemux->pesfilter[i] = NULL; dvbdemux->pids[i] = 0xffff; @@ -1251,7 +1270,7 @@ int dvb_dmx_init(struct dvb_demux *dvbde dmx->frontend = NULL; dmx->reg_list.prev = dmx->reg_list.next = &dmx->reg_list; - dmx->priv = (void *) dvbdemux; + dmx->priv = dvbdemux; dmx->open = dvbdmx_open; dmx->close = dvbdmx_close; dmx->write = dvbdmx_write; _