From fb51f97cc85e031277be1316b1e15b185c7965a3 Mon Sep 17 00:00:00 2001 From: Alessandro Rubini <rubini@gnudd.com> Date: Mon, 29 Oct 2012 07:38:21 +0100 Subject: [PATCH] buffers/kmalloc: fix buffer-full check, as size may change If the user changes the buffer size, this might make more space for a sleeping writer. Similarly, the buffer may be fuller than the new value after a change, so we check for ">= limit" and not "== limit". This doesn't apply to the vmalloc buffer, that currently doesn't allow a size change. Signed-off-by: Alessandro Rubini <rubini@gnudd.com> Acked-by: Federico Vaga <federico.vaga@gmail.com> --- buffers/zio-buf-kmalloc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/buffers/zio-buf-kmalloc.c b/buffers/zio-buf-kmalloc.c index ca952c3..52f50e7 100644 --- a/buffers/zio-buf-kmalloc.c +++ b/buffers/zio-buf-kmalloc.c @@ -48,6 +48,11 @@ static DEFINE_ZATTR_STD(ZBUF, zbk_std_zattr) = { static int zbk_conf_set(struct device *dev, struct zio_attribute *zattr, uint32_t usr_val) { + struct zio_bi *bi = to_zio_bi(dev); + + /* If somebody is sleeping for write and we increase the size... */ + wake_up_interruptible(&bi->q); + return 0; } struct zio_sysfs_operations zbk_sysfs_ops = { @@ -144,7 +149,7 @@ static int zbk_store_block(struct zio_bi *bi, struct zio_block *block) /* add to the buffer instance or push to the trigger */ spin_lock(&bi->lock); - if (zbki->nitem == bi->zattr_set.std_zattr[ZATTR_ZBUF_MAXLEN].value) + if (zbki->nitem >= bi->zattr_set.std_zattr[ZATTR_ZBUF_MAXLEN].value) goto out_unlock; list_add_tail(&item->list, &zbki->list); if (!zbki->nitem) { -- GitLab