linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] DCB netlink: Fine-tuning for some function implementations
@ 2017-01-28  9:32 SF Markus Elfring
  2017-01-28  9:33 ` [PATCH 1/4] dcbnl: Use kmalloc_array() in dcbnl_build_peer_app() SF Markus Elfring
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: SF Markus Elfring @ 2017-01-28  9:32 UTC (permalink / raw)
  To: netdev, David S. Miller, Pan Bian; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 28 Jan 2017 10:28:19 +0100

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (4):
  Use kmalloc_array() in dcbnl_build_peer_app()
  Adjust four function calls together with a variable assignment
  Adjust five checks for null pointers
  Add some spaces for better code readability

 net/dcb/dcbnl.c | 36 ++++++++++++++++++++----------------
 1 file changed, 20 insertions(+), 16 deletions(-)

-- 
2.11.0

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

* [PATCH 1/4] dcbnl: Use kmalloc_array() in dcbnl_build_peer_app()
  2017-01-28  9:32 [PATCH 0/4] DCB netlink: Fine-tuning for some function implementations SF Markus Elfring
@ 2017-01-28  9:33 ` SF Markus Elfring
  2017-01-28  9:34 ` [PATCH 2/4] dcbnl: Adjust four function calls together with a variable assignment SF Markus Elfring
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: SF Markus Elfring @ 2017-01-28  9:33 UTC (permalink / raw)
  To: netdev, David S. Miller, Pan Bian; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 27 Jan 2017 22:30:09 +0100

* A multiplication for the size determination of a memory allocation
  indicated that an array data structure should be processed.
  Thus use the corresponding function "kmalloc_array".

  This issue was detected by using the Coccinelle software.

* Replace the specification of a data structure by a pointer dereference
  to make the corresponding size determination a bit safer according to
  the Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 net/dcb/dcbnl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/dcb/dcbnl.c b/net/dcb/dcbnl.c
index 3202d75329b5..76fd727e2eb4 100644
--- a/net/dcb/dcbnl.c
+++ b/net/dcb/dcbnl.c
@@ -990,7 +990,7 @@ static int dcbnl_build_peer_app(struct net_device *netdev, struct sk_buff* skb,
 	 */
 	err = ops->peer_getappinfo(netdev, &info, &app_count);
 	if (!err && app_count) {
-		table = kmalloc(sizeof(struct dcb_app) * app_count, GFP_KERNEL);
+		table = kmalloc_array(app_count, sizeof(*table), GFP_KERNEL);
 		if (!table)
 			return -ENOMEM;
 
-- 
2.11.0

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

* [PATCH 2/4] dcbnl: Adjust four function calls together with a variable assignment
  2017-01-28  9:32 [PATCH 0/4] DCB netlink: Fine-tuning for some function implementations SF Markus Elfring
  2017-01-28  9:33 ` [PATCH 1/4] dcbnl: Use kmalloc_array() in dcbnl_build_peer_app() SF Markus Elfring
