oss: Make oss_open() a no-op.
authorAndre Noll <maan@systemlinux.org>
Fri, 5 Nov 2010 18:45:00 +0000 (19:45 +0100)
committerAndre Noll <maan@systemlinux.org>
Tue, 23 Nov 2010 16:43:08 +0000 (17:43 +0100)
Move the allocation of the private_oss_write_data struct to oss_init() and
adjust the the check whether oss has been initialized accordingly.

oss_write.c

index 687275f..80777ea 100644 (file)
@@ -54,7 +54,7 @@ static void oss_pre_select(struct sched *s, struct task *t)
 
        if (ret == 0)
                return;
-       if (ret < 0 || powd->fd < 0)
+       if (ret < 0 || !powd)
                return sched_min_delay(s);
        para_fd_set(powd->fd, &s->wfds, &s->max_fileno);
 }
@@ -63,8 +63,9 @@ static void oss_close(struct writer_node *wn)
 {
        struct private_oss_write_data *powd = wn->private_data;
 
-       if (powd->fd >= 0)
-               close(powd->fd);
+       if (!powd)
+               return;
+       close(powd->fd);
        free(powd);
 }
 
@@ -85,12 +86,13 @@ static int oss_init(struct writer_node *wn, unsigned sample_rate,
        int ret, format;
        unsigned ch, rate;
        struct oss_write_args_info *conf = wn->conf;
-       struct private_oss_write_data *powd = wn->private_data;
+       struct private_oss_write_data *powd = para_calloc(sizeof(*powd));
 
+       wn->private_data = powd;
        PARA_INFO_LOG("opening %s\n", conf->device_arg);
        ret = para_open(conf->device_arg, O_WRONLY, 0);
        if (ret < 0)
-               return ret;
+               goto err_free;
        powd->fd = ret;
        ret = mark_fd_nonblocking(powd->fd);
        if (ret < 0)
@@ -150,7 +152,8 @@ static int oss_init(struct writer_node *wn, unsigned sample_rate,
        return 1;
 err:
        close(powd->fd);
-       powd->fd = -1;
+err_free:
+       free(powd);
        return ret;
 }
 
@@ -168,7 +171,7 @@ static void oss_post_select(__a_unused struct sched *s,
                goto out;
        if (ret == 0)
                return;
-       if (powd->fd < 0) {
+       if (!powd) {
                int32_t rate, ch, format;
                get_btr_sample_rate(btrn, &rate);
                get_btr_channels(btrn, &ch);
@@ -199,12 +202,8 @@ out:
                btr_remove_node(btrn);
 }
 
-static void oss_open(struct writer_node *wn)
+static void oss_open(__a_unused struct writer_node *wn)
 {
-       struct private_oss_write_data *powd = para_calloc(sizeof(*powd));
-
-       powd->fd = -1;
-       wn->private_data = powd;
 }
 
 __malloc static void *oss_parse_config_or_die(const char *options)