The only difference between comedi_but_write_alloc() and the *_strict() version is that the *_strick() one will only allocate the chuck if it can completely fulfill the request. Factor out the common code and add a flag parameter to indicate the 'strict' usage. Change the exported functions so they are just wrappers around the common function. Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx> Cc: Ian Abbott <abbobbi@xxxxxxxxx> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/staging/comedi/comedi_buf.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c index fe2dcae..838f089 100644 --- a/drivers/staging/comedi/comedi_buf.c +++ b/drivers/staging/comedi/comedi_buf.c @@ -191,14 +191,18 @@ unsigned int comedi_buf_write_n_available(struct comedi_async *async) return nbytes; } -/* allocates chunk for the writer from free buffer space */ -unsigned int comedi_buf_write_alloc(struct comedi_async *async, - unsigned int nbytes) +static unsigned int __comedi_buf_write_alloc(struct comedi_async *async, + unsigned int nbytes, + int strict) { unsigned int free_end = async->buf_read_count + async->prealloc_bufsz; - if ((int)(async->buf_write_alloc_count + nbytes - free_end) > 0) - nbytes = free_end - async->buf_write_alloc_count; + if ((int)(async->buf_write_alloc_count + nbytes - free_end) > 0) { + if (strict) + nbytes = 0; + else + nbytes = free_end - async->buf_write_alloc_count; + } async->buf_write_alloc_count += nbytes; /* barrier insures the read of buf_read_count above occurs before @@ -206,22 +210,20 @@ unsigned int comedi_buf_write_alloc(struct comedi_async *async, smp_mb(); return nbytes; } + +/* allocates chunk for the writer from free buffer space */ +unsigned int comedi_buf_write_alloc(struct comedi_async *async, + unsigned int nbytes) +{ + return __comedi_buf_write_alloc(async, nbytes, 0); +} EXPORT_SYMBOL(comedi_buf_write_alloc); /* allocates nothing unless it can completely fulfill the request */ unsigned int comedi_buf_write_alloc_strict(struct comedi_async *async, unsigned int nbytes) { - unsigned int free_end = async->buf_read_count + async->prealloc_bufsz; - - if ((int)(async->buf_write_alloc_count + nbytes - free_end) > 0) - nbytes = 0; - - async->buf_write_alloc_count += nbytes; - /* barrier insures the read of buf_read_count above occurs before - we write data to the write-alloc'ed buffer space */ - smp_mb(); - return nbytes; + return __comedi_buf_write_alloc(async, nbytes, 1); } /* munging is applied to data by core as it passes between user -- 1.8.0 _______________________________________________ devel mailing list devel@xxxxxxxxxxxxxxxxxxxxxx http://driverdev.linuxdriverproject.org/mailman/listinfo/devel