@ 2017-01-28  9:34 ` SF Markus Elfring
  2017-01-28  9:36 ` [PATCH 3/4] dcbnl: Adjust five checks for null pointers SF Markus Elfring
  2017-01-28  9:37 ` [PATCH 4/4] dcbnl: Add some spaces for better code readability SF Markus Elfring
  3 siblings, 0 replies; 5+ messages in thread
From: SF Markus Elfring @ 2017-01-28  9:34 UTC (permalink / raw)
  To: netdev, David S. Miller, Pan Bian; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 28 Jan 2017 09:19:58 +0100

The script "checkpatch.pl" pointed information out like the following.

ERROR: do not use assignment in if condition

Thus fix the affected source code places.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 net/dcb/dcbnl.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/net/dcb/dcbnl.c b/net/dcb/dcbnl.c
index 76fd727e2eb4..f29e19d962ec 100644
--- a/net/dcb/dcbnl.c
+++ b/net/dcb/dcbnl.c
@@ -1799,7 +1799,8 @@ u8 dcb_getapp(struct net_device *dev, struct dcb_app *app)
 	u8 prio = 0;
 
 	spin_lock_bh(&dcb_lock);
-	if ((itr = dcb_app_lookup(app, dev->ifindex, 0)))
+	itr = dcb_app_lookup(app, dev->ifindex, 0);
+	if (itr)
 		prio = itr->app.priority;
 	spin_unlock_bh(&dcb_lock);
 
@@ -1827,7 +1828,8 @@ int dcb_setapp(struct net_device *dev, struct dcb_app *new)
 
 	spin_lock_bh(&dcb_lock);
 	/* Search for existing match and replace */
-	if ((itr = dcb_app_lookup(new, dev->ifindex, 0))) {
+	itr = dcb_app_lookup(new, dev->ifindex, 0);
+	if (itr) {
 		if (new->priority)
 			itr->app.priority = new->priority;
 		else {
@@ -1860,7 +1862,8 @@ u8 dcb_ieee_getapp_mask(struct net_device *dev, struct dcb_app *app)
 	u8 prio = 0;
 
 	spin_lock_bh(&dcb_lock);
-	if ((itr = dcb_app_lookup(app, dev->ifindex, 0)))
+	itr = dcb_app_lookup(app, dev->ifindex, 0);
+	if (itr)
 		prio |= 1 << itr->app.priority;
 	spin_unlock_bh(&dcb_lock);
 
@@ -1920,7 +1923,8 @@ int dcb_ieee_delapp(struct net_device *dev, struct dcb_app *del)
 
 	spin_lock_bh(&dcb_lock);
 	/* Search for existing match and remove it. */
-	if ((itr = dcb_app_lookup(del, dev->ifindex, del->priority))) {
+	itr = dcb_app_lookup(del, dev->ifindex, del->priority);
+	if (itr) {
 		list_del(&itr->list);
 		kfree(itr);
 		err = 0;
-- 
2.11.0

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

* [PATCH 3/4] dcbnl: Adjust five checks for null pointers
  2017-01-28  9:32 [PATCH 0/4] DCB netlink: Fine-tuning for some function implementations SF Markus Elfring
  2017-01-28  9:33 ` [PATCH 1/4] dcbnl: Use kmalloc_array() in dcbnl_build_peer_app() SF Markus Elfring
  2017-01-28  9:34 ` [PATCH 2/4] dcbnl: Adjust four function calls together with a variable assignment SF Markus Elfring
@ 2017-01-28  9:36 ` SF Markus Elfring
  2017-01-28  9:37 ` [PATCH 4/4] dcbnl: Add some spaces for better code readability SF Markus Elfring
  3 siblings, 0 replies; 5+ messages in thread
From: SF Markus Elfring @ 2017-01-28  9:36 UTC (permalink / raw)
  To: netdev, David S. Miller, Pan Bian; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 28 Jan 2017 09:56:36 +0100
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The script "checkpatch.pl" pointed information out like the following.

Comparison to NULL could be written !…

Thus fix the affected source code places.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 net/dcb/dcbnl.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/net/dcb/dcbnl.c b/net/dcb/dcbnl.c
index f29e19d962ec..0903081a1212 100644
--- a/net/dcb/dcbnl.c
+++ b/net/dcb/dcbnl.c
@@ -398,7 +398,7 @@ static int dcbnl_setnumtcs(struct net_device *netdev, struct nlmsghdr *nlh,
 		return ret;
 
 	for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) {
-		if (data[i] == NULL)
+		if (!data[i])
 			continue;
 
 		value = nla_get_u8(data[i]);
@@ -741,7 +741,7 @@ static int dcbnl_setpfccfg(struct net_device *netdev, struct nlmsghdr *nlh,
 		return ret;
 
 	for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
-		if (data[i] == NULL)
+		if (!data[i])
 			continue;
 		value = nla_get_u8(data[i]);
 		netdev->dcbnl_ops->setpfccfg(netdev,
@@ -955,7 +955,7 @@ static int dcbnl_bcn_setcfg(struct net_device *netdev, struct nlmsghdr *nlh,
 		return ret;
 
 	for (i = DCB_BCN_ATTR_RP_0; i <= DCB_BCN_ATTR_RP_7; i++) {
-		if (data[i] == NULL)
+		if (!data[i])
 			continue;
 		value_byte = nla_get_u8(data[i]);
 		netdev->dcbnl_ops->setbcnrp(netdev,
@@ -963,7 +963,7 @@ static int dcbnl_bcn_setcfg(struct net_device *netdev, struct nlmsghdr *nlh,
 	}
 
 	for (i = DCB_BCN_ATTR_BCNA_0; i <= DCB_BCN_ATTR_RI; i++) {
-		if (data[i] == NULL)
+		if (!data[i])
 			continue;
 		value_int = nla_get_u32(data[i]);
 		netdev->dcbnl_ops->setbcncfg(netdev,
@@ -1632,7 +1632,7 @@ static int dcbnl_setfeatcfg(struct net_device *netdev, struct nlmsghdr *nlh,
 		goto err;
 
 	for (i = DCB_FEATCFG_ATTR_ALL+1; i <= DCB_FEATCFG_ATTR_MAX; i++) {
-		if (data[i] == NULL)
+		if (!data[i])
 			continue;
 
 		value = nla_get_u8(data[i]);
-- 
2.11.0

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

* [PATCH 4/4] dcbnl: Add some spaces for better code readability
  2017-01-28  9:32 [PATCH 0/4] DCB netlink: Fine-tuning for some function implementations SF Markus Elfring
                   ` (2 preceding siblings ...)
  2017-01-28  9:36 ` [PATCH 3/4] dcbnl: Adjust five checks for null pointers SF Markus Elfring
@ 2017-01-28  9:37 ` SF Markus Elfring
  3 siblings, 0 replies; 5+ messages in thread
