whitespace cleanup
added a function for safely incrementing the sequence number counter for
netlink communication
moved clearing of file operation queue to separate function to do it
before freeing netdev_data since it will remove the semaphor as well
formatting and shortening of printk output
added curseq to count used sequence numbers in netlink communication
changed argument name to match rest of the code
changed argument name to match rest of the code
reduced arguments of netlink_send_fo to just netdev_data and fo_req
since message type is already in netdev_data and fo_req contains length
and seq
more clear kernel message when removing module and cleaning after it
used kfifo_is_empty for loop test and break out of loop if size doesn't
match to avoid endless loop
diff --git a/kernel/netdevmgm.c b/kernel/netdevmgm.c
index 4452bae..a2f1ec4 100644
--- a/kernel/netdevmgm.c
+++ b/kernel/netdevmgm.c
@@ -81,11 +81,12 @@ int ndmgm_free_queue(struct netdev_data *nddata) {
     struct fo_req *req = NULL;

     /* destroy all requests in the queue */
-    while (kfifo_avail(&nddata->fo_queue)) {
+    while (!kfifo_is_empty(&nddata->fo_queue)) {
+        printk(KERN_ERR "netdev_destroy: queue not emtpy\n");
         size = kfifo_out(&nddata->fo_queue, &req, sizeof(struct fo_req *));
         if ( size != sizeof(struct fo_req *) ) {
-            printk(KERN_ERR "netdev_destroy: failed to fetch from queue\n");
-            continue;
+            printk(KERN_ERR "netdev_destroy: failed to fetch from queue, size = %d\n", size);
+            return 0; /* failure */
         }

         req->rvalue = -ENODATA;
@@ -94,10 +95,8 @@ int ndmgm_free_queue(struct netdev_data *nddata) {
         kmem_cache_free(nddata->queue_pool, req);
     }

-    kmem_cache_destroy(nddata->queue_pool);
-    kfifo_free(&nddata->fo_queue);
-    kfree(nddata->cdev);
-    kfree(nddata);
+    return 1; /* success */
+}

 int ndmgm_incseq(struct netdev_data *nddata) {
     int seq = 0; /* failure */
unlock semaphor after I complete all pending file operations and destroy
the device to make sure I don't leave some process hanging with a
pointer to random kernel memory
added curseq to keep track of sequence numbers used in netlink messages,
      to increment it a function that locks netdev_data is created,
      incseq
ndmgm_free_queue needs to be done separately from freeing memory to
unlock the semaphore after all pending operations are completed
added netlink_send_fo since it's a specific type of message
sequence number is nedded for echo to use the same oen for reply
moved netlink_echo lower
serialization most probably won't be needed since I'm sending from
kernel to kernel
added seq to netlink_echo since it needs to reply to the same one
ndmgm_create will have to take the name from the server process, this is
a good start
this is not needed in this function