Re: [PATCH net 5/5] net: ipa: avoid going past end of resource group array

From: Willem de Bruijn
Date: Wed Oct 28 2020 - 19:44:06 EST


> >> + /* We program at most 6 source or destination resource group limits */
> >> + BUILD_BUG_ON(IPA_RESOURCE_GROUP_SRC_MAX > 6);
> >> +
> >> group_count = ipa_resource_group_src_count(ipa->version);
> >> - if (!group_count)
> >> + if (!group_count || group_count >= IPA_RESOURCE_GROUP_SRC_MAX)
> >> return false;
> >
> > Perhaps more a comment to the previous patch, but _MAX usually denotes
> > the end of an inclusive range, here 5. The previous name COUNT better
> > reflects the number of elements in range [0, 5], which is 6.
>
> I agree with your point, but the max here represents something different
> from what you're expecting.
>
> For a given resource type (source or destination) there is some fixed
> number (count) of resources available based on the version of SoC.
> The *driver* can handle any number of them up to the maximum number
> (max) for any SoC it supports. In that respect, it *does* represent
> the largest value in an inclusive range.
>
> I could change the suffix to something like SRC_COUNT_MAX, but in
> general the symbol names are longer than I like in this driver and
> I'm trying to shorten them where possible.

Makes sense. Can you then call this out more explicitly in the commit
message? That MAX here means max count, not max element id.