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

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

kfifo: move out spinlock



Move the pointer to the spinlock out of struct kfifo.  Most users in
tree do not actually use a spinlock, so the few exceptions now have to
call kfifo_{get,put}_locked, which takes an extra argument to a
spinlock.

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 45465487
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -686,7 +686,7 @@ static int nozomi_read_config_table(struct nozomi *dc)


		for (i = PORT_MDM; i < MAX_PORT; i++) {
		for (i = PORT_MDM; i < MAX_PORT; i++) {
			kfifo_alloc(&dc->port[i].fifo_ul,
			kfifo_alloc(&dc->port[i].fifo_ul,
				FIFO_BUFFER_SIZE_UL, GFP_ATOMIC, NULL);
				FIFO_BUFFER_SIZE_UL, GFP_ATOMIC);
			memset(&dc->port[i].ctrl_dl, 0, sizeof(struct ctrl_dl));
			memset(&dc->port[i].ctrl_dl, 0, sizeof(struct ctrl_dl));
			memset(&dc->port[i].ctrl_ul, 0, sizeof(struct ctrl_ul));
			memset(&dc->port[i].ctrl_ul, 0, sizeof(struct ctrl_ul));
		}
		}
+12 −9
Original line number Original line Diff line number Diff line
@@ -777,8 +777,9 @@ static void input_keyrelease(struct work_struct *work)
{
{
	struct sonypi_keypress kp;
	struct sonypi_keypress kp;


	while (kfifo_get(&sonypi_device.input_fifo, (unsigned char *)&kp,
	while (kfifo_get_locked(&sonypi_device.input_fifo, (unsigned char *)&kp,
			 sizeof(kp)) == sizeof(kp)) {
			 sizeof(kp), &sonypi_device.input_fifo_lock)
			== sizeof(kp)) {
		msleep(10);
		msleep(10);
		input_report_key(kp.dev, kp.key, 0);
		input_report_key(kp.dev, kp.key, 0);
		input_sync(kp.dev);
		input_sync(kp.dev);
@@ -827,8 +828,9 @@ static void sonypi_report_input_event(u8 event)
	if (kp.dev) {
	if (kp.dev) {
		input_report_key(kp.dev, kp.key, 1);
		input_report_key(kp.dev, kp.key, 1);
		input_sync(kp.dev);
		input_sync(kp.dev);
		kfifo_put(&sonypi_device.input_fifo,
		kfifo_put_locked(&sonypi_device.input_fifo,
			  (unsigned char *)&kp, sizeof(kp));
			(unsigned char *)&kp, sizeof(kp),
			&sonypi_device.input_fifo_lock);
		schedule_work(&sonypi_device.input_work);
		schedule_work(&sonypi_device.input_work);
	}
	}
}
}
@@ -880,7 +882,8 @@ found:
		acpi_bus_generate_proc_event(sonypi_acpi_device, 1, event);
		acpi_bus_generate_proc_event(sonypi_acpi_device, 1, event);
#endif
#endif


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


@@ -929,7 +932,8 @@ static ssize_t sonypi_misc_read(struct file *file, char __user *buf,
		return ret;
		return ret;


	while (ret < count &&
	while (ret < count &&
	       (kfifo_get(&sonypi_device.fifo, &c, sizeof(c)) == sizeof(c))) {
	       (kfifo_get_locked(&sonypi_device.fifo, &c, sizeof(c),
				 &sonypi_device.fifo_lock) == sizeof(c))) {
		if (put_user(c, buf++))
		if (put_user(c, buf++))
			return -EFAULT;
			return -EFAULT;
		ret++;
		ret++;
@@ -1313,8 +1317,7 @@ static int __devinit sonypi_probe(struct platform_device *dev)
			"http://www.linux.it/~malattia/wiki/index.php/Sony_drivers\n");
			"http://www.linux.it/~malattia/wiki/index.php/Sony_drivers\n");


	spin_lock_init(&sonypi_device.fifo_lock);
	spin_lock_init(&sonypi_device.fifo_lock);
	error = kfifo_alloc(&sonypi_device.fifo, SONYPI_BUF_SIZE, GFP_KERNEL,
	error = kfifo_alloc(&sonypi_device.fifo, SONYPI_BUF_SIZE, GFP_KERNEL);
					 &sonypi_device.fifo_lock);
	if (error) {
	if (error) {
		printk(KERN_ERR "sonypi: kfifo_alloc failed\n");
		printk(KERN_ERR "sonypi: kfifo_alloc failed\n");
		return error;
		return error;
@@ -1394,7 +1397,7 @@ static int __devinit sonypi_probe(struct platform_device *dev)


		spin_lock_init(&sonypi_device.input_fifo_lock);
		spin_lock_init(&sonypi_device.input_fifo_lock);
		error = kfifo_alloc(&sonypi_device.input_fifo, SONYPI_BUF_SIZE,
		error = kfifo_alloc(&sonypi_device.input_fifo, SONYPI_BUF_SIZE,
				GFP_KERNEL, &sonypi_device.input_fifo_lock);
				GFP_KERNEL);
		if (error) {
		if (error) {
			printk(KERN_ERR "sonypi: kfifo_alloc failed\n");
			printk(KERN_ERR "sonypi: kfifo_alloc failed\n");
			goto err_inpdev_unregister;
			goto err_inpdev_unregister;
+20 −16
Original line number Original line Diff line number Diff line
@@ -55,7 +55,7 @@ static int __cxio_init_resource_fifo(struct kfifo *fifo,
	u32 rarray[16];
	u32 rarray[16];
	spin_lock_init(fifo_lock);
	spin_lock_init(fifo_lock);


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


	for (i = 0; i < skip_low + skip_high; i++)
	for (i = 0; i < skip_low + skip_high; i++)
@@ -86,7 +86,8 @@ static int __cxio_init_resource_fifo(struct kfifo *fifo,
			__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++)
	for (i = 0; i < skip_low + skip_high; i++)
		kfifo_get(fifo, (unsigned char *) &entry, sizeof(u32));
		kfifo_get_locked(fifo, (unsigned char *) &entry,
				sizeof(u32), fifo_lock);
	return 0;
	return 0;
}
}


@@ -113,8 +114,7 @@ static int cxio_init_qpid_fifo(struct cxio_rdev *rdev_p)
	spin_lock_init(&rdev_p->rscp->qpid_fifo_lock);
	spin_lock_init(&rdev_p->rscp->qpid_fifo_lock);


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


	for (i = 16; i < T3_MAX_NUM_QP; i++)
	for (i = 16; i < T3_MAX_NUM_QP; i++)
@@ -177,33 +177,37 @@ tpt_err:
/*
/*
 * returns 0 if no resource available
 * returns 0 if no resource available
 */
 */
static u32 cxio_hal_get_resource(struct kfifo *fifo)
static u32 cxio_hal_get_resource(struct kfifo *fifo, spinlock_t * lock)
{
{
	u32 entry;
	u32 entry;
	if (kfifo_get(fifo, (unsigned char *) &entry, sizeof(u32)))
	if (kfifo_get_locked(fifo, (unsigned char *) &entry, sizeof(u32), lock))
		return entry;
		return entry;
	else
	else
		return 0;	/* fifo emptry */
		return 0;	/* fifo emptry */
}
}


static void cxio_hal_put_resource(struct kfifo *fifo, u32 entry)
static void cxio_hal_put_resource(struct kfifo *fifo, spinlock_t * lock,
		u32 entry)
{
{
	BUG_ON(kfifo_put(fifo, (unsigned char *) &entry, sizeof(u32)) == 0);
	BUG_ON(
	kfifo_put_locked(fifo, (unsigned char *) &entry, sizeof(u32), lock)
	== 0);
}
}


u32 cxio_hal_get_stag(struct cxio_hal_resource *rscp)
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, &rscp->tpt_fifo_lock);
}
}


void cxio_hal_put_stag(struct cxio_hal_resource *rscp, u32 stag)
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, &rscp->tpt_fifo_lock, stag);
}
}


