Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752375AbcCGIQG (ORCPT ); Mon, 7 Mar 2016 03:16:06 -0500 Received: from down.free-electrons.com ([37.187.137.238]:59679 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752157AbcCGIPz (ORCPT ); Mon, 7 Mar 2016 03:15:55 -0500 From: Gregory CLEMENT To: Marcin Wojtas Cc: "David S. Miller" , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Thomas Petazzoni , Florian Fainelli , Jason Cooper , Andrew Lunn , Sebastian Hesselbarth , "linux-arm-kernel\@lists.infradead.org" , Lior Amsalem , Nadav Haklai , Simon Guinot , Russell King - ARM Linux , Willy Tarreau , Timor Kardashov , Sebastian Careba Subject: Re: [PATCH v4 net-next 8/9] net: add a hardware buffer management helper API References: <1457217507-10778-1-git-send-email-gregory.clement@free-electrons.com> <1457217507-10778-9-git-send-email-gregory.clement@free-electrons.com> Date: Mon, 07 Mar 2016 09:15:53 +0100 In-Reply-To: (Marcin Wojtas's message of "Sun, 6 Mar 2016 20:21:51 +0100") Message-ID: <87pov666va.fsf@free-electrons.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1466 Lines: 53 Hi Marcin, On dim., mars 06 2016, Marcin Wojtas wrote: > Hi Gregory, > > >> +int hwbm_pool_add(struct hwbm_pool *bm_pool, unsigned int buf_num, gfp_t gfp) >> +{ >> + int err, i; >> + unsigned long flags; >> + >> + spin_lock_irqsave(&bm_pool->lock, flags); >> + if (bm_pool->buf_num == bm_pool->size) { > > 'size' field is used as a 'frag_size' but here it means pool capacity. > I think it's better to keep 'size' for pool capacity and add > 'buf_size' field to struct hwbm_pool. I thought I already added this field, but it seems that I didn't so. So I will add it. > >> + pr_warn("pool already filled\n"); >> + return bm_pool->buf_num; >> + } >> + >> + if (buf_num + bm_pool->buf_num > bm_pool->size) { >> + pr_warn("cannot allocate %d buffers for pool\n", >> + buf_num); >> + return 0; >> + } >> + >> + if ((buf_num + bm_pool->buf_num) < bm_pool->buf_num) { > > What is a point of this condition? How possibly after checking if > capacity of pool is not exceeded, this one would ever be true? see http://thread.gmane.org/gmane.linux.kernel/2125152/focus=2137421 this test is here to ensure that (buf_num + bm_pool->buf_nu doesn't wrap. Thanks, Gregory -- Gregory Clement, Free Electrons Kernel, drivers, real-time and embedded Linux development, consulting, training and support. http://free-electrons.com