diff
+ struct bmap_ref {
+ 	void *bmap;
+ 	int ref_count;
+ };

+ static void bmap_put(struct bmap_ref *ref) {
+ 	if (ref && --ref->ref_count == 0) {
+ 		kfree(ref->bmap);
+ 		kfree(ref);
+ 	}
+ }

// Modify the structure definition (not shown in the snippet)
// struct npc_mcam_counters {
//     struct bmap_ref *bmap_ref;
//     // other members...
// };

// In the original function:
- 	kfree(mcam->counters.bmap);
+ 	if (mcam->counters.bmap_ref) {
+ 		bmap_put(mcam->counters.bmap_ref);
+ 		mcam->counters.bmap_ref = NULL;
+ 	}