u32 cxio_hal_get_qpid(struct cxio_hal_resource *rscp)
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,
			&rscp->qpid_fifo_lock);
	PDBG("%s qpid 0x%x\n", __func__, qpid);
	PDBG("%s qpid 0x%x\n", __func__, qpid);
	return qpid;
	return qpid;
}
}
@@ -211,27 +215,27 @@ u32 cxio_hal_get_qpid(struct cxio_hal_resource *rscp)
void cxio_hal_put_qpid(struct cxio_hal_resource *rscp, u32 qpid)
void cxio_hal_put_qpid(struct cxio_hal_resource *rscp, u32 qpid)
{
{
	PDBG("%s qpid 0x%x\n", __func__, qpid);
	PDBG("%s qpid 0x%x\n", __func__, qpid);
	cxio_hal_put_resource(&rscp->qpid_fifo, qpid);
	cxio_hal_put_resource(&rscp->qpid_fifo, &rscp->qpid_fifo_lock, qpid);
}
}


u32 cxio_hal_get_cqid(struct cxio_hal_resource *rscp)
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, &rscp->cqid_fifo_lock);
}
}


void cxio_hal_put_cqid(struct cxio_hal_resource *rscp, u32 cqid)
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, &rscp->cqid_fifo_lock, cqid);
}
}


