Skip to contentSkip to conversation

net: microchip: sparx5: Match keys in configured port keysets

bug report Dan Carpenter 2 participants 2 messages Nov 15, 2022 Kernel janitors

lore
Share & tools
lore
#0 lore raw

Hello Steen Hegelund,

The patch abc4010d1f6e: "net: microchip: sparx5: Match keys in configured port keysets" from Nov 9, 2022, leads to the following Smatch static checker warning:

drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c:598 sparx5_tc_flower_replace()
error: uninitialized symbol 'l3_proto'.

drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c

    532 static int sparx5_tc_flower_replace(struct net_device *ndev,
    533                                     struct flow_cls_offload *fco,
    534                                     struct vcap_admin *admin)
    535 {
    536         struct sparx5_port *port = netdev_priv(ndev);
    537         struct flow_action_entry *act;
    538         struct vcap_control *vctrl;
    539         struct flow_rule *frule;
    540         struct vcap_rule *vrule;
    541         u16 l3_proto;
    542         int err, idx;
    543 
    544         vctrl = port->sparx5->vcap_ctrl;
    545 
    546         err = sparx5_tc_flower_action_check(vctrl, fco, admin);
    547         if (err)
    548                 return err;
    549 
    550         vrule = vcap_alloc_rule(vctrl, ndev, fco->common.chain_index, VCAP_USER_TC,
    551                                 fco->common.prio, 0);
    552         if (IS_ERR(vrule))
    553                 return PTR_ERR(vrule);
    554 
    555         vrule->cookie = fco->cookie;
    556         sparx5_tc_use_dissectors(fco, admin, vrule, &l3_proto);

Should this call to sparx5_tc_use_dissectors() have error checking?

    557         frule = flow_cls_offload_flow_rule(fco);
    558         flow_action_for_each(idx, act, &frule->action) {
    559                 switch (act->id) {
    560                 case FLOW_ACTION_TRAP:
    561                         err = vcap_rule_add_action_bit(vrule,
    562                                                        VCAP_AF_CPU_COPY_ENA,
    563                                                        VCAP_BIT_1);
    564                         if (err)
    565                                 goto out;
    566                         err = vcap_rule_add_action_u32(vrule,
    567                                                        VCAP_AF_CPU_QUEUE_NUM, 0);
    568                         if (err)
    569                                 goto out;
    570                         err = vcap_rule_add_action_u32(vrule, VCAP_AF_MASK_MODE,
    571                                                        SPX5_PMM_REPLACE_ALL);
    572                         if (err)
    573                                 goto out;
    574                         /* For now the actionset is hardcoded */
    575                         err = vcap_set_rule_set_actionset(vrule,
    576                                                           VCAP_AFS_BASE_TYPE);
    577                         if (err)
    578                                 goto out;
    579                         break;
    580                 case FLOW_ACTION_ACCEPT:
    581                         /* For now the actionset is hardcoded */
    582                         err = vcap_set_rule_set_actionset(vrule,
    583                                                           VCAP_AFS_BASE_TYPE);
    584                         if (err)
    585                                 goto out;
    586                         break;
    587                 case FLOW_ACTION_GOTO:
    588                         /* Links between VCAPs will be added later */
    589                         break;
    590                 default:
    591                         NL_SET_ERR_MSG_MOD(fco->common.extack,
    592                                            "Unsupported TC action");
    593                         err = -EOPNOTSUPP;
    594                         goto out;
    595                 }
    596         }
    597         /* provide the l3 protocol to guide the keyset selection */
--> 598         err = vcap_val_rule(vrule, l3_proto);
    599         if (err) {
    600                 vcap_set_tc_exterr(fco, vrule);
    601                 goto out;
    602         }
    603         err = vcap_add_rule(vrule);
    604         if (err)
    605                 NL_SET_ERR_MSG_MOD(fco->common.extack,
    606                                    "Could not add the filter");
    607 out:
    608         vcap_free_rule(vrule);
    609         return err;
    610 }

regards,
dan carpenter

#1 lore raw

Hi Dan,

Quoted 8 lines · Dan Carpenter

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Hello Steen Hegelund,

Quoted 7 lines

The patch abc4010d1f6e: "net: microchip: sparx5: Match keys in configured port keysets" from Nov 9, 2022, leads to the following Smatch static checker warning:

        drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c:598 sparx5_tc_flower_replace()
        error: uninitialized symbol 'l3_proto'.

Yes this should be initialized in case the "basic" dissector is not triggered (which is probably not possible since the TC framework would prevent this).

Quoted 29 lines

drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c
    532 static int sparx5_tc_flower_replace(struct net_device *ndev, 533                                     struct flow_cls_offload *fco, 534                                     struct vcap_admin *admin) 535 {
    536         struct sparx5_port *port = netdev_priv(ndev);
    537         struct flow_action_entry *act;
    538         struct vcap_control *vctrl;
    539         struct flow_rule *frule;
    540         struct vcap_rule *vrule;
    541         u16 l3_proto;
    542         int err, idx;
    543
    544         vctrl = port->sparx5->vcap_ctrl;
    545
    546         err = sparx5_tc_flower_action_check(vctrl, fco, admin); 547         if (err)
    548                 return err;
    549
    550         vrule = vcap_alloc_rule(vctrl, ndev, fco->common.chain_index, VCAP_USER_TC,
    551                                 fco->common.prio, 0);
    552         if (IS_ERR(vrule))
    553                 return PTR_ERR(vrule);
    554
    555         vrule->cookie = fco->cookie;
    556         sparx5_tc_use_dissectors(fco, admin, vrule, &l3_proto);

Quoted 1 line

Should this call to sparx5_tc_use_dissectors() have error checking?

I will add that.

Quoted 62 lines

    557         frule = flow_cls_offload_flow_rule(fco);
    558         flow_action_for_each(idx, act, &frule->action) { 559                 switch (act->id) {
    560                 case FLOW_ACTION_TRAP:
    561                         err = vcap_rule_add_action_bit(vrule, 562
VCAP_AF_CPU_COPY_ENA,
    563                                                        VCAP_BIT_1); 564                         if (err)
    565                                 goto out;
    566                         err = vcap_rule_add_action_u32(vrule, 567
VCAP_AF_CPU_QUEUE_NUM, 0);
    568                         if (err)
    569                                 goto out;
    570                         err = vcap_rule_add_action_u32(vrule, VCAP_AF_MASK_MODE,
    571
SPX5_PMM_REPLACE_ALL);
    572                         if (err)
    573                                 goto out;
    574                         /* For now the actionset is hardcoded */ 575                         err = vcap_set_rule_set_actionset(vrule, 576
VCAP_AFS_BASE_TYPE);
    577                         if (err)
    578                                 goto out;
    579                         break;
    580                 case FLOW_ACTION_ACCEPT:
    581                         /* For now the actionset is hardcoded */ 582                         err = vcap_set_rule_set_actionset(vrule, 583
VCAP_AFS_BASE_TYPE);
    584                         if (err)
    585                                 goto out;
    586                         break;
    587                 case FLOW_ACTION_GOTO:
    588                         /* Links between VCAPs will be added later */ 589                         break;
    590                 default:
    591                         NL_SET_ERR_MSG_MOD(fco->common.extack, 592                                            "Unsupported TC action"); 593                         err = -EOPNOTSUPP;
    594                         goto out;
    595                 }
    596         }
    597         /* provide the l3 protocol to guide the keyset selection */ --> 598         err = vcap_val_rule(vrule, l3_proto);
    599         if (err) {
    600                 vcap_set_tc_exterr(fco, vrule);
    601                 goto out;
    602         }
    603         err = vcap_add_rule(vrule);
    604         if (err)
    605                 NL_SET_ERR_MSG_MOD(fco->common.extack, 606                                    "Could not add the filter"); 607 out:
    608         vcap_free_rule(vrule);
    609         return err;
    610 }

Quoted 2 lines

regards,
dan carpenter

Thanks for the error report.

I will add the fixes for this in my next series.

BR
Steen