Skip to contentSkip to conversation

staging: ozwpan: Remove allocation from delaration line

PATCH In review Quentin Lambert 3 participants 3 messages Feb 10, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 staging: ozwpan: Remove allocation from delaration line

This patch removes allocation from declaration line because people are known to gloss over declarations.

---
Changes since v1:
- Remove the blank line between allocation and NULL check

 drivers/staging/ozwpan/ozhcd.c | 5 +++--
 drivers/staging/ozwpan/ozpd.c  | 8 +++++---
 2 files changed, 8 insertions(+), 5 deletions(-)
drivers/staging/ozwpan/ozhcd.c +3 -2
index 8543bb2..96e95bf 100644
@@ -280,8 +280,9 @@ static void oz_free_urb_link(struct oz_urb_link *urbl)
  */
 static struct oz_endpoint *oz_ep_alloc(int buffer_size, gfp_t mem_flags)
 {
-	struct oz_endpoint *ep =
-		kzalloc(sizeof(struct oz_endpoint)+buffer_size, mem_flags);
+	struct oz_endpoint *ep;
+
+	ep = kzalloc(sizeof(struct oz_endpoint)+buffer_size, mem_flags);
 	if (ep) {
 		INIT_LIST_HEAD(&ep->urb_list);
 		INIT_LIST_HEAD(&ep->link);
drivers/staging/ozwpan/ozpd.c +5 -3
index 852c288..1c95d57 100644
@@ -102,8 +102,9 @@ void oz_pd_put(struct oz_pd *pd)
  */
 struct oz_pd *oz_pd_alloc(const u8 *mac_addr)
 {
-	struct oz_pd *pd = kzalloc(sizeof(struct oz_pd), GFP_ATOMIC);
+	struct oz_pd *pd;
 
+	pd = kzalloc(sizeof(struct oz_pd), GFP_ATOMIC);
 	if (pd) {
 		int i;
 
@@ -652,8 +653,9 @@ static struct oz_isoc_stream *pd_stream_find(struct oz_pd *pd, u8 ep_num)
  */
 int oz_isoc_stream_create(struct oz_pd *pd, u8 ep_num)
 {
-	struct oz_isoc_stream *st =
-		kzalloc(sizeof(struct oz_isoc_stream), GFP_ATOMIC);
+	struct oz_isoc_stream *st;
+
+	st = kzalloc(sizeof(struct oz_isoc_stream), GFP_ATOMIC);
 	if (!st)
 		return -ENOMEM;
 	st->ep_num = ep_num;
Signature · 1 line
1.9.1
#1 lore raw

Looks good. Thanks!

drivers/staging/ozwpan/ozhcd.c static void oz_free_urb_link(struct oz_urb_link *urbl) · line 286

Quoted 13 lines
drivers/staging/ozwpan/ozhcd.c +3 -1
index 8543bb2..96e95bf 100644
@@ -280,8 +280,9 @@ static void oz_free_urb_link(struct oz_urb_link *urbl)
  */
 static struct oz_endpoint *oz_ep_alloc(int buffer_size, gfp_t mem_flags)
 {
-	struct oz_endpoint *ep > -		kzalloc(sizeof(struct oz_endpoint)+buffer_size, mem_flags);
+	struct oz_endpoint *ep;
+
+	ep = kzalloc(sizeof(struct oz_endpoint)+buffer_size, mem_flags);
 	if (ep) {

Also notice how in the original code, we had to mangle the code to make it fit into 80 characters so the new code looks much better.

regards,
dan
carpenter

#2 lore raw
Quoted 1 line · Dan Carpenter

drivers/staging/ozwpan/ozhcd.c

Quoted 1 line
drivers/staging/ozwpan/ozhcd.c +0 -0

[]

Quoted 4 lines
Quoted 4 lines
drivers/staging/ozwpan/ozhcd.c +0 -0
@@ -280,8 +280,9 @@ static void oz_free_urb_link(struct oz_urb_link *urbl)
  */
 static struct oz_endpoint *oz_ep_alloc(int buffer_size, gfp_t mem_flags)
 {
Quoted 8 lines

drivers/staging/ozwpan/ozhcd.c static void oz_free_urb_link(struct oz_urb_link *urbl) · line 286

Quoted 5 lines
drivers/staging/ozwpan/ozhcd.c +3 -1
-	struct oz_endpoint *ep > > -		kzalloc(sizeof(struct oz_endpoint)+buffer_size, mem_flags);
+	struct oz_endpoint *ep;
+
+	ep = kzalloc(sizeof(struct oz_endpoint)+buffer_size, mem_flags);
 	if (ep) {

Also notice how in the original code, we had to mangle the code to make it fit into 80 characters so the new code looks much better.

or maybe

	ep = kzalloc(sizeof(*ep) + buffer_size, mem_flags);

The current function also tests the return of ep slightly backwards.

static struct oz_endpoint *oz_ep_alloc(int buffer_size, gfp_t mem_flags)

{
	struct oz_endpoint *ep 		kzalloc(sizeof(struct oz_endpoint)+buffer_size, mem_flags);
	if (ep) {
		INIT_LIST_HEAD(&ep->urb_list);
		INIT_LIST_HEAD(&ep->link);
		ep->credit = -1;
		if (buffer_size) {
			ep->buffer_size = buffer_size;
			ep->buffer = (u8 *)(ep+1);
		}
	}
	return ep;
}

Perhaps more typical would be:

static struct oz_endpoint *oz_ep_alloc(int buffer_size, gfp_t mem_flags)

{
	struct oz_endpoint *ep;

	ep = kzalloc(sizeof(*ep) + buffer_size, mem_flags);
	if (!ep)
		return NULL;

	INIT_LIST_HEAD(&ep->urb_list);
	INIT_LIST_HEAD(&ep->link);
	ep->credit = -1;
	if (buffer_size) {
		ep->buffer_size = buffer_size;
		ep->buffer = (u8 *)(ep + 1);
	}

	return ep;
}

Maybe buffer_size should be size_t too to avoid
possible negative values.