u32 cxio_hal_get_pdid(struct cxio_hal_resource *rscp)
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, &rscp->pdid_fifo_lock);
}
}


void cxio_hal_put_pdid(struct cxio_hal_resource *rscp, u32 pdid)
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, &rscp->pdid_fifo_lock, pdid);
}
}


void cxio_hal_destroy_resource(struct cxio_hal_resource *rscp)
void cxio_hal_destroy_resource(struct cxio_hal_resource *rscp)
+20 −15
Original line number Original line Diff line number Diff line
@@ -800,8 +800,8 @@ again:
		return IRQ_HANDLED;
		return IRQ_HANDLED;


	if (meye.mchip_mode == MCHIP_HIC_MODE_CONT_OUT) {
	if (meye.mchip_mode == MCHIP_HIC_MODE_CONT_OUT) {
		if (kfifo_get(&meye.grabq, (unsigned char *)&reqnr,
		if (kfifo_get_locked(&meye.grabq, (unsigned char *)&reqnr,
			      sizeof(int)) != sizeof(int)) {
			      sizeof(int), &meye.grabq_lock) != sizeof(int)) {
			mchip_free_frame();
			mchip_free_frame();
			return IRQ_HANDLED;
			return IRQ_HANDLED;
		}
		}
@@ -811,7 +811,8 @@ again:
		meye.grab_buffer[reqnr].state = MEYE_BUF_DONE;
		meye.grab_buffer[reqnr].state = MEYE_BUF_DONE;
		do_gettimeofday(&meye.grab_buffer[reqnr].timestamp);
		do_gettimeofday(&meye.grab_buffer[reqnr].timestamp);
		meye.grab_buffer[reqnr].sequence = sequence++;
		meye.grab_buffer[reqnr].sequence = sequence++;
		kfifo_put(&meye.doneq, (unsigned char *)&reqnr, sizeof(int));
		kfifo_put_locked(&meye.doneq, (unsigned char *)&reqnr,
				sizeof(int), &meye.doneq_lock);
		wake_up_interruptible(&meye.proc_list);
		wake_up_interruptible(&meye.proc_list);
	} else {
	} else {
		int size;
		int size;
@@ -820,8 +821,8 @@ again:
			mchip_free_frame();
			mchip_free_frame();
			goto again;
			goto again;
		}
		}
		if (kfifo_get(&meye.grabq, (unsigned char *)&reqnr,
		if (kfifo_get_locked(&meye.grabq, (unsigned char *)&reqnr,
			      sizeof(int)) != sizeof(int)) {
			      sizeof(int), &meye.grabq_lock) != sizeof(int)) {
			mchip_free_frame();
			mchip_free_frame();
			goto again;
			goto again;
		}
		}
