diff options
author | Stefani Seibold <stefani@seibold.net> | 2009-12-21 17:37:26 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-12-22 17:17:55 -0500 |
commit | 45465487897a1c6d508b14b904dc5777f7ec7e04 (patch) | |
tree | 935c8dae68dc793ff2f795d57cf027531475cd53 /drivers/net/wireless/libertas/main.c | |
parent | 2ec91eec47f713e3d158ba5b28a24a85a2cf3650 (diff) |
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>
Diffstat (limited to 'drivers/net/wireless/libertas/main.c')
-rw-r--r-- | drivers/net/wireless/libertas/main.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/drivers/net/wireless/libertas/main.c b/drivers/net/wireless/libertas/main.c index db38a5a719f..40390928741 100644 --- a/drivers/net/wireless/libertas/main.c +++ b/drivers/net/wireless/libertas/main.c | |||
@@ -459,7 +459,7 @@ static int lbs_thread(void *data) | |||
459 | else if (!list_empty(&priv->cmdpendingq) && | 459 | else if (!list_empty(&priv->cmdpendingq) && |
460 | !(priv->wakeup_dev_required)) | 460 | !(priv->wakeup_dev_required)) |
461 | shouldsleep = 0; /* We have a command to send */ | 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 | shouldsleep = 0; /* We have an event to process */ | 463 | shouldsleep = 0; /* We have an event to process */ |
464 | else | 464 | else |
465 | shouldsleep = 1; /* No command */ | 465 | shouldsleep = 1; /* No command */ |
@@ -511,9 +511,9 @@ static int lbs_thread(void *data) | |||
511 | 511 | ||
512 | /* Process hardware events, e.g. card removed, link lost */ | 512 | /* Process hardware events, e.g. card removed, link lost */ |
513 | spin_lock_irq(&priv->driver_lock); | 513 | spin_lock_irq(&priv->driver_lock); |
514 | while (__kfifo_len(priv->event_fifo)) { | 514 | while (__kfifo_len(&priv->event_fifo)) { |
515 | u32 event; | 515 | u32 event; |
516 | __kfifo_get(priv->event_fifo, (unsigned char *) &event, | 516 | __kfifo_get(&priv->event_fifo, (unsigned char *) &event, |
517 | sizeof(event)); | 517 | sizeof(event)); |
518 | spin_unlock_irq(&priv->driver_lock); | 518 | spin_unlock_irq(&priv->driver_lock); |
519 | lbs_process_event(priv, event); | 519 | lbs_process_event(priv, event); |
@@ -883,10 +883,9 @@ 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 | priv->event_fifo = kfifo_alloc(sizeof(u32) * 16, GFP_KERNEL, NULL); | 886 | ret = kfifo_alloc(&priv->event_fifo, sizeof(u32) * 16, GFP_KERNEL, NULL); |
887 | if (IS_ERR(priv->event_fifo)) { | 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 | ret = -ENOMEM; | ||
890 | goto out; | 889 | goto out; |
891 | } | 890 | } |
892 | 891 | ||
@@ -901,8 +900,7 @@ static void lbs_free_adapter(struct lbs_private *priv) | |||
901 | lbs_deb_enter(LBS_DEB_MAIN); | 900 | lbs_deb_enter(LBS_DEB_MAIN); |
902 | 901 | ||
903 | lbs_free_cmd_buffer(priv); | 902 | lbs_free_cmd_buffer(priv); |
904 | if (priv->event_fifo) | 903 | kfifo_free(&priv->event_fifo); |
905 | kfifo_free(priv->event_fifo); | ||
906 | del_timer(&priv->command_timer); | 904 | del_timer(&priv->command_timer); |
907 | del_timer(&priv->auto_deepsleep_timer); | 905 | del_timer(&priv->auto_deepsleep_timer); |
908 | kfree(priv->networks); | 906 | kfree(priv->networks); |
@@ -1177,7 +1175,7 @@ void lbs_queue_event(struct lbs_private *priv, u32 event) | |||
1177 | if (priv->psstate == PS_STATE_SLEEP) | 1175 | if (priv->psstate == PS_STATE_SLEEP) |
1178 | priv->psstate = PS_STATE_AWAKE; | 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 | wake_up_interruptible(&priv->waitq); | 1180 | wake_up_interruptible(&priv->waitq); |
1183 | 1181 | ||