netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] net: dcb: move getapptrust to separate function
@ 2022-11-10  9:46 Daniel Machon
  2022-11-10 16:30 ` Petr Machata
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Machon @ 2022-11-10  9:46 UTC (permalink / raw)
  To: netdev
  Cc: davem, edumazet, kuba, pabeni, joe, daniel.machon,
	vladimir.oltean, petrm, linux-kernel, UNGLinuxDriver,
	kernel test robot

This patch fixes a frame size warning, reported by kernel test robot.

>> net/dcb/dcbnl.c:1230:1: warning: the frame size of 1244 bytes is
>> larger than 1024 bytes [-Wframe-larger-than=]

The getapptrust part of dcbnl_ieee_fill is moved to a separate function,
and the selector array is now dynamically allocated, instead of stack
allocated.

Tested on microchip sparx5 driver.

Fixes: 6182d5875c33 ("net: dcb: add new apptrust attribute")
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Daniel Machon <daniel.machon@microchip.com>
---
 net/dcb/dcbnl.c | 67 +++++++++++++++++++++++++++++++++----------------
 1 file changed, 45 insertions(+), 22 deletions(-)

diff --git a/net/dcb/dcbnl.c b/net/dcb/dcbnl.c
index cec0632f96db..3f4d88c1ec78 100644
--- a/net/dcb/dcbnl.c
+++ b/net/dcb/dcbnl.c
@@ -1060,11 +1060,52 @@ static int dcbnl_build_peer_app(struct net_device *netdev, struct sk_buff* skb,
 	return err;
 }
 
+static int dcbnl_getapptrust(struct net_device *netdev, struct sk_buff *skb)
+{
+	const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
+	int nselectors, err;
+	u8 *selectors;
+
+	selectors = kzalloc(IEEE_8021QAZ_APP_SEL_MAX + 1, GFP_KERNEL);
+	if (!selectors)
+		return -ENOMEM;
+
+	err = ops->dcbnl_getapptrust(netdev, selectors, &nselectors);
+
+	if (!err) {
+		struct nlattr *apptrust;
+		int i;
+
+		err = -EMSGSIZE;
+
+		apptrust = nla_nest_start(skb, DCB_ATTR_DCB_APP_TRUST_TABLE);
+		if (!apptrust)
+			goto nla_put_failure;
+
+		for (i = 0; i < nselectors; i++) {
+			enum ieee_attrs_app type =
+				dcbnl_app_attr_type_get(selectors[i]);
+			err = nla_put_u8(skb, type, selectors[i]);
+			if (err) {
+				nla_nest_cancel(skb, apptrust);
+				goto nla_put_failure;
+			}
+		}
+		nla_nest_end(skb, apptrust);
+	}
+
+	err = 0;
+
+nla_put_failure:
+	kfree(selectors);
+	return err;
+}
+
 /* Handle IEEE 802.1Qaz/802.1Qau/802.1Qbb GET commands. */
 static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
 {
 	const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
-	struct nlattr *ieee, *app, *apptrust;
+	struct nlattr *ieee, *app;
 	struct dcb_app_type *itr;
 	int dcbx;
 	int err;
@@ -1168,27 +1209,9 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
 	nla_nest_end(skb, app);
 
 	if (ops->dcbnl_getapptrust) {
-		u8 selectors[IEEE_8021QAZ_APP_SEL_MAX + 1] = {0};
-		int nselectors, i;
-
-		apptrust = nla_nest_start(skb, DCB_ATTR_DCB_APP_TRUST_TABLE);
-		if (!apptrust)
-			return -EMSGSIZE;
-
-		err = ops->dcbnl_getapptrust(netdev, selectors, &nselectors);
-		if (!err) {
-			for (i = 0; i < nselectors; i++) {
-				enum ieee_attrs_app type =
-					dcbnl_app_attr_type_get(selectors[i]);
-				err = nla_put_u8(skb, type, selectors[i]);
-				if (err) {
-					nla_nest_cancel(skb, apptrust);
-					return err;
-				}
-			}
-		}
-
-		nla_nest_end(skb, apptrust);
+		err = dcbnl_getapptrust(netdev, skb);
+		if (err)
+			return err;
 	}
 
 	/* get peer info if available */
-- 
2.34.1


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

end of thread, other threads:[~2022-11-14  8:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-10  9:46 [PATCH net-next] net: dcb: move getapptrust to separate function Daniel Machon
2022-11-10 16:30 ` Petr Machata
2022-11-11  6:45   ` Daniel.Machon
2022-11-11 11:24     ` Petr Machata
2022-11-11 12:47     ` Joe Perches
2022-11-14  8:45       ` Daniel.Machon

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).