Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 45465487 authored by Stefani Seibold's avatar Stefani Seibold Committed by Linus Torvalds
Browse files

kfifo: move struct kfifo in place



This is a new generic kernel FIFO implementation.

The current kernel fifo API is not very widely used, because it has to
many constrains.  Only 17 files in the current 2.6.31-rc5 used it.
FIFO's are like list's a very basic thing and a kfifo API which handles
the most use case would save a lot of development time and memory
resources.

I think this are the reasons why kfifo is not in use:

 - The API is to simple, important functions are missing
 - A fifo can be only allocated dynamically
 - There is a requirement of a spinlock whether you need it or not
 - There is no support for data records inside a fifo

So I decided to extend the kfifo in a more generic way without blowing up
the API to much.  The new API has the following benefits:

 - Generic usage: For kernel internal use and/or device driver.
 - Provide an API for the most use case.
 - Slim API: The whole API provides 25 functions.
 - Linux style habit.
 - DECLARE_KFIFO, DEFINE_KFIFO and INIT_KFIFO Macros
 - Direct copy_to_user from the fifo and copy_from_user into the fifo.
 - The kfifo itself is an in place member of the using data structure, this save an
   indirection access and does not waste the kernel allocator.
 - Lockless access: if only one reader and one writer is active on the fifo,
   which is the common use case, no additional locking is necessary.
 - Remove spinlock - give the user the freedom of choice what kind of locking to use if
   one is required.
 - Ability to handle records. Three type of records are supported:
   - Variable length records between 0-255 bytes, with a record size
     field of 1 bytes.
   - Variable length records between 0-65535 bytes, with a record size
     field of 2 bytes.
   - Fixed size records, which no record size field.
 - Preserve memory resource.
 - Performance!
 - Easy to use!

This patch:

Since most users want to have the kfifo as part of another object,
reorganize the code to allow including struct kfifo in another data
structure.  This requires changing the kfifo_alloc and kfifo_init
prototypes so that we pass an existing kfifo pointer into them.  This
patch changes the implementation and all existing users.

