Module: xenomai-gch
Branch: for-forge
Commit: 0f81d2d55707cc4a0122962952b3b4ade38754f0
URL:    
http://git.xenomai.org/?p=xenomai-gch.git;a=commit;h=0f81d2d55707cc4a0122962952b3b4ade38754f0

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Sun Oct 11 16:04:40 2015 +0200

rtnet: fix reference count issues

---

 kernel/drivers/net/stack/include/rtskb.h    |    3 +--
 kernel/drivers/net/stack/ipv4/ip_input.c    |    1 +
 kernel/drivers/net/stack/rtmac/rtmac_vnic.c |    5 +----
 kernel/drivers/net/stack/rtskb.c            |   17 ++++-------------
 4 files changed, 7 insertions(+), 19 deletions(-)

diff --git a/kernel/drivers/net/stack/include/rtskb.h 
b/kernel/drivers/net/stack/include/rtskb.h
index a6ef860..7489aa6 100644
--- a/kernel/drivers/net/stack/include/rtskb.h
+++ b/kernel/drivers/net/stack/include/rtskb.h
@@ -242,7 +242,6 @@ struct rtskb_pool_lock_ops {
 struct rtskb_pool {
     struct rtskb_queue queue;
     const struct rtskb_pool_lock_ops *lock_ops;
-    unsigned lock_count;
     void *lock_cookie;
 };
 
@@ -736,7 +735,7 @@ extern unsigned int __rtskb_module_pool_init(struct 
rtskb_pool *pool,
 #define rtskb_module_pool_init(pool, size) \
     __rtskb_module_pool_init(pool, size, THIS_MODULE)
 
-extern int rtskb_pool_release(struct rtskb_pool *pool);
+extern void rtskb_pool_release(struct rtskb_pool *pool);
 
 extern unsigned int rtskb_pool_extend(struct rtskb_pool *pool,
                                      unsigned int add_rtskbs);
diff --git a/kernel/drivers/net/stack/ipv4/ip_input.c 
b/kernel/drivers/net/stack/ipv4/ip_input.c
index c9c871e..2d2a751 100644
--- a/kernel/drivers/net/stack/ipv4/ip_input.c
+++ b/kernel/drivers/net/stack/ipv4/ip_input.c
@@ -88,6 +88,7 @@ static inline void rt_ip_local_deliver(struct rtskb *skb)
 
             if (err) {
                 kfree_rtskb(skb);
+               rt_socket_dereference(sock);
                 return;
             }
         }
diff --git a/kernel/drivers/net/stack/rtmac/rtmac_vnic.c 
b/kernel/drivers/net/stack/rtmac/rtmac_vnic.c
index 510e714..3bdb760 100644
--- a/kernel/drivers/net/stack/rtmac/rtmac_vnic.c
+++ b/kernel/drivers/net/stack/rtmac/rtmac_vnic.c
@@ -286,12 +286,9 @@ int rtmac_vnic_add(struct rtnet_device *rtdev, 
vnic_xmit_handler vnic_xmit)
 int rtmac_vnic_unregister(struct rtnet_device *rtdev)
 {
     struct rtmac_priv   *mac_priv = rtdev->mac_priv;
-    int err;
 
     if (mac_priv->vnic) {
-       err = rtskb_pool_release(&mac_priv->vnic_skb_pool);
-       if (err < 0)
-           return err;
+       rtskb_pool_release(&mac_priv->vnic_skb_pool);
        unregister_netdev(mac_priv->vnic);
        free_netdev(mac_priv->vnic);
        mac_priv->vnic = NULL;
diff --git a/kernel/drivers/net/stack/rtskb.c b/kernel/drivers/net/stack/rtskb.c
index 8afd6a6..f560902 100644
--- a/kernel/drivers/net/stack/rtskb.c
+++ b/kernel/drivers/net/stack/rtskb.c
@@ -156,14 +156,11 @@ static struct rtskb *__rtskb_pool_dequeue(struct 
rtskb_pool *pool)
     struct rtskb_queue *queue = &pool->queue;
     struct rtskb *skb;
 
-    if (pool->lock_count == 0 && !pool->lock_ops->trylock(pool->lock_cookie))
+    if (!pool->lock_ops->trylock(pool->lock_cookie))
            return NULL;
     skb = __rtskb_dequeue(queue);
-    if (skb == NULL) {
-       if (pool->lock_count == 0) /* This can only happen if pool has 0 
packets */
+    if (skb == NULL)
            pool->lock_ops->unlock(pool->lock_cookie);
-    } else
-       ++pool->lock_count;
 
     return skb;
 }
@@ -187,8 +184,7 @@ static void __rtskb_pool_queue_tail(struct rtskb_pool 
*pool, struct rtskb *skb)
     struct rtskb_queue *queue = &pool->queue;
 
     __rtskb_queue_tail(queue,skb);
-    if (--pool->lock_count == 0)
-       pool->lock_ops->unlock(pool->lock_cookie);
+    pool->lock_ops->unlock(pool->lock_cookie);
 }
 
 void rtskb_pool_queue_tail(struct rtskb_pool *pool, struct rtskb *skb)
@@ -332,7 +328,6 @@ unsigned int rtskb_pool_init(struct rtskb_pool *pool,
        rtskb_pools_max = rtskb_pools;
 
     pool->lock_ops = lock_ops ?: &rtskb_nop_pool_lock_ops;
-    pool->lock_count = 0;
     pool->lock_cookie = lock_cookie;
 
     return i;
@@ -372,13 +367,10 @@ EXPORT_SYMBOL_GPL(__rtskb_module_pool_init);
  *  __rtskb_pool_release
  *  @pool: pool to release
  */
-int rtskb_pool_release(struct rtskb_pool *pool)
+void rtskb_pool_release(struct rtskb_pool *pool)
 {
     struct rtskb *skb;
 
-    if (pool->lock_count)
-       return -EBUSY;
-
     while ((skb = rtskb_dequeue(&pool->queue)) != NULL) {
        rtdev_unmap_rtskb(skb);
        kmem_cache_free(rtskb_slab_pool, skb);
@@ -386,7 +378,6 @@ int rtskb_pool_release(struct rtskb_pool *pool)
     }
 
     rtskb_pools--;
-    return 0;
 }
 
 EXPORT_SYMBOL_GPL(rtskb_pool_release);


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://xenomai.org/mailman/listinfo/xenomai-git

Reply via email to