Skip to contentSkip to conversation

staging: rtl8712: use list macros

PATCH Superseded Himadri Pandya 3 participants 27 messages Mar 30, 2019 – Apr 1, 2019 Staging

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover staging: rtl8712: use list macros

This patchset

-  Replaces usage of container_of with list_entry
-  Replaces a while loop with list_for_each
-  Removes an unnecessary NULL check 

V2:
- Include new patches for using list_for_each and removing unnecessary NULL check

Himadri Pandya (7):
staging: rtl8712: use list_entry in function _r8712_find_network
staging: rtl8712: use list_for_each in function _r8712_find_network
staging: rtl8712: use list_entry in function _free_network_queue
staging: rtl8712: use list_entry in function

    r8712_get_oldest_wlan_network
  staging: rtl8712: use list_entry in function update_scanned_network
  staging: rtl8712: remove unnecessary NULL check
  staging: rtl8712: use list_entry in function
    r8712_select_and_join_from_scan
 drivers/staging/rtl8712/rtl871x_mlme.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/7 staging: rtl8712: use list_entry in function _r8712_find_network

Use list_entry instead of container_of for conversion to wlan_network in function _r8712_find_network().

---
 drivers/staging/rtl8712/rtl871x_mlme.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8712/rtl871x_mlme.c +1 -1