[akpm@linux-foundation.org: fix warning]
Signed-off-by: default avatarStefani Seibold <stefani@seibold.net>
Acked-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
Acked-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
Acked-by: default avatarAndi Kleen <ak@linux.intel.com>
Acked-by: default avatarArnd Bergmann <arnd@arndb.de>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 2ec91eec
Loading
Loading
Loading
Loading
+10 −11
Original line number Diff line number Diff line
@@ -358,7 +358,7 @@ struct port {
	u8 update_flow_control;
	struct ctrl_ul ctrl_ul;
	struct ctrl_dl ctrl_dl;
	struct kfifo *fifo_ul;
	struct kfifo fifo_ul;
	void __iomem *dl_addr[2];
	u32 dl_size[2];
	u8 toggle_dl;
@@ -685,8 +685,8 @@ static int nozomi_read_config_table(struct nozomi *dc)
		dump_table(dc);

		for (i = PORT_MDM; i < MAX_PORT; i++) {
			dc->port[i].fifo_ul =
			    kfifo_alloc(FIFO_BUFFER_SIZE_UL, GFP_ATOMIC, NULL);
			kfifo_alloc(&dc->port[i].fifo_ul,
				FIFO_BUFFER_SIZE_UL, GFP_ATOMIC, NULL);
			memset(&dc->port[i].ctrl_dl, 0, sizeof(struct ctrl_dl));
			memset(&dc->port[i].ctrl_ul, 0, sizeof(struct ctrl_ul));
		}
@@ -798,7 +798,7 @@ static int send_data(enum port_type index, struct nozomi *dc)
	struct tty_struct *tty = tty_port_tty_get(&port->port);

	/* Get data from tty and place in buf for now */
	size = __kfifo_get(port->fifo_ul, dc->send_buf,
	size = __kfifo_get(&port->fifo_ul, dc->send_buf,
			   ul_size < SEND_BUF_MAX ? ul_size : SEND_BUF_MAX);

	if (size == 0) {
@@ -988,11 +988,11 @@ static int receive_flow_control(struct nozomi *dc)

	} else if (old_ctrl.CTS == 0 && ctrl_dl.CTS == 1) {

		if (__kfifo_len(dc->port[port].fifo_ul)) {
		if (__kfifo_len(&dc->port[port].fifo_ul)) {
			DBG1("Enable interrupt (0x%04X) on port: %d",
				enable_ier, port);
			DBG1("Data in buffer [%d], enable transmit! ",
				__kfifo_len(dc->port[port].fifo_ul));
				__kfifo_len(&dc->port[port].fifo_ul));
			enable_transmit_ul(port, dc);
		} else {
			DBG1("No data in buffer...");
@@ -1536,8 +1536,7 @@ static void __devexit nozomi_card_exit(struct pci_dev *pdev)
	free_irq(pdev->irq, dc);

	for (i = 0; i < MAX_PORT; i++)
		if (dc->port[i].fifo_ul)
			kfifo_free(dc->port[i].fifo_ul);
		kfifo_free(&dc->port[i].fifo_ul);

	kfree(dc->send_buf);

@@ -1673,7 +1672,7 @@ static int ntty_write(struct tty_struct *tty, const unsigned char *buffer,
		goto exit;
	}

	rval = __kfifo_put(port->fifo_ul, (unsigned char *)buffer, count);
	rval = __kfifo_put(&port->fifo_ul, (unsigned char *)buffer, count);

	/* notify card */
	if (unlikely(dc == NULL)) {
@@ -1721,7 +1720,7 @@ static int ntty_write_room(struct tty_struct *tty)
	if (!port->port.count)
		goto exit;

	room = port->fifo_ul->size - __kfifo_len(port->fifo_ul);
	room = port->fifo_ul.size - __kfifo_len(&port->fifo_ul);

exit:
	mutex_unlock(&port->tty_sem);
@@ -1878,7 +1877,7 @@ static s32 ntty_chars_in_buffer(struct tty_struct *tty)
		goto exit_in_buffer;
	}

	rval = __kfifo_len(port->fifo_ul);
	rval = __kfifo_len(&port->fifo_ul);

exit_in_buffer:
	return rval;
+19 −21
Original line number Diff line number Diff line
@@ -487,7 +487,7 @@ static struct sonypi_device {
	int camera_power;
	int bluetooth_power;
	struct mutex lock;
	struct kfifo *fifo;
	struct kfifo fifo;
	spinlock_t fifo_lock;
	wait_queue_head_t fifo_proc_list;
	struct fasync_struct *fifo_async;
@@ -496,7 +496,7 @@ static struct sonypi_device {
	struct input_dev *input_jog_dev;
	struct input_dev *input_key_dev;
	struct work_struct input_work;
	struct kfifo *input_fifo;
	struct kfifo input_fifo;
	spinlock_t input_fifo_lock;
} sonypi_device;

@@ -777,7 +777,7 @@ static void input_keyrelease(struct work_struct *work)
{
	struct sonypi_keypress kp;

	while (kfifo_get(sonypi_device.input_fifo, (unsigned char *)&kp,
	while (kfifo_get(&sonypi_device.input_fifo, (unsigned char *)&kp,
			 sizeof(kp)) == sizeof(kp)) {
		msleep(10);
		input_report_key(kp.dev, kp.key, 0);
@@ -827,7 +827,7 @@ static void sonypi_report_input_event(u8 event)
	if (kp.dev) {
		input_report_key(kp.dev, kp.key, 1);
		input_sync(kp.dev);
		kfifo_put(sonypi_device.input_fifo,
		kfifo_put(&sonypi_device.input_fifo,
			  (unsigned char *)&kp, sizeof(kp));
		schedule_work(&sonypi_device.input_work);
	}
@@ -880,7 +880,7 @@ static irqreturn_t sonypi_irq(int irq, void *dev_id)
		acpi_bus_generate_proc_event(sonypi_acpi_device, 1, event);
#endif

	kfifo_put(sonypi_device.fifo, (unsigned char *)&event, sizeof(event));
	kfifo_put(&sonypi_device.fifo, (unsigned char *)&event, sizeof(event));
	kill_fasync(&sonypi_device.fifo_async, SIGIO, POLL_IN);
	wake_up_interruptible(&sonypi_device.fifo_proc_list);

@@ -906,7 +906,7 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
	mutex_lock(&sonypi_device.lock);
	/* Flush input queue on first open */
	if (!sonypi_device.open_count)
		kfifo_reset(sonypi_device.fifo);
		kfifo_reset(&sonypi_device.fifo);
	sonypi_device.open_count++;
	mutex_unlock(&sonypi_device.lock);
	unlock_kernel();
@@ -919,17 +919,17 @@ static ssize_t sonypi_misc_read(struct file *file, char __user *buf,
	ssize_t ret;
	unsigned char c;

	if ((kfifo_len(sonypi_device.fifo) == 0) &&
	if ((kfifo_len(&sonypi_device.fifo) == 0) &&
	    (file->f_flags & O_NONBLOCK))
		return -EAGAIN;

	ret = wait_event_interruptible(sonypi_device.fifo_proc_list,
				       kfifo_len(sonypi_device.fifo) != 0);
				       kfifo_len(&sonypi_device.fifo) != 0);
	if (ret)
		return ret;

	while (ret < count &&
	       (kfifo_get(sonypi_device.fifo, &c, sizeof(c)) == sizeof(c))) {
	       (kfifo_get(&sonypi_device.fifo, &c, sizeof(c)) == sizeof(c))) {
		if (put_user(c, buf++))
			return -EFAULT;
		ret++;
@@ -946,7 +946,7 @@ static ssize_t sonypi_misc_read(struct file *file, char __user *buf,
static unsigned int sonypi_misc_poll(struct file *file, poll_table *wait)
{
	poll_wait(file, &sonypi_device.fifo_proc_list, wait);
	if (kfifo_len(sonypi_device.fifo))
	if (kfifo_len(&sonypi_device.fifo))
		return POLLIN | POLLRDNORM;
	return 0;
}
@@ -1313,11 +1313,11 @@ static int __devinit sonypi_probe(struct platform_device *dev)
			"http://www.linux.it/~malattia/wiki/index.php/Sony_drivers\n");

	spin_lock_init(&sonypi_device.fifo_lock);
	sonypi_device.fifo = kfifo_alloc(SONYPI_BUF_SIZE, GFP_KERNEL,
	error = kfifo_alloc(&sonypi_device.fifo, SONYPI_BUF_SIZE, GFP_KERNEL,
					 &sonypi_device.fifo_lock);
	if (IS_ERR(sonypi_device.fifo)) {
	if (error) {
		printk(KERN_ERR "sonypi: kfifo_alloc failed\n");
		return PTR_ERR(sonypi_device.fifo);
		return error;
	}

	init_waitqueue_head(&sonypi_device.fifo_proc_list);
@@ -1393,12 +1393,10 @@ static int __devinit sonypi_probe(struct platform_device *dev)
		}

		spin_lock_init(&sonypi_device.input_fifo_lock);
		sonypi_device.input_fifo =
			kfifo_alloc(SONYPI_BUF_SIZE, GFP_KERNEL,
				    &sonypi_device.input_fifo_lock);
		if (IS_ERR(sonypi_device.input_fifo)) {
		error = kfifo_alloc(&sonypi_device.input_fifo, SONYPI_BUF_SIZE,
				GFP_KERNEL, &sonypi_device.input_fifo_lock);
		if (error) {
			printk(KERN_ERR "sonypi: kfifo_alloc failed\n");
			error = PTR_ERR(sonypi_device.input_fifo);
			goto err_inpdev_unregister;
		}

@@ -1423,7 +1421,7 @@ static int __devinit sonypi_probe(struct platform_device *dev)
		pci_disable_device(pcidev);
 err_put_pcidev:
	pci_dev_put(pcidev);
	kfifo_free(sonypi_device.fifo);
	kfifo_free(&sonypi_device.fifo);

	return error;
}
@@ -1438,7 +1436,7 @@ static int __devexit sonypi_remove(struct platform_device *dev)
	if (useinput) {
		input_unregister_device(sonypi_device.input_key_dev);
		input_unregister_device(sonypi_device.input_jog_dev);
		kfifo_free(sonypi_device.input_fifo);
		kfifo_free(&sonypi_device.input_fifo);
	}

	misc_deregister(&sonypi_misc_device);
@@ -1451,7 +1449,7 @@ static int __devexit sonypi_remove(struct platform_device *dev)
		pci_dev_put(sonypi_device.dev);
	}

	kfifo_free(sonypi_device.fifo);
	kfifo_free(&sonypi_device.fifo);

	return 0;
}
+5 −4
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@

#include <linux/list.h>
#include <linux/mutex.h>
#include <linux/kfifo.h>

#include "t3_cpl.h"
#include "t3cdev.h"
@@ -75,13 +76,13 @@ struct cxio_hal_ctrl_qp {
};

struct cxio_hal_resource {
	struct kfifo *tpt_fifo;
	struct kfifo tpt_fifo;
	spinlock_t tpt_fifo_lock;
	struct kfifo *qpid_fifo;
	struct kfifo qpid_fifo;
	spinlock_t qpid_fifo_lock;
	struct kfifo *cqid_fifo;
	struct kfifo cqid_fifo;
	spinlock_t cqid_fifo_lock;
	struct kfifo *pdid_fifo;
	struct kfifo pdid_fifo;
	spinlock_t pdid_fifo_lock;
};

+29 −31
Original line number Diff line number Diff line
@@ -39,12 +39,12 @@
#include "cxio_resource.h"
#include "cxio_hal.h"

static struct kfifo *rhdl_fifo;
static struct kfifo rhdl_fifo;
static spinlock_t rhdl_fifo_lock;

#define RANDOM_SIZE 16

static int __cxio_init_resource_fifo(struct kfifo **fifo,
static int __cxio_init_resource_fifo(struct kfifo *fifo,
				   spinlock_t *fifo_lock,
				   u32 nr, u32 skip_low,
				   u32 skip_high,
@@ -55,12 +55,11 @@ static int __cxio_init_resource_fifo(struct kfifo **fifo,
	u32 rarray[16];
	spin_lock_init(fifo_lock);

	*fifo = kfifo_alloc(nr * sizeof(u32), GFP_KERNEL, fifo_lock);
	if (IS_ERR(*fifo))
	if (kfifo_alloc(fifo, nr * sizeof(u32), GFP_KERNEL, fifo_lock))
		return -ENOMEM;

	for (i = 0; i < skip_low + skip_high; i++)
		__kfifo_put(*fifo, (unsigned char *) &entry, sizeof(u32));
		__kfifo_put(fifo, (unsigned char *) &entry, sizeof(u32));
	if (random) {
		j = 0;
		random_bytes = random32();
@@ -72,33 +71,33 @@ static int __cxio_init_resource_fifo(struct kfifo **fifo,
				random_bytes = random32();
			}
			idx = (random_bytes >> (j * 2)) & 0xF;
			__kfifo_put(*fifo,
			__kfifo_put(fifo,
				(unsigned char *) &rarray[idx],
				sizeof(u32));
			rarray[idx] = i;
			j++;
		}
		for (i = 0; i < RANDOM_SIZE; i++)
			__kfifo_put(*fifo,
			__kfifo_put(fifo,
				(unsigned char *) &rarray[i],
				sizeof(u32));
	} else
		for (i = skip_low; i < nr - skip_high; i++)
			__kfifo_put(*fifo, (unsigned char *) &i, sizeof(u32));
			__kfifo_put(fifo, (unsigned char *) &i, sizeof(u32));

	for (i = 0; i < skip_low + skip_high; i++)
		kfifo_get(*fifo, (unsigned char *) &entry, sizeof(u32));
		kfifo_get(fifo, (unsigned char *) &entry, sizeof(u32));
	return 0;
}

static int cxio_init_resource_fifo(struct kfifo **fifo, spinlock_t * fifo_lock,
static int cxio_init_resource_fifo(struct kfifo *fifo, spinlock_t * fifo_lock,
				   u32 nr, u32 skip_low, u32 skip_high)
{
	return (__cxio_init_resource_fifo(fifo, fifo_lock, nr, skip_low,
					  skip_high, 0));
}

static int cxio_init_resource_fifo_random(struct kfifo **fifo,
static int cxio_init_resource_fifo_random(struct kfifo *fifo,
				   spinlock_t * fifo_lock,
				   u32 nr, u32 skip_low, u32 skip_high)
{
@@ -113,15 +112,14 @@ static int cxio_init_qpid_fifo(struct cxio_rdev *rdev_p)

	spin_lock_init(&rdev_p->rscp->qpid_fifo_lock);

	rdev_p->rscp->qpid_fifo = kfifo_alloc(T3_MAX_NUM_QP * sizeof(u32),
	if (kfifo_alloc(&rdev_p->rscp->qpid_fifo, T3_MAX_NUM_QP * sizeof(u32),
					      GFP_KERNEL,
					      &rdev_p->rscp->qpid_fifo_lock);
	if (IS_ERR(rdev_p->rscp->qpid_fifo))
					      &rdev_p->rscp->qpid_fifo_lock))
		return -ENOMEM;

	for (i = 16; i < T3_MAX_NUM_QP; i++)
		if (!(i & rdev_p->qpmask))
			__kfifo_put(rdev_p->rscp->qpid_fifo,
			__kfifo_put(&rdev_p->rscp->qpid_fifo,
				    (unsigned char *) &i, sizeof(u32));
	return 0;
}
@@ -134,7 +132,7 @@ int cxio_hal_init_rhdl_resource(u32 nr_rhdl)

void cxio_hal_destroy_rhdl_resource(void)
{
	kfifo_free(rhdl_fifo);
	kfifo_free(&rhdl_fifo);
}

/* nr_* must be power of 2 */
@@ -167,11 +165,11 @@ int cxio_hal_init_resource(struct cxio_rdev *rdev_p,
		goto pdid_err;
	return 0;
pdid_err:
	kfifo_free(rscp->cqid_fifo);
	kfifo_free(&rscp->cqid_fifo);
cqid_err:
	kfifo_free(rscp->qpid_fifo);
	kfifo_free(&rscp->qpid_fifo);
qpid_err:
	kfifo_free(rscp->tpt_fifo);
	kfifo_free(&rscp->tpt_fifo);
tpt_err:
	return -ENOMEM;
}
@@ -195,17 +193,17 @@ static void cxio_hal_put_resource(struct kfifo *fifo, u32 entry)

u32 cxio_hal_get_stag(struct cxio_hal_resource *rscp)
{
	return cxio_hal_get_resource(rscp->tpt_fifo);
	return cxio_hal_get_resource(&rscp->tpt_fifo);
}

void cxio_hal_put_stag(struct cxio_hal_resource *rscp, u32 stag)
{
	cxio_hal_put_resource(rscp->tpt_fifo, stag);
	cxio_hal_put_resource(&rscp->tpt_fifo, stag);
}

u32 cxio_hal_get_qpid(struct cxio_hal_resource *rscp)
{
	u32 qpid = cxio_hal_get_resource(rscp->qpid_fifo);
	u32 qpid = cxio_hal_get_resource(&rscp->qpid_fifo);
	PDBG("%s qpid 0x%x\n", __func__, qpid);
	return qpid;
}
@@ -213,35 +211,35 @@ u32 cxio_hal_get_qpid(struct cxio_hal_resource *rscp)
void cxio_hal_put_qpid(struct cxio_hal_resource *rscp, u32 qpid)
{
	PDBG("%s qpid 0x%x\n", __func__, qpid);
	cxio_hal_put_resource(rscp->qpid_fifo, qpid);
	cxio_hal_put_resource(&rscp->qpid_fifo, qpid);
}

u32 cxio_hal_get_cqid(struct cxio_hal_resource *rscp)
{
	return cxio_hal_get_resource(rscp->cqid_fifo);
	return cxio_hal_get_resource(&rscp->cqid_fifo);
}

void cxio_hal_put_cqid(struct cxio_hal_resource *rscp, u32 cqid)
{
	cxio_hal_put_resource(rscp->cqid_fifo, cqid);
	cxio_hal_put_resource(&rscp->cqid_fifo, cqid);
}

u32 cxio_hal_get_pdid(struct cxio_hal_resource *rscp)
{
	return cxio_hal_get_resource(rscp->pdid_fifo);
	return cxio_hal_get_resource(&rscp->pdid_fifo);
}

void cxio_hal_put_pdid(struct cxio_hal_resource *rscp, u32 pdid)
{
	cxio_hal_put_resource(rscp->pdid_fifo, pdid);
	cxio_hal_put_resource(&rscp->pdid_fifo, pdid);
}

void cxio_hal_destroy_resource(struct cxio_hal_resource *rscp)
{
	kfifo_free(rscp->tpt_fifo);
	kfifo_free(rscp->cqid_fifo);
	kfifo_free(rscp->qpid_fifo);
	kfifo_free(rscp->pdid_fifo);
	kfifo_free(&rscp->tpt_fifo);
	kfifo_free(&rscp->cqid_fifo);
	kfifo_free(&rscp->qpid_fifo);
	kfifo_free(&rscp->pdid_fifo);
	kfree(rscp);
}

+23 −25
Original line number Diff line number Diff line
@@ -800,7 +800,7 @@ static irqreturn_t meye_irq(int irq, void *dev_id)
		return IRQ_HANDLED;

	if (meye.mchip_mode == MCHIP_HIC_MODE_CONT_OUT) {
		if (kfifo_get(meye.grabq, (unsigned char *)&reqnr,
		if (kfifo_get(&meye.grabq, (unsigned char *)&reqnr,
			      sizeof(int)) != sizeof(int)) {
			mchip_free_frame();
			return IRQ_HANDLED;
@@ -811,7 +811,7 @@ static irqreturn_t meye_irq(int irq, void *dev_id)
		meye.grab_buffer[reqnr].state = MEYE_BUF_DONE;
		do_gettimeofday(&meye.grab_buffer[reqnr].timestamp);
		meye.grab_buffer[reqnr].sequence = sequence++;
		kfifo_put(meye.doneq, (unsigned char *)&reqnr, sizeof(int));
		kfifo_put(&meye.doneq, (unsigned char *)&reqnr, sizeof(int));
		wake_up_interruptible(&meye.proc_list);
	} else {
		int size;
@@ -820,7 +820,7 @@ static irqreturn_t meye_irq(int irq, void *dev_id)
			mchip_free_frame();
			goto again;
		}
		if (kfifo_get(meye.grabq, (unsigned char *)&reqnr,
		if (kfifo_get(&meye.grabq, (unsigned char *)&reqnr,
			      sizeof(int)) != sizeof(int)) {
			mchip_free_frame();
			goto again;
@@ -831,7 +831,7 @@ static irqreturn_t meye_irq(int irq, void *dev_id)
		meye.grab_buffer[reqnr].state = MEYE_BUF_DONE;
		do_gettimeofday(&meye.grab_buffer[reqnr].timestamp);
		meye.grab_buffer[reqnr].sequence = sequence++;
		kfifo_put(meye.doneq, (unsigned char *)&reqnr, sizeof(int));
		kfifo_put(&meye.doneq, (unsigned char *)&reqnr, sizeof(int));
		wake_up_interruptible(&meye.proc_list);
	}
	mchip_free_frame();
@@ -859,8 +859,8 @@ static int meye_open(struct file *file)

	for (i = 0; i < MEYE_MAX_BUFNBRS; i++)
		meye.grab_buffer[i].state = MEYE_BUF_UNUSED;
	kfifo_reset(meye.grabq);
	kfifo_reset(meye.doneq);
	kfifo_reset(&meye.grabq);
	kfifo_reset(&meye.doneq);
	return 0;
}

@@ -933,7 +933,7 @@ static int meyeioc_qbuf_capt(int *nb)
		mchip_cont_compression_start();

	meye.grab_buffer[*nb].state = MEYE_BUF_USING;
	kfifo_put(meye.grabq, (unsigned char *)nb, sizeof(int));
	kfifo_put(&meye.grabq, (unsigned char *)nb, sizeof(int));
	mutex_unlock(&meye.lock);

	return 0;
@@ -965,7 +965,7 @@ static int meyeioc_sync(struct file *file, void *fh, int *i)
		/* fall through */
	case MEYE_BUF_DONE:
		meye.grab_buffer[*i].state = MEYE_BUF_UNUSED;
		kfifo_get(meye.doneq, (unsigned char *)&unused, sizeof(int));
		kfifo_get(&meye.doneq, (unsigned char *)&unused, sizeof(int));
	}
	*i = meye.grab_buffer[*i].size;
	mutex_unlock(&meye.lock);
@@ -1452,7 +1452,7 @@ static int vidioc_qbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
	buf->flags |= V4L2_BUF_FLAG_QUEUED;
	buf->flags &= ~V4L2_BUF_FLAG_DONE;
	meye.grab_buffer[buf->index].state = MEYE_BUF_USING;
	kfifo_put(meye.grabq, (unsigned char *)&buf->index, sizeof(int));
	kfifo_put(&meye.grabq, (unsigned char *)&buf->index, sizeof(int));
	mutex_unlock(&meye.lock);

	return 0;
@@ -1467,18 +1467,18 @@ static int vidioc_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf)

	mutex_lock(&meye.lock);

	if (kfifo_len(meye.doneq) == 0 && file->f_flags & O_NONBLOCK) {
	if (kfifo_len(&meye.doneq) == 0 && file->f_flags & O_NONBLOCK) {
		mutex_unlock(&meye.lock);
		return -EAGAIN;
	}

	if (wait_event_interruptible(meye.proc_list,
				     kfifo_len(meye.doneq) != 0) < 0) {
				     kfifo_len(&meye.doneq) != 0) < 0) {
		mutex_unlock(&meye.lock);
		return -EINTR;
	}

	if (!kfifo_get(meye.doneq, (unsigned char *)&reqnr,
	if (!kfifo_get(&meye.doneq, (unsigned char *)&reqnr,
		       sizeof(int))) {
		mutex_unlock(&meye.lock);
		return -EBUSY;
@@ -1529,8 +1529,8 @@ static int vidioc_streamoff(struct file *file, void *fh, enum v4l2_buf_type i)
{
	mutex_lock(&meye.lock);
	mchip_hic_stop();
	kfifo_reset(meye.grabq);
	kfifo_reset(meye.doneq);
	kfifo_reset(&meye.grabq);
	kfifo_reset(&meye.doneq);

	for (i = 0; i < MEYE_MAX_BUFNBRS; i++)
		meye.grab_buffer[i].state = MEYE_BUF_UNUSED;
@@ -1572,7 +1572,7 @@ static unsigned int meye_poll(struct file *file, poll_table *wait)

	mutex_lock(&meye.lock);
	poll_wait(file, &meye.proc_list, wait);
	if (kfifo_len(meye.doneq))
	if (kfifo_len(&meye.doneq))
		res = POLLIN | POLLRDNORM;
	mutex_unlock(&meye.lock);
	return res;
@@ -1745,16 +1745,14 @@ static int __devinit meye_probe(struct pci_dev *pcidev,
	}

	spin_lock_init(&meye.grabq_lock);
	meye.grabq = kfifo_alloc(sizeof(int) * MEYE_MAX_BUFNBRS, GFP_KERNEL,
				 &meye.grabq_lock);
	if (IS_ERR(meye.grabq)) {
	if (kfifo_alloc(&meye.grabq, sizeof(int) * MEYE_MAX_BUFNBRS, GFP_KERNEL,
				 &meye.grabq_lock)) {
		printk(KERN_ERR "meye: fifo allocation failed\n");
		goto outkfifoalloc1;
	}
	spin_lock_init(&meye.doneq_lock);
	meye.doneq = kfifo_alloc(sizeof(int) * MEYE_MAX_BUFNBRS, GFP_KERNEL,
				 &meye.doneq_lock);
	if (IS_ERR(meye.doneq)) {
	if (kfifo_alloc(&meye.doneq, sizeof(int) * MEYE_MAX_BUFNBRS, GFP_KERNEL,
				 &meye.doneq_lock)) {
		printk(KERN_ERR "meye: fifo allocation failed\n");
		goto outkfifoalloc2;
	}
@@ -1868,9 +1866,9 @@ static int __devinit meye_probe(struct pci_dev *pcidev,
outenabledev:
	sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERA, 0);
outsonypienable:
	kfifo_free(meye.doneq);
	kfifo_free(&meye.doneq);
outkfifoalloc2:
	kfifo_free(meye.grabq);
	kfifo_free(&meye.grabq);
outkfifoalloc1:
	vfree(meye.grab_temp);
outvmalloc:
@@ -1901,8 +1899,8 @@ static void __devexit meye_remove(struct pci_dev *pcidev)

	sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERA, 0);

	kfifo_free(meye.doneq);
	kfifo_free(meye.grabq);
	kfifo_free(&meye.doneq);
	kfifo_free(&meye.grabq);

	vfree(meye.grab_temp);

Loading