@@ -831,7 +832,8 @@ again:
		meye.grab_buffer[reqnr].state = MEYE_BUF_DONE;
		meye.grab_buffer[reqnr].state = MEYE_BUF_DONE;
		do_gettimeofday(&meye.grab_buffer[reqnr].timestamp);
		do_gettimeofday(&meye.grab_buffer[reqnr].timestamp);
		meye.grab_buffer[reqnr].sequence = sequence++;
		meye.grab_buffer[reqnr].sequence = sequence++;
		kfifo_put(&meye.doneq, (unsigned char *)&reqnr, sizeof(int));
		kfifo_put_locked(&meye.doneq, (unsigned char *)&reqnr,
				sizeof(int), &meye.doneq_lock);
		wake_up_interruptible(&meye.proc_list);
		wake_up_interruptible(&meye.proc_list);
	}
	}
	mchip_free_frame();
	mchip_free_frame();
@@ -933,7 +935,8 @@ static int meyeioc_qbuf_capt(int *nb)
		mchip_cont_compression_start();
		mchip_cont_compression_start();


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


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


	return 0;
	return 0;
@@ -1478,8 +1483,8 @@ static int vidioc_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
		return -EINTR;
		return -EINTR;
	}
	}


	if (!kfifo_get(&meye.doneq, (unsigned char *)&reqnr,
	if (!kfifo_get_locked(&meye.doneq, (unsigned char *)&reqnr,
		       sizeof(int))) {
		       sizeof(int), &meye.doneq_lock)) {
		mutex_unlock(&meye.lock);
		mutex_unlock(&meye.lock);
		return -EBUSY;
		return -EBUSY;
	}
	}
@@ -1745,14 +1750,14 @@ static int __devinit meye_probe(struct pci_dev *pcidev,
	}
	}


	spin_lock_init(&meye.grabq_lock);
	spin_lock_init(&meye.grabq_lock);
	if (kfifo_alloc(&meye.grabq, sizeof(int) * MEYE_MAX_BUFNBRS, GFP_KERNEL,
	if (kfifo_alloc(&meye.grabq, sizeof(int) * MEYE_MAX_BUFNBRS,
				 &meye.grabq_lock)) {
				GFP_KERNEL)) {
		printk(KERN_ERR "meye: fifo allocation failed\n");
		printk(KERN_ERR "meye: fifo allocation failed\n");
		goto outkfifoalloc1;
		goto outkfifoalloc1;
	}
	}
	spin_lock_init(&meye.doneq_lock);
	spin_lock_init(&meye.doneq_lock);
	if (kfifo_alloc(&meye.doneq, sizeof(int) * MEYE_MAX_BUFNBRS, GFP_KERNEL,
	if (kfifo_alloc(&meye.doneq, sizeof(int) * MEYE_MAX_BUFNBRS,
				 &meye.doneq_lock)) {
				GFP_KERNEL)) {
		printk(KERN_ERR "meye: fifo allocation failed\n");
		printk(KERN_ERR "meye: fifo allocation failed\n");
		goto outkfifoalloc2;
		goto outkfifoalloc2;
	}
	}
+1 −1
Original line number Original line Diff line number Diff line
@@ -883,7 +883,7 @@ static int lbs_init_adapter(struct lbs_private *priv)
	priv->resp_len[0] = priv->resp_len[1] = 0;
	priv->resp_len[0] = priv->resp_len[1] = 0;


	/* Create the event FIFO */
	/* Create the event FIFO */
	ret = kfifo_alloc(&priv->event_fifo, sizeof(u32) * 16, GFP_KERNEL, NULL);
	ret = kfifo_alloc(&priv->event_fifo, sizeof(u32) * 16, GFP_KERNEL);
	if (ret) {
	if (ret) {
		lbs_pr_err("Out of memory allocating event FIFO buffer\n");
		lbs_pr_err("Out of memory allocating event FIFO buffer\n");
		goto out;
		goto out;
Loading