From f6581430c952d4ea38c8a45a18b1321e0b3bf96d Mon Sep 17 00:00:00 2001 From: Federico Vaga <federico.vaga@gmail.com> Date: Tue, 13 Mar 2012 11:15:14 +0100 Subject: [PATCH] bugfix: assign bi and ti after their registration The bug was evident in zio_change_current_buffer. When you change the buffer, zio registers a new bi, but the old __bi_register() overwrites the current bi in use by the channel; so, when zio tries to unregister the old bi, there is not any reference to it. Now you must assign a bi to a channel after its registration. For simmetry and to prevent future bugs, also ti assignment must be done after __ti_registration(). Signed-off-by: Federico Vaga <federico.vaga@gmail.com> Acked-by: Alessandro Rubini <rubini@gnudd.com> --- zio-sys.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/zio-sys.c b/zio-sys.c index 5ac953b..5aad6cc 100644 --- a/zio-sys.c +++ b/zio-sys.c @@ -519,6 +519,7 @@ static int zio_change_current_trigger(struct zio_cset *cset, char *name) /* Set new trigger*/ mb(); cset->trig = trig; + cset->ti = ti; /* Rename trigger-tmp to trigger */ err = kobject_rename(&ti->head.kobj, "trigger"); if (err) @@ -1086,10 +1087,8 @@ static int __bi_register(struct zio_buffer_type *zbuf, list_add(&bi->list, &zbuf->list); spin_unlock(&zbuf->lock); bi->cset = chan->cset; - chan->bi = bi; - /* Done. This chan->bi marks everything is running (FIXME: audit) */ - mb(); bi->chan = chan; + /* Done. This bi->chan marks everything is running */ return 0; @@ -1181,10 +1180,8 @@ static int __ti_register(struct zio_trigger_type *trig, struct zio_cset *cset, spin_lock(&trig->lock); list_add(&ti->list, &trig->list); spin_unlock(&trig->lock); - cset->ti = ti; - /* Done. This cset->ti marks everything is running (FIXME: audit) */ - mb(); ti->cset = cset; + /* Done. This ti->cset marks everything is running */ return 0; @@ -1251,7 +1248,8 @@ static int chan_register(struct zio_channel *chan) err = __bi_register(chan->cset->zbuf, chan, bi, "buffer"); if (err) goto out_bi_destroy; - + /* Assign the buffer instance to this channel */ + chan->bi = bi; /* Create channel char devices*/ err = zio_create_chan_devices(chan); if (err) @@ -1465,6 +1463,7 @@ static int cset_register(struct zio_cset *cset) if (err) goto out_tr; cset->trig = trig; + cset->ti = ti; } spin_lock(&zstat->lock); list_add(&cset->list_cset, &zstat->list_cset); -- GitLab