diff mbox series

[net-next] net: dcb: move getapptrust to separate function

Message ID 20221110094623.3395670-1-daniel.machon@microchip.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: dcb: move getapptrust to separate function | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 2 this patch: 2
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 5 this patch: 5
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 2 this patch: 2
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 83 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Daniel Machon Nov. 10, 2022, 9:46 a.m. UTC
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(-)

Comments

Petr Machata Nov. 10, 2022, 4:30 p.m. UTC | #1
Daniel Machon <daniel.machon@microchip.com> writes:

> 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;

(Maybe consider moving these up to the function scope. This scope
business made sense in the generic function, IMHO is not as useful with
a focused function like this one.)

> +
> +		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]);

Doesn't checkpatch warn about this? There should be a blank line after
the variable declaration block. (Even if there wasn't one there in the
original code either.)

> +			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;
> +}
> +
Daniel Machon Nov. 11, 2022, 6:45 a.m. UTC | #2
Den Thu, Nov 10, 2022 at 05:30:43PM +0100 skrev Petr Machata:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> Daniel Machon <daniel.machon@microchip.com> writes:
> 
> > 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;
> 
> (Maybe consider moving these up to the function scope. This scope
> business made sense in the generic function, IMHO is not as useful with
> a focused function like this one.)

I dont mind doing that, however, this 'scope business' is just staying true
to the rest of the dcbnl code :-) - that said, I think I agree with your
point.

> 
> > +
> > +             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]);
> 
> Doesn't checkpatch warn about this? There should be a blank line after
> the variable declaration block. (Even if there wasn't one there in the
> original code either.)

Nope, no warning. And I think it has something to do with the way the line
is split.

> 
> > +                     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;
> > +}
> > +
Petr Machata Nov. 11, 2022, 11:24 a.m. UTC | #3
<Daniel.Machon@microchip.com> writes:

> Den Thu, Nov 10, 2022 at 05:30:43PM +0100 skrev Petr Machata:
>> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
>> 
>> Daniel Machon <daniel.machon@microchip.com> writes:
>> 
>> > 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;
>> 
>> (Maybe consider moving these up to the function scope. This scope
>> business made sense in the generic function, IMHO is not as useful with
>> a focused function like this one.)
>
> I dont mind doing that, however, this 'scope business' is just staying true
> to the rest of the dcbnl code :-) - that said, I think I agree with your
> point.
>
>> 
>> > +
>> > +             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]);
>> 
>> Doesn't checkpatch warn about this? There should be a blank line after
>> the variable declaration block. (Even if there wasn't one there in the
>> original code either.)
>
> Nope, no warning. And I think it has something to do with the way the line
> is split.

OK. I find the code readable just fine, so I'm fine with it as it
stands:

Reviewed-by: Petr Machata <petrm@nvidia.com>
Joe Perches Nov. 11, 2022, 12:47 p.m. UTC | #4
On Fri, 2022-11-11 at 06:45 +0000, Daniel.Machon@microchip.com wrote:
> Den Thu, Nov 10, 2022 at 05:30:43PM +0100 skrev Petr Machata:
> > EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> > 
> > Daniel Machon <daniel.machon@microchip.com> writes:
> > 
> > > 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;
> > 
> > (Maybe consider moving these up to the function scope. This scope
> > business made sense in the generic function, IMHO is not as useful with
> > a focused function like this one.)
> 
> I dont mind doing that, however, this 'scope business' is just staying true
> to the rest of the dcbnl code :-) - that said, I think I agree with your
> point.
> 
> > 
> > > +
> > > +             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]);
> > 
> > Doesn't checkpatch warn about this? There should be a blank line after
> > the variable declaration block. (Even if there wasn't one there in the
> > original code either.)
> 
> Nope, no warning. And I think it has something to do with the way the line
> is split.

yup.

And style trivia:

I suggest adding error types after specific errors,
reversing the test and unindenting the code too. 

Something like:

	err = ops->dcbnl_getapptrust(netdev, selectors, &nselectors);
	if (err) {
		err = 0;
		goto out;
	}

	apptrust = nla_nest_start(skb, DCB_ATTR_DCB_APP_TRUST_TABLE);
	if (!apptrust) {
		err = -EMSGSIZE;
		goto out;
	}

	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 out;
		}
	}
	nla_nest_end(skb, apptrust);

	err = 0;

out:
	kfree(selectors);
	return err;
}
Daniel Machon Nov. 14, 2022, 8:45 a.m. UTC | #5
> > > > +
> > > > +             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]);
> > >
> > > Doesn't checkpatch warn about this? There should be a blank line after
> > > the variable declaration block. (Even if there wasn't one there in the
> > > original code either.)
> >
> > Nope, no warning. And I think it has something to do with the way the line
> > is split.
> 
> yup.
> 
> And style trivia:
> 
> I suggest adding error types after specific errors,
> reversing the test and unindenting the code too.
> 
> Something like:
> 
>         err = ops->dcbnl_getapptrust(netdev, selectors, &nselectors);
>         if (err) {
>                 err = 0;
>                 goto out;
>         }
> 
>         apptrust = nla_nest_start(skb, DCB_ATTR_DCB_APP_TRUST_TABLE);
>         if (!apptrust) {
>                 err = -EMSGSIZE;
>                 goto out;
>         }
> 
>         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 out;
>                 }
>         }
>         nla_nest_end(skb, apptrust);
> 
>         err = 0;
> 
> out:
>         kfree(selectors);
>         return err;
> }
>

LGTM.

The last err = 0 can even be removed, as I see it.
Will submit a new version with the changes suggested.

/ Daniel
diff mbox series

Patch

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 */