On Mon, 29 Apr 2024 10:47:41 -0700, Jakub Kicinski <k...@kernel.org> wrote:
> On Sun, 28 Apr 2024 22:49:09 +0800 Heng Qi wrote:
> > >> +        nla_for_each_nested_type(nest, 
> > >> ETHTOOL_A_PROFILE_IRQ_MODERATION, nests, rem) {
> > >> +                ret = nla_parse_nested(moder,
> > >> +                                       
> > >> ARRAY_SIZE(coalesce_irq_moderation_policy) - 1,
> > >> +                                       nest, 
> > >> coalesce_irq_moderation_policy,
> > >> +                                       extack);
> > >> +                if (ret)
> > >> +                        return ret;
> > >> +
> > >> +                if (!NL_REQ_ATTR_CHECK(extack, nest, moder, 
> > >> ETHTOOL_A_IRQ_MODERATION_USEC)) {
> > >> +                        if (irq_moder->coal_flags & DIM_COALESCE_USEC)  
> > > There are 3 options here, not 2:
> > >
> > >   if (irq_moder->coal_flags & flag) {
> > >           if (NL_REQ_ATTR_CHECK())
> > >                   val = nla_get_u32(...);
> > >           else
> > >                   return -EINVAL;
> > >   } else {
> > >           if (moder[attr_type)) {
> > >                   BAD_ATTR()
> > >                   return -EOPNOTSUPP;
> > >           }
> > >   }  
> > 
> > Maybe we missed something.
> > 
> > As shown in the commit log, the user is allowed to modify only
> > a certain fields in irq-moderation. It is assumed that the driver
> > supports modification of usec and pkts, but the user may only
> > modify usec and only fill in the usec attr.
> > 
> > Therefore, the kernel only gets usec attr here. Of course, the user
> > may have passed in 5 groups of "n, n, n", which means that nothing
> > is modified, and rx_profile and irq_moderation attrs are all empty.
> 
> What you describe sounds good, but it's not what the code seems to be
> doing. NL_REQ_ATTR_CHECK() will set an error attribute if the attr is
> not present.

So here we can use:

+ if (moder[ETHTOOL_A_IRQ_MODERATION_USEC]) {
+       if (irq_moder->coal_flags & DIM_COALESCE_USEC)
+               new_profile[i].usec =
+                       nla_get_u32(moder[ETHTOOL_A_IRQ_MODERATION_USEC]);
+       else
+               return -EOPNOTSUPP;
+ }

instead of:

+ if (!NL_REQ_ATTR_CHECK(extack, nest, moder, ETHTOOL_A_IRQ_MODERATION_USEC)) {
+       if (irq_moder->coal_flags & DIM_COALESCE_USEC)
+               new_profile[i].usec =
+                       nla_get_u32(moder[ETHTOOL_A_IRQ_MODERATION_USEC]);
+       else
+               return -EOPNOTSUPP;
+ }

to avoid missing information set in extack?

Thanks.

Reply via email to