index c666e038f43e..9bfceaeaa05e 100644
@@ -142,7 +142,7 @@ static struct wlan_network *_r8712_find_network(struct  __queue *scanned_queue,
 	phead = &scanned_queue->queue;
 	plist = phead->next;
 	while (plist != phead) {
-		pnetwork = container_of(plist, struct wlan_network, list);
+		pnetwork = list_entry(plist, struct wlan_network, list);
 		plist = plist->next;
 		if (!memcmp(addr, pnetwork->network.MacAddress, ETH_ALEN))
 			break;
Signature · 1 line
2.17.1
#2 lore raw

PATCH v2 2/7 staging: rtl8712: use list_for_each in function _r8712_find_network

In reply to Himadri Pandya

Use list_for_each to iterate over list scanned_queue->queue in function _r8712_find_network().

---
 drivers/staging/rtl8712/rtl871x_mlme.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/rtl8712/rtl871x_mlme.c +1 -2
index 9bfceaeaa05e..6912d73e8172 100644
@@ -141,9 +141,8 @@ static struct wlan_network *_r8712_find_network(struct  __queue *scanned_queue,
 	spin_lock_irqsave(&scanned_queue->lock, irqL);
 	phead = &scanned_queue->queue;
 	plist = phead->next;
-	while (plist != phead) {
+	list_for_each(plist, phead) {
 		pnetwork = list_entry(plist, struct wlan_network, list);
-		plist = plist->next;
 		if (!memcmp(addr, pnetwork->network.MacAddress, ETH_ALEN))
 			break;
 	}
Signature · 1 line
2.17.1
#3 lore raw

PATCH v2 3/7 staging: rtl8712: use list_entry in function _free_network_queue

In reply to Himadri Pandya

Use list_entry instead of container_of for conversion to wlan_network in function _free_network_queue()

---
 drivers/staging/rtl8712/rtl871x_mlme.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8712/rtl871x_mlme.c +1 -1
index 6912d73e8172..e0b4b8fbcc0e 100644
@@ -162,7 +162,7 @@ static void _free_network_queue(struct _adapter *padapter)
 	phead = &scanned_queue->queue;
 	plist = phead->next;
 	while (!end_of_queue_search(phead, plist)) {
-		pnetwork = container_of(plist, struct wlan_network, list);
+		pnetwork = list_entry(plist, struct wlan_network, list);
 		plist = plist->next;
 		_free_network(pmlmepriv, pnetwork);
 	}
Signature · 1 line
2.17.1
#4 lore raw

PATCH v2 4/7 staging: rtl8712: use list_entry in function r8712_get_oldest_wlan_network

In reply to Himadri Pandya

Use list_entry instead of container_of for conversion to wlan_network in function r8712_get_oldest_wlan_network().

---
 drivers/staging/rtl8712/rtl871x_mlme.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8712/rtl871x_mlme.c +1 -1
index e0b4b8fbcc0e..05bfc2a60eb9 100644
@@ -289,7 +289,7 @@ struct	wlan_network *r8712_get_oldest_wlan_network(
 	while (1) {
 		if (end_of_queue_search(phead, plist) ==  true)
 			break;
-		pwlan = container_of(plist, struct wlan_network, list);
+		pwlan = list_entry(plist, struct wlan_network, list);
 		if (pwlan->fixed != true) {
 			if (oldest == NULL ||
 			    time_after((unsigned long)oldest->last_scanned,
Signature · 1 line
2.17.1
#5 lore raw

PATCH v2 5/7 staging: rtl8712: use list_entry in function update_scanned_network

In reply to Himadri Pandya

Use list_entry instead of container_of for conversion to wlan_network in function update_scanned_network().

---
 drivers/staging/rtl8712/rtl871x_mlme.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8712/rtl871x_mlme.c +1 -1
index 05bfc2a60eb9..1a15c45aa83b 100644
@@ -370,7 +370,7 @@ static void update_scanned_network(struct _adapter *adapter,
 		if (end_of_queue_search(phead, plist))
 			break;
 
-		pnetwork = container_of(plist, struct wlan_network, list);
+		pnetwork = list_entry(plist, struct wlan_network, list);
 		if (is_same_network(&pnetwork->network, target))
 			break;
 		if ((oldest == ((struct wlan_network *)0)) ||
Signature · 1 line
2.17.1
#6 lore raw

PATCH v2 6/7 staging: rtl8712: remove unnecessary NULL check

In reply to Himadri Pandya

Remove unnecessary NULL check for wlan_network *pnetwork as container_of will not return NULL in this usage.

---
 drivers/staging/rtl8712/rtl871x_mlme.c | 2 --
 1 file changed, 2 deletions(-)
drivers/staging/rtl8712/rtl871x_mlme.c +0 -2
index 1a15c45aa83b..be44c6b2819b 100644
@@ -1119,8 +1119,6 @@ int r8712_select_and_join_from_scan(struct mlme_priv *pmlmepriv)
 		}
 		pnetwork = container_of(pmlmepriv->pscanned,
 					struct wlan_network, list);
-		if (pnetwork == NULL)
-			return _FAIL;
 		pmlmepriv->pscanned = pmlmepriv->pscanned->next;
 		if (pmlmepriv->assoc_by_bssid) {
 			dst_ssid = pnetwork->network.MacAddress;
Signature · 1 line
2.17.1
#7 lore raw

PATCH v2 7/7 staging: rtl8712: use list_entry in function r8712_select_and_join_from_scan

In reply to Himadri Pandya

Use list_entry instead of container_of for conversion to wlan_network in function r8712_select_and_join_from_scan().

---
 drivers/staging/rtl8712/rtl871x_mlme.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/rtl8712/rtl871x_mlme.c +2 -2
index be44c6b2819b..504c96993adb 100644
@@ -1117,8 +1117,8 @@ int r8712_select_and_join_from_scan(struct mlme_priv *pmlmepriv)
 			}
 			return _FAIL;
 		}
-		pnetwork = container_of(pmlmepriv->pscanned,
-					struct wlan_network, list);
+		pnetwork = list_entry(pmlmepriv->pscanned,
+				      struct wlan_network, list);
 		pmlmepriv->pscanned = pmlmepriv->pscanned->next;
 		if (pmlmepriv->assoc_by_bssid) {
 			dst_ssid = pnetwork->network.MacAddress;
Signature · 1 line
2.17.1
#8 lore raw
In reply to Himadri Pandya

Review

Quoted 4 lines · Himadri Pandya

This patchset

(quoted diff) +0 -3
-  Replaces usage of container_of with list_entry
-  Replaces a while loop with list_for_each
-  Removes an unnecessary NULL check

It would be good to redo all of the log messages to explain why the change is correct.

julia

Quoted 29 lines

V2:
- Include new patches for using list_for_each and removing unnecessary NULL check

Himadri Pandya (7):
staging: rtl8712: use list_entry in function _r8712_find_network
staging: rtl8712: use list_for_each in function _r8712_find_network
staging: rtl8712: use list_entry in function _free_network_queue
staging: rtl8712: use list_entry in function

    r8712_get_oldest_wlan_network
  staging: rtl8712: use list_entry in function update_scanned_network
  staging: rtl8712: remove unnecessary NULL check
  staging: rtl8712: use list_entry in function
    r8712_select_and_join_from_scan
 drivers/staging/rtl8712/rtl871x_mlme.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

--
2.17.1

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20190330192742.65250-1-himadri18.07%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

#9 lore raw
Quoted 9 lines · Julia Lawall,

Review

Quoted 4 lines · Himadri Pandya

This patchset

(quoted diff) +0 -3
-  Replaces usage of container_of with list_entry
-  Replaces a while loop with list_for_each
-  Removes an unnecessary NULL check
Quoted 5 lines

It would be good to redo all of the log messages to explain why the change is correct.

julia

Sure. Sending version 3 with explanation.

Thank you.

- Himadri

Quoted 34 lines
Quoted 16 lines

V2:
- Include new patches for using list_for_each and removing unnecessary NULL check

Himadri Pandya (7):
staging: rtl8712: use list_entry in function _r8712_find_network
staging: rtl8712: use list_for_each in function _r8712_find_network
staging: rtl8712: use list_entry in function _free_network_queue
staging: rtl8712: use list_entry in function

    r8712_get_oldest_wlan_network
  staging: rtl8712: use list_entry in function update_scanned_network
  staging: rtl8712: remove unnecessary NULL check
  staging: rtl8712: use list_entry in function
    r8712_select_and_join_from_scan
Quoted 8 lines
 drivers/staging/rtl8712/rtl871x_mlme.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

--
2.17.1

--
You received this message because you are subscribed to the Google

Groups "outreachy-kernel" group.

Quoted 1 line

To unsubscribe from this group and stop receiving emails from it, send

an email to [email protected].

Quoted 2 lines

To post to this group, send email to [email protected]. To view this discussion on the web visit

https://groups.google.com/d/msgid/outreachy-kernel/20190330192742.65250-1-himadri18.07%40gmail.com
.

Quoted 2 lines

For more options, visit https://groups.google.com/d/optout.

#10 lore raw

v3 cover staging: rtl8712: use list macros

In reply to Himadri Pandya

This patchset

-  Replaces usage of container_of with list_entry
-  Replaces a while loop with list_for_each
-  Removes an unnecessary NULL check 

V2:
- Include new patches for using list_for_each and removing unnecessary NULL check

V3:
- Include explanations for the changes in log messages

*** BLURB HERE ***

Himadri Pandya (7):
staging: rtl8712: use list_entry in function _r8712_find_network
staging: rtl8712: use list_for_each in function _r8712_find_network
staging: rtl8712: use list_entry in function _free_network_queue
staging: rtl8712: use list_entry in function

    r8712_get_oldest_wlan_network
  staging: rtl8712: use list_entry in function update_scanned_network
  staging: rtl8712: remove unnecessary NULL check
  staging: rtl8712: use list_entry in function
    r8712_select_and_join_from_scan
 drivers/staging/rtl8712/rtl871x_mlme.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
Signature · 1 line
2.17.1
#11 lore raw

PATCH v3 1/7 staging: rtl8712: use list_entry in function _r8712_find_network

Use list_entry instead of container_of for conversion to wlan_network in function _r8712_find_network() because it is a better practice to use list_entry for list manipulations in kerel.

---
Changes in V3:
- Improve log message

---
 drivers/staging/rtl8712/rtl871x_mlme.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8712/rtl871x_mlme.c +1 -1
index c666e038f43e..9bfceaeaa05e 100644
@@ -142,7 +142,7 @@ static struct wlan_network *_r8712_find_network(struct  __queue *scanned_queue,
 	phead = &scanned_queue->queue;
 	plist = phead->next;
 	while (plist != phead) {
-		pnetwork = container_of(plist, struct wlan_network, list);
+		pnetwork = list_entry(plist, struct wlan_network, list);
 		plist = plist->next;
 		if (!memcmp(addr, pnetwork->network.MacAddress, ETH_ALEN))
 			break;
Signature · 1 line
2.17.1
#12 lore raw

Re: [Outreachy kernel] [PATCH v3 1/7] staging: rtl8712: use list_entry in function _r8712_find_network

Quoted 3 lines · Himadri Pandya

Use list_entry instead of container_of for conversion to wlan_network in function _r8712_find_network() because it is a better practice to use list_entry for list manipulations in kerel.

Better practice is random.

The point is that the field has type list_head and in that case list_entry is equivalent to container_of:

#define list_entry(ptr, type, member) \
container_of(ptr, type, member)

julia

Quoted 32 lines

---
Changes in V3:
- Improve log message

---
 drivers/staging/rtl8712/rtl871x_mlme.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8712/rtl871x_mlme.c +1 -2
index c666e038f43e..9bfceaeaa05e 100644
@@ -142,7 +142,7 @@ static struct wlan_network *_r8712_find_network(struct  __queue *scanned_queue,
 	phead = &scanned_queue->queue;
 	plist = phead->next;
 	while (plist != phead) {
-		pnetwork = container_of(plist, struct wlan_network, list);
+		pnetwork = list_entry(plist, struct wlan_network, list);
 		plist = plist->next;
 		if (!memcmp(addr, pnetwork->network.MacAddress, ETH_ALEN))
 			break;
--

2.17.1

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20190331022155.68569-2-himadri18.07%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

#13 lore raw

Re: [Outreachy kernel] [PATCH v3 1/7] staging: rtl8712: use list_entry in function _r8712_find_network

Quoted 10 lines · Julia Lawall,
Quoted 3 lines · Himadri Pandya

Use list_entry instead of container_of for conversion to wlan_network in function _r8712_find_network() because it is a better practice to use list_entry for list manipulations in kerel.

Better practice is random.

Quoted 8 lines

The point is that the field has type list_head and in that case list_entry is equivalent to container_of:

#define list_entry(ptr, type, member) \
container_of(ptr, type, member)

julia

Okay. Including this point in next revision. Thank you.

- Himadri

Quoted 40 lines

Review

Quoted 11 lines

---
Changes in V3:
- Improve log message

---
 drivers/staging/rtl8712/rtl871x_mlme.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
(quoted diff) +0 -0

b/drivers/staging/rtl8712/rtl871x_mlme.c

drivers/staging/rtl8712/rtl871x_mlme.c static struct wlan_network

Quoted 4 lines

index c666e038f43e..9bfceaeaa05e 100644

drivers/staging/rtl8712/rtl871x_mlme.c +0 -0
@@ -142,7 +142,7 @@ static struct wlan_network

*_r8712_find_network(struct __queue *scanned_queue,

Quoted 11 lines
drivers/staging/rtl8712/rtl871x_mlme.c +1 -2
      phead = &scanned_queue->queue;
      plist = phead->next;
      while (plist != phead) {
-             pnetwork = container_of(plist, struct wlan_network, list);
+             pnetwork = list_entry(plist, struct wlan_network, list);
              plist = plist->next;
              if (!memcmp(addr, pnetwork->network.MacAddress, ETH_ALEN))
                      break;
--

2.17.1

Quoted 2 lines

--
You received this message because you are subscribed to the Google

Groups "outreachy-kernel" group.

Quoted 1 line

To unsubscribe from this group and stop receiving emails from it, send

an email to [email protected].

Quoted 2 lines

To post to this group, send email to [email protected]. To view this discussion on the web visit

https://groups.google.com/d/msgid/outreachy-kernel/20190331022155.68569-2-himadri18.07%40gmail.com
.

Quoted 2 lines

For more options, visit https://groups.google.com/d/optout.

#14 lore raw

PATCH v3 2/7 staging: rtl8712: use list_for_each in function _r8712_find_network

In reply to Himadri Pandya

Use list_for_each to iterate over list scanned_queue->queue in function _r8712_find_network() because it is a better practice to use list macros for list manipulations in kerel.

---
Changes in V3:
- Improve log message

---
 drivers/staging/rtl8712/rtl871x_mlme.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/rtl8712/rtl871x_mlme.c +1 -2
index 9bfceaeaa05e..6912d73e8172 100644
@@ -141,9 +141,8 @@ static struct wlan_network *_r8712_find_network(struct  __queue *scanned_queue,
 	spin_lock_irqsave(&scanned_queue->lock, irqL);
 	phead = &scanned_queue->queue;
 	plist = phead->next;
-	while (plist != phead) {
+	list_for_each(plist, phead) {
 		pnetwork = list_entry(plist, struct wlan_network, list);
-		plist = plist->next;
 		if (!memcmp(addr, pnetwork->network.MacAddress, ETH_ALEN))
 			break;
 	}
Signature · 1 line
2.17.1
#15 lore raw

PATCH v3 3/7 staging: rtl8712: use list_entry in function _free_network_queue

In reply to Himadri Pandya

Use list_entry instead of container_of for conversion to wlan_network in function _free_network_queue() because it is a better practice to use list_entry for such list manipulations in kerel.

---
Changes in V3:
- Improve log message

---
 drivers/staging/rtl8712/rtl871x_mlme.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8712/rtl871x_mlme.c +1 -1
index 6912d73e8172..e0b4b8fbcc0e 100644
@@ -162,7 +162,7 @@ static void _free_network_queue(struct _adapter *padapter)
 	phead = &scanned_queue->queue;
 	plist = phead->next;
 	while (!end_of_queue_search(phead, plist)) {
-		pnetwork = container_of(plist, struct wlan_network, list);
+		pnetwork = list_entry(plist, struct wlan_network, list);
 		plist = plist->next;
 		_free_network(pmlmepriv, pnetwork);
 	}
Signature · 1 line
2.17.1
#16 lore raw

PATCH v3 4/7 staging: rtl8712: use list_entry in function r8712_get_oldest_wlan_network

In reply to Himadri Pandya

Use list_entry instead of container_of for conversion to wlan_network in function r8712_get_oldest_wlan_network() because it is a better practice to use list_entry for such list manipulations in kerel.

---
Changes in V3:
- Improve log message

---
 drivers/staging/rtl8712/rtl871x_mlme.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8712/rtl871x_mlme.c +1 -1
index e0b4b8fbcc0e..05bfc2a60eb9 100644
@@ -289,7 +289,7 @@ struct	wlan_network *r8712_get_oldest_wlan_network(
 	while (1) {
 		if (end_of_queue_search(phead, plist) ==  true)
 			break;
-		pwlan = container_of(plist, struct wlan_network, list);
+		pwlan = list_entry(plist, struct wlan_network, list);
 		if (pwlan->fixed != true) {
 			if (oldest == NULL ||
 			    time_after((unsigned long)oldest->last_scanned,
Signature · 1 line
2.17.1
#17 lore raw

PATCH v3 5/7 staging: rtl8712: use list_entry in function update_scanned_network

In reply to Himadri Pandya

Use list_entry instead of container_of for conversion to wlan_network in function update_scanned_network() because it is a better practice to use list_entry for such list manipulations in kerel.

---
Changes in V3:
- Improve log message

---
 drivers/staging/rtl8712/rtl871x_mlme.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8712/rtl871x_mlme.c +1 -1
index 05bfc2a60eb9..1a15c45aa83b 100644
@@ -370,7 +370,7 @@ static void update_scanned_network(struct _adapter *adapter,
 		if (end_of_queue_search(phead, plist))
 			break;
 
-		pnetwork = container_of(plist, struct wlan_network, list);
+		pnetwork = list_entry(plist, struct wlan_network, list);
 		if (is_same_network(&pnetwork->network, target))
 			break;
 		if ((oldest == ((struct wlan_network *)0)) ||
Signature · 1 line
2.17.1
#18 lore raw

PATCH v3 6/7 staging: rtl8712: remove unnecessary NULL check

In reply to Himadri Pandya

Remove unnecessary NULL check for wlan_network *pnetwork because container_of will not return NULL in this usage.

---
 drivers/staging/rtl8712/rtl871x_mlme.c | 2 --
 1 file changed, 2 deletions(-)
drivers/staging/rtl8712/rtl871x_mlme.c +0 -2
index 1a15c45aa83b..be44c6b2819b 100644
@@ -1119,8 +1119,6 @@ int r8712_select_and_join_from_scan(struct mlme_priv *pmlmepriv)
 		}
 		pnetwork = container_of(pmlmepriv->pscanned,
 					struct wlan_network, list);
-		if (pnetwork == NULL)
-			return _FAIL;
 		pmlmepriv->pscanned = pmlmepriv->pscanned->next;
 		if (pmlmepriv->assoc_by_bssid) {
 			dst_ssid = pnetwork->network.MacAddress;
Signature · 1 line
2.17.1
#19 lore raw

Re: [Outreachy kernel] [PATCH v3 6/7] staging: rtl8712: remove unnecessary NULL check

Quoted 2 lines · Himadri Pandya

Remove unnecessary NULL check for wlan_network *pnetwork because container_of will not return NULL in this usage.

Actually, it is possible that it can, because of the obscure reason that the list field is at the top of the structure. You can see if it is possible and useful to make the same check without the container_of call.

julia

Quoted 29 lines
---
 drivers/staging/rtl8712/rtl871x_mlme.c | 2 --
 1 file changed, 2 deletions(-)
drivers/staging/rtl8712/rtl871x_mlme.c +0 -3
index 1a15c45aa83b..be44c6b2819b 100644
@@ -1119,8 +1119,6 @@ int r8712_select_and_join_from_scan(struct mlme_priv *pmlmepriv)
 		}
 		pnetwork = container_of(pmlmepriv->pscanned,
 					struct wlan_network, list);
-		if (pnetwork == NULL)
-			return _FAIL;
 		pmlmepriv->pscanned = pmlmepriv->pscanned->next;
 		if (pmlmepriv->assoc_by_bssid) {
 			dst_ssid = pnetwork->network.MacAddress;
--

2.17.1

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20190331022155.68569-7-himadri18.07%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

#20 lore raw

Re: [Outreachy kernel] [PATCH v3 6/7] staging: rtl8712: remove unnecessary NULL check

Quoted 4 lines · Julia Lawall

On Sun, 31 Mar 2019, Himadri Pandya wrote:

Quoted 9 lines
Quoted 2 lines

Remove unnecessary NULL check for wlan_network *pnetwork because container_of will not return NULL in this usage.

Actually, it is possible that it can, because of the obscure reason that the list field is at the top of the structure. You can see if it is possible and useful to make the same check without the container_of call.

julia

Okay.

I think pmlmepriv->pscanned is used to get the address of mlme_priv 's member struct wlan_network cur_network using container_of(). I can directly check if struct wlan_netowrk's member struct list_head list is allocated memory or not. Because it is the first member and if the memory is allocated, the pointer to it won't be NULL. So instead of using container_of(), I think I should just check if pmlmepriv->cur_network->list is NULL or not.

Please correct me if I am mistaken.

Thank you.

- Himadri

Quoted 49 lines

Review

Quoted 9 lines
---
 drivers/staging/rtl8712/rtl871x_mlme.c | 2 --
 1 file changed, 2 deletions(-)
(quoted diff) +0 -0

b/drivers/staging/rtl8712/rtl871x_mlme.c

drivers/staging/rtl8712/rtl871x_mlme.c int r8712_select_and_join_from_scan(struct

Quoted 4 lines

index 1a15c45aa83b..be44c6b2819b 100644

drivers/staging/rtl8712/rtl871x_mlme.c +0 -0
@@ -1119,8 +1119,6 @@ int r8712_select_and_join_from_scan(struct

mlme_priv *pmlmepriv)

Quoted 11 lines
drivers/staging/rtl8712/rtl871x_mlme.c +0 -3
              }
              pnetwork = container_of(pmlmepriv->pscanned,
                                      struct wlan_network, list);
-             if (pnetwork == NULL)
-                     return _FAIL;
              pmlmepriv->pscanned = pmlmepriv->pscanned->next;
              if (pmlmepriv->assoc_by_bssid) {
                      dst_ssid = pnetwork->network.MacAddress;
--

2.17.1

Quoted 2 lines

--
You received this message because you are subscribed to the Google

Groups "outreachy-kernel" group.

Quoted 1 line

To unsubscribe from this group and stop receiving emails from it, send

an email to [email protected].

Quoted 2 lines

To post to this group, send email to [email protected]. To view this discussion on the web visit

https://groups.google.com/d/msgid/outreachy-kernel/20190331022155.68569-7-himadri18.07%40gmail.com
.

Quoted 2 lines

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected]. To view this discussion on the web visit
https://groups.google.com/d/msgid/outreachy-kernel/alpine.DEB.2.21.1903311013430.2578%40hadrien
.
For more options, visit https://groups.google.com/d/optout.

#21 lore raw

Re: [Outreachy kernel] [PATCH v3 6/7] staging: rtl8712: remove unnecessary NULL check

Quoted 17 lines · Himadri Pandya

On Sun, Mar 31, 2019 at 1:45 PM Julia Lawall <[email protected]> wrote:

On Sun, 31 Mar 2019, Himadri Pandya wrote:

> Remove unnecessary NULL check for wlan_network *pnetwork because > container_of will not return NULL in this usage.

Actually, it is possible that it can, because of the obscure reason that the list field is at the top of the structure.  You can see if it is possible and useful to make the same check without the container_of call.

julia

Quoted 6 lines

Okay.

I think pmlmepriv->pscanned is used to get the address of mlme_priv 's member struct wlan_network cur_network using container_of(). I can directly check if struct wlan_netowrk's member struct list_head list is allocated memory or not. Because it is the first member and if the memory is allocated, the pointer to it won't be NULL. So instead of using container_of(), I think I should just check if pmlmepriv->cur_network->list is NULL or not.

Please correct me if I am mistaken.

I think that you can test the value before the call to container_of.

julia

Quoted 45 lines

Thank you.

- Himadri

      >
      > Signed-off-by: Himadri Pandya <[email protected]>
      > ---
      >  drivers/staging/rtl8712/rtl871x_mlme.c | 2 --
      >  1 file changed, 2 deletions(-)
      >
      > diff --git a/drivers/staging/rtl8712/rtl871x_mlme.c b/drivers/staging/rtl8712/rtl871x_mlme.c
      > index 1a15c45aa83b..be44c6b2819b 100644
      > --- a/drivers/staging/rtl8712/rtl871x_mlme.c
      > +++ b/drivers/staging/rtl8712/rtl871x_mlme.c
      > @@ -1119,8 +1119,6 @@ int r8712_select_and_join_from_scan(struct mlme_priv *pmlmepriv)
      >               }
      >               pnetwork = container_of(pmlmepriv->pscanned,
      >                                       struct wlan_network, list);
      > -             if (pnetwork == NULL)
      > -                     return _FAIL;
      >               pmlmepriv->pscanned = pmlmepriv->pscanned->next;
      >               if (pmlmepriv->assoc_by_bssid) {
      >                       dst_ssid = pnetwork->network.MacAddress;
      > --
      > 2.17.1
      >
      > --
      > You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
      > To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
      > To post to this group, send email to [email protected].
      > To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20190331022155.68569-7-himadri18.07%40gmail.com.
      > For more options, visit https://groups.google.com/d/optout.
      >

      --
      You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
      To post to this group, send email to [email protected].
      To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/alpine.DEB.2.21.1903311013430.2578%40hadrien.
      For more options, visit https://groups.google.com/d/optout.
#22 lore raw

Re: [Outreachy kernel] [PATCH v3 6/7] staging: rtl8712: remove unnecessary NULL check

Quoted 32 lines · Julia Lawall,
Quoted 3 lines · Himadri Pandya

On Sun, Mar 31, 2019 at 1:45 PM Julia Lawall <[email protected]>

Quoted 8 lines · wrote:

On Sun, 31 Mar 2019, Himadri Pandya wrote:

> Remove unnecessary NULL check for wlan_network *pnetwork because > container_of will not return NULL in this usage.

Actually, it is possible that it can, because of the obscure

reason that

Quoted 1 line

the list field is at the top of the structure. You can see if it

is

Quoted 1 line

possible and useful to make the same check without the

container_of call.

Quoted 7 lines

julia

Okay.

I think pmlmepriv->pscanned is used to get the address of mlme_priv 's

member struct wlan_network cur_network using container_of(). I can directly check if struct wlan_netowrk's member struct list_head list is allocated memory or not. Because it is

Quoted 1 line

the first member and if the memory is allocated, the pointer to it won't

Quoted 8 lines

be NULL. So instead of using container_of(), I think I should just check if pmlmepriv->cur_network->list is NULL or not.

Quoted 2 lines

Please correct me if I am mistaken.

I think that you can test the value before the call to container_of.

julia

Yes. I'm dropping this change from this patchset for now. I'll send a separate patch for it after the other patches of this series gets accepted.

Thank you.

- Himadri

Quoted 69 lines
Quoted 6 lines

Thank you.

- Himadri

Quoted 7 lines
      >
      > Signed-off-by: Himadri Pandya <[email protected]>
      > ---
      >  drivers/staging/rtl8712/rtl871x_mlme.c | 2 --
      >  1 file changed, 2 deletions(-)
      >
      > diff --git a/drivers/staging/rtl8712/rtl871x_mlme.c

b/drivers/staging/rtl8712/rtl871x_mlme.c

Quoted 4 lines
      > index 1a15c45aa83b..be44c6b2819b 100644
      > --- a/drivers/staging/rtl8712/rtl871x_mlme.c
      > +++ b/drivers/staging/rtl8712/rtl871x_mlme.c
      > @@ -1119,8 +1119,6 @@ int r8712_select_and_join_from_scan(struct

mlme_priv *pmlmepriv)

Quoted 5 lines
      >               }
      >               pnetwork = container_of(pmlmepriv->pscanned,
      >                                       struct wlan_network, list);
      > -             if (pnetwork == NULL)
      > -                     return _FAIL;
Quoted 8 lines
      >               pmlmepriv->pscanned = pmlmepriv->pscanned->next;
      >               if (pmlmepriv->assoc_by_bssid) {
      >                       dst_ssid = pnetwork->network.MacAddress;
      > --
      > 2.17.1
      >
      > --
      > You received this message because you are subscribed to the

Google Groups "outreachy-kernel" group.

Quoted 1 line

> To unsubscribe from this group and stop receiving emails from

it, send an email to [email protected].

Quoted 1 line

> To post to this group, send email to

[email protected].

Quoted 1 line

> To view this discussion on the web visit

https://groups.google.com/d/msgid/outreachy-kernel/20190331022155.68569-7-himadri18.07%40gmail.com
.

Quoted 5 lines

> For more options, visit https://groups.google.com/d/optout.
>

--
You received this message because you are subscribed to the Google

Groups "outreachy-kernel" group.

Quoted 1 line

To unsubscribe from this group and stop receiving emails from it,

send an email to [email protected].

Quoted 1 line

To post to this group, send email to

[email protected].

Quoted 1 line

To view this discussion on the web visit

https://groups.google.com/d/msgid/outreachy-kernel/alpine.DEB.2.21.1903311013430.2578%40hadrien
.

Quoted 4 lines

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected]. To view this discussion on the web visit
https://groups.google.com/d/msgid/outreachy-kernel/alpine.DEB.2.21.1904012151530.2530%40hadrien
.
For more options, visit https://groups.google.com/d/optout.

#23 lore raw

PATCH v3 7/7 staging: rtl8712: use list_entry in function r8712_select_and_join_from_scan

In reply to Himadri Pandya

Use list_entry instead of container_of for conversion to wlan_network in function r8712_select_and_join_from_scan() because it is a better practice to use list_entry for such list manipulations in kerel.

---
Changes in V3:
- Improve log message

---
 drivers/staging/rtl8712/rtl871x_mlme.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/rtl8712/rtl871x_mlme.c +2 -2
index be44c6b2819b..504c96993adb 100644
@@ -1117,8 +1117,8 @@ int r8712_select_and_join_from_scan(struct mlme_priv *pmlmepriv)
 			}
 			return _FAIL;
 		}
-		pnetwork = container_of(pmlmepriv->pscanned,
-					struct wlan_network, list);
+		pnetwork = list_entry(pmlmepriv->pscanned,
+				      struct wlan_network, list);
 		pmlmepriv->pscanned = pmlmepriv->pscanned->next;
 		if (pmlmepriv->assoc_by_bssid) {
 			dst_ssid = pnetwork->network.MacAddress;
Signature · 1 line
2.17.1
Tested-by on v3 7/7
#24 lore raw

Re: [PATCH v3 7/7] staging: rtl8712: use list_entry in function r8712_select_and_join_from_scan

Quoted 9 lines · Himadri Pandya

Use list_entry instead of container_of for conversion to wlan_network in function r8712_select_and_join_from_scan() because it is a better practice to use list_entry for such list manipulations in kerel.

---
Changes in V3:
- Improve log message

I have tested these patches, and they do not break the driver.

If "container_of()" resolves to "list_entry()" in this case, why is it "better practice" to use the latter. It probably is more clear what is happening, but you need to give your reason.

You also have a typo for kernel in every patch.

Larry

#25 lore raw

Re: [PATCH v3 7/7] staging: rtl8712: use list_entry in function r8712_select_and_join_from_scan

Quoted 13 lines · Larry Finger,
Quoted 9 lines · Himadri Pandya

Use list_entry instead of container_of for conversion to wlan_network in function r8712_select_and_join_from_scan() because it is a better practice to use list_entry for such list manipulations in kerel.

---
Changes in V3:
- Improve log message

I have tested these patches, and they do not break the driver.

Quoted 8 lines

If "container_of()" resolves to "list_entry()" in this case, why is it "better
practice" to use the latter. It probably is more clear what is happening, but
you need to give your reason.

Including more appropriate explanation in next revision.

Quoted 2 lines

You also have a typo for kernel in every patch.

My bad. Fixing them in the next revision.

Thank you.

- Himadri

Quoted 2 lines

Larry

#26 lore raw

v3 cover staging: rtl8712: use list macros

In reply to Himadri Pandya

This patchset

-  Replaces usage of container_of with list_entry
-  Replaces a while loop with list_for_each
-  Removes an unnecessary NULL check 

V2:
- Include new patches for using list_for_each and removing unnecessary NULL check

V3:
- Include explanations for the changes in log messages

Himadri Pandya (7):
staging: rtl8712: use list_entry in function _r8712_find_network
staging: rtl8712: use list_for_each in function _r8712_find_network
staging: rtl8712: use list_entry in function _free_network_queue
staging: rtl8712: use list_entry in function

    r8712_get_oldest_wlan_network
  staging: rtl8712: use list_entry in function update_scanned_network
  staging: rtl8712: remove unnecessary NULL check
  staging: rtl8712: use list_entry in function
    r8712_select_and_join_from_scan
 drivers/staging/rtl8712/rtl871x_mlme.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
Signature · 1 line
2.17.1