* [PATCH net] net: mscc: ocelot: return error if VCAP filter is not found
@ 2020-09-21 23:36 Vladimir Oltean
2020-09-22 0:31 ` David Miller
0 siblings, 1 reply; 4+ messages in thread
From: Vladimir Oltean @ 2020-09-21 23:36 UTC (permalink / raw)
To: davem, netdev
Cc: yangbo.lu, xiaoliang.yang_1, UNGLinuxDriver, claudiu.manoil,
alexandre.belloni, andrew, vivien.didelot, f.fainelli, kuba
From: Xiaoliang Yang <xiaoliang.yang_1@nxp.com>
There are 2 separate, but related, issues.
First, the ocelot_vcap_block_get_filter_index function, née
ocelot_ace_rule_get_index_id prior to the aae4e500e106 ("net: mscc:
ocelot: generalize the "ACE/ACL" names") rename, does not do what the
author probably intended. If the desired filter entry is not present in
the ACL block, this function returns an index equal to the total number
of filters, instead of -1, which is maybe what was intended, judging
from the curious initialization with -1, and the "++index" idioms.
Either way, none of the callers seems to expect this behavior.
Second issue, the callers don't actually check the return value at all.
So in case the filter is not found in the rule list, propagate the
return code to avoid kernel panics.
So update the callers and also take the opportunity to get rid of the
odd coding idioms that appear to work but don't.
Signed-off-by: Xiaoliang Yang <xiaoliang.yang_1@nxp.com>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
drivers/net/ethernet/mscc/ocelot_vcap.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/mscc/ocelot_vcap.c b/drivers/net/ethernet/mscc/ocelot_vcap.c
index 3ef620faf995..39edaaca836e 100644
--- a/drivers/net/ethernet/mscc/ocelot_vcap.c
+++ b/drivers/net/ethernet/mscc/ocelot_vcap.c
@@ -726,14 +726,15 @@ static int ocelot_vcap_block_get_filter_index(struct ocelot_vcap_block *block,
struct ocelot_vcap_filter *filter)
{
struct ocelot_vcap_filter *tmp;
- int index = -1;
+ int index = 0;
list_for_each_entry(tmp, &block->rules, list) {
- ++index;
if (filter->id == tmp->id)
break;
+ index++;
}
- return index;
+
+ return -ENOENT;
}
static struct ocelot_vcap_filter*
@@ -877,6 +878,8 @@ int ocelot_vcap_filter_add(struct ocelot *ocelot,
/* Get the index of the inserted filter */
index = ocelot_vcap_block_get_filter_index(block, filter);
+ if (index < 0)
+ return index;
/* Move down the rules to make place for the new filter */
for (i = block->count - 1; i > index; i--) {
@@ -924,6 +927,8 @@ int ocelot_vcap_filter_del(struct ocelot *ocelot,
/* Gets index of the filter */
index = ocelot_vcap_block_get_filter_index(block, filter);
+ if (index < 0)
+ return index;
/* Delete filter */
ocelot_vcap_block_remove_filter(ocelot, block, filter);
@@ -950,6 +955,9 @@ int ocelot_vcap_filter_stats_update(struct ocelot *ocelot,
int index;
index = ocelot_vcap_block_get_filter_index(block, filter);
+ if (index < 0)
+ return index;
+
is2_entry_get(ocelot, filter, index);
/* After we get the result we need to clear the counters */
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net] net: mscc: ocelot: return error if VCAP filter is not found
2020-09-21 23:36 [PATCH net] net: mscc: ocelot: return error if VCAP filter is not found Vladimir Oltean
@ 2020-09-22 0:31 ` David Miller
2020-09-22 0:39 ` Vladimir Oltean
0 siblings, 1 reply; 4+ messages in thread
From: David Miller @ 2020-09-22 0:31 UTC (permalink / raw)
To: vladimir.oltean
Cc: netdev, yangbo.lu, xiaoliang.yang_1, UNGLinuxDriver,
claudiu.manoil, alexandre.belloni, andrew, vivien.didelot,
f.fainelli, kuba
From: Vladimir Oltean <vladimir.oltean@nxp.com>
Date: Tue, 22 Sep 2020 02:36:37 +0300
> From: Xiaoliang Yang <xiaoliang.yang_1@nxp.com>
>
> There are 2 separate, but related, issues.
>
> First, the ocelot_vcap_block_get_filter_index function, née
> ocelot_ace_rule_get_index_id prior to the aae4e500e106 ("net: mscc:
> ocelot: generalize the "ACE/ACL" names") rename, does not do what the
> author probably intended. If the desired filter entry is not present in
> the ACL block, this function returns an index equal to the total number
> of filters, instead of -1, which is maybe what was intended, judging
> from the curious initialization with -1, and the "++index" idioms.
> Either way, none of the callers seems to expect this behavior.
>
> Second issue, the callers don't actually check the return value at all.
> So in case the filter is not found in the rule list, propagate the
> return code to avoid kernel panics.
>
> So update the callers and also take the opportunity to get rid of the
> odd coding idioms that appear to work but don't.
>
> Signed-off-by: Xiaoliang Yang <xiaoliang.yang_1@nxp.com>
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Please repost this with an appropriate Fixes: tag.
Thank you.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] net: mscc: ocelot: return error if VCAP filter is not found
2020-09-22 0:31 ` David Miller
@ 2020-09-22 0:39 ` Vladimir Oltean
2020-09-22 0:42 ` David Miller
0 siblings, 1 reply; 4+ messages in thread
From: Vladimir Oltean @ 2020-09-22 0:39 UTC (permalink / raw)
To: David Miller
Cc: netdev@vger.kernel.org, Y.b. Lu, Xiaoliang Yang,
UNGLinuxDriver@microchip.com, Claudiu Manoil,
alexandre.belloni@bootlin.com, andrew@lunn.ch,
vivien.didelot@gmail.com, f.fainelli@gmail.com, kuba@kernel.org
On Mon, Sep 21, 2020 at 05:31:02PM -0700, David Miller wrote:
> Please repost this with an appropriate Fixes: tag.
I shouldn't need to do that if you apply the patch using patchwork:
Fixes: b596229448dd ("net: mscc: ocelot: Add support for tcam")
But this tag is more or less decorative, since even the file name has
been renamed in the meantime.
Thanks,
-Vladimir
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] net: mscc: ocelot: return error if VCAP filter is not found
2020-09-22 0:39 ` Vladimir Oltean
@ 2020-09-22 0:42 ` David Miller
0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2020-09-22 0:42 UTC (permalink / raw)
To: vladimir.oltean
Cc: netdev, yangbo.lu, xiaoliang.yang_1, UNGLinuxDriver,
claudiu.manoil, alexandre.belloni, andrew, vivien.didelot,
f.fainelli, kuba
From: Vladimir Oltean <vladimir.oltean@nxp.com>
Date: Tue, 22 Sep 2020 00:39:13 +0000
> On Mon, Sep 21, 2020 at 05:31:02PM -0700, David Miller wrote:
>> Please repost this with an appropriate Fixes: tag.
>
> I shouldn't need to do that if you apply the patch using patchwork:
>
> Fixes: b596229448dd ("net: mscc: ocelot: Add support for tcam")
Patchwork on ozlabs doesn't pick up Fixes: tags automatically.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-09-22 0:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-21 23:36 [PATCH net] net: mscc: ocelot: return error if VCAP filter is not found Vladimir Oltean
2020-09-22 0:31 ` David Miller
2020-09-22 0:39 ` Vladimir Oltean
2020-09-22 0:42 ` David Miller
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).