diff options
-rw-r--r-- | drivers/char/nozomi.c | 2 | ||||
-rw-r--r-- | drivers/char/sonypi.c | 21 | ||||
-rw-r--r-- | drivers/infiniband/hw/cxgb3/cxio_resource.c | 36 | ||||
-rw-r--r-- | drivers/media/video/meye.c | 35 | ||||
-rw-r--r-- | drivers/net/wireless/libertas/main.c | 2 | ||||
-rw-r--r-- | drivers/platform/x86/fujitsu-laptop.c | 18 | ||||
-rw-r--r-- | drivers/platform/x86/sony-laptop.c | 22 | ||||
-rw-r--r-- | drivers/scsi/libiscsi.c | 2 | ||||
-rw-r--r-- | drivers/scsi/libiscsi_tcp.c | 2 | ||||
-rw-r--r-- | drivers/scsi/libsrp.c | 9 | ||||
-rw-r--r-- | drivers/usb/host/fhci.h | 2 | ||||
-rw-r--r-- | drivers/usb/serial/generic.c | 4 | ||||
-rw-r--r-- | drivers/usb/serial/usb-serial.c | 3 | ||||
-rw-r--r-- | include/linux/kfifo.h | 80 | ||||
-rw-r--r-- | kernel/kfifo.c | 17 | ||||
-rw-r--r-- | net/dccp/probe.c | 6 |
16 files changed, 131 insertions, 130 deletions
diff --git a/drivers/char/nozomi.c b/drivers/char/nozomi.c index 0f39bec28b45..935b30d80adf 100644 --- a/drivers/char/nozomi.c +++ b/drivers/char/nozomi.c | |||
@@ -686,7 +686,7 @@ static int nozomi_read_config_table(struct nozomi *dc) | |||
686 | 686 | ||
687 | for (i = PORT_MDM; i < MAX_PORT; i++) { | 687 | for (i = PORT_MDM; i < MAX_PORT; i++) { |
688 | kfifo_alloc(&dc->port[i].fifo_ul, | 688 | kfifo_alloc(&dc->port[i].fifo_ul, |
689 | FIFO_BUFFER_SIZE_UL, GFP_ATOMIC, NULL); | 689 | FIFO_BUFFER_SIZE_UL, GFP_ATOMIC); |
690 | memset(&dc->port[i].ctrl_dl, 0, sizeof(struct ctrl_dl)); | 690 | memset(&dc->port[i].ctrl_dl, 0, sizeof(struct ctrl_dl)); |
691 | memset(&dc->port[i].ctrl_ul, 0, sizeof(struct ctrl_ul)); | 691 | memset(&dc->port[i].ctrl_ul, 0, sizeof(struct ctrl_ul)); |
692 | } | 692 | } |
diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c index 9e6efb1f029f..dbcb3bd192c7 100644 --- a/drivers/char/sonypi.c +++ b/drivers/char/sonypi.c | |||
@@ -777,8 +777,9 @@ static void input_keyrelease(struct work_struct *work) | |||
777 | { | 777 | { |
778 | struct sonypi_keypress kp; | 778 | struct sonypi_keypress kp; |
779 | 779 | ||
780 | while (kfifo_get(&sonypi_device.input_fifo, (unsigned char *)&kp, | 780 | while (kfifo_get_locked(&sonypi_device.input_fifo, (unsigned char *)&kp, |
781 | sizeof(kp)) == sizeof(kp)) { | 781 | sizeof(kp), &sonypi_device.input_fifo_lock) |
782 | == sizeof(kp)) { | ||
782 | msleep(10); | 783 | msleep(10); |
783 | input_report_key(kp.dev, kp.key, 0); | 784 | input_report_key(kp.dev, kp.key, 0); |
784 | input_sync(kp.dev); | 785 | input_sync(kp.dev); |
@@ -827,8 +828,9 @@ static void sonypi_report_input_event(u8 event) | |||
827 | if (kp.dev) { | 828 | if (kp.dev) { |
828 | input_report_key(kp.dev, kp.key, 1); | 829 | input_report_key(kp.dev, kp.key, 1); |
829 | input_sync(kp.dev); | 830 | input_sync(kp.dev); |
830 | kfifo_put(&sonypi_device.input_fifo, | 831 | kfifo_put_locked(&sonypi_device.input_fifo, |
831 | (unsigned char *)&kp, sizeof(kp)); | 832 | (unsigned char *)&kp, sizeof(kp), |
833 | &sonypi_device.input_fifo_lock); | ||
832 | schedule_work(&sonypi_device.input_work); | 834 | schedule_work(&sonypi_device.input_work); |
833 | } | 835 | } |
834 | } | 836 | } |
@@ -880,7 +882,8 @@ found: | |||
880 | acpi_bus_generate_proc_event(sonypi_acpi_device, 1, event); | 882 | acpi_bus_generate_proc_event(sonypi_acpi_device, 1, event); |
881 | #endif | 883 | #endif |
882 | 884 | ||
883 | kfifo_put(&sonypi_device.fifo, (unsigned char *)&event, sizeof(event)); | 885 | kfifo_put_locked(&sonypi_device.fifo, (unsigned char *)&event, |
886 | sizeof(event), &sonypi_device.fifo_lock); | ||
884 | kill_fasync(&sonypi_device.fifo_async, SIGIO, POLL_IN); | 887 | kill_fasync(&sonypi_device.fifo_async, SIGIO, POLL_IN); |
885 | wake_up_interruptible(&sonypi_device.fifo_proc_list); | 888 | wake_up_interruptible(&sonypi_device.fifo_proc_list); |
886 | 889 | ||
@@ -929,7 +932,8 @@ static ssize_t sonypi_misc_read(struct file *file, char __user *buf, | |||
929 | return ret; | 932 | return ret; |
930 | 933 | ||
931 | while (ret < count && | 934 | while (ret < count && |
932 | (kfifo_get(&sonypi_device.fifo, &c, sizeof(c)) == sizeof(c))) { | 935 | (kfifo_get_locked(&sonypi_device.fifo, &c, sizeof(c), |
936 | &sonypi_device.fifo_lock) == sizeof(c))) { | ||
933 | if (put_user(c, buf++)) | 937 | if (put_user(c, buf++)) |
934 | return -EFAULT; | 938 | return -EFAULT; |
935 | ret++; | 939 | ret++; |
@@ -1313,8 +1317,7 @@ static int __devinit sonypi_probe(struct platform_device *dev) | |||
1313 | "http://www.linux.it/~malattia/wiki/index.php/Sony_drivers\n"); | 1317 | "http://www.linux.it/~malattia/wiki/index.php/Sony_drivers\n"); |
1314 | 1318 | ||
1315 | spin_lock_init(&sonypi_device.fifo_lock); | 1319 | spin_lock_init(&sonypi_device.fifo_lock); |
1316 | error = kfifo_alloc(&sonypi_device.fifo, SONYPI_BUF_SIZE, GFP_KERNEL, | 1320 | error = kfifo_alloc(&sonypi_device.fifo, SONYPI_BUF_SIZE, GFP_KERNEL); |
1317 | &sonypi_device.fifo_lock); | ||
1318 | if (error) { | 1321 | if (error) { |
1319 | printk(KERN_ERR "sonypi: kfifo_alloc failed\n"); | 1322 | printk(KERN_ERR "sonypi: kfifo_alloc failed\n"); |
1320 | return error; | 1323 | return error; |
@@ -1394,7 +1397,7 @@ static int __devinit sonypi_probe(struct platform_device *dev) | |||
1394 | 1397 | ||
1395 | spin_lock_init(&sonypi_device.input_fifo_lock); | 1398 | spin_lock_init(&sonypi_device.input_fifo_lock); |
1396 | error = kfifo_alloc(&sonypi_device.input_fifo, SONYPI_BUF_SIZE, | 1399 | error = kfifo_alloc(&sonypi_device.input_fifo, SONYPI_BUF_SIZE, |
1397 | GFP_KERNEL, &sonypi_device.input_fifo_lock); | 1400 | GFP_KERNEL); |
1398 | if (error) { | 1401 | if (error) { |
1399 | printk(KERN_ERR "sonypi: kfifo_alloc failed\n"); | 1402 | printk(KERN_ERR "sonypi: kfifo_alloc failed\n"); |
1400 | goto err_inpdev_unregister; | 1403 | goto err_inpdev_unregister; |
diff --git a/drivers/infiniband/hw/cxgb3/cxio_resource.c b/drivers/infiniband/hw/cxgb3/cxio_resource.c index 65072bdfc1bf..98f24e6d906e 100644 --- a/drivers/infiniband/hw/cxgb3/cxio_resource.c +++ b/drivers/infiniband/hw/cxgb3/cxio_resource.c | |||
@@ -55,7 +55,7 @@ static int __cxio_init_resource_fifo(struct kfifo *fifo, | |||
55 | u32 rarray[16]; | 55 | u32 rarray[16]; |
56 | spin_lock_init(fifo_lock); | 56 | spin_lock_init(fifo_lock); |
57 | 57 | ||
58 | if (kfifo_alloc(fifo, nr * sizeof(u32), GFP_KERNEL, fifo_lock)) | 58 | if (kfifo_alloc(fifo, nr * sizeof(u32), GFP_KERNEL)) |
59 | return -ENOMEM; | 59 | return -ENOMEM; |
60 | 60 | ||
61 | for (i = 0; i < skip_low + skip_high; i++) | 61 | for (i = 0; i < skip_low + skip_high; i++) |
@@ -86,7 +86,8 @@ static int __cxio_init_resource_fifo(struct kfifo *fifo, | |||
86 | __kfifo_put(fifo, (unsigned char *) &i, sizeof(u32)); | 86 | __kfifo_put(fifo, (unsigned char *) &i, sizeof(u32)); |
87 | 87 | ||
88 | for (i = 0; i < skip_low + skip_high; i++) | 88 | for (i = 0; i < skip_low + skip_high; i++) |
89 | kfifo_get(fifo, (unsigned char *) &entry, sizeof(u32)); | 89 | kfifo_get_locked(fifo, (unsigned char *) &entry, |
90 | sizeof(u32), fifo_lock); | ||
90 | return 0; | 91 | return 0; |
91 | } | 92 | } |
92 | 93 | ||
@@ -113,8 +114,7 @@ static int cxio_init_qpid_fifo(struct cxio_rdev *rdev_p) | |||
113 | spin_lock_init(&rdev_p->rscp->qpid_fifo_lock); | 114 | spin_lock_init(&rdev_p->rscp->qpid_fifo_lock); |
114 | 115 | ||
115 | if (kfifo_alloc(&rdev_p->rscp->qpid_fifo, T3_MAX_NUM_QP * sizeof(u32), | 116 | if (kfifo_alloc(&rdev_p->rscp->qpid_fifo, T3_MAX_NUM_QP * sizeof(u32), |
116 | GFP_KERNEL, | 117 | GFP_KERNEL)) |
117 | &rdev_p->rscp->qpid_fifo_lock)) | ||
118 | return -ENOMEM; | 118 | return -ENOMEM; |
119 | 119 | ||
120 | for (i = 16; i < T3_MAX_NUM_QP; i++) | 120 | for (i = 16; i < T3_MAX_NUM_QP; i++) |
@@ -177,33 +177,37 @@ tpt_err: | |||
177 | /* | 177 | /* |
178 | * returns 0 if no resource available | 178 | * returns 0 if no resource available |
179 | */ | 179 | */ |
180 | static u32 cxio_hal_get_resource(struct kfifo *fifo) | 180 | static u32 cxio_hal_get_resource(struct kfifo *fifo, spinlock_t * lock) |
181 | { | 181 | { |
182 | u32 entry; | 182 | u32 entry; |
183 | if (kfifo_get(fifo, (unsigned char *) &entry, sizeof(u32))) | 183 | if (kfifo_get_locked(fifo, (unsigned char *) &entry, sizeof(u32), lock)) |
184 | return entry; | 184 | return entry; |
185 | else | 185 | else |
186 | return 0; /* fifo emptry */ | 186 | return 0; /* fifo emptry */ |
187 | } | 187 | } |
188 | 188 | ||
189 | static void cxio_hal_put_resource(struct kfifo *fifo, u32 entry) | 189 | static void cxio_hal_put_resource(struct kfifo *fifo, spinlock_t * lock, |
190 | u32 entry) | ||
190 | { | 191 | { |
191 | BUG_ON(kfifo_put(fifo, (unsigned char *) &entry, sizeof(u32)) == 0); | 192 | BUG_ON( |
193 | kfifo_put_locked(fifo, (unsigned char *) &entry, sizeof(u32), lock) | ||
194 | == 0); | ||
192 | } | 195 | } |
193 | 196 | ||
194 | u32 cxio_hal_get_stag(struct cxio_hal_resource *rscp) | 197 | u32 cxio_hal_get_stag(struct cxio_hal_resource *rscp) |
195 | { | 198 | { |
196 | return cxio_hal_get_resource(&rscp->tpt_fifo); | 199 | return cxio_hal_get_resource(&rscp->tpt_fifo, &rscp->tpt_fifo_lock); |
197 | } | 200 | } |
198 | 201 | ||
199 | void cxio_hal_put_stag(struct cxio_hal_resource *rscp, u32 stag) | 202 | void cxio_hal_put_stag(struct cxio_hal_resource *rscp, u32 stag) |
200 | { | 203 | { |
201 | cxio_hal_put_resource(&rscp->tpt_fifo, stag); | 204 | cxio_hal_put_resource(&rscp->tpt_fifo, &rscp->tpt_fifo_lock, stag); |
202 | } | 205 | } |
203 | 206 | ||
204 | u32 cxio_hal_get_qpid(struct cxio_hal_resource *rscp) | 207 | u32 cxio_hal_get_qpid(struct cxio_hal_resource *rscp) |
205 | { | 208 | { |
206 | u32 qpid = cxio_hal_get_resource(&rscp->qpid_fifo); | 209 | u32 qpid = cxio_hal_get_resource(&rscp->qpid_fifo, |
210 | &rscp->qpid_fifo_lock); | ||
207 | PDBG("%s qpid 0x%x\n", __func__, qpid); | 211 | PDBG("%s qpid 0x%x\n", __func__, qpid); |
208 | return qpid; | 212 | return qpid; |
209 | } | 213 | } |
@@ -211,27 +215,27 @@ u32 cxio_hal_get_qpid(struct cxio_hal_resource *rscp) | |||
211 | void cxio_hal_put_qpid(struct cxio_hal_resource *rscp, u32 qpid) | 215 | void cxio_hal_put_qpid(struct cxio_hal_resource *rscp, u32 qpid) |
212 | { | 216 | { |
213 | PDBG("%s qpid 0x%x\n", __func__, qpid); | 217 | PDBG("%s qpid 0x%x\n", __func__, qpid); |
214 | cxio_hal_put_resource(&rscp->qpid_fifo, qpid); | 218 | cxio_hal_put_resource(&rscp->qpid_fifo, &rscp->qpid_fifo_lock, qpid); |
215 | } | 219 | } |
216 | 220 | ||
217 | u32 cxio_hal_get_cqid(struct cxio_hal_resource *rscp) | 221 | u32 cxio_hal_get_cqid(struct cxio_hal_resource *rscp) |
218 | { | 222 | { |
219 | return cxio_hal_get_resource(&rscp->cqid_fifo); | 223 | return cxio_hal_get_resource(&rscp->cqid_fifo, &rscp->cqid_fifo_lock); |
220 | } | 224 | } |
221 | 225 | ||
222 | void cxio_hal_put_cqid(struct cxio_hal_resource *rscp, u32 cqid) | 226 | void cxio_hal_put_cqid(struct cxio_hal_resource *rscp, u32 cqid) |
223 | { | 227 | { |
224 | cxio_hal_put_resource(&rscp->cqid_fifo, cqid); | 228 | cxio_hal_put_resource(&rscp->cqid_fifo, &rscp->cqid_fifo_lock, cqid); |
225 | } | 229 | } |
226 | 230 | ||
227 | u32 cxio_hal_get_pdid(struct cxio_hal_resource *rscp) | 231 | u32 cxio_hal_get_pdid(struct cxio_hal_resource *rscp) |
228 | { | 232 | { |
229 | return cxio_hal_get_resource(&rscp->pdid_fifo); | 233 | return cxio_hal_get_resource(&rscp->pdid_fifo, &rscp->pdid_fifo_lock); |
230 | } | 234 | } |
231 | 235 | ||
232 | void cxio_hal_put_pdid(struct cxio_hal_resource *rscp, u32 pdid) | 236 | void cxio_hal_put_pdid(struct cxio_hal_resource *rscp, u32 pdid) |
233 | { | 237 | { |
234 | cxio_hal_put_resource(&rscp->pdid_fifo, pdid); | 238 | cxio_hal_put_resource(&rscp->pdid_fifo, &rscp->pdid_fifo_lock, pdid); |
235 | } | 239 | } |
236 | 240 | ||
237 | void cxio_hal_destroy_resource(struct cxio_hal_resource *rscp) | 241 | void cxio_hal_destroy_resource(struct cxio_hal_resource *rscp) |
diff --git a/drivers/media/video/meye.c b/drivers/media/video/meye.c index dacbbb839b9e..38bcedfd9fec 100644 --- a/drivers/media/video/meye.c +++ b/drivers/media/video/meye.c | |||
@@ -800,8 +800,8 @@ again: | |||
800 | return IRQ_HANDLED; | 800 | return IRQ_HANDLED; |
801 | 801 | ||
802 | if (meye.mchip_mode == MCHIP_HIC_MODE_CONT_OUT) { | 802 | if (meye.mchip_mode == MCHIP_HIC_MODE_CONT_OUT) { |
803 | if (kfifo_get(&meye.grabq, (unsigned char *)&reqnr, | 803 | if (kfifo_get_locked(&meye.grabq, (unsigned char *)&reqnr, |
804 | sizeof(int)) != sizeof(int)) { | 804 | sizeof(int), &meye.grabq_lock) != sizeof(int)) { |
805 | mchip_free_frame(); | 805 | mchip_free_frame(); |
806 | return IRQ_HANDLED; | 806 | return IRQ_HANDLED; |
807 | } | 807 | } |
@@ -811,7 +811,8 @@ again: | |||
811 | meye.grab_buffer[reqnr].state = MEYE_BUF_DONE; | 811 | meye.grab_buffer[reqnr].state = MEYE_BUF_DONE; |
812 | do_gettimeofday(&meye.grab_buffer[reqnr].timestamp); | 812 | do_gettimeofday(&meye.grab_buffer[reqnr].timestamp); |
813 | meye.grab_buffer[reqnr].sequence = sequence++; | 813 | meye.grab_buffer[reqnr].sequence = sequence++; |
814 | kfifo_put(&meye.doneq, (unsigned char *)&reqnr, sizeof(int)); | 814 | kfifo_put_locked(&meye.doneq, (unsigned char *)&reqnr, |
815 | sizeof(int), &meye.doneq_lock); | ||
815 | wake_up_interruptible(&meye.proc_list); | 816 | wake_up_interruptible(&meye.proc_list); |
816 | } else { | 817 | } else { |
817 | int size; | 818 | int size; |
@@ -820,8 +821,8 @@ again: | |||
820 | mchip_free_frame(); | 821 | mchip_free_frame(); |
821 | goto again; | 822 | goto again; |
822 | } | 823 | } |
823 | if (kfifo_get(&meye.grabq, (unsigned char *)&reqnr, | 824 | if (kfifo_get_locked(&meye.grabq, (unsigned char *)&reqnr, |
824 | sizeof(int)) != sizeof(int)) { | 825 | sizeof(int), &meye.grabq_lock) != sizeof(int)) { |
825 | mchip_free_frame(); | 826 | mchip_free_frame(); |
826 | goto again; | 827 | goto again; |
827 | } | 828 | } |
@@ -831,7 +832,8 @@ again: | |||
831 | meye.grab_buffer[reqnr].state = MEYE_BUF_DONE; | 832 | meye.grab_buffer[reqnr].state = MEYE_BUF_DONE; |
832 | do_gettimeofday(&meye.grab_buffer[reqnr].timestamp); | 833 | do_gettimeofday(&meye.grab_buffer[reqnr].timestamp); |
833 | meye.grab_buffer[reqnr].sequence = sequence++; | 834 | meye.grab_buffer[reqnr].sequence = sequence++; |
834 | kfifo_put(&meye.doneq, (unsigned char *)&reqnr, sizeof(int)); | 835 | kfifo_put_locked(&meye.doneq, (unsigned char *)&reqnr, |
836 | sizeof(int), &meye.doneq_lock); | ||
835 | wake_up_interruptible(&meye.proc_list); | 837 | wake_up_interruptible(&meye.proc_list); |
836 | } | 838 | } |
837 | mchip_free_frame(); | 839 | mchip_free_frame(); |
@@ -933,7 +935,8 @@ static int meyeioc_qbuf_capt(int *nb) | |||
933 | mchip_cont_compression_start(); | 935 | mchip_cont_compression_start(); |
934 | 936 | ||
935 | meye.grab_buffer[*nb].state = MEYE_BUF_USING; | 937 | meye.grab_buffer[*nb].state = MEYE_BUF_USING; |
936 | kfifo_put(&meye.grabq, (unsigned char *)nb, sizeof(int)); | 938 | kfifo_put_locked(&meye.grabq, (unsigned char *)nb, sizeof(int), |
939 | &meye.grabq_lock); | ||
937 | mutex_unlock(&meye.lock); | 940 | mutex_unlock(&meye.lock); |
938 | 941 | ||
939 | return 0; | 942 | return 0; |
@@ -965,7 +968,8 @@ static int meyeioc_sync(struct file *file, void *fh, int *i) | |||
965 | /* fall through */ | 968 | /* fall through */ |
966 | case MEYE_BUF_DONE: | 969 | case MEYE_BUF_DONE: |
967 | meye.grab_buffer[*i].state = MEYE_BUF_UNUSED; | 970 | meye.grab_buffer[*i].state = MEYE_BUF_UNUSED; |
968 | kfifo_get(&meye.doneq, (unsigned char *)&unused, sizeof(int)); | 971 | kfifo_get_locked(&meye.doneq, (unsigned char *)&unused, |
972 | sizeof(int), &meye.doneq_lock); | ||
969 | } | 973 | } |
970 | *i = meye.grab_buffer[*i].size; | 974 | *i = meye.grab_buffer[*i].size; |
971 | mutex_unlock(&meye.lock); | 975 | mutex_unlock(&meye.lock); |
@@ -1452,7 +1456,8 @@ static int vidioc_qbuf(struct file *file, void *fh, struct v4l2_buffer *buf) | |||
1452 | buf->flags |= V4L2_BUF_FLAG_QUEUED; | 1456 | buf->flags |= V4L2_BUF_FLAG_QUEUED; |
1453 | buf->flags &= ~V4L2_BUF_FLAG_DONE; | 1457 | buf->flags &= ~V4L2_BUF_FLAG_DONE; |
1454 | meye.grab_buffer[buf->index].state = MEYE_BUF_USING; | 1458 | meye.grab_buffer[buf->index].state = MEYE_BUF_USING; |
1455 | kfifo_put(&meye.grabq, (unsigned char *)&buf->index, sizeof(int)); | 1459 | kfifo_put_locked(&meye.grabq, (unsigned char *)&buf->index, |
1460 | sizeof(int), &meye.grabq_lock); | ||
1456 | mutex_unlock(&meye.lock); | 1461 | mutex_unlock(&meye.lock); |
1457 | 1462 | ||
1458 | return 0; | 1463 | return 0; |
@@ -1478,8 +1483,8 @@ static int vidioc_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf) | |||
1478 | return -EINTR; | 1483 | return -EINTR; |
1479 | } | 1484 | } |
1480 | 1485 | ||
1481 | if (!kfifo_get(&meye.doneq, (unsigned char *)&reqnr, | 1486 | if (!kfifo_get_locked(&meye.doneq, (unsigned char *)&reqnr, |
1482 | sizeof(int))) { | 1487 | sizeof(int), &meye.doneq_lock)) { |
1483 | mutex_unlock(&meye.lock); | 1488 | mutex_unlock(&meye.lock); |
1484 | return -EBUSY; | 1489 | return -EBUSY; |
1485 | } | 1490 | } |
@@ -1745,14 +1750,14 @@ static int __devinit meye_probe(struct pci_dev *pcidev, | |||
1745 | } | 1750 | } |
1746 | 1751 | ||
1747 | spin_lock_init(&meye.grabq_lock); | 1752 | spin_lock_init(&meye.grabq_lock); |
1748 | if (kfifo_alloc(&meye.grabq, sizeof(int) * MEYE_MAX_BUFNBRS, GFP_KERNEL, | 1753 | if (kfifo_alloc(&meye.grabq, sizeof(int) * MEYE_MAX_BUFNBRS, |
1749 | &meye.grabq_lock)) { | 1754 | GFP_KERNEL)) { |
1750 | printk(KERN_ERR "meye: fifo allocation failed\n"); | 1755 | printk(KERN_ERR "meye: fifo allocation failed\n"); |
1751 | goto outkfifoalloc1; | 1756 | goto outkfifoalloc1; |
1752 | } | 1757 | } |
1753 | spin_lock_init(&meye.doneq_lock); | 1758 | spin_lock_init(&meye.doneq_lock); |
1754 | if (kfifo_alloc(&meye.doneq, sizeof(int) * MEYE_MAX_BUFNBRS, GFP_KERNEL, | 1759 | if (kfifo_alloc(&meye.doneq, sizeof(int) * MEYE_MAX_BUFNBRS, |
1755 | &meye.doneq_lock)) { | 1760 | GFP_KERNEL)) { |
1756 | printk(KERN_ERR "meye: fifo allocation failed\n"); | 1761 | printk(KERN_ERR "meye: fifo allocation failed\n"); |
1757 | goto outkfifoalloc2; | 1762 | goto outkfifoalloc2; |
1758 | } | 1763 | } |
diff --git a/drivers/net/wireless/libertas/main.c b/drivers/net/wireless/libertas/main.c index 403909287414..2cc7ecd8d123 100644 --- a/drivers/net/wireless/libertas/main.c +++ b/drivers/net/wireless/libertas/main.c | |||
@@ -883,7 +883,7 @@ static int lbs_init_adapter(struct lbs_private *priv) | |||
883 | priv->resp_len[0] = priv->resp_len[1] = 0; | 883 | priv->resp_len[0] = priv->resp_len[1] = 0; |
884 | 884 | ||
885 | /* Create the event FIFO */ | 885 | /* Create the event FIFO */ |
886 | ret = kfifo_alloc(&priv->event_fifo, sizeof(u32) * 16, GFP_KERNEL, NULL); | 886 | ret = kfifo_alloc(&priv->event_fifo, sizeof(u32) * 16, GFP_KERNEL); |
887 | if (ret) { | 887 | if (ret) { |
888 | lbs_pr_err("Out of memory allocating event FIFO buffer\n"); | 888 | lbs_pr_err("Out of memory allocating event FIFO buffer\n"); |
889 | goto out; | 889 | goto out; |
diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c index f999fba0e25e..13dc7bedcfce 100644 --- a/drivers/platform/x86/fujitsu-laptop.c +++ b/drivers/platform/x86/fujitsu-laptop.c | |||
@@ -825,7 +825,7 @@ static int acpi_fujitsu_hotkey_add(struct acpi_device *device) | |||
825 | /* kfifo */ | 825 | /* kfifo */ |
826 | spin_lock_init(&fujitsu_hotkey->fifo_lock); | 826 | spin_lock_init(&fujitsu_hotkey->fifo_lock); |
827 | error = kfifo_alloc(&fujitsu_hotkey->fifo, RINGBUFFERSIZE * sizeof(int), | 827 | error = kfifo_alloc(&fujitsu_hotkey->fifo, RINGBUFFERSIZE * sizeof(int), |
828 | GFP_KERNEL, &fujitsu_hotkey->fifo_lock); | 828 | GFP_KERNEL); |
829 | if (error) { | 829 | if (error) { |
830 | printk(KERN_ERR "kfifo_alloc failed\n"); | 830 | printk(KERN_ERR "kfifo_alloc failed\n"); |
831 | goto err_stop; | 831 | goto err_stop; |
@@ -1006,9 +1006,10 @@ static void acpi_fujitsu_hotkey_notify(struct acpi_device *device, u32 event) | |||
1006 | vdbg_printk(FUJLAPTOP_DBG_TRACE, | 1006 | vdbg_printk(FUJLAPTOP_DBG_TRACE, |
1007 | "Push keycode into ringbuffer [%d]\n", | 1007 | "Push keycode into ringbuffer [%d]\n", |
1008 | keycode); | 1008 | keycode); |
1009 | status = kfifo_put(&fujitsu_hotkey->fifo, | 1009 | status = kfifo_put_locked(&fujitsu_hotkey->fifo, |
1010 | (unsigned char *)&keycode, | 1010 | (unsigned char *)&keycode, |
1011 | sizeof(keycode)); | 1011 | sizeof(keycode), |
1012 | &fujitsu_hotkey->fifo_lock); | ||
1012 | if (status != sizeof(keycode)) { | 1013 | if (status != sizeof(keycode)) { |
1013 | vdbg_printk(FUJLAPTOP_DBG_WARN, | 1014 | vdbg_printk(FUJLAPTOP_DBG_WARN, |
1014 | "Could not push keycode [0x%x]\n", | 1015 | "Could not push keycode [0x%x]\n", |
@@ -1019,11 +1020,12 @@ static void acpi_fujitsu_hotkey_notify(struct acpi_device *device, u32 event) | |||
1019 | } | 1020 | } |
1020 | } else if (keycode == 0) { | 1021 | } else if (keycode == 0) { |
1021 | while ((status = | 1022 | while ((status = |
1022 | kfifo_get | 1023 | kfifo_get_locked( |
1023 | (&fujitsu_hotkey->fifo, (unsigned char *) | 1024 | &fujitsu_hotkey->fifo, |
1024 | &keycode_r, | 1025 | (unsigned char *) &keycode_r, |
1025 | sizeof | 1026 | sizeof(keycode_r), |
1026 | (keycode_r))) == sizeof(keycode_r)) { | 1027 | &fujitsu_hotkey->fifo_lock)) |
1028 | == sizeof(keycode_r)) { | ||
1027 | input_report_key(input, keycode_r, 0); | 1029 | input_report_key(input, keycode_r, 0); |
1028 | input_sync(input); | 1030 | input_sync(input); |
1029 | vdbg_printk(FUJLAPTOP_DBG_TRACE, | 1031 | vdbg_printk(FUJLAPTOP_DBG_TRACE, |
diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c index 04625a048e74..1538a0a3c0af 100644 --- a/drivers/platform/x86/sony-laptop.c +++ b/drivers/platform/x86/sony-laptop.c | |||
@@ -300,8 +300,9 @@ static void do_sony_laptop_release_key(struct work_struct *work) | |||
300 | { | 300 | { |
301 | struct sony_laptop_keypress kp; | 301 | struct sony_laptop_keypress kp; |
302 | 302 | ||
303 | while (kfifo_get(&sony_laptop_input.fifo, (unsigned char *)&kp, | 303 | while (kfifo_get_locked(&sony_laptop_input.fifo, (unsigned char *)&kp, |
304 | sizeof(kp)) == sizeof(kp)) { | 304 | sizeof(kp), &sony_laptop_input.fifo_lock) |
305 | == sizeof(kp)) { | ||
305 | msleep(10); | 306 | msleep(10); |
306 | input_report_key(kp.dev, kp.key, 0); | 307 | input_report_key(kp.dev, kp.key, 0); |
307 | input_sync(kp.dev); | 308 | input_sync(kp.dev); |
@@ -362,8 +363,9 @@ static void sony_laptop_report_input_event(u8 event) | |||
362 | /* we emit the scancode so we can always remap the key */ | 363 | /* we emit the scancode so we can always remap the key */ |
363 | input_event(kp.dev, EV_MSC, MSC_SCAN, event); | 364 | input_event(kp.dev, EV_MSC, MSC_SCAN, event); |
364 | input_sync(kp.dev); | 365 | input_sync(kp.dev); |
365 | kfifo_put(&sony_laptop_input.fifo, | 366 | kfifo_put_locked(&sony_laptop_input.fifo, |
366 | (unsigned char *)&kp, sizeof(kp)); | 367 | (unsigned char *)&kp, sizeof(kp), |
368 | &sony_laptop_input.fifo_lock); | ||
367 | 369 | ||
368 | if (!work_pending(&sony_laptop_release_key_work)) | 370 | if (!work_pending(&sony_laptop_release_key_work)) |
369 | queue_work(sony_laptop_input.wq, | 371 | queue_work(sony_laptop_input.wq, |
@@ -386,8 +388,7 @@ static int sony_laptop_setup_input(struct acpi_device *acpi_device) | |||
386 | /* kfifo */ | 388 | /* kfifo */ |
387 | spin_lock_init(&sony_laptop_input.fifo_lock); | 389 | spin_lock_init(&sony_laptop_input.fifo_lock); |
388 | error = | 390 | error = |
389 | kfifo_alloc(&sony_laptop_input.fifo, SONY_LAPTOP_BUF_SIZE, GFP_KERNEL, | 391 | kfifo_alloc(&sony_laptop_input.fifo, SONY_LAPTOP_BUF_SIZE, GFP_KERNEL); |
390 | &sony_laptop_input.fifo_lock); | ||
391 | if (error) { | 392 | if (error) { |
392 | printk(KERN_ERR DRV_PFX "kfifo_alloc failed\n"); | 393 | printk(KERN_ERR DRV_PFX "kfifo_alloc failed\n"); |
393 | goto err_dec_users; | 394 | goto err_dec_users; |
@@ -2129,7 +2130,8 @@ static ssize_t sonypi_misc_read(struct file *file, char __user *buf, | |||
2129 | return ret; | 2130 | return ret; |
2130 | 2131 | ||
2131 | while (ret < count && | 2132 | while (ret < count && |
2132 | (kfifo_get(&sonypi_compat.fifo, &c, sizeof(c)) == sizeof(c))) { | 2133 | (kfifo_get_locked(&sonypi_compat.fifo, &c, sizeof(c), |
2134 | &sonypi_compat.fifo_lock) == sizeof(c))) { | ||
2133 | if (put_user(c, buf++)) | 2135 | if (put_user(c, buf++)) |
2134 | return -EFAULT; | 2136 | return -EFAULT; |
2135 | ret++; | 2137 | ret++; |
@@ -2308,7 +2310,8 @@ static struct miscdevice sonypi_misc_device = { | |||
2308 | 2310 | ||
2309 | static void sonypi_compat_report_event(u8 event) | 2311 | static void sonypi_compat_report_event(u8 event) |
2310 | { | 2312 | { |
2311 | kfifo_put(&sonypi_compat.fifo, (unsigned char *)&event, sizeof(event)); | 2313 | kfifo_put_locked(&sonypi_compat.fifo, (unsigned char *)&event, |
2314 | sizeof(event), &sonypi_compat.fifo_lock); | ||
2312 | kill_fasync(&sonypi_compat.fifo_async, SIGIO, POLL_IN); | 2315 | kill_fasync(&sonypi_compat.fifo_async, SIGIO, POLL_IN); |
2313 | wake_up_interruptible(&sonypi_compat.fifo_proc_list); | 2316 | wake_up_interruptible(&sonypi_compat.fifo_proc_list); |
2314 | } | 2317 | } |
@@ -2319,8 +2322,7 @@ static int sonypi_compat_init(void) | |||
2319 | 2322 | ||
2320 | spin_lock_init(&sonypi_compat.fifo_lock); | 2323 | spin_lock_init(&sonypi_compat.fifo_lock); |
2321 | error = | 2324 | error = |
2322 | kfifo_alloc(&sonypi_compat.fifo, SONY_LAPTOP_BUF_SIZE, GFP_KERNEL, | 2325 | kfifo_alloc(&sonypi_compat.fifo, SONY_LAPTOP_BUF_SIZE, GFP_KERNEL); |
2323 | &sonypi_compat.fifo_lock); | ||
2324 | if (error) { | 2326 | if (error) { |
2325 | printk(KERN_ERR DRV_PFX "kfifo_alloc failed\n"); | 2327 | printk(KERN_ERR DRV_PFX "kfifo_alloc failed\n"); |
2326 | return error; | 2328 | return error; |
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c index cf0aa7e90be9..1bccbc1e588e 100644 --- a/drivers/scsi/libiscsi.c +++ b/drivers/scsi/libiscsi.c | |||
@@ -2461,7 +2461,7 @@ iscsi_pool_init(struct iscsi_pool *q, int max, void ***items, int item_size) | |||
2461 | if (q->pool == NULL) | 2461 | if (q->pool == NULL) |
2462 | return -ENOMEM; | 2462 | return -ENOMEM; |
2463 | 2463 | ||
2464 | kfifo_init(&q->queue, (void*)q->pool, max * sizeof(void*), NULL); | 2464 | kfifo_init(&q->queue, (void*)q->pool, max * sizeof(void*)); |
2465 | 2465 | ||
2466 | for (i = 0; i < max; i++) { | 2466 | for (i = 0; i < max; i++) { |
2467 | q->pool[i] = kzalloc(item_size, GFP_KERNEL); | 2467 | q->pool[i] = kzalloc(item_size, GFP_KERNEL); |
diff --git a/drivers/scsi/libiscsi_tcp.c b/drivers/scsi/libiscsi_tcp.c index a83ee56a185e..41643c860d26 100644 --- a/drivers/scsi/libiscsi_tcp.c +++ b/drivers/scsi/libiscsi_tcp.c | |||
@@ -1128,7 +1128,7 @@ int iscsi_tcp_r2tpool_alloc(struct iscsi_session *session) | |||
1128 | 1128 | ||
1129 | /* R2T xmit queue */ | 1129 | /* R2T xmit queue */ |
1130 | if (kfifo_alloc(&tcp_task->r2tqueue, | 1130 | if (kfifo_alloc(&tcp_task->r2tqueue, |
1131 | session->max_r2t * 4 * sizeof(void*), GFP_KERNEL, NULL)) { | 1131 | session->max_r2t * 4 * sizeof(void*), GFP_KERNEL)) { |
1132 | iscsi_pool_free(&tcp_task->r2tpool); | 1132 | iscsi_pool_free(&tcp_task->r2tpool); |
1133 | goto r2t_alloc_fail; | 1133 | goto r2t_alloc_fail; |
1134 | } | 1134 | } |
diff --git a/drivers/scsi/libsrp.c b/drivers/scsi/libsrp.c index b1b5e51ca8e3..db1b41c55fd3 100644 --- a/drivers/scsi/libsrp.c +++ b/drivers/scsi/libsrp.c | |||
@@ -58,8 +58,7 @@ static int srp_iu_pool_alloc(struct srp_queue *q, size_t max, | |||
58 | goto free_pool; | 58 | goto free_pool; |
59 | 59 | ||
60 | spin_lock_init(&q->lock); | 60 | spin_lock_init(&q->lock); |
61 | kfifo_init(&q->queue, (void *) q->pool, max * sizeof(void *), | 61 | kfifo_init(&q->queue, (void *) q->pool, max * sizeof(void *)); |
62 | &q->lock); | ||
63 | 62 | ||
64 | for (i = 0, iue = q->items; i < max; i++) { | 63 | for (i = 0, iue = q->items; i < max; i++) { |
65 | __kfifo_put(&q->queue, (void *) &iue, sizeof(void *)); | 64 | __kfifo_put(&q->queue, (void *) &iue, sizeof(void *)); |
@@ -164,7 +163,8 @@ struct iu_entry *srp_iu_get(struct srp_target *target) | |||
164 | { | 163 | { |
165 | struct iu_entry *iue = NULL; | 164 | struct iu_entry *iue = NULL; |
166 | 165 | ||
167 | kfifo_get(&target->iu_queue.queue, (void *) &iue, sizeof(void *)); | 166 | kfifo_get_locked(&target->iu_queue.queue, (void *) &iue, |
167 | sizeof(void *), &target->iu_queue.lock); | ||
168 | if (!iue) | 168 | if (!iue) |
169 | return iue; | 169 | return iue; |
170 | iue->target = target; | 170 | iue->target = target; |
@@ -176,7 +176,8 @@ EXPORT_SYMBOL_GPL(srp_iu_get); | |||
176 | 176 | ||
177 | void srp_iu_put(struct iu_entry *iue) | 177 | void srp_iu_put(struct iu_entry *iue) |
178 | { | 178 | { |
179 | kfifo_put(&iue->target->iu_queue.queue, (void *) &iue, sizeof(void *)); | 179 | kfifo_put_locked(&iue->target->iu_queue.queue, (void *) &iue, |
180 | sizeof(void *), &iue->target->iu_queue.lock); | ||
180 | } | 181 | } |
181 | EXPORT_SYMBOL_GPL(srp_iu_put); | 182 | EXPORT_SYMBOL_GPL(srp_iu_put); |
182 | 183 | ||
diff --git a/drivers/usb/host/fhci.h b/drivers/usb/host/fhci.h index 2277428ef5d3..a76da201183b 100644 --- a/drivers/usb/host/fhci.h +++ b/drivers/usb/host/fhci.h | |||
@@ -495,7 +495,7 @@ static inline struct usb_hcd *fhci_to_hcd(struct fhci_hcd *fhci) | |||
495 | /* fifo of pointers */ | 495 | /* fifo of pointers */ |
496 | static inline int cq_new(struct kfifo *fifo, int size) | 496 | static inline int cq_new(struct kfifo *fifo, int size) |
497 | { | 497 | { |
498 | return kfifo_alloc(fifo, size * sizeof(void *), GFP_KERNEL, NULL); | 498 | return kfifo_alloc(fifo, size * sizeof(void *), GFP_KERNEL); |
499 | } | 499 | } |
500 | 500 | ||
501 | static inline void cq_delete(struct kfifo *kfifo) | 501 | static inline void cq_delete(struct kfifo *kfifo) |
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c index bbe005cefcfb..61eef18218be 100644 --- a/drivers/usb/serial/generic.c +++ b/drivers/usb/serial/generic.c | |||
@@ -285,7 +285,7 @@ static int usb_serial_generic_write_start(struct usb_serial_port *port) | |||
285 | return 0; | 285 | return 0; |
286 | 286 | ||
287 | data = port->write_urb->transfer_buffer; | 287 | data = port->write_urb->transfer_buffer; |
288 | count = kfifo_get(port->write_fifo, data, port->bulk_out_size); | 288 | count = kfifo_get_locked(port->write_fifo, data, port->bulk_out_size, &port->lock); |
289 | usb_serial_debug_data(debug, &port->dev, __func__, count, data); | 289 | usb_serial_debug_data(debug, &port->dev, __func__, count, data); |
290 | 290 | ||
291 | /* set up our urb */ | 291 | /* set up our urb */ |
@@ -345,7 +345,7 @@ int usb_serial_generic_write(struct tty_struct *tty, | |||
345 | return usb_serial_multi_urb_write(tty, port, | 345 | return usb_serial_multi_urb_write(tty, port, |
346 | buf, count); | 346 | buf, count); |
347 | 347 | ||
348 | count = kfifo_put(port->write_fifo, buf, count); | 348 | count = kfifo_put_locked(port->write_fifo, buf, count, &port->lock); |
349 | result = usb_serial_generic_write_start(port); | 349 | result = usb_serial_generic_write_start(port); |
350 | 350 | ||
351 | if (result >= 0) | 351 | if (result >= 0) |
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c index 44b72d47fac2..636a4f23445e 100644 --- a/drivers/usb/serial/usb-serial.c +++ b/drivers/usb/serial/usb-serial.c | |||
@@ -939,8 +939,7 @@ int usb_serial_probe(struct usb_interface *interface, | |||
939 | dev_err(&interface->dev, "No free urbs available\n"); | 939 | dev_err(&interface->dev, "No free urbs available\n"); |
940 | goto probe_error; | 940 | goto probe_error; |
941 | } | 941 | } |
942 | if (kfifo_alloc(&port->write_fifo, PAGE_SIZE, GFP_KERNEL, | 942 | if (kfifo_alloc(port->write_fifo, PAGE_SIZE, GFP_KERNEL)) |
943 | &port->lock)) | ||
944 | goto probe_error; | 943 | goto probe_error; |
945 | buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); | 944 | buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); |
946 | port->bulk_out_size = buffer_size; | 945 | port->bulk_out_size = buffer_size; |
diff --git a/include/linux/kfifo.h b/include/linux/kfifo.h index c3f8d82efd34..e0f5c9d4197d 100644 --- a/include/linux/kfifo.h +++ b/include/linux/kfifo.h | |||
@@ -30,13 +30,12 @@ struct kfifo { | |||
30 | unsigned int size; /* the size of the allocated buffer */ | 30 | unsigned int size; /* the size of the allocated buffer */ |
31 | unsigned int in; /* data is added at offset (in % size) */ | 31 | unsigned int in; /* data is added at offset (in % size) */ |
32 | unsigned int out; /* data is extracted from off. (out % size) */ | 32 | unsigned int out; /* data is extracted from off. (out % size) */ |
33 | spinlock_t *lock; /* protects concurrent modifications */ | ||
34 | }; | 33 | }; |
35 | 34 | ||
36 | extern void kfifo_init(struct kfifo *fifo, unsigned char *buffer, | 35 | extern void kfifo_init(struct kfifo *fifo, unsigned char *buffer, |
37 | unsigned int size, spinlock_t *lock); | 36 | unsigned int size); |
38 | extern __must_check int kfifo_alloc(struct kfifo *fifo, unsigned int size, | 37 | extern __must_check int kfifo_alloc(struct kfifo *fifo, unsigned int size, |
39 | gfp_t gfp_mask, spinlock_t *lock); | 38 | gfp_t gfp_mask); |
40 | extern void kfifo_free(struct kfifo *fifo); | 39 | extern void kfifo_free(struct kfifo *fifo); |
41 | extern unsigned int __kfifo_put(struct kfifo *fifo, | 40 | extern unsigned int __kfifo_put(struct kfifo *fifo, |
42 | const unsigned char *buffer, unsigned int len); | 41 | const unsigned char *buffer, unsigned int len); |
@@ -58,58 +57,67 @@ static inline void __kfifo_reset(struct kfifo *fifo) | |||
58 | */ | 57 | */ |
59 | static inline void kfifo_reset(struct kfifo *fifo) | 58 | static inline void kfifo_reset(struct kfifo *fifo) |
60 | { | 59 | { |
61 | unsigned long flags; | ||
62 | |||
63 | spin_lock_irqsave(fifo->lock, flags); | ||
64 | |||
65 | __kfifo_reset(fifo); | 60 | __kfifo_reset(fifo); |
61 | } | ||
62 | |||
63 | /** | ||
64 | * __kfifo_len - returns the number of bytes available in the FIFO | ||
65 | * @fifo: the fifo to be used. | ||
66 | */ | ||
67 | static inline unsigned int __kfifo_len(struct kfifo *fifo) | ||
68 | { | ||
69 | register unsigned int out; | ||
66 | 70 | ||
67 | spin_unlock_irqrestore(fifo->lock, flags); | 71 | out = fifo->out; |
72 | smp_rmb(); | ||
73 | return fifo->in - out; | ||
68 | } | 74 | } |
69 | 75 | ||
70 | /** | 76 | /** |
71 | * kfifo_put - puts some data into the FIFO | 77 | * kfifo_put_locked - puts some data into the FIFO using a spinlock for locking |
72 | * @fifo: the fifo to be used. | 78 | * @fifo: the fifo to be used. |
73 | * @buffer: the data to be added. | 79 | * @from: the data to be added. |
74 | * @len: the length of the data to be added. | 80 | * @n: the length of the data to be added. |
81 | * @lock: pointer to the spinlock to use for locking. | ||
75 | * | 82 | * |
76 | * This function copies at most @len bytes from the @buffer into | 83 | * This function copies at most @len bytes from the @from buffer into |
77 | * the FIFO depending on the free space, and returns the number of | 84 | * the FIFO depending on the free space, and returns the number of |
78 | * bytes copied. | 85 | * bytes copied. |
79 | */ | 86 | */ |
80 | static inline unsigned int kfifo_put(struct kfifo *fifo, | 87 | static inline __must_check unsigned int kfifo_put_locked(struct kfifo *fifo, |
81 | const unsigned char *buffer, unsigned int len) | 88 | const unsigned char *from, unsigned int n, spinlock_t *lock) |
82 | { | 89 | { |
83 | unsigned long flags; | 90 | unsigned long flags; |
84 | unsigned int ret; | 91 | unsigned int ret; |
85 | 92 | ||
86 | spin_lock_irqsave(fifo->lock, flags); | 93 | spin_lock_irqsave(lock, flags); |
87 | 94 | ||
88 | ret = __kfifo_put(fifo, buffer, len); | 95 | ret = __kfifo_put(fifo, from, n); |
89 | 96 | ||
90 | spin_unlock_irqrestore(fifo->lock, flags); | 97 | spin_unlock_irqrestore(lock, flags); |
91 | 98 | ||
92 | return ret; | 99 | return ret; |
93 | } | 100 | } |
94 | 101 | ||
95 | /** | 102 | /** |
96 | * kfifo_get - gets some data from the FIFO | 103 | * kfifo_get_locked - gets some data from the FIFO using a spinlock for locking |
97 | * @fifo: the fifo to be used. | 104 | * @fifo: the fifo to be used. |
98 | * @buffer: where the data must be copied. | 105 | * @to: where the data must be copied. |
99 | * @len: the size of the destination buffer. | 106 | * @n: the size of the destination buffer. |
107 | * @lock: pointer to the spinlock to use for locking. | ||
100 | * | 108 | * |
101 | * This function copies at most @len bytes from the FIFO into the | 109 | * This function copies at most @len bytes from the FIFO into the |
102 | * @buffer and returns the number of copied bytes. | 110 | * @to buffer and returns the number of copied bytes. |
103 | */ | 111 | */ |
104 | static inline unsigned int kfifo_get(struct kfifo *fifo, | 112 | static inline __must_check unsigned int kfifo_get_locked(struct kfifo *fifo, |
105 | unsigned char *buffer, unsigned int len) | 113 | unsigned char *to, unsigned int n, spinlock_t *lock) |
106 | { | 114 | { |
107 | unsigned long flags; | 115 | unsigned long flags; |
108 | unsigned int ret; | 116 | unsigned int ret; |
109 | 117 | ||
110 | spin_lock_irqsave(fifo->lock, flags); | 118 | spin_lock_irqsave(lock, flags); |
111 | 119 | ||
112 | ret = __kfifo_get(fifo, buffer, len); | 120 | ret = __kfifo_get(fifo, to, n); |
113 | 121 | ||
114 | /* | 122 | /* |
115 | * optimization: if the FIFO is empty, set the indices to 0 | 123 | * optimization: if the FIFO is empty, set the indices to 0 |
@@ -118,36 +126,18 @@ static inline unsigned int kfifo_get(struct kfifo *fifo, | |||
118 | if (fifo->in == fifo->out) | 126 | if (fifo->in == fifo->out) |
119 | fifo->in = fifo->out = 0; | 127 | fifo->in = fifo->out = 0; |
120 | 128 | ||
121 | spin_unlock_irqrestore(fifo->lock, flags); | 129 | spin_unlock_irqrestore(lock, flags); |
122 | 130 | ||
123 | return ret; | 131 | return ret; |
124 | } | 132 | } |
125 | 133 | ||
126 | /** | 134 | /** |
127 | * __kfifo_len - returns the number of bytes available in the FIFO, no locking version | ||
128 | * @fifo: the fifo to be used. | ||
129 | */ | ||
130 | static inline unsigned int __kfifo_len(struct kfifo *fifo) | ||
131 | { | ||
132 | return fifo->in - fifo->out; | ||
133 | } | ||
134 | |||
135 | /** | ||
136 | * kfifo_len - returns the number of bytes available in the FIFO | 135 | * kfifo_len - returns the number of bytes available in the FIFO |
137 | * @fifo: the fifo to be used. | 136 | * @fifo: the fifo to be used. |
138 | */ | 137 | */ |
139 | static inline unsigned int kfifo_len(struct kfifo *fifo) | 138 | static inline unsigned int kfifo_len(struct kfifo *fifo) |
140 | { | 139 | { |
141 | unsigned long flags; | 140 | return __kfifo_len(fifo); |
142 | unsigned int ret; | ||
143 | |||
144 | spin_lock_irqsave(fifo->lock, flags); | ||
145 | |||
146 | ret = __kfifo_len(fifo); | ||
147 | |||
148 | spin_unlock_irqrestore(fifo->lock, flags); | ||
149 | |||
150 | return ret; | ||
151 | } | 141 | } |
152 | 142 | ||
153 | #endif | 143 | #endif |
diff --git a/kernel/kfifo.c b/kernel/kfifo.c index 8da6bb9782bb..4950bdbe3477 100644 --- a/kernel/kfifo.c +++ b/kernel/kfifo.c | |||
@@ -28,11 +28,10 @@ | |||
28 | #include <linux/log2.h> | 28 | #include <linux/log2.h> |
29 | 29 | ||
30 | static void _kfifo_init(struct kfifo *fifo, unsigned char *buffer, | 30 | static void _kfifo_init(struct kfifo *fifo, unsigned char *buffer, |
31 | unsigned int size, spinlock_t *lock) | 31 | unsigned int size) |
32 | { | 32 | { |
33 | fifo->buffer = buffer; | 33 | fifo->buffer = buffer; |
34 | fifo->size = size; | 34 | fifo->size = size; |
35 | fifo->lock = lock; | ||
36 | 35 | ||
37 | kfifo_reset(fifo); | 36 | kfifo_reset(fifo); |
38 | } | 37 | } |
@@ -42,16 +41,14 @@ static void _kfifo_init(struct kfifo *fifo, unsigned char *buffer, | |||
42 | * @fifo: the fifo to assign the buffer | 41 | * @fifo: the fifo to assign the buffer |
43 | * @buffer: the preallocated buffer to be used. | 42 | * @buffer: the preallocated buffer to be used. |
44 | * @size: the size of the internal buffer, this have to be a power of 2. | 43 | * @size: the size of the internal buffer, this have to be a power of 2. |
45 | * @lock: the lock to be used to protect the fifo buffer | ||
46 | * | 44 | * |
47 | */ | 45 | */ |
48 | void kfifo_init(struct kfifo *fifo, unsigned char *buffer, unsigned int size, | 46 | void kfifo_init(struct kfifo *fifo, unsigned char *buffer, unsigned int size) |
49 | spinlock_t *lock) | ||
50 | { | 47 | { |
51 | /* size must be a power of 2 */ | 48 | /* size must be a power of 2 */ |
52 | BUG_ON(!is_power_of_2(size)); | 49 | BUG_ON(!is_power_of_2(size)); |
53 | 50 | ||
54 | _kfifo_init(fifo, buffer, size, lock); | 51 | _kfifo_init(fifo, buffer, size); |
55 | } | 52 | } |
56 | EXPORT_SYMBOL(kfifo_init); | 53 | EXPORT_SYMBOL(kfifo_init); |
57 | 54 | ||
@@ -60,7 +57,6 @@ EXPORT_SYMBOL(kfifo_init); | |||
60 | * @fifo: the fifo to assign then new buffer | 57 | * @fifo: the fifo to assign then new buffer |
61 | * @size: the size of the buffer to be allocated, this have to be a power of 2. | 58 | * @size: the size of the buffer to be allocated, this have to be a power of 2. |
62 | * @gfp_mask: get_free_pages mask, passed to kmalloc() | 59 | * @gfp_mask: get_free_pages mask, passed to kmalloc() |
63 | * @lock: the lock to be used to protect the fifo buffer | ||
64 | * | 60 | * |
65 | * This function dynamically allocates a new fifo internal buffer | 61 | * This function dynamically allocates a new fifo internal buffer |
66 | * | 62 | * |
@@ -68,8 +64,7 @@ EXPORT_SYMBOL(kfifo_init); | |||
68 | * The buffer will be release with kfifo_free(). | 64 | * The buffer will be release with kfifo_free(). |
69 | * Return 0 if no error, otherwise the an error code | 65 | * Return 0 if no error, otherwise the an error code |
70 | */ | 66 | */ |
71 | int kfifo_alloc(struct kfifo *fifo, unsigned int size, gfp_t gfp_mask, | 67 | int kfifo_alloc(struct kfifo *fifo, unsigned int size, gfp_t gfp_mask) |
72 | spinlock_t *lock) | ||
73 | { | 68 | { |
74 | unsigned char *buffer; | 69 | unsigned char *buffer; |
75 | 70 | ||
@@ -84,11 +79,11 @@ int kfifo_alloc(struct kfifo *fifo, unsigned int size, gfp_t gfp_mask, | |||
84 | 79 | ||
85 | buffer = kmalloc(size, gfp_mask); | 80 | buffer = kmalloc(size, gfp_mask); |
86 | if (!buffer) { | 81 | if (!buffer) { |
87 | _kfifo_init(fifo, 0, 0, NULL); | 82 | _kfifo_init(fifo, 0, 0); |
88 | return -ENOMEM; | 83 | return -ENOMEM; |
89 | } | 84 | } |
90 | 85 | ||
91 | _kfifo_init(fifo, buffer, size, lock); | 86 | _kfifo_init(fifo, buffer, size); |
92 | 87 | ||
93 | return 0; | 88 | return 0; |
94 | } | 89 | } |
diff --git a/net/dccp/probe.c b/net/dccp/probe.c index 6230ceb0823e..c6b50351aa78 100644 --- a/net/dccp/probe.c +++ b/net/dccp/probe.c | |||
@@ -67,7 +67,7 @@ static void printl(const char *fmt, ...) | |||
67 | len += vscnprintf(tbuf+len, sizeof(tbuf)-len, fmt, args); | 67 | len += vscnprintf(tbuf+len, sizeof(tbuf)-len, fmt, args); |
68 | va_end(args); | 68 | va_end(args); |
69 | 69 | ||
70 | kfifo_put(&dccpw.fifo, tbuf, len); | 70 | kfifo_put_locked(&dccpw.fifo, tbuf, len, &dccpw.lock); |
71 | wake_up(&dccpw.wait); | 71 | wake_up(&dccpw.wait); |
72 | } | 72 | } |
73 | 73 | ||
@@ -135,7 +135,7 @@ static ssize_t dccpprobe_read(struct file *file, char __user *buf, | |||
135 | if (error) | 135 | if (error) |
136 | goto out_free; | 136 | goto out_free; |
137 | 137 | ||
138 | cnt = kfifo_get(&dccpw.fifo, tbuf, len); | 138 | cnt = kfifo_get_locked(&dccpw.fifo, tbuf, len, &dccpw.lock); |
139 | error = copy_to_user(buf, tbuf, cnt) ? -EFAULT : 0; | 139 | error = copy_to_user(buf, tbuf, cnt) ? -EFAULT : 0; |
140 | 140 | ||
141 | out_free: | 141 | out_free: |
@@ -156,7 +156,7 @@ static __init int dccpprobe_init(void) | |||
156 | 156 | ||
157 | init_waitqueue_head(&dccpw.wait); | 157 | init_waitqueue_head(&dccpw.wait); |
158 | spin_lock_init(&dccpw.lock); | 158 | spin_lock_init(&dccpw.lock); |
159 | if (kfifo_alloc(&dccpw.fifo, bufsize, GFP_KERNEL, &dccpw.lock)) | 159 | if (kfifo_alloc(&dccpw.fifo, bufsize, GFP_KERNEL)) |
160 | return ret; | 160 | return ret; |
161 | if (!proc_net_fops_create(&init_net, procname, S_IRUSR, &dccpprobe_fops)) | 161 | if (!proc_net_fops_create(&init_net, procname, S_IRUSR, &dccpprobe_fops)) |
162 | goto err0; | 162 | goto err0; |