From: SF Markus Elfring @ 2017-01-28  9:37 UTC (permalink / raw)
  To: netdev, David S. Miller, Pan Bian; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 28 Jan 2017 10:15:59 +0100

Use space characters at some source code places according to
the Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 net/dcb/dcbnl.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/net/dcb/dcbnl.c b/net/dcb/dcbnl.c
index 0903081a1212..0150de92c8ba 100644
--- a/net/dcb/dcbnl.c
+++ b/net/dcb/dcbnl.c
@@ -315,7 +315,7 @@ static int dcbnl_getcap(struct net_device *netdev, struct nlmsghdr *nlh,
 	if (data[DCB_CAP_ATTR_ALL])
 		getall = 1;
 
-	for (i = DCB_CAP_ATTR_ALL+1; i <= DCB_CAP_ATTR_MAX; i++) {
+	for (i = DCB_CAP_ATTR_ALL + 1; i <= DCB_CAP_ATTR_MAX; i++) {
 		if (!getall && !data[i])
 			continue;
 
@@ -359,7 +359,7 @@ static int dcbnl_getnumtcs(struct net_device *netdev, struct nlmsghdr *nlh,
 	if (data[DCB_NUMTCS_ATTR_ALL])
 		getall = 1;
 
-	for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) {
+	for (i = DCB_NUMTCS_ATTR_ALL + 1; i <= DCB_NUMTCS_ATTR_MAX; i++) {
 		if (!getall && !data[i])
 			continue;
 
@@ -397,7 +397,7 @@ static int dcbnl_setnumtcs(struct net_device *netdev, struct nlmsghdr *nlh,
 	if (ret)
 		return ret;
 
-	for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) {
+	for (i = DCB_NUMTCS_ATTR_ALL + 1; i <= DCB_NUMTCS_ATTR_MAX; i++) {
 		if (!data[i])
 			continue;
 
@@ -1593,7 +1593,7 @@ static int dcbnl_getfeatcfg(struct net_device *netdev, struct nlmsghdr *nlh,
 	if (data[DCB_FEATCFG_ATTR_ALL])
 		getall = 1;
 
-	for (i = DCB_FEATCFG_ATTR_ALL+1; i <= DCB_FEATCFG_ATTR_MAX; i++) {
+	for (i = DCB_FEATCFG_ATTR_ALL + 1; i <= DCB_FEATCFG_ATTR_MAX; i++) {
 		if (!getall && !data[i])
 			continue;
 
@@ -1631,7 +1631,7 @@ static int dcbnl_setfeatcfg(struct net_device *netdev, struct nlmsghdr *nlh,
 	if (ret)
 		goto err;
 
-	for (i = DCB_FEATCFG_ATTR_ALL+1; i <= DCB_FEATCFG_ATTR_MAX; i++) {
+	for (i = DCB_FEATCFG_ATTR_ALL + 1; i <= DCB_FEATCFG_ATTR_MAX; i++) {
 		if (!data[i])
 			continue;
 
@@ -1669,7 +1669,7 @@ struct reply_func {
 		    struct nlattr **, struct sk_buff *);
 };
 
-static const struct reply_func reply_funcs[DCB_CMD_MAX+1] = {
+static const struct reply_func reply_funcs[DCB_CMD_MAX + 1] = {
 	[DCB_CMD_GSTATE]	= { RTM_GETDCB, dcbnl_getstate },
 	[DCB_CMD_SSTATE]	= { RTM_SETDCB, dcbnl_setstate },
 	[DCB_CMD_PFC_GCFG]	= { RTM_GETDCB, dcbnl_getpfccfg },
-- 
2.11.0

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

end of thread, other threads:[~2017-01-28  9:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-28  9:32 [PATCH 0/4] DCB netlink: Fine-tuning for some function implementations SF Markus Elfring
2017-01-28  9:33 ` [PATCH 1/4] dcbnl: Use kmalloc_array() in dcbnl_build_peer_app() SF Markus Elfring
2017-01-28  9:34 ` [PATCH 2/4] dcbnl: Adjust four function calls together with a variable assignment SF Markus Elfring
2017-01-28  9:36 ` [PATCH 3/4] dcbnl: Adjust five checks for null pointers SF Markus Elfring
2017-01-28  9:37 ` [PATCH 4/4] dcbnl: Add some spaces for better code readability SF Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).