Skip to contentSkip to conversation

net: add a hardware buffer management helper API

DISCUSSION Dan Carpenter 2 participants 2 messages Mar 16, 2016 – Mar 18, 2016 Kernel janitors

lore
Share & tools
lore
#0 lore raw

Hello Gregory CLEMENT,

The patch 8cb2d8bf57e6: "net: add a hardware buffer management helper API" from Mar 14, 2016, leads to the following static checker warning:

	net/core/hwbm.c:46 hwbm_pool_refill()
	warn: possible memory leak of 'buf'

net/core/hwbm.c

    26  /* Refill processing for HW buffer management */
    27  int hwbm_pool_refill(struct hwbm_pool *bm_pool, gfp_t gfp)
    28  {
    29          int frag_size = bm_pool->frag_size;
    30          void *buf;
    31  
    32          if (likely(frag_size <= PAGE_SIZE))
    33                  buf = netdev_alloc_frag(frag_size);
    34          else
    35                  buf = kmalloc(frag_size, gfp);
    36  
    37          if (!buf)
    38                  return -ENOMEM;
    39  
    40          if (bm_pool->construct)

If we don't have a ->construct() then we leak memory. This test should probably be moved to the start of the function or deleted.

    41                  if (bm_pool->construct(bm_pool, buf)) {
    42                          hwbm_buf_free(bm_pool, buf);
    43                          return -ENOMEM;
    44                  }
    45  
    46          return 0;
    47  }
    48  EXPORT_SYMBOL_GPL(hwbm_pool_refill);

regards,
dan carpenter

#1 lore raw

Hi Dan,

Quoted 25 lines · Dan Carpenter

Hello Gregory CLEMENT,

The patch 8cb2d8bf57e6: "net: add a hardware buffer management helper API" from Mar 14, 2016, leads to the following static checker warning:

	net/core/hwbm.c:46 hwbm_pool_refill()
	warn: possible memory leak of 'buf'

net/core/hwbm.c

    26  /* Refill processing for HW buffer management */
    27  int hwbm_pool_refill(struct hwbm_pool *bm_pool, gfp_t gfp)
    28  {
    29          int frag_size = bm_pool->frag_size;
    30          void *buf;
    31  
    32          if (likely(frag_size <= PAGE_SIZE))
    33                  buf = netdev_alloc_frag(frag_size);
    34          else
    35                  buf = kmalloc(frag_size, gfp);
    36  
    37          if (!buf)
    38                  return -ENOMEM;
    39  
    40          if (bm_pool->construct)
Quoted 2 lines

If we don't have a ->construct() then we leak memory. This test should probably be moved to the start of the function or deleted.

I will prepare a patch to fix it.

Thanks,

Gregory

Quoted 12 lines
    41                  if (bm_pool->construct(bm_pool, buf)) {
    42                          hwbm_buf_free(bm_pool, buf);
    43                          return -ENOMEM;
    44                  }
    45  
    46          return 0;
    47  }
    48  EXPORT_SYMBOL_GPL(hwbm_pool_refill);

regards,
dan carpenter

Signature · 4 lines
Gregory Clement, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com