Commit 45465487897a1c6d508b14b904dc5777f7ec7e04

Authored by Stefani Seibold
Committed by Linus Torvalds
1 parent 2ec91eec47

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: Stefani Seibold <stefani@seibold.net>
Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
Acked-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 24 changed files with 238 additions and 259 deletions Side-by-side Diff

drivers/char/nozomi.c
... ... @@ -358,7 +358,7 @@
358 358 u8 update_flow_control;
359 359 struct ctrl_ul ctrl_ul;
360 360 struct ctrl_dl ctrl_dl;
361   - struct kfifo *fifo_ul;
  361 + struct kfifo fifo_ul;
362 362 void __iomem *dl_addr[2];
363 363 u32 dl_size[2];
364 364 u8 toggle_dl;
... ... @@ -685,8 +685,8 @@
685 685 dump_table(dc);
686 686  
687 687 for (i = PORT_MDM; i < MAX_PORT; i++) {
688   - dc->port[i].fifo_ul =
689   - kfifo_alloc(FIFO_BUFFER_SIZE_UL, GFP_ATOMIC, NULL);
  688 + kfifo_alloc(&dc->port[i].fifo_ul,
  689 + FIFO_BUFFER_SIZE_UL, GFP_ATOMIC, NULL);
690 690 memset(&dc->port[i].ctrl_dl, 0, sizeof(struct ctrl_dl));
691 691 memset(&dc->port[i].ctrl_ul, 0, sizeof(struct ctrl_ul));
692 692 }
... ... @@ -798,7 +798,7 @@
798 798 struct tty_struct *tty = tty_port_tty_get(&port->port);
799 799  
800 800 /* Get data from tty and place in buf for now */
801   - size = __kfifo_get(port->fifo_ul, dc->send_buf,
  801 + size = __kfifo_get(&port->fifo_ul, dc->send_buf,
802 802 ul_size < SEND_BUF_MAX ? ul_size : SEND_BUF_MAX);
803 803  
804 804 if (size == 0) {
805 805  
... ... @@ -988,11 +988,11 @@
988 988  
989 989 } else if (old_ctrl.CTS == 0 && ctrl_dl.CTS == 1) {
990 990  
991   - if (__kfifo_len(dc->port[port].fifo_ul)) {
  991 + if (__kfifo_len(&dc->port[port].fifo_ul)) {
992 992 DBG1("Enable interrupt (0x%04X) on port: %d",
993 993 enable_ier, port);
994 994 DBG1("Data in buffer [%d], enable transmit! ",
995   - __kfifo_len(dc->port[port].fifo_ul));
  995 + __kfifo_len(&dc->port[port].fifo_ul));
996 996 enable_transmit_ul(port, dc);
997 997 } else {
998 998 DBG1("No data in buffer...");
... ... @@ -1536,8 +1536,7 @@
1536 1536 free_irq(pdev->irq, dc);
1537 1537  
1538 1538 for (i = 0; i < MAX_PORT; i++)
1539   - if (dc->port[i].fifo_ul)
1540   - kfifo_free(dc->port[i].fifo_ul);
  1539 + kfifo_free(&dc->port[i].fifo_ul);
1541 1540  
1542 1541 kfree(dc->send_buf);
1543 1542  
... ... @@ -1673,7 +1672,7 @@
1673 1672 goto exit;
1674 1673 }
1675 1674  
1676   - rval = __kfifo_put(port->fifo_ul, (unsigned char *)buffer, count);
  1675 + rval = __kfifo_put(&port->fifo_ul, (unsigned char *)buffer, count);
1677 1676  
1678 1677 /* notify card */
1679 1678 if (unlikely(dc == NULL)) {
... ... @@ -1721,7 +1720,7 @@
1721 1720 if (!port->port.count)
1722 1721 goto exit;
1723 1722  
1724   - room = port->fifo_ul->size - __kfifo_len(port->fifo_ul);
  1723 + room = port->fifo_ul.size - __kfifo_len(&port->fifo_ul);
1725 1724  
1726 1725 exit:
1727 1726 mutex_unlock(&port->tty_sem);
... ... @@ -1878,7 +1877,7 @@
1878 1877 goto exit_in_buffer;
1879 1878 }
1880 1879  
1881   - rval = __kfifo_len(port->fifo_ul);
  1880 + rval = __kfifo_len(&port->fifo_ul);
1882 1881  
1883 1882 exit_in_buffer:
1884 1883 return rval;
drivers/char/sonypi.c
... ... @@ -487,7 +487,7 @@
487 487 int camera_power;
488 488 int bluetooth_power;
489 489 struct mutex lock;
490   - struct kfifo *fifo;
  490 + struct kfifo fifo;
491 491 spinlock_t fifo_lock;
492 492 wait_queue_head_t fifo_proc_list;
493 493 struct fasync_struct *fifo_async;
... ... @@ -496,7 +496,7 @@
496 496 struct input_dev *input_jog_dev;
497 497 struct input_dev *input_key_dev;
498 498 struct work_struct input_work;
499   - struct kfifo *input_fifo;
  499 + struct kfifo input_fifo;
500 500 spinlock_t input_fifo_lock;
501 501 } sonypi_device;
502 502  
... ... @@ -777,7 +777,7 @@
777 777 {
778 778 struct sonypi_keypress kp;
779 779  
780   - while (kfifo_get(sonypi_device.input_fifo, (unsigned char *)&kp,
  780 + while (kfifo_get(&sonypi_device.input_fifo, (unsigned char *)&kp,
781 781 sizeof(kp)) == sizeof(kp)) {
782 782 msleep(10);
783 783 input_report_key(kp.dev, kp.key, 0);
... ... @@ -827,7 +827,7 @@
827 827 if (kp.dev) {
828 828 input_report_key(kp.dev, kp.key, 1);
829 829 input_sync(kp.dev);
830   - kfifo_put(sonypi_device.input_fifo,
  830 + kfifo_put(&sonypi_device.input_fifo,
831 831 (unsigned char *)&kp, sizeof(kp));
832 832 schedule_work(&sonypi_device.input_work);
833 833 }
... ... @@ -880,7 +880,7 @@
880 880 acpi_bus_generate_proc_event(sonypi_acpi_device, 1, event);
881 881 #endif
882 882  
883   - kfifo_put(sonypi_device.fifo, (unsigned char *)&event, sizeof(event));
  883 + kfifo_put(&sonypi_device.fifo, (unsigned char *)&event, sizeof(event));
884 884 kill_fasync(&sonypi_device.fifo_async, SIGIO, POLL_IN);
885 885 wake_up_interruptible(&sonypi_device.fifo_proc_list);
886 886  
... ... @@ -906,7 +906,7 @@
906 906 mutex_lock(&sonypi_device.lock);
907 907 /* Flush input queue on first open */
908 908 if (!sonypi_device.open_count)
909   - kfifo_reset(sonypi_device.fifo);
  909 + kfifo_reset(&sonypi_device.fifo);
910 910 sonypi_device.open_count++;
911 911 mutex_unlock(&sonypi_device.lock);
912 912 unlock_kernel();
913 913  
914 914  
... ... @@ -919,17 +919,17 @@
919 919 ssize_t ret;
920 920 unsigned char c;
921 921  
922   - if ((kfifo_len(sonypi_device.fifo) == 0) &&
  922 + if ((kfifo_len(&sonypi_device.fifo) == 0) &&
923 923 (file->f_flags & O_NONBLOCK))
924 924 return -EAGAIN;
925 925  
926 926 ret = wait_event_interruptible(sonypi_device.fifo_proc_list,
927   - kfifo_len(sonypi_device.fifo) != 0);
  927 + kfifo_len(&sonypi_device.fifo) != 0);
928 928 if (ret)
929 929 return ret;
930 930  
931 931 while (ret < count &&
932   - (kfifo_get(sonypi_device.fifo, &c, sizeof(c)) == sizeof(c))) {
  932 + (kfifo_get(&sonypi_device.fifo, &c, sizeof(c)) == sizeof(c))) {
933 933 if (put_user(c, buf++))
934 934 return -EFAULT;
935 935 ret++;
... ... @@ -946,7 +946,7 @@
946 946 static unsigned int sonypi_misc_poll(struct file *file, poll_table *wait)
947 947 {
948 948 poll_wait(file, &sonypi_device.fifo_proc_list, wait);
949   - if (kfifo_len(sonypi_device.fifo))
  949 + if (kfifo_len(&sonypi_device.fifo))
950 950 return POLLIN | POLLRDNORM;
951 951 return 0;
952 952 }
953 953  
954 954  
... ... @@ -1313,11 +1313,11 @@
1313 1313 "http://www.linux.it/~malattia/wiki/index.php/Sony_drivers\n");
1314 1314  
1315 1315 spin_lock_init(&sonypi_device.fifo_lock);
1316   - sonypi_device.fifo = kfifo_alloc(SONYPI_BUF_SIZE, GFP_KERNEL,
  1316 + error = kfifo_alloc(&sonypi_device.fifo, SONYPI_BUF_SIZE, GFP_KERNEL,
1317 1317 &sonypi_device.fifo_lock);
1318   - if (IS_ERR(sonypi_device.fifo)) {
  1318 + if (error) {
1319 1319 printk(KERN_ERR "sonypi: kfifo_alloc failed\n");
1320   - return PTR_ERR(sonypi_device.fifo);
  1320 + return error;
1321 1321 }
1322 1322  
1323 1323 init_waitqueue_head(&sonypi_device.fifo_proc_list);
1324 1324  
... ... @@ -1393,12 +1393,10 @@
1393 1393 }
1394 1394  
1395 1395 spin_lock_init(&sonypi_device.input_fifo_lock);
1396   - sonypi_device.input_fifo =
1397   - kfifo_alloc(SONYPI_BUF_SIZE, GFP_KERNEL,
1398   - &sonypi_device.input_fifo_lock);
1399   - if (IS_ERR(sonypi_device.input_fifo)) {
  1396 + error = kfifo_alloc(&sonypi_device.input_fifo, SONYPI_BUF_SIZE,
  1397 + GFP_KERNEL, &sonypi_device.input_fifo_lock);
  1398 + if (error) {
1400 1399 printk(KERN_ERR "sonypi: kfifo_alloc failed\n");
1401   - error = PTR_ERR(sonypi_device.input_fifo);
1402 1400 goto err_inpdev_unregister;
1403 1401 }
1404 1402  
... ... @@ -1423,7 +1421,7 @@
1423 1421 pci_disable_device(pcidev);
1424 1422 err_put_pcidev:
1425 1423 pci_dev_put(pcidev);
1426   - kfifo_free(sonypi_device.fifo);
  1424 + kfifo_free(&sonypi_device.fifo);
1427 1425  
1428 1426 return error;
1429 1427 }
... ... @@ -1438,7 +1436,7 @@
1438 1436 if (useinput) {
1439 1437 input_unregister_device(sonypi_device.input_key_dev);
1440 1438 input_unregister_device(sonypi_device.input_jog_dev);
1441   - kfifo_free(sonypi_device.input_fifo);
  1439 + kfifo_free(&sonypi_device.input_fifo);
1442 1440 }
1443 1441  
1444 1442 misc_deregister(&sonypi_misc_device);
... ... @@ -1451,7 +1449,7 @@
1451 1449 pci_dev_put(sonypi_device.dev);
1452 1450 }
1453 1451  
1454   - kfifo_free(sonypi_device.fifo);
  1452 + kfifo_free(&sonypi_device.fifo);
1455 1453  
1456 1454 return 0;
1457 1455 }
drivers/infiniband/hw/cxgb3/cxio_hal.h
... ... @@ -34,6 +34,7 @@
34 34  
35 35 #include <linux/list.h>
36 36 #include <linux/mutex.h>
  37 +#include <linux/kfifo.h>
37 38  
38 39 #include "t3_cpl.h"
39 40 #include "t3cdev.h"
40 41  
41 42  
42 43  
... ... @@ -75,13 +76,13 @@
75 76 };
76 77  
77 78 struct cxio_hal_resource {
78   - struct kfifo *tpt_fifo;
  79 + struct kfifo tpt_fifo;
79 80 spinlock_t tpt_fifo_lock;
80   - struct kfifo *qpid_fifo;
  81 + struct kfifo qpid_fifo;
81 82 spinlock_t qpid_fifo_lock;
82   - struct kfifo *cqid_fifo;
  83 + struct kfifo cqid_fifo;
83 84 spinlock_t cqid_fifo_lock;
84   - struct kfifo *pdid_fifo;
  85 + struct kfifo pdid_fifo;
85 86 spinlock_t pdid_fifo_lock;
86 87 };
87 88  
drivers/infiniband/hw/cxgb3/cxio_resource.c
... ... @@ -39,12 +39,12 @@
39 39 #include "cxio_resource.h"
40 40 #include "cxio_hal.h"
41 41  
42   -static struct kfifo *rhdl_fifo;
  42 +static struct kfifo rhdl_fifo;
43 43 static spinlock_t rhdl_fifo_lock;
44 44  
45 45 #define RANDOM_SIZE 16
46 46  
47   -static int __cxio_init_resource_fifo(struct kfifo **fifo,
  47 +static int __cxio_init_resource_fifo(struct kfifo *fifo,
48 48 spinlock_t *fifo_lock,
49 49 u32 nr, u32 skip_low,
50 50 u32 skip_high,
51 51  
... ... @@ -55,12 +55,11 @@
55 55 u32 rarray[16];
56 56 spin_lock_init(fifo_lock);
57 57  
58   - *fifo = kfifo_alloc(nr * sizeof(u32), GFP_KERNEL, fifo_lock);
59   - if (IS_ERR(*fifo))
  58 + if (kfifo_alloc(fifo, nr * sizeof(u32), GFP_KERNEL, fifo_lock))
60 59 return -ENOMEM;
61 60  
62 61 for (i = 0; i < skip_low + skip_high; i++)
63   - __kfifo_put(*fifo, (unsigned char *) &entry, sizeof(u32));
  62 + __kfifo_put(fifo, (unsigned char *) &entry, sizeof(u32));
64 63 if (random) {
65 64 j = 0;
66 65 random_bytes = random32();
67 66  
68 67  
69 68  
70 69  
71 70  
... ... @@ -72,33 +71,33 @@
72 71 random_bytes = random32();
73 72 }
74 73 idx = (random_bytes >> (j * 2)) & 0xF;
75   - __kfifo_put(*fifo,
  74 + __kfifo_put(fifo,
76 75 (unsigned char *) &rarray[idx],
77 76 sizeof(u32));
78 77 rarray[idx] = i;
79 78 j++;
80 79 }
81 80 for (i = 0; i < RANDOM_SIZE; i++)
82   - __kfifo_put(*fifo,
  81 + __kfifo_put(fifo,
83 82 (unsigned char *) &rarray[i],
84 83 sizeof(u32));
85 84 } else
86 85 for (i = skip_low; i < nr - skip_high; i++)
87   - __kfifo_put(*fifo, (unsigned char *) &i, sizeof(u32));
  86 + __kfifo_put(fifo, (unsigned char *) &i, sizeof(u32));
88 87  
89 88 for (i = 0; i < skip_low + skip_high; i++)
90   - kfifo_get(*fifo, (unsigned char *) &entry, sizeof(u32));
  89 + kfifo_get(fifo, (unsigned char *) &entry, sizeof(u32));
91 90 return 0;
92 91 }
93 92  
94   -static int cxio_init_resource_fifo(struct kfifo **fifo, spinlock_t * fifo_lock,
  93 +static int cxio_init_resource_fifo(struct kfifo *fifo, spinlock_t * fifo_lock,
95 94 u32 nr, u32 skip_low, u32 skip_high)
96 95 {
97 96 return (__cxio_init_resource_fifo(fifo, fifo_lock, nr, skip_low,
98 97 skip_high, 0));
99 98 }
100 99  
101   -static int cxio_init_resource_fifo_random(struct kfifo **fifo,
  100 +static int cxio_init_resource_fifo_random(struct kfifo *fifo,
102 101 spinlock_t * fifo_lock,
103 102 u32 nr, u32 skip_low, u32 skip_high)
104 103 {
105 104  
106 105  
... ... @@ -113,15 +112,14 @@
113 112  
114 113 spin_lock_init(&rdev_p->rscp->qpid_fifo_lock);
115 114  
116   - rdev_p->rscp->qpid_fifo = kfifo_alloc(T3_MAX_NUM_QP * sizeof(u32),
  115 + if (kfifo_alloc(&rdev_p->rscp->qpid_fifo, T3_MAX_NUM_QP * sizeof(u32),
117 116 GFP_KERNEL,
118   - &rdev_p->rscp->qpid_fifo_lock);
119   - if (IS_ERR(rdev_p->rscp->qpid_fifo))
  117 + &rdev_p->rscp->qpid_fifo_lock))
120 118 return -ENOMEM;
121 119  
122 120 for (i = 16; i < T3_MAX_NUM_QP; i++)
123 121 if (!(i & rdev_p->qpmask))
124   - __kfifo_put(rdev_p->rscp->qpid_fifo,
  122 + __kfifo_put(&rdev_p->rscp->qpid_fifo,
125 123 (unsigned char *) &i, sizeof(u32));
126 124 return 0;
127 125 }
... ... @@ -134,7 +132,7 @@
134 132  
135 133 void cxio_hal_destroy_rhdl_resource(void)
136 134 {
137   - kfifo_free(rhdl_fifo);
  135 + kfifo_free(&rhdl_fifo);
138 136 }
139 137  
140 138 /* nr_* must be power of 2 */
141 139  
142 140  
... ... @@ -167,11 +165,11 @@
167 165 goto pdid_err;
168 166 return 0;
169 167 pdid_err:
170   - kfifo_free(rscp->cqid_fifo);
  168 + kfifo_free(&rscp->cqid_fifo);
171 169 cqid_err:
172   - kfifo_free(rscp->qpid_fifo);
  170 + kfifo_free(&rscp->qpid_fifo);
173 171 qpid_err:
174   - kfifo_free(rscp->tpt_fifo);
  172 + kfifo_free(&rscp->tpt_fifo);
175 173 tpt_err:
176 174 return -ENOMEM;
177 175 }
178 176  
179 177  
... ... @@ -195,17 +193,17 @@
195 193  
196 194 u32 cxio_hal_get_stag(struct cxio_hal_resource *rscp)
197 195 {
198   - return cxio_hal_get_resource(rscp->tpt_fifo);
  196 + return cxio_hal_get_resource(&rscp->tpt_fifo);
199 197 }
200 198  
201 199 void cxio_hal_put_stag(struct cxio_hal_resource *rscp, u32 stag)
202 200 {
203   - cxio_hal_put_resource(rscp->tpt_fifo, stag);
  201 + cxio_hal_put_resource(&rscp->tpt_fifo, stag);
204 202 }
205 203  
206 204 u32 cxio_hal_get_qpid(struct cxio_hal_resource *rscp)
207 205 {
208   - u32 qpid = cxio_hal_get_resource(rscp->qpid_fifo);
  206 + u32 qpid = cxio_hal_get_resource(&rscp->qpid_fifo);
209 207 PDBG("%s qpid 0x%x\n", __func__, qpid);
210 208 return qpid;
211 209 }
212 210  
213 211  
214 212  
215 213  
216 214  
... ... @@ -213,35 +211,35 @@
213 211 void cxio_hal_put_qpid(struct cxio_hal_resource *rscp, u32 qpid)
214 212 {
215 213 PDBG("%s qpid 0x%x\n", __func__, qpid);
216   - cxio_hal_put_resource(rscp->qpid_fifo, qpid);
  214 + cxio_hal_put_resource(&rscp->qpid_fifo, qpid);
217 215 }
218 216  
219 217 u32 cxio_hal_get_cqid(struct cxio_hal_resource *rscp)
220 218 {
221   - return cxio_hal_get_resource(rscp->cqid_fifo);
  219 + return cxio_hal_get_resource(&rscp->cqid_fifo);
222 220 }
223 221  
224 222 void cxio_hal_put_cqid(struct cxio_hal_resource *rscp, u32 cqid)
225 223 {
226   - cxio_hal_put_resource(rscp->cqid_fifo, cqid);
  224 + cxio_hal_put_resource(&rscp->cqid_fifo, cqid);
227 225 }
228 226  
229 227 u32 cxio_hal_get_pdid(struct cxio_hal_resource *rscp)
230 228 {
231   - return cxio_hal_get_resource(rscp->pdid_fifo);
  229 + return cxio_hal_get_resource(&rscp->pdid_fifo);
232 230 }
233 231  
234 232 void cxio_hal_put_pdid(struct cxio_hal_resource *rscp, u32 pdid)
235 233 {
236   - cxio_hal_put_resource(rscp->pdid_fifo, pdid);
  234 + cxio_hal_put_resource(&rscp->pdid_fifo, pdid);
237 235 }
238 236  
239 237 void cxio_hal_destroy_resource(struct cxio_hal_resource *rscp)
240 238 {
241   - kfifo_free(rscp->tpt_fifo);
242   - kfifo_free(rscp->cqid_fifo);
243   - kfifo_free(rscp->qpid_fifo);
244   - kfifo_free(rscp->pdid_fifo);
  239 + kfifo_free(&rscp->tpt_fifo);
  240 + kfifo_free(&rscp->cqid_fifo);
  241 + kfifo_free(&rscp->qpid_fifo);
  242 + kfifo_free(&rscp->pdid_fifo);
245 243 kfree(rscp);
246 244 }
247 245  
drivers/media/video/meye.c
... ... @@ -800,7 +800,7 @@
800 800 return IRQ_HANDLED;
801 801  
802 802 if (meye.mchip_mode == MCHIP_HIC_MODE_CONT_OUT) {
803   - if (kfifo_get(meye.grabq, (unsigned char *)&reqnr,
  803 + if (kfifo_get(&meye.grabq, (unsigned char *)&reqnr,
804 804 sizeof(int)) != sizeof(int)) {
805 805 mchip_free_frame();
806 806 return IRQ_HANDLED;
... ... @@ -811,7 +811,7 @@
811 811 meye.grab_buffer[reqnr].state = MEYE_BUF_DONE;
812 812 do_gettimeofday(&meye.grab_buffer[reqnr].timestamp);
813 813 meye.grab_buffer[reqnr].sequence = sequence++;
814   - kfifo_put(meye.doneq, (unsigned char *)&reqnr, sizeof(int));
  814 + kfifo_put(&meye.doneq, (unsigned char *)&reqnr, sizeof(int));
815 815 wake_up_interruptible(&meye.proc_list);
816 816 } else {
817 817 int size;
... ... @@ -820,7 +820,7 @@
820 820 mchip_free_frame();
821 821 goto again;
822 822 }
823   - if (kfifo_get(meye.grabq, (unsigned char *)&reqnr,
  823 + if (kfifo_get(&meye.grabq, (unsigned char *)&reqnr,
824 824 sizeof(int)) != sizeof(int)) {
825 825 mchip_free_frame();
826 826 goto again;
... ... @@ -831,7 +831,7 @@
831 831 meye.grab_buffer[reqnr].state = MEYE_BUF_DONE;
832 832 do_gettimeofday(&meye.grab_buffer[reqnr].timestamp);
833 833 meye.grab_buffer[reqnr].sequence = sequence++;
834   - kfifo_put(meye.doneq, (unsigned char *)&reqnr, sizeof(int));
  834 + kfifo_put(&meye.doneq, (unsigned char *)&reqnr, sizeof(int));
835 835 wake_up_interruptible(&meye.proc_list);
836 836 }
837 837 mchip_free_frame();
... ... @@ -859,8 +859,8 @@
859 859  
860 860 for (i = 0; i < MEYE_MAX_BUFNBRS; i++)
861 861 meye.grab_buffer[i].state = MEYE_BUF_UNUSED;
862   - kfifo_reset(meye.grabq);
863   - kfifo_reset(meye.doneq);
  862 + kfifo_reset(&meye.grabq);
  863 + kfifo_reset(&meye.doneq);
864 864 return 0;
865 865 }
866 866  
... ... @@ -933,7 +933,7 @@
933 933 mchip_cont_compression_start();
934 934  
935 935 meye.grab_buffer[*nb].state = MEYE_BUF_USING;
936   - kfifo_put(meye.grabq, (unsigned char *)nb, sizeof(int));
  936 + kfifo_put(&meye.grabq, (unsigned char *)nb, sizeof(int));
937 937 mutex_unlock(&meye.lock);
938 938  
939 939 return 0;
... ... @@ -965,7 +965,7 @@
965 965 /* fall through */
966 966 case MEYE_BUF_DONE:
967 967 meye.grab_buffer[*i].state = MEYE_BUF_UNUSED;
968   - kfifo_get(meye.doneq, (unsigned char *)&unused, sizeof(int));
  968 + kfifo_get(&meye.doneq, (unsigned char *)&unused, sizeof(int));
969 969 }
970 970 *i = meye.grab_buffer[*i].size;
971 971 mutex_unlock(&meye.lock);
... ... @@ -1452,7 +1452,7 @@
1452 1452 buf->flags |= V4L2_BUF_FLAG_QUEUED;
1453 1453 buf->flags &= ~V4L2_BUF_FLAG_DONE;
1454 1454 meye.grab_buffer[buf->index].state = MEYE_BUF_USING;
1455   - kfifo_put(meye.grabq, (unsigned char *)&buf->index, sizeof(int));
  1455 + kfifo_put(&meye.grabq, (unsigned char *)&buf->index, sizeof(int));
1456 1456 mutex_unlock(&meye.lock);
1457 1457  
1458 1458 return 0;
1459 1459  
1460 1460  
... ... @@ -1467,18 +1467,18 @@
1467 1467  
1468 1468 mutex_lock(&meye.lock);
1469 1469  
1470   - if (kfifo_len(meye.doneq) == 0 && file->f_flags & O_NONBLOCK) {
  1470 + if (kfifo_len(&meye.doneq) == 0 && file->f_flags & O_NONBLOCK) {
1471 1471 mutex_unlock(&meye.lock);
1472 1472 return -EAGAIN;
1473 1473 }
1474 1474  
1475 1475 if (wait_event_interruptible(meye.proc_list,
1476   - kfifo_len(meye.doneq) != 0) < 0) {
  1476 + kfifo_len(&meye.doneq) != 0) < 0) {
1477 1477 mutex_unlock(&meye.lock);
1478 1478 return -EINTR;
1479 1479 }
1480 1480  
1481   - if (!kfifo_get(meye.doneq, (unsigned char *)&reqnr,
  1481 + if (!kfifo_get(&meye.doneq, (unsigned char *)&reqnr,
1482 1482 sizeof(int))) {
1483 1483 mutex_unlock(&meye.lock);
1484 1484 return -EBUSY;
... ... @@ -1529,8 +1529,8 @@
1529 1529 {
1530 1530 mutex_lock(&meye.lock);
1531 1531 mchip_hic_stop();
1532   - kfifo_reset(meye.grabq);
1533   - kfifo_reset(meye.doneq);
  1532 + kfifo_reset(&meye.grabq);
  1533 + kfifo_reset(&meye.doneq);
1534 1534  
1535 1535 for (i = 0; i < MEYE_MAX_BUFNBRS; i++)
1536 1536 meye.grab_buffer[i].state = MEYE_BUF_UNUSED;
... ... @@ -1572,7 +1572,7 @@
1572 1572  
1573 1573 mutex_lock(&meye.lock);
1574 1574 poll_wait(file, &meye.proc_list, wait);
1575   - if (kfifo_len(meye.doneq))
  1575 + if (kfifo_len(&meye.doneq))
1576 1576 res = POLLIN | POLLRDNORM;
1577 1577 mutex_unlock(&meye.lock);
1578 1578 return res;
1579 1579  
... ... @@ -1745,16 +1745,14 @@
1745 1745 }
1746 1746  
1747 1747 spin_lock_init(&meye.grabq_lock);
1748   - meye.grabq = kfifo_alloc(sizeof(int) * MEYE_MAX_BUFNBRS, GFP_KERNEL,
1749   - &meye.grabq_lock);
1750   - if (IS_ERR(meye.grabq)) {
  1748 + if (kfifo_alloc(&meye.grabq, sizeof(int) * MEYE_MAX_BUFNBRS, GFP_KERNEL,
  1749 + &meye.grabq_lock)) {
1751 1750 printk(KERN_ERR "meye: fifo allocation failed\n");
1752 1751 goto outkfifoalloc1;
1753 1752 }
1754 1753 spin_lock_init(&meye.doneq_lock);
1755   - meye.doneq = kfifo_alloc(sizeof(int) * MEYE_MAX_BUFNBRS, GFP_KERNEL,
1756   - &meye.doneq_lock);
1757   - if (IS_ERR(meye.doneq)) {
  1754 + if (kfifo_alloc(&meye.doneq, sizeof(int) * MEYE_MAX_BUFNBRS, GFP_KERNEL,
  1755 + &meye.doneq_lock)) {
1758 1756 printk(KERN_ERR "meye: fifo allocation failed\n");
1759 1757 goto outkfifoalloc2;
1760 1758 }
1761 1759  
... ... @@ -1868,9 +1866,9 @@
1868 1866 outenabledev:
1869 1867 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERA, 0);
1870 1868 outsonypienable:
1871   - kfifo_free(meye.doneq);
  1869 + kfifo_free(&meye.doneq);
1872 1870 outkfifoalloc2:
1873   - kfifo_free(meye.grabq);
  1871 + kfifo_free(&meye.grabq);
1874 1872 outkfifoalloc1:
1875 1873 vfree(meye.grab_temp);
1876 1874 outvmalloc:
... ... @@ -1901,8 +1899,8 @@
1901 1899  
1902 1900 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERA, 0);
1903 1901  
1904   - kfifo_free(meye.doneq);
1905   - kfifo_free(meye.grabq);
  1902 + kfifo_free(&meye.doneq);
  1903 + kfifo_free(&meye.grabq);
1906 1904  
1907 1905 vfree(meye.grab_temp);
1908 1906  
drivers/media/video/meye.h
... ... @@ -303,9 +303,9 @@
303 303 struct meye_grab_buffer grab_buffer[MEYE_MAX_BUFNBRS];
304 304 int vma_use_count[MEYE_MAX_BUFNBRS]; /* mmap count */
305 305 struct mutex lock; /* mutex for open/mmap... */
306   - struct kfifo *grabq; /* queue for buffers to be grabbed */
  306 + struct kfifo grabq; /* queue for buffers to be grabbed */
307 307 spinlock_t grabq_lock; /* lock protecting the queue */
308   - struct kfifo *doneq; /* queue for grabbed buffers */
  308 + struct kfifo doneq; /* queue for grabbed buffers */
309 309 spinlock_t doneq_lock; /* lock protecting the queue */
310 310 wait_queue_head_t proc_list; /* wait queue */
311 311 struct video_device *video_dev; /* video device parameters */
drivers/net/wireless/libertas/cmd.c
... ... @@ -1365,7 +1365,7 @@
1365 1365 priv->dnld_sent = DNLD_RES_RECEIVED;
1366 1366  
1367 1367 /* If nothing to do, go back to sleep (?) */
1368   - if (!__kfifo_len(priv->event_fifo) && !priv->resp_len[priv->resp_idx])
  1368 + if (!__kfifo_len(&priv->event_fifo) && !priv->resp_len[priv->resp_idx])
1369 1369 priv->psstate = PS_STATE_SLEEP;
1370 1370  
1371 1371 spin_unlock_irqrestore(&priv->driver_lock, flags);
... ... @@ -1439,7 +1439,7 @@
1439 1439 }
1440 1440  
1441 1441 /* Pending events or command responses? */
1442   - if (__kfifo_len(priv->event_fifo) || priv->resp_len[priv->resp_idx]) {
  1442 + if (__kfifo_len(&priv->event_fifo) || priv->resp_len[priv->resp_idx]) {
1443 1443 allowed = 0;
1444 1444 lbs_deb_host("pending events or command responses\n");
1445 1445 }
drivers/net/wireless/libertas/dev.h
... ... @@ -10,8 +10,8 @@
10 10 #include "scan.h"
11 11 #include "assoc.h"
12 12  
  13 +#include <linux/kfifo.h>
13 14  
14   -
15 15 /** sleep_params */
16 16 struct sleep_params {
17 17 uint16_t sp_error;
... ... @@ -120,7 +120,7 @@
120 120 u32 resp_len[2];
121 121  
122 122 /* Events sent from hardware to driver */
123   - struct kfifo *event_fifo;
  123 + struct kfifo event_fifo;
124 124  
125 125 /** thread to service interrupts */
126 126 struct task_struct *main_thread;
drivers/net/wireless/libertas/main.c
... ... @@ -459,7 +459,7 @@
459 459 else if (!list_empty(&priv->cmdpendingq) &&
460 460 !(priv->wakeup_dev_required))
461 461 shouldsleep = 0; /* We have a command to send */
462   - else if (__kfifo_len(priv->event_fifo))
  462 + else if (__kfifo_len(&priv->event_fifo))
463 463 shouldsleep = 0; /* We have an event to process */
464 464 else
465 465 shouldsleep = 1; /* No command */
466 466  
... ... @@ -511,9 +511,9 @@
511 511  
512 512 /* Process hardware events, e.g. card removed, link lost */
513 513 spin_lock_irq(&priv->driver_lock);
514   - while (__kfifo_len(priv->event_fifo)) {
  514 + while (__kfifo_len(&priv->event_fifo)) {
515 515 u32 event;
516   - __kfifo_get(priv->event_fifo, (unsigned char *) &event,
  516 + __kfifo_get(&priv->event_fifo, (unsigned char *) &event,
517 517 sizeof(event));
518 518 spin_unlock_irq(&priv->driver_lock);
519 519 lbs_process_event(priv, event);
520 520  
... ... @@ -883,10 +883,9 @@
883 883 priv->resp_len[0] = priv->resp_len[1] = 0;
884 884  
885 885 /* Create the event FIFO */
886   - priv->event_fifo = kfifo_alloc(sizeof(u32) * 16, GFP_KERNEL, NULL);
887   - if (IS_ERR(priv->event_fifo)) {
  886 + ret = kfifo_alloc(&priv->event_fifo, sizeof(u32) * 16, GFP_KERNEL, NULL);
  887 + if (ret) {
888 888 lbs_pr_err("Out of memory allocating event FIFO buffer\n");
889   - ret = -ENOMEM;
890 889 goto out;
891 890 }
892 891  
... ... @@ -901,8 +900,7 @@
901 900 lbs_deb_enter(LBS_DEB_MAIN);
902 901  
903 902 lbs_free_cmd_buffer(priv);
904   - if (priv->event_fifo)
905   - kfifo_free(priv->event_fifo);
  903 + kfifo_free(&priv->event_fifo);
906 904 del_timer(&priv->command_timer);
907 905 del_timer(&priv->auto_deepsleep_timer);
908 906 kfree(priv->networks);
... ... @@ -1177,7 +1175,7 @@
1177 1175 if (priv->psstate == PS_STATE_SLEEP)
1178 1176 priv->psstate = PS_STATE_AWAKE;
1179 1177  
1180   - __kfifo_put(priv->event_fifo, (unsigned char *) &event, sizeof(u32));
  1178 + __kfifo_put(&priv->event_fifo, (unsigned char *) &event, sizeof(u32));
1181 1179  
1182 1180 wake_up_interruptible(&priv->waitq);
1183 1181  
drivers/platform/x86/fujitsu-laptop.c
... ... @@ -164,7 +164,7 @@
164 164 struct input_dev *input;
165 165 char phys[32];
166 166 struct platform_device *pf_device;
167   - struct kfifo *fifo;
  167 + struct kfifo fifo;
168 168 spinlock_t fifo_lock;
169 169 int rfkill_supported;
170 170 int rfkill_state;
171 171  
... ... @@ -824,12 +824,10 @@
824 824  
825 825 /* kfifo */
826 826 spin_lock_init(&fujitsu_hotkey->fifo_lock);
827   - fujitsu_hotkey->fifo =
828   - kfifo_alloc(RINGBUFFERSIZE * sizeof(int), GFP_KERNEL,
829   - &fujitsu_hotkey->fifo_lock);
830   - if (IS_ERR(fujitsu_hotkey->fifo)) {
  827 + error = kfifo_alloc(&fujitsu_hotkey->fifo, RINGBUFFERSIZE * sizeof(int),
  828 + GFP_KERNEL, &fujitsu_hotkey->fifo_lock);
  829 + if (error) {
831 830 printk(KERN_ERR "kfifo_alloc failed\n");
832   - error = PTR_ERR(fujitsu_hotkey->fifo);
833 831 goto err_stop;
834 832 }
835 833  
... ... @@ -934,7 +932,7 @@
934 932 err_free_input_dev:
935 933 input_free_device(input);
936 934 err_free_fifo:
937   - kfifo_free(fujitsu_hotkey->fifo);
  935 + kfifo_free(&fujitsu_hotkey->fifo);
938 936 err_stop:
939 937 return result;
940 938 }
... ... @@ -956,7 +954,7 @@
956 954  
957 955 input_free_device(input);
958 956  
959   - kfifo_free(fujitsu_hotkey->fifo);
  957 + kfifo_free(&fujitsu_hotkey->fifo);
960 958  
961 959 fujitsu_hotkey->acpi_handle = NULL;
962 960  
... ... @@ -1008,7 +1006,7 @@
1008 1006 vdbg_printk(FUJLAPTOP_DBG_TRACE,
1009 1007 "Push keycode into ringbuffer [%d]\n",
1010 1008 keycode);
1011   - status = kfifo_put(fujitsu_hotkey->fifo,
  1009 + status = kfifo_put(&fujitsu_hotkey->fifo,
1012 1010 (unsigned char *)&keycode,
1013 1011 sizeof(keycode));
1014 1012 if (status != sizeof(keycode)) {
... ... @@ -1022,7 +1020,7 @@
1022 1020 } else if (keycode == 0) {
1023 1021 while ((status =
1024 1022 kfifo_get
1025   - (fujitsu_hotkey->fifo, (unsigned char *)
  1023 + (&fujitsu_hotkey->fifo, (unsigned char *)
1026 1024 &keycode_r,
1027 1025 sizeof
1028 1026 (keycode_r))) == sizeof(keycode_r)) {
drivers/platform/x86/sony-laptop.c
... ... @@ -142,7 +142,7 @@
142 142 atomic_t users;
143 143 struct input_dev *jog_dev;
144 144 struct input_dev *key_dev;
145   - struct kfifo *fifo;
  145 + struct kfifo fifo;
146 146 spinlock_t fifo_lock;
147 147 struct workqueue_struct *wq;
148 148 };
... ... @@ -300,7 +300,7 @@
300 300 {
301 301 struct sony_laptop_keypress kp;
302 302  
303   - while (kfifo_get(sony_laptop_input.fifo, (unsigned char *)&kp,
  303 + while (kfifo_get(&sony_laptop_input.fifo, (unsigned char *)&kp,
304 304 sizeof(kp)) == sizeof(kp)) {
305 305 msleep(10);
306 306 input_report_key(kp.dev, kp.key, 0);
... ... @@ -362,7 +362,7 @@
362 362 /* we emit the scancode so we can always remap the key */
363 363 input_event(kp.dev, EV_MSC, MSC_SCAN, event);
364 364 input_sync(kp.dev);
365   - kfifo_put(sony_laptop_input.fifo,
  365 + kfifo_put(&sony_laptop_input.fifo,
366 366 (unsigned char *)&kp, sizeof(kp));
367 367  
368 368 if (!work_pending(&sony_laptop_release_key_work))
369 369  
370 370  
... ... @@ -385,12 +385,11 @@
385 385  
386 386 /* kfifo */
387 387 spin_lock_init(&sony_laptop_input.fifo_lock);
388   - sony_laptop_input.fifo =
389   - kfifo_alloc(SONY_LAPTOP_BUF_SIZE, GFP_KERNEL,
  388 + error =
  389 + kfifo_alloc(&sony_laptop_input.fifo, SONY_LAPTOP_BUF_SIZE, GFP_KERNEL,
390 390 &sony_laptop_input.fifo_lock);
391   - if (IS_ERR(sony_laptop_input.fifo)) {
  391 + if (error) {
392 392 printk(KERN_ERR DRV_PFX "kfifo_alloc failed\n");
393   - error = PTR_ERR(sony_laptop_input.fifo);
394 393 goto err_dec_users;
395 394 }
396 395  
... ... @@ -474,7 +473,7 @@
474 473 destroy_workqueue(sony_laptop_input.wq);
475 474  
476 475 err_free_kfifo:
477   - kfifo_free(sony_laptop_input.fifo);
  476 + kfifo_free(&sony_laptop_input.fifo);
478 477  
479 478 err_dec_users:
480 479 atomic_dec(&sony_laptop_input.users);
... ... @@ -500,7 +499,7 @@
500 499 }
501 500  
502 501 destroy_workqueue(sony_laptop_input.wq);
503   - kfifo_free(sony_laptop_input.fifo);
  502 + kfifo_free(&sony_laptop_input.fifo);
504 503 }
505 504  
506 505 /*********** Platform Device ***********/
... ... @@ -2079,7 +2078,7 @@
2079 2078  
2080 2079 struct sonypi_compat_s {
2081 2080 struct fasync_struct *fifo_async;
2082   - struct kfifo *fifo;
  2081 + struct kfifo fifo;
2083 2082 spinlock_t fifo_lock;
2084 2083 wait_queue_head_t fifo_proc_list;
2085 2084 atomic_t open_count;
2086 2085  
2087 2086  
... ... @@ -2104,12 +2103,12 @@
2104 2103 /* Flush input queue on first open */
2105 2104 unsigned long flags;
2106 2105  
2107   - spin_lock_irqsave(sonypi_compat.fifo->lock, flags);
  2106 + spin_lock_irqsave(&sonypi_compat.fifo_lock, flags);
2108 2107  
2109 2108 if (atomic_inc_return(&sonypi_compat.open_count) == 1)
2110   - __kfifo_reset(sonypi_compat.fifo);
  2109 + __kfifo_reset(&sonypi_compat.fifo);
2111 2110  
2112   - spin_unlock_irqrestore(sonypi_compat.fifo->lock, flags);
  2111 + spin_unlock_irqrestore(&sonypi_compat.fifo_lock, flags);
2113 2112  
2114 2113 return 0;
2115 2114 }
2116 2115  
2117 2116  
... ... @@ -2120,17 +2119,17 @@
2120 2119 ssize_t ret;
2121 2120 unsigned char c;
2122 2121  
2123   - if ((kfifo_len(sonypi_compat.fifo) == 0) &&
  2122 + if ((kfifo_len(&sonypi_compat.fifo) == 0) &&
2124 2123 (file->f_flags & O_NONBLOCK))
2125 2124 return -EAGAIN;
2126 2125  
2127 2126 ret = wait_event_interruptible(sonypi_compat.fifo_proc_list,
2128   - kfifo_len(sonypi_compat.fifo) != 0);
  2127 + kfifo_len(&sonypi_compat.fifo) != 0);
2129 2128 if (ret)
2130 2129 return ret;
2131 2130  
2132 2131 while (ret < count &&
2133   - (kfifo_get(sonypi_compat.fifo, &c, sizeof(c)) == sizeof(c))) {
  2132 + (kfifo_get(&sonypi_compat.fifo, &c, sizeof(c)) == sizeof(c))) {
2134 2133 if (put_user(c, buf++))
2135 2134 return -EFAULT;
2136 2135 ret++;
... ... @@ -2147,7 +2146,7 @@
2147 2146 static unsigned int sonypi_misc_poll(struct file *file, poll_table *wait)
2148 2147 {
2149 2148 poll_wait(file, &sonypi_compat.fifo_proc_list, wait);
2150   - if (kfifo_len(sonypi_compat.fifo))
  2149 + if (kfifo_len(&sonypi_compat.fifo))
2151 2150 return POLLIN | POLLRDNORM;
2152 2151 return 0;
2153 2152 }
... ... @@ -2309,7 +2308,7 @@
2309 2308  
2310 2309 static void sonypi_compat_report_event(u8 event)
2311 2310 {
2312   - kfifo_put(sonypi_compat.fifo, (unsigned char *)&event, sizeof(event));
  2311 + kfifo_put(&sonypi_compat.fifo, (unsigned char *)&event, sizeof(event));
2313 2312 kill_fasync(&sonypi_compat.fifo_async, SIGIO, POLL_IN);
2314 2313 wake_up_interruptible(&sonypi_compat.fifo_proc_list);
2315 2314 }
2316 2315  
2317 2316  
... ... @@ -2319,11 +2318,12 @@
2319 2318 int error;
2320 2319  
2321 2320 spin_lock_init(&sonypi_compat.fifo_lock);
2322   - sonypi_compat.fifo = kfifo_alloc(SONY_LAPTOP_BUF_SIZE, GFP_KERNEL,
  2321 + error =
  2322 + kfifo_alloc(&sonypi_compat.fifo, SONY_LAPTOP_BUF_SIZE, GFP_KERNEL,
2323 2323 &sonypi_compat.fifo_lock);
2324   - if (IS_ERR(sonypi_compat.fifo)) {
  2324 + if (error) {
2325 2325 printk(KERN_ERR DRV_PFX "kfifo_alloc failed\n");
2326   - return PTR_ERR(sonypi_compat.fifo);
  2326 + return error;
2327 2327 }
2328 2328  
2329 2329 init_waitqueue_head(&sonypi_compat.fifo_proc_list);
2330 2330  
... ... @@ -2342,14 +2342,14 @@
2342 2342 return 0;
2343 2343  
2344 2344 err_free_kfifo:
2345   - kfifo_free(sonypi_compat.fifo);
  2345 + kfifo_free(&sonypi_compat.fifo);
2346 2346 return error;
2347 2347 }
2348 2348  
2349 2349 static void sonypi_compat_exit(void)
2350 2350 {
2351 2351 misc_deregister(&sonypi_misc_device);
2352   - kfifo_free(sonypi_compat.fifo);
  2352 + kfifo_free(&sonypi_compat.fifo);
2353 2353 }
2354 2354 #else
2355 2355 static int sonypi_compat_init(void) { return 0; }
drivers/scsi/libiscsi.c
... ... @@ -517,7 +517,7 @@
517 517 if (conn->login_task == task)
518 518 return;
519 519  
520   - __kfifo_put(session->cmdpool.queue, (void*)&task, sizeof(void*));
  520 + __kfifo_put(&session->cmdpool.queue, (void*)&task, sizeof(void*));
521 521  
522 522 if (sc) {
523 523 task->sc = NULL;
... ... @@ -737,7 +737,7 @@
737 737 BUG_ON(conn->c_stage == ISCSI_CONN_INITIAL_STAGE);
738 738 BUG_ON(conn->c_stage == ISCSI_CONN_STOPPED);
739 739  
740   - if (!__kfifo_get(session->cmdpool.queue,
  740 + if (!__kfifo_get(&session->cmdpool.queue,
741 741 (void*)&task, sizeof(void*)))
742 742 return NULL;
743 743 }
... ... @@ -1567,7 +1567,7 @@
1567 1567 {
1568 1568 struct iscsi_task *task;
1569 1569  
1570   - if (!__kfifo_get(conn->session->cmdpool.queue,
  1570 + if (!__kfifo_get(&conn->session->cmdpool.queue,
1571 1571 (void *) &task, sizeof(void *)))
1572 1572 return NULL;
1573 1573  
... ... @@ -2461,12 +2461,7 @@
2461 2461 if (q->pool == NULL)
2462 2462 return -ENOMEM;
2463 2463  
2464   - q->queue = kfifo_init((void*)q->pool, max * sizeof(void*),
2465   - GFP_KERNEL, NULL);
2466   - if (IS_ERR(q->queue)) {
2467   - q->queue = NULL;
2468   - goto enomem;
2469   - }
  2464 + kfifo_init(&q->queue, (void*)q->pool, max * sizeof(void*), NULL);
2470 2465  
2471 2466 for (i = 0; i < max; i++) {
2472 2467 q->pool[i] = kzalloc(item_size, GFP_KERNEL);
... ... @@ -2474,7 +2469,7 @@
2474 2469 q->max = i;
2475 2470 goto enomem;
2476 2471 }
2477   - __kfifo_put(q->queue, (void*)&q->pool[i], sizeof(void*));
  2472 + __kfifo_put(&q->queue, (void*)&q->pool[i], sizeof(void*));
2478 2473 }
2479 2474  
2480 2475 if (items) {
... ... @@ -2497,7 +2492,6 @@
2497 2492 for (i = 0; i < q->max; i++)
2498 2493 kfree(q->pool[i]);
2499 2494 kfree(q->pool);
2500   - kfree(q->queue);
2501 2495 }
2502 2496 EXPORT_SYMBOL_GPL(iscsi_pool_free);
2503 2497  
... ... @@ -2825,7 +2819,7 @@
2825 2819  
2826 2820 /* allocate login_task used for the login/text sequences */
2827 2821 spin_lock_bh(&session->lock);
2828   - if (!__kfifo_get(session->cmdpool.queue,
  2822 + if (!__kfifo_get(&session->cmdpool.queue,
2829 2823 (void*)&conn->login_task,
2830 2824 sizeof(void*))) {
2831 2825 spin_unlock_bh(&session->lock);
... ... @@ -2845,7 +2839,7 @@
2845 2839 return cls_conn;
2846 2840  
2847 2841 login_task_data_alloc_fail:
2848   - __kfifo_put(session->cmdpool.queue, (void*)&conn->login_task,
  2842 + __kfifo_put(&session->cmdpool.queue, (void*)&conn->login_task,
2849 2843 sizeof(void*));
2850 2844 login_task_alloc_fail:
2851 2845 iscsi_destroy_conn(cls_conn);
... ... @@ -2908,7 +2902,7 @@
2908 2902 free_pages((unsigned long) conn->data,
2909 2903 get_order(ISCSI_DEF_MAX_RECV_SEG_LEN));
2910 2904 kfree(conn->persistent_address);
2911   - __kfifo_put(session->cmdpool.queue, (void*)&conn->login_task,
  2905 + __kfifo_put(&session->cmdpool.queue, (void*)&conn->login_task,
2912 2906 sizeof(void*));
2913 2907 if (session->leadconn == conn)
2914 2908 session->leadconn = NULL;
drivers/scsi/libiscsi_tcp.c
... ... @@ -445,15 +445,15 @@
445 445 return;
446 446  
447 447 /* flush task's r2t queues */
448   - while (__kfifo_get(tcp_task->r2tqueue, (void*)&r2t, sizeof(void*))) {
449   - __kfifo_put(tcp_task->r2tpool.queue, (void*)&r2t,
  448 + while (__kfifo_get(&tcp_task->r2tqueue, (void*)&r2t, sizeof(void*))) {
  449 + __kfifo_put(&tcp_task->r2tpool.queue, (void*)&r2t,
450 450 sizeof(void*));
451 451 ISCSI_DBG_TCP(task->conn, "pending r2t dropped\n");
452 452 }
453 453  
454 454 r2t = tcp_task->r2t;
455 455 if (r2t != NULL) {
456   - __kfifo_put(tcp_task->r2tpool.queue, (void*)&r2t,
  456 + __kfifo_put(&tcp_task->r2tpool.queue, (void*)&r2t,
457 457 sizeof(void*));
458 458 tcp_task->r2t = NULL;
459 459 }
... ... @@ -541,7 +541,7 @@
541 541 return 0;
542 542 }
543 543  
544   - rc = __kfifo_get(tcp_task->r2tpool.queue, (void*)&r2t, sizeof(void*));
  544 + rc = __kfifo_get(&tcp_task->r2tpool.queue, (void*)&r2t, sizeof(void*));
545 545 if (!rc) {
546 546 iscsi_conn_printk(KERN_ERR, conn, "Could not allocate R2T. "
547 547 "Target has sent more R2Ts than it "
... ... @@ -554,7 +554,7 @@
554 554 if (r2t->data_length == 0) {
555 555 iscsi_conn_printk(KERN_ERR, conn,
556 556 "invalid R2T with zero data len\n");
557   - __kfifo_put(tcp_task->r2tpool.queue, (void*)&r2t,
  557 + __kfifo_put(&tcp_task->r2tpool.queue, (void*)&r2t,
558 558 sizeof(void*));
559 559 return ISCSI_ERR_DATALEN;
560 560 }
... ... @@ -570,7 +570,7 @@
570 570 "invalid R2T with data len %u at offset %u "
571 571 "and total length %d\n", r2t->data_length,
572 572 r2t->data_offset, scsi_out(task->sc)->length);
573   - __kfifo_put(tcp_task->r2tpool.queue, (void*)&r2t,
  573 + __kfifo_put(&tcp_task->r2tpool.queue, (void*)&r2t,
574 574 sizeof(void*));
575 575 return ISCSI_ERR_DATALEN;
576 576 }
... ... @@ -580,7 +580,7 @@
580 580 r2t->sent = 0;
581 581  
582 582 tcp_task->exp_datasn = r2tsn + 1;
583   - __kfifo_put(tcp_task->r2tqueue, (void*)&r2t, sizeof(void*));
  583 + __kfifo_put(&tcp_task->r2tqueue, (void*)&r2t, sizeof(void*));
584 584 conn->r2t_pdus_cnt++;
585 585  
586 586 iscsi_requeue_task(task);
... ... @@ -951,7 +951,7 @@
951 951 return conn->session->tt->init_pdu(task, 0, task->data_count);
952 952 }
953 953  
954   - BUG_ON(__kfifo_len(tcp_task->r2tqueue));
  954 + BUG_ON(__kfifo_len(&tcp_task->r2tqueue));
955 955 tcp_task->exp_datasn = 0;
956 956  
957 957 /* Prepare PDU, optionally w/ immediate data */
... ... @@ -982,7 +982,7 @@
982 982 if (r2t->data_length <= r2t->sent) {
983 983 ISCSI_DBG_TCP(task->conn,
984 984 " done with r2t %p\n", r2t);
985   - __kfifo_put(tcp_task->r2tpool.queue,
  985 + __kfifo_put(&tcp_task->r2tpool.queue,
986 986 (void *)&tcp_task->r2t,
987 987 sizeof(void *));
988 988 tcp_task->r2t = r2t = NULL;
... ... @@ -990,7 +990,7 @@
990 990 }
991 991  
992 992 if (r2t == NULL) {
993   - __kfifo_get(tcp_task->r2tqueue,
  993 + __kfifo_get(&tcp_task->r2tqueue,
994 994 (void *)&tcp_task->r2t, sizeof(void *));
995 995 r2t = tcp_task->r2t;
996 996 }
... ... @@ -1127,9 +1127,8 @@
1127 1127 }
1128 1128  
1129 1129 /* R2T xmit queue */
1130   - tcp_task->r2tqueue = kfifo_alloc(
1131   - session->max_r2t * 4 * sizeof(void*), GFP_KERNEL, NULL);
1132   - if (tcp_task->r2tqueue == ERR_PTR(-ENOMEM)) {
  1130 + if (kfifo_alloc(&tcp_task->r2tqueue,
  1131 + session->max_r2t * 4 * sizeof(void*), GFP_KERNEL, NULL)) {
1133 1132 iscsi_pool_free(&tcp_task->r2tpool);
1134 1133 goto r2t_alloc_fail;
1135 1134 }
... ... @@ -1142,7 +1141,7 @@
1142 1141 struct iscsi_task *task = session->cmds[i];
1143 1142 struct iscsi_tcp_task *tcp_task = task->dd_data;
1144 1143  
1145   - kfifo_free(tcp_task->r2tqueue);
  1144 + kfifo_free(&tcp_task->r2tqueue);
1146 1145 iscsi_pool_free(&tcp_task->r2tpool);
1147 1146 }
1148 1147 return -ENOMEM;
... ... @@ -1157,7 +1156,7 @@
1157 1156 struct iscsi_task *task = session->cmds[i];
1158 1157 struct iscsi_tcp_task *tcp_task = task->dd_data;
1159 1158  
1160   - kfifo_free(tcp_task->r2tqueue);
  1159 + kfifo_free(&tcp_task->r2tqueue);
1161 1160 iscsi_pool_free(&tcp_task->r2tpool);
1162 1161 }
1163 1162 }
drivers/scsi/libsrp.c
... ... @@ -58,19 +58,16 @@
58 58 goto free_pool;
59 59  
60 60 spin_lock_init(&q->lock);
61   - q->queue = kfifo_init((void *) q->pool, max * sizeof(void *),
62   - GFP_KERNEL, &q->lock);
63   - if (IS_ERR(q->queue))
64   - goto free_item;
  61 + kfifo_init(&q->queue, (void *) q->pool, max * sizeof(void *),
  62 + &q->lock);
65 63  
66 64 for (i = 0, iue = q->items; i < max; i++) {
67   - __kfifo_put(q->queue, (void *) &iue, sizeof(void *));
  65 + __kfifo_put(&q->queue, (void *) &iue, sizeof(void *));
68 66 iue->sbuf = ring[i];
69 67 iue++;
70 68 }
71 69 return 0;
72 70  
73   -free_item:
74 71 kfree(q->items);
75 72 free_pool:
76 73 kfree(q->pool);
... ... @@ -167,7 +164,7 @@
167 164 {
168 165 struct iu_entry *iue = NULL;
169 166  
170   - kfifo_get(target->iu_queue.queue, (void *) &iue, sizeof(void *));
  167 + kfifo_get(&target->iu_queue.queue, (void *) &iue, sizeof(void *));
171 168 if (!iue)
172 169 return iue;
173 170 iue->target = target;
... ... @@ -179,7 +176,7 @@
179 176  
180 177 void srp_iu_put(struct iu_entry *iue)
181 178 {
182   - kfifo_put(iue->target->iu_queue.queue, (void *) &iue, sizeof(void *));
  179 + kfifo_put(&iue->target->iu_queue.queue, (void *) &iue, sizeof(void *));
183 180 }
184 181 EXPORT_SYMBOL_GPL(srp_iu_put);
185 182  
drivers/usb/host/fhci-sched.c
... ... @@ -37,7 +37,7 @@
37 37 pkt->info = 0;
38 38 pkt->priv_data = NULL;
39 39  
40   - cq_put(usb->ep0->empty_frame_Q, pkt);
  40 + cq_put(&usb->ep0->empty_frame_Q, pkt);
41 41 }
42 42  
43 43 /* confirm submitted packet */
... ... @@ -57,7 +57,7 @@
57 57 if ((td->data + td->actual_len) && trans_len)
58 58 memcpy(td->data + td->actual_len, pkt->data,
59 59 trans_len);
60   - cq_put(usb->ep0->dummy_packets_Q, pkt->data);
  60 + cq_put(&usb->ep0->dummy_packets_Q, pkt->data);
61 61 }
62 62  
63 63 recycle_frame(usb, pkt);
... ... @@ -213,7 +213,7 @@
213 213 }
214 214  
215 215 /* update frame object fields before transmitting */
216   - pkt = cq_get(usb->ep0->empty_frame_Q);
  216 + pkt = cq_get(&usb->ep0->empty_frame_Q);
217 217 if (!pkt) {
218 218 fhci_dbg(usb->fhci, "there is no empty frame\n");
219 219 return -1;
... ... @@ -222,7 +222,7 @@
222 222  
223 223 pkt->info = 0;
224 224 if (data == NULL) {
225   - data = cq_get(usb->ep0->dummy_packets_Q);
  225 + data = cq_get(&usb->ep0->dummy_packets_Q);
226 226 BUG_ON(!data);
227 227 pkt->info = PKT_DUMMY_PACKET;
228 228 }
... ... @@ -246,7 +246,7 @@
246 246 list_del_init(&td->frame_lh);
247 247 td->status = USB_TD_OK;
248 248 if (pkt->info & PKT_DUMMY_PACKET)
249   - cq_put(usb->ep0->dummy_packets_Q, pkt->data);
  249 + cq_put(&usb->ep0->dummy_packets_Q, pkt->data);
250 250 recycle_frame(usb, pkt);
251 251 usb->actual_frame->total_bytes -= (len + PROTOCOL_OVERHEAD);
252 252 fhci_err(usb->fhci, "host transaction failed\n");
drivers/usb/host/fhci-tds.c
... ... @@ -106,33 +106,33 @@
106 106 cpm_muram_free(cpm_muram_offset(ep->td_base));
107 107  
108 108 if (ep->conf_frame_Q) {
109   - size = cq_howmany(ep->conf_frame_Q);
  109 + size = cq_howmany(&ep->conf_frame_Q);
110 110 for (; size; size--) {
111   - struct packet *pkt = cq_get(ep->conf_frame_Q);
  111 + struct packet *pkt = cq_get(&ep->conf_frame_Q);
112 112  
113 113 kfree(pkt);
114 114 }
115   - cq_delete(ep->conf_frame_Q);
  115 + cq_delete(&ep->conf_frame_Q);
116 116 }
117 117  
118 118 if (ep->empty_frame_Q) {
119   - size = cq_howmany(ep->empty_frame_Q);
  119 + size = cq_howmany(&ep->empty_frame_Q);
120 120 for (; size; size--) {
121   - struct packet *pkt = cq_get(ep->empty_frame_Q);
  121 + struct packet *pkt = cq_get(&ep->empty_frame_Q);
122 122  
123 123 kfree(pkt);
124 124 }
125   - cq_delete(ep->empty_frame_Q);
  125 + cq_delete(&ep->empty_frame_Q);
126 126 }
127 127  
128 128 if (ep->dummy_packets_Q) {
129   - size = cq_howmany(ep->dummy_packets_Q);
  129 + size = cq_howmany(&ep->dummy_packets_Q);
130 130 for (; size; size--) {
131   - u8 *buff = cq_get(ep->dummy_packets_Q);
  131 + u8 *buff = cq_get(&ep->dummy_packets_Q);
132 132  
133 133 kfree(buff);
134 134 }
135   - cq_delete(ep->dummy_packets_Q);
  135 + cq_delete(&ep->dummy_packets_Q);
136 136 }
137 137  
138 138 kfree(ep);
... ... @@ -175,10 +175,9 @@
175 175 ep->td_base = cpm_muram_addr(ep_offset);
176 176  
177 177 /* zero all queue pointers */
178   - ep->conf_frame_Q = cq_new(ring_len + 2);
179   - ep->empty_frame_Q = cq_new(ring_len + 2);
180   - ep->dummy_packets_Q = cq_new(ring_len + 2);
181   - if (!ep->conf_frame_Q || !ep->empty_frame_Q || !ep->dummy_packets_Q) {
  178 + if (cq_new(&ep->conf_frame_Q, ring_len + 2) ||
  179 + cq_new(&ep->empty_frame_Q, ring_len + 2) ||
  180 + cq_new(&ep->dummy_packets_Q, ring_len + 2)) {
182 181 err_for = "frame_queues";
183 182 goto err;
184 183 }
... ... @@ -199,8 +198,8 @@
199 198 err_for = "buffer";
200 199 goto err;
201 200 }
202   - cq_put(ep->empty_frame_Q, pkt);
203   - cq_put(ep->dummy_packets_Q, buff);
  201 + cq_put(&ep->empty_frame_Q, pkt);
  202 + cq_put(&ep->dummy_packets_Q, buff);
204 203 }
205 204  
206 205 /* we put the endpoint parameter RAM right behind the TD ring */
... ... @@ -319,7 +318,7 @@
319 318 if ((buf == DUMMY2_BD_BUFFER) && !(td_status & ~TD_W))
320 319 continue;
321 320  
322   - pkt = cq_get(ep->conf_frame_Q);
  321 + pkt = cq_get(&ep->conf_frame_Q);
323 322 if (!pkt)
324 323 fhci_err(usb->fhci, "no frame to confirm\n");
325 324  
326 325  
... ... @@ -460,9 +459,9 @@
460 459 out_be16(&td->length, pkt->len);
461 460  
462 461 /* put the frame to the confirmation queue */
463   - cq_put(ep->conf_frame_Q, pkt);
  462 + cq_put(&ep->conf_frame_Q, pkt);
464 463  
465   - if (cq_howmany(ep->conf_frame_Q) == 1)
  464 + if (cq_howmany(&ep->conf_frame_Q) == 1)
466 465 out_8(&usb->fhci->regs->usb_comm, USB_CMD_STR_FIFO);
467 466  
468 467 return 0;
drivers/usb/host/fhci.h
... ... @@ -423,9 +423,9 @@
423 423 struct usb_td __iomem *td_base; /* first TD in the ring */
424 424 struct usb_td __iomem *conf_td; /* next TD for confirm after transac */
425 425 struct usb_td __iomem *empty_td;/* next TD for new transaction req. */
426   - struct kfifo *empty_frame_Q; /* Empty frames list to use */
427   - struct kfifo *conf_frame_Q; /* frames passed to TDs,waiting for tx */
428   - struct kfifo *dummy_packets_Q;/* dummy packets for the CRC overun */
  426 + struct kfifo empty_frame_Q; /* Empty frames list to use */
  427 + struct kfifo conf_frame_Q; /* frames passed to TDs,waiting for tx */
  428 + struct kfifo dummy_packets_Q;/* dummy packets for the CRC overun */
429 429  
430 430 bool already_pushed_dummy_bd;
431 431 };
432 432  
... ... @@ -493,9 +493,9 @@
493 493 }
494 494  
495 495 /* fifo of pointers */
496   -static inline struct kfifo *cq_new(int size)
  496 +static inline int cq_new(struct kfifo *fifo, int size)
497 497 {
498   - return kfifo_alloc(size * sizeof(void *), GFP_KERNEL, NULL);
  498 + return kfifo_alloc(fifo, size * sizeof(void *), GFP_KERNEL, NULL);
499 499 }
500 500  
501 501 static inline void cq_delete(struct kfifo *kfifo)
drivers/usb/serial/usb-serial.c
... ... @@ -939,9 +939,8 @@
939 939 dev_err(&interface->dev, "No free urbs available\n");
940 940 goto probe_error;
941 941 }
942   - port->write_fifo = kfifo_alloc(PAGE_SIZE, GFP_KERNEL,
943   - &port->lock);
944   - if (IS_ERR(port->write_fifo))
  942 + if (kfifo_alloc(&port->write_fifo, PAGE_SIZE, GFP_KERNEL,
  943 + &port->lock))
945 944 goto probe_error;
946 945 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
947 946 port->bulk_out_size = buffer_size;
include/linux/kfifo.h
1 1 /*
2   - * A simple kernel FIFO implementation.
  2 + * A generic kernel FIFO implementation.
3 3 *
  4 + * Copyright (C) 2009 Stefani Seibold <stefani@seibold.net>
4 5 * Copyright (C) 2004 Stelian Pop <stelian@popies.net>
5 6 *
6 7 * This program is free software; you can redistribute it and/or modify
... ... @@ -32,10 +33,10 @@
32 33 spinlock_t *lock; /* protects concurrent modifications */
33 34 };
34 35  
35   -extern struct kfifo *kfifo_init(unsigned char *buffer, unsigned int size,
36   - gfp_t gfp_mask, spinlock_t *lock);
37   -extern struct kfifo *kfifo_alloc(unsigned int size, gfp_t gfp_mask,
38   - spinlock_t *lock);
  36 +extern void kfifo_init(struct kfifo *fifo, unsigned char *buffer,
  37 + unsigned int size, spinlock_t *lock);
  38 +extern __must_check int kfifo_alloc(struct kfifo *fifo, unsigned int size,
  39 + gfp_t gfp_mask, spinlock_t *lock);
39 40 extern void kfifo_free(struct kfifo *fifo);
40 41 extern unsigned int __kfifo_put(struct kfifo *fifo,
41 42 const unsigned char *buffer, unsigned int len);
include/scsi/libiscsi.h
... ... @@ -28,6 +28,7 @@
28 28 #include <linux/mutex.h>
29 29 #include <linux/timer.h>
30 30 #include <linux/workqueue.h>
  31 +#include <linux/kfifo.h>
31 32 #include <scsi/iscsi_proto.h>
32 33 #include <scsi/iscsi_if.h>
33 34 #include <scsi/scsi_transport_iscsi.h>
... ... @@ -231,7 +232,7 @@
231 232 };
232 233  
233 234 struct iscsi_pool {
234   - struct kfifo *queue; /* FIFO Queue */
  235 + struct kfifo queue; /* FIFO Queue */
235 236 void **pool; /* Pool of elements */
236 237 int max; /* Max number of elements */
237 238 };
include/scsi/libiscsi_tcp.h
... ... @@ -80,7 +80,7 @@
80 80 int data_offset;
81 81 struct iscsi_r2t_info *r2t; /* in progress solict R2T */
82 82 struct iscsi_pool r2tpool;
83   - struct kfifo *r2tqueue;
  83 + struct kfifo r2tqueue;
84 84 void *dd_data;
85 85 };
86 86  
include/scsi/libsrp.h
... ... @@ -21,7 +21,7 @@
21 21 struct srp_queue {
22 22 void *pool;
23 23 void *items;
24   - struct kfifo *queue;
  24 + struct kfifo queue;
25 25 spinlock_t lock;
26 26 };
27 27  
1 1 /*
2   - * A simple kernel FIFO implementation.
  2 + * A generic kernel FIFO implementation.
3 3 *
  4 + * Copyright (C) 2009 Stefani Seibold <stefani@seibold.net>
4 5 * Copyright (C) 2004 Stelian Pop <stelian@popies.net>
5 6 *
6 7 * This program is free software; you can redistribute it and/or modify
7 8  
8 9  
9 10  
10 11  
11 12  
12 13  
13 14  
14 15  
15 16  
16 17  
17 18  
... ... @@ -26,49 +27,51 @@
26 27 #include <linux/kfifo.h>
27 28 #include <linux/log2.h>
28 29  
  30 +static void _kfifo_init(struct kfifo *fifo, unsigned char *buffer,
  31 + unsigned int size, spinlock_t *lock)
  32 +{
  33 + fifo->buffer = buffer;
  34 + fifo->size = size;
  35 + fifo->lock = lock;
  36 +
  37 + kfifo_reset(fifo);
  38 +}
  39 +
29 40 /**
30   - * kfifo_init - allocates a new FIFO using a preallocated buffer
  41 + * kfifo_init - initialize a FIFO using a preallocated buffer
  42 + * @fifo: the fifo to assign the buffer
31 43 * @buffer: the preallocated buffer to be used.
32 44 * @size: the size of the internal buffer, this have to be a power of 2.
33   - * @gfp_mask: get_free_pages mask, passed to kmalloc()
34 45 * @lock: the lock to be used to protect the fifo buffer
35 46 *
36   - * Do NOT pass the kfifo to kfifo_free() after use! Simply free the
37   - * &struct kfifo with kfree().
38 47 */
39   -struct kfifo *kfifo_init(unsigned char *buffer, unsigned int size,
40   - gfp_t gfp_mask, spinlock_t *lock)
  48 +void kfifo_init(struct kfifo *fifo, unsigned char *buffer, unsigned int size,
  49 + spinlock_t *lock)
41 50 {
42   - struct kfifo *fifo;
43   -
44 51 /* size must be a power of 2 */
45 52 BUG_ON(!is_power_of_2(size));
46 53  
47   - fifo = kmalloc(sizeof(struct kfifo), gfp_mask);
48   - if (!fifo)
49   - return ERR_PTR(-ENOMEM);
50   -
51   - fifo->buffer = buffer;
52   - fifo->size = size;
53   - fifo->in = fifo->out = 0;
54   - fifo->lock = lock;
55   -
56   - return fifo;
  54 + _kfifo_init(fifo, buffer, size, lock);
57 55 }
58 56 EXPORT_SYMBOL(kfifo_init);
59 57  
60 58 /**
61   - * kfifo_alloc - allocates a new FIFO and its internal buffer
62   - * @size: the size of the internal buffer to be allocated.
  59 + * kfifo_alloc - allocates a new FIFO internal buffer
  60 + * @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.
63 62 * @gfp_mask: get_free_pages mask, passed to kmalloc()
64 63 * @lock: the lock to be used to protect the fifo buffer
65 64 *
  65 + * This function dynamically allocates a new fifo internal buffer
  66 + *
66 67 * The size will be rounded-up to a power of 2.
  68 + * The buffer will be release with kfifo_free().
  69 + * Return 0 if no error, otherwise the an error code
67 70 */
68   -struct kfifo *kfifo_alloc(unsigned int size, gfp_t gfp_mask, spinlock_t *lock)
  71 +int kfifo_alloc(struct kfifo *fifo, unsigned int size, gfp_t gfp_mask,
  72 + spinlock_t *lock)
69 73 {
70 74 unsigned char *buffer;
71   - struct kfifo *ret;
72 75  
73 76 /*
74 77 * round up to the next power of 2, since our 'let the indices
75 78  
76 79  
77 80  
78 81  
... ... @@ -80,26 +83,24 @@
80 83 }
81 84  
82 85 buffer = kmalloc(size, gfp_mask);
83   - if (!buffer)
84   - return ERR_PTR(-ENOMEM);
  86 + if (!buffer) {
  87 + _kfifo_init(fifo, 0, 0, NULL);
  88 + return -ENOMEM;
  89 + }
85 90  
86   - ret = kfifo_init(buffer, size, gfp_mask, lock);
  91 + _kfifo_init(fifo, buffer, size, lock);
87 92  
88   - if (IS_ERR(ret))
89   - kfree(buffer);
90   -
91   - return ret;
  93 + return 0;
92 94 }
93 95 EXPORT_SYMBOL(kfifo_alloc);
94 96  
95 97 /**
96   - * kfifo_free - frees the FIFO
  98 + * kfifo_free - frees the FIFO internal buffer
97 99 * @fifo: the fifo to be freed.
98 100 */
99 101 void kfifo_free(struct kfifo *fifo)
100 102 {
101 103 kfree(fifo->buffer);
102   - kfree(fifo);
103 104 }
104 105 EXPORT_SYMBOL(kfifo_free);
105 106  
... ... @@ -43,7 +43,7 @@
43 43 static const char procname[] = "dccpprobe";
44 44  
45 45 static struct {
46   - struct kfifo *fifo;
  46 + struct kfifo fifo;
47 47 spinlock_t lock;
48 48 wait_queue_head_t wait;
49 49 struct timespec tstart;
... ... @@ -67,7 +67,7 @@
67 67 len += vscnprintf(tbuf+len, sizeof(tbuf)-len, fmt, args);
68 68 va_end(args);
69 69  
70   - kfifo_put(dccpw.fifo, tbuf, len);
  70 + kfifo_put(&dccpw.fifo, tbuf, len);
71 71 wake_up(&dccpw.wait);
72 72 }
73 73  
... ... @@ -109,7 +109,7 @@
109 109  
110 110 static int dccpprobe_open(struct inode *inode, struct file *file)
111 111 {
112   - kfifo_reset(dccpw.fifo);
  112 + kfifo_reset(&dccpw.fifo);
113 113 getnstimeofday(&dccpw.tstart);
114 114 return 0;
115 115 }
116 116  
... ... @@ -131,11 +131,11 @@
131 131 return -ENOMEM;
132 132  
133 133 error = wait_event_interruptible(dccpw.wait,
134   - __kfifo_len(dccpw.fifo) != 0);
  134 + __kfifo_len(&dccpw.fifo) != 0);
135 135 if (error)
136 136 goto out_free;
137 137  
138   - cnt = kfifo_get(dccpw.fifo, tbuf, len);
  138 + cnt = kfifo_get(&dccpw.fifo, tbuf, len);
139 139 error = copy_to_user(buf, tbuf, cnt) ? -EFAULT : 0;
140 140  
141 141 out_free:
... ... @@ -156,10 +156,8 @@
156 156  
157 157 init_waitqueue_head(&dccpw.wait);
158 158 spin_lock_init(&dccpw.lock);
159   - dccpw.fifo = kfifo_alloc(bufsize, GFP_KERNEL, &dccpw.lock);
160   - if (IS_ERR(dccpw.fifo))
161   - return PTR_ERR(dccpw.fifo);
162   -
  159 + if (kfifo_alloc(&dccpw.fifo, bufsize, GFP_KERNEL, &dccpw.lock))
  160 + return ret;
163 161 if (!proc_net_fops_create(&init_net, procname, S_IRUSR, &dccpprobe_fops))
164 162 goto err0;
165 163  
166 164  
... ... @@ -172,14 +170,14 @@
172 170 err1:
173 171 proc_net_remove(&init_net, procname);
174 172 err0:
175   - kfifo_free(dccpw.fifo);
  173 + kfifo_free(&dccpw.fifo);
176 174 return ret;
177 175 }
178 176 module_init(dccpprobe_init);
179 177  
180 178 static __exit void dccpprobe_exit(void)
181 179 {
182   - kfifo_free(dccpw.fifo);
  180 + kfifo_free(&dccpw.fifo);
183 181 proc_net_remove(&init_net, procname);
184 182 unregister_jprobe(&dccp_send_probe);
185 183