mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/6] staging: ozwpan: Use Kernel API & Bug fixes
@ 2013-08-01 17:39 Rupesh Gujare
  2013-08-01 17:40 ` [PATCH 1/6] staging: ozwpan: Use kernel list function for managing interface list Rupesh Gujare
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Rupesh Gujare @ 2013-08-01 17:39 UTC (permalink / raw)
  To: devel; +Cc: linux-usb, linux-kernel, gregkh

This patch series removes duplicate code, & replaces it
with kernel library functions, and few bug fixes.

Rupesh Gujare (6):
  staging: ozwpan: Use kernel list function for managing interface
    list.
  staging: ozwpan: Mark string as const
  staging: ozwpan: Use kernel strncmp function.
  staging: ozwpan: Drop oldest ISOC frame instead of dropping latest.
  staging: ozwpan: Increase farewell report size.
  staging: ozwpan: Set farewell report length.

 drivers/staging/ozwpan/ozpd.c    |   13 +++++++++-
 drivers/staging/ozwpan/ozpd.h    |    2 +-
 drivers/staging/ozwpan/ozproto.c |   51 +++++++++++++-------------------------
 drivers/staging/ozwpan/ozproto.h |    4 +--
 4 files changed, 32 insertions(+), 38 deletions(-)

-- 
1.7.9.5


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/6] staging: ozwpan: Use kernel list function for managing interface list.
  2013-08-01 17:39 [PATCH 0/6] staging: ozwpan: Use Kernel API & Bug fixes Rupesh Gujare
@ 2013-08-01 17:40 ` Rupesh Gujare
  2013-08-01 17:40 ` [PATCH 2/6] staging: ozwpan: Mark string as const Rupesh Gujare
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Rupesh Gujare @ 2013-08-01 17:40 UTC (permalink / raw)
  To: devel; +Cc: linux-usb, linux-kernel, gregkh

Managing interface list, is easier if we use kernel list_* API
than managing it on our own.

Signed-off-by: Rupesh Gujare <rupesh.gujare@atmel.com>
---
 drivers/staging/ozwpan/ozproto.c |   29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/ozwpan/ozproto.c b/drivers/staging/ozwpan/ozproto.c
index ed22729..500800f 100644
--- a/drivers/staging/ozwpan/ozproto.c
+++ b/drivers/staging/ozwpan/ozproto.c
@@ -37,7 +37,7 @@
 struct oz_binding {
 	struct packet_type ptype;
 	char name[OZ_MAX_BINDING_LEN];
-	struct oz_binding *next;
+	struct list_head link;
 };
 
 /*------------------------------------------------------------------------------
@@ -45,7 +45,7 @@ struct oz_binding {
  */
 static DEFINE_SPINLOCK(g_polling_lock);
 static LIST_HEAD(g_pd_list);
-static struct oz_binding *g_binding ;
+static LIST_HEAD(g_binding);
 static DEFINE_SPINLOCK(g_binding_lock);
 static struct sk_buff_head g_rx_queue;
 static u8 g_session_id;
@@ -437,12 +437,13 @@ done:
  */
 void oz_protocol_term(void)
 {
+	struct oz_binding *b, *t;
+
 	/* Walk the list of bindings and remove each one.
 	 */
 	spin_lock_bh(&g_binding_lock);
-	while (g_binding) {
-		struct oz_binding *b = g_binding;
-		g_binding = b->next;
+	list_for_each_entry_safe(b, t, &g_binding, link) {
+		list_del(&b->link);
 		spin_unlock_bh(&g_binding_lock);
 		dev_remove_pack(&b->ptype);
 		if (b->ptype.dev)
@@ -660,8 +661,7 @@ void oz_binding_add(char *net_dev)
 		if (binding) {
 			dev_add_pack(&binding->ptype);
 			spin_lock_bh(&g_binding_lock);
-			binding->next = g_binding;
-			g_binding = binding;
+			list_add_tail(&binding->link, &g_binding);
 			spin_unlock_bh(&g_binding_lock);
 		}
 	}
@@ -710,28 +710,25 @@ static void pd_stop_all_for_device(struct net_device *net_dev)
 void oz_binding_remove(char *net_dev)
 {
 	struct oz_binding *binding;
-	struct oz_binding **link;
+	int found = 0;
+
 	oz_dbg(ON, "Removing binding: %s\n", net_dev);
 	spin_lock_bh(&g_binding_lock);
-	binding = g_binding;
-	link = &g_binding;
-	while (binding) {
+	list_for_each_entry(binding, &g_binding, link) {
 		if (compare_binding_name(binding->name, net_dev)) {
 			oz_dbg(ON, "Binding '%s' found\n", net_dev);
-			*link = binding->next;
+			found = 1;
 			break;
-		} else {
-			link = &binding;
-			binding = binding->next;
 		}
 	}
 	spin_unlock_bh(&g_binding_lock);
-	if (binding) {
+	if (found) {
 		dev_remove_pack(&binding->ptype);
 		if (binding->ptype.dev) {
 			dev_put(binding->ptype.dev);
 			pd_stop_all_for_device(binding->ptype.dev);
 		}
+		list_del(&binding->link);
 		kfree(binding);
 	}
 }
-- 
1.7.9.5


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/6] staging: ozwpan: Mark string as const
  2013-08-01 17:39 [PATCH 0/6] staging: ozwpan: Use Kernel API & Bug fixes Rupesh Gujare
  2013-08-01 17:40 ` [PATCH 1/6] staging: ozwpan: Use kernel list function for managing interface list Rupesh Gujare
@ 2013-08-01 17:40 ` Rupesh Gujare
  2013-08-01 18:17   ` Joe Perches
  2013-08-01 17:40 ` [PATCH 3/6] staging: ozwpan: Use kernel strncmp function Rupesh Gujare
  2013-08-01 17:40 ` [PATCH 4/6] staging: ozwpan: Drop oldest ISOC frame instead of dropping latest Rupesh Gujare
  3 siblings, 1 reply; 6+ messages in thread
From: Rupesh Gujare @ 2013-08-01 17:40 UTC (permalink / raw)
  To: devel; +Cc: linux-usb, linux-kernel, gregkh

Make sure that we mark const string so that it does not get modified.

Signed-off-by: Rupesh Gujare <rupesh.gujare@atmel.com>
---
 drivers/staging/ozwpan/ozproto.c |    6 +++---
 drivers/staging/ozwpan/ozproto.h |    4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/ozwpan/ozproto.c b/drivers/staging/ozwpan/ozproto.c
index 500800f..2dbaba6 100644
--- a/drivers/staging/ozwpan/ozproto.c
+++ b/drivers/staging/ozwpan/ozproto.c
@@ -636,7 +636,7 @@ static int oz_pkt_recv(struct sk_buff *skb, struct net_device *dev,
 /*------------------------------------------------------------------------------
  * Context: process
  */
-void oz_binding_add(char *net_dev)
+void oz_binding_add(const char *net_dev)
 {
 	struct oz_binding *binding;
 
@@ -669,7 +669,7 @@ void oz_binding_add(char *net_dev)
 /*------------------------------------------------------------------------------
  * Context: process
  */
-static int compare_binding_name(char *s1, char *s2)
+static int compare_binding_name(const char *s1, const char *s2)
 {
 	int i;
 	for (i = 0; i < OZ_MAX_BINDING_LEN; i++) {
@@ -707,7 +707,7 @@ static void pd_stop_all_for_device(struct net_device *net_dev)
 /*------------------------------------------------------------------------------
  * Context: process
  */
-void oz_binding_remove(char *net_dev)
+void oz_binding_remove(const char *net_dev)
 {
 	struct oz_binding *binding;
 	int found = 0;
diff --git a/drivers/staging/ozwpan/ozproto.h b/drivers/staging/ozwpan/ozproto.h
index 305c532..e532347 100644
--- a/drivers/staging/ozwpan/ozproto.h
+++ b/drivers/staging/ozwpan/ozproto.h
@@ -54,8 +54,8 @@ void oz_protocol_term(void);
 int oz_get_pd_list(struct oz_mac_addr *addr, int max_count);
 void oz_app_enable(int app_id, int enable);
 struct oz_pd *oz_pd_find(const u8 *mac_addr);
-void oz_binding_add(char *net_dev);
-void oz_binding_remove(char *net_dev);
+void oz_binding_add(const char *net_dev);
+void oz_binding_remove(const char *net_dev);
 void oz_timer_add(struct oz_pd *pd, int type, unsigned long due_time);
 void oz_timer_delete(struct oz_pd *pd, int type);
 void oz_pd_request_heartbeat(struct oz_pd *pd);
-- 
1.7.9.5


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3/6] staging: ozwpan: Use kernel strncmp function.
  2013-08-01 17:39 [PATCH 0/6] staging: ozwpan: Use Kernel API & Bug fixes Rupesh Gujare
  2013-08-01 17:40 ` [PATCH 1/6] staging: ozwpan: Use kernel list function for managing interface list Rupesh Gujare
  2013-08-01 17:40 ` [PATCH 2/6] staging: ozwpan: Mark string as const Rupesh Gujare
@ 2013-08-01 17:40 ` Rupesh Gujare
  2013-08-01 17:40 ` [PATCH 4/6] staging: ozwpan: Drop oldest ISOC frame instead of dropping latest Rupesh Gujare
  3 siblings, 0 replies; 6+ messages in thread
From: Rupesh Gujare @ 2013-08-01 17:40 UTC (permalink / raw)
  To: devel; +Cc: linux-usb, linux-kernel, gregkh

Use kernel's strncmp() function instead of defining same within driver.

Signed-off-by: Rupesh Gujare <rupesh.gujare@atmel.com>
---
 drivers/staging/ozwpan/ozproto.c |   17 +----------------
 1 file changed, 1 insertion(+), 16 deletions(-)

diff --git a/drivers/staging/ozwpan/ozproto.c b/drivers/staging/ozwpan/ozproto.c
index 2dbaba6..ec60286 100644
--- a/drivers/staging/ozwpan/ozproto.c
+++ b/drivers/staging/ozwpan/ozproto.c
@@ -669,21 +669,6 @@ void oz_binding_add(const char *net_dev)
 /*------------------------------------------------------------------------------
  * Context: process
  */
-static int compare_binding_name(const char *s1, const char *s2)
-{
-	int i;
-	for (i = 0; i < OZ_MAX_BINDING_LEN; i++) {
-		if (*s1 != *s2)
-			return 0;
-		if (!*s1++)
-			return 1;
-		s2++;
-	}
-	return 1;
-}
-/*------------------------------------------------------------------------------
- * Context: process
- */
 static void pd_stop_all_for_device(struct net_device *net_dev)
 {
 	struct list_head h;
@@ -715,7 +700,7 @@ void oz_binding_remove(const char *net_dev)
 	oz_dbg(ON, "Removing binding: %s\n", net_dev);
 	spin_lock_bh(&g_binding_lock);
 	list_for_each_entry(binding, &g_binding, link) {
-		if (compare_binding_name(binding->name, net_dev)) {
+		if (strncmp(binding->name, net_dev, OZ_MAX_BINDING_LEN) == 0) {
 			oz_dbg(ON, "Binding '%s' found\n", net_dev);
 			found = 1;
 			break;
-- 
1.7.9.5


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 4/6] staging: ozwpan: Drop oldest ISOC frame instead of dropping latest.
  2013-08-01 17:39 [PATCH 0/6] staging: ozwpan: Use Kernel API & Bug fixes Rupesh Gujare
                   ` (2 preceding siblings ...)
  2013-08-01 17:40 ` [PATCH 3/6] staging: ozwpan: Use kernel strncmp function Rupesh Gujare
@ 2013-08-01 17:40 ` Rupesh Gujare
  3 siblings, 0 replies; 6+ messages in thread
From: Rupesh Gujare @ 2013-08-01 17:40 UTC (permalink / raw)
  To: devel; +Cc: linux-usb, linux-kernel, gregkh

In case of ISOC transfer, if TX queue is full then we start
dropping latest frame, instead we should drop oldest frame &
add latest frame to TX queue.

Signed-off-by: Rupesh Gujare <rupesh.gujare@atmel.com>
---
 drivers/staging/ozwpan/ozpd.c |   13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/ozwpan/ozpd.c b/drivers/staging/ozwpan/ozpd.c
index 86876bd..17fd7b2 100644
--- a/drivers/staging/ozwpan/ozpd.c
+++ b/drivers/staging/ozwpan/ozpd.c
@@ -844,9 +844,20 @@ int oz_send_isoc_unit(struct oz_pd *pd, u8 ep_num, const u8 *data, int len)
 			struct oz_tx_frame *isoc_unit = NULL;
 			int nb = pd->nb_queued_isoc_frames;
 			if (nb >= pd->isoc_latency) {
+				struct list_head *e;
+				struct oz_tx_frame *f;
 				oz_dbg(TX_FRAMES, "Dropping ISOC Unit nb= %d\n",
 				       nb);
-				goto out;
+				spin_lock(&pd->tx_frame_lock);
+				list_for_each(e, &pd->tx_queue) {
+					f = container_of(e, struct oz_tx_frame,
+									link);
+					if (f->skb != NULL) {
+						oz_tx_isoc_free(pd, f);
+						break;
+					}
+				}
+				spin_unlock(&pd->tx_frame_lock);
 			}
 			isoc_unit = oz_tx_frame_alloc(pd);
 			if (isoc_unit == NULL)
-- 
1.7.9.5


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/6] staging: ozwpan: Mark string as const
  2013-08-01 17:40 ` [PATCH 2/6] staging: ozwpan: Mark string as const Rupesh Gujare
@ 2013-08-01 18:17   ` Joe Perches
  0 siblings, 0 replies; 6+ messages in thread
From: Joe Perches @ 2013-08-01 18:17 UTC (permalink / raw)
  To: Rupesh Gujare; +Cc: devel, linux-usb, linux-kernel, gregkh

On Thu, 2013-08-01 at 18:40 +0100, Rupesh Gujare wrote:
> Make sure that we mark const string so that it does not get modified.
[]
> diff --git a/drivers/staging/ozwpan/ozproto.h b/drivers/staging/ozwpan/ozproto.h
[]
> -void oz_binding_add(char *net_dev);
> -void oz_binding_remove(char *net_dev);
> +void oz_binding_add(const char *net_dev);
> +void oz_binding_remove(const char *net_dev);

const char *net_dev is a poor naming choice.
const char *name might be better.



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-08-01 18:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-01 17:39 [PATCH 0/6] staging: ozwpan: Use Kernel API & Bug fixes Rupesh Gujare
2013-08-01 17:40 ` [PATCH 1/6] staging: ozwpan: Use kernel list function for managing interface list Rupesh Gujare
2013-08-01 17:40 ` [PATCH 2/6] staging: ozwpan: Mark string as const Rupesh Gujare
2013-08-01 18:17   ` Joe Perches
2013-08-01 17:40 ` [PATCH 3/6] staging: ozwpan: Use kernel strncmp function Rupesh Gujare
2013-08-01 17:40 ` [PATCH 4/6] staging: ozwpan: Drop oldest ISOC frame instead of dropping latest Rupesh Gujare

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®