public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@linaro.org>
To: Steen Hegelund <steen.hegelund@microchip.com>
Cc: kernel-janitors@vger.kernel.org
Subject: [bug report] net: microchip: sparx5: Add KUNIT test of counters and sorted rules
Date: Thu, 7 Aug 2025 19:00:18 +0300	[thread overview]
Message-ID: <aJTNklKQ-yuxW0ck@stanley.mountain> (raw)

Hello Steen Hegelund,

Commit dccc30cc4906 ("net: microchip: sparx5: Add KUNIT test of
counters and sorted rules") from Nov 11, 2022 (linux-next), leads to
the following Smatch static checker warning:

drivers/net/ethernet/microchip/vcap/vcap_api_kunit.c:305 test_vcap_xn_rule_creator() error: 'rule' dereferencing possible ERR_PTR()
drivers/net/ethernet/microchip/vcap/vcap_api_kunit.c:1422 vcap_api_encode_rule_test() error: 'rule' dereferencing possible ERR_PTR()

drivers/net/ethernet/microchip/vcap/vcap_api_kunit.c
    246 static void test_vcap_xn_rule_creator(struct kunit *test, int cid,
    247                                       enum vcap_user user, u16 priority,
    248                                       int id, int size, int expected_addr)
    249 {
    250         struct vcap_rule *rule;
    251         struct vcap_rule_internal *ri;
    252         enum vcap_keyfield_set keyset = VCAP_KFS_NO_VALUE;
    253         enum vcap_actionfield_set actionset = VCAP_AFS_NO_VALUE;
    254         int ret;
    255 
    256         /* init before testing */
    257         memset(test_updateaddr, 0, sizeof(test_updateaddr));
    258         test_updateaddridx = 0;
    259         test_move_addr = 0;
    260         test_move_offset = 0;
    261         test_move_count = 0;
    262 
    263         switch (size) {
    264         case 2:
    265                 keyset = VCAP_KFS_ETAG;
    266                 actionset = VCAP_AFS_CLASS_REDUCED;
    267                 break;
    268         case 3:
    269                 keyset = VCAP_KFS_PURE_5TUPLE_IP4;
    270                 actionset = VCAP_AFS_CLASSIFICATION;
    271                 break;
    272         case 6:
    273                 keyset = VCAP_KFS_NORMAL_5TUPLE_IP4;
    274                 actionset = VCAP_AFS_CLASSIFICATION;
    275                 break;
    276         case 12:
    277                 keyset = VCAP_KFS_NORMAL_7TUPLE;
    278                 actionset = VCAP_AFS_FULL;
    279                 break;
    280         default:
    281                 break;
    282         }
    283 
    284         /* Check that a valid size was used */
    285         KUNIT_ASSERT_NE(test, VCAP_KFS_NO_VALUE, keyset);
    286 
    287         /* Allocate the rule */
    288         rule = vcap_alloc_rule(&test_vctrl, &test_netdev, cid, user, priority,
    289                                id);
    290         KUNIT_EXPECT_PTR_NE(test, NULL, rule);
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
vcap_alloc_rule() doesn't return NULL, it returns error pointers.

    291 
    292         ri = (struct vcap_rule_internal *)rule;
    293 
    294         /* Override rule keyset */
    295         ret = vcap_set_rule_set_keyset(rule, keyset);
    296 
    297         /* Add rule actions : there must be at least one action */
    298         ret = vcap_rule_add_action_u32(rule, VCAP_AF_ISDX_VAL, 0);
    299 
    300         /* Override rule actionset */
    301         ret = vcap_set_rule_set_actionset(rule, actionset);
    302 
    303         ret = vcap_val_rule(rule, ETH_P_ALL);
    304         KUNIT_EXPECT_EQ(test, 0, ret);
--> 305         KUNIT_EXPECT_EQ(test, keyset, rule->keyset);
    306         KUNIT_EXPECT_EQ(test, actionset, rule->actionset);
    307         KUNIT_EXPECT_EQ(test, size, ri->size);
    308 
    309         /* Add rule with write callback */
    310         ret = vcap_add_rule(rule);
    311         KUNIT_EXPECT_EQ(test, 0, ret);
    312         KUNIT_EXPECT_EQ(test, expected_addr, ri->addr);
    313         vcap_free_rule(rule);
    314 }

regards,
dan carpenter

                 reply	other threads:[~2025-08-07 16:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aJTNklKQ-yuxW0ck@stanley.mountain \
    --to=dan.carpenter@linaro.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=steen.hegelund@microchip.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox