Re: [PATCH net-next 2/3] net: prestera: add counter HW API
From: Jakub Kicinski
Date: Wed Nov 24 2021 - 22:18:57 EST
On Tue, 23 Nov 2021 18:58:01 +0200 Volodymyr Mytnyk wrote:
> + block = prestera_counter_block_lookup_not_full(counter, client);
> + if (!block) {
if (block)
return block;
> + block = kzalloc(sizeof(*block), GFP_KERNEL);
> + if (!block)
> + return ERR_PTR(-ENOMEM);
> +
> + err = prestera_hw_counter_block_get(counter->sw, client,
> + &block->id, &block->offset,
> + &block->num_counters);
> + if (err)
> + goto err_block;
> +
> + block->stats = kcalloc(block->num_counters,
> + sizeof(*block->stats), GFP_KERNEL);
> + if (!block->stats) {
> + err = -ENOMEM;
> + goto err_stats;
> + }
> +
> + block->counter_flag = kcalloc(block->num_counters,
> + sizeof(*block->counter_flag),
> + GFP_KERNEL);
> + if (!block->counter_flag) {
> + err = -ENOMEM;
> + goto err_flag;
> + }
> +
> + block->client = client;
> + mutex_init(&block->mtx);
> + refcount_set(&block->refcnt, 1);
> + idr_init_base(&block->counter_idr, block->offset);
> +
> + err = prestera_counter_block_list_add(counter, block);
> + if (err)
> + goto err_list_add;
> + }
> +
> + return block;