ozeltbuf.o \
ozproto.o \
ozcdev.o \
- ozalloc.o \
ozurbparanoia.o \
oztrace.o \
ozevent.o
+++ /dev/null
-/* -----------------------------------------------------------------------------
- * Copyright (c) 2011 Ozmo Inc
- * Released under the GNU General Public License Version 2 (GPLv2).
- * This file contains debug allocation and free functions. These are turned on
- * by the configuration switch WANT_DEBUG_KMALLOC. This flags should be turned
- * off in the release version but facilitate memory leak and corruption during
- * development.
- * -----------------------------------------------------------------------------
- */
-#include <linux/module.h>
-#include "ozconfig.h"
-#include "ozalloc.h"
-#include "oztrace.h"
-#ifdef WANT_DEBUG_KMALLOC
-/*------------------------------------------------------------------------------
- */
-#define MAGIC_1 0x12848796
-#define MAGIC_2 0x87465920
-#define MAGIC_3 0x80288264
-/*------------------------------------------------------------------------------
- */
-struct oz_alloc_hdr {
- int size;
- int line;
- unsigned magic;
- struct list_head link;
-};
-/*------------------------------------------------------------------------------
- */
-static unsigned long g_total_alloc_size;
-static int g_alloc_count;
-static DEFINE_SPINLOCK(g_alloc_lock);
-static LIST_HEAD(g_alloc_list);
-/*------------------------------------------------------------------------------
- * Context: any
- */
-void *oz_alloc_debug(size_t size, gfp_t flags, int line)
-{
- struct oz_alloc_hdr *hdr = (struct oz_alloc_hdr *)
- kmalloc(size + sizeof(struct oz_alloc_hdr) +
- sizeof(unsigned), flags);
- if (hdr) {
- unsigned long irq_state;
- hdr->size = size;
- hdr->line = line;
- hdr->magic = MAGIC_1;
- *(unsigned *)(((u8 *)(hdr + 1)) + size) = MAGIC_2;
- spin_lock_irqsave(&g_alloc_lock, irq_state);
- g_total_alloc_size += size;
- g_alloc_count++;
- list_add_tail(&hdr->link, &g_alloc_list);
- spin_unlock_irqrestore(&g_alloc_lock, irq_state);
- return hdr + 1;
- }
- return 0;
-}
-/*------------------------------------------------------------------------------
- * Context: any
- */
-void oz_free_debug(void *p)
-{
- if (p) {
- struct oz_alloc_hdr *hdr = (struct oz_alloc_hdr *)
- (((unsigned char *)p) - sizeof(struct oz_alloc_hdr));
- if (hdr->magic == MAGIC_1) {
- unsigned long irq_state;
- if (*(unsigned *)(((u8 *)(hdr + 1)) + hdr->size)
- != MAGIC_2) {
- oz_trace("oz_free_debug: Corrupted beyond"
- " %p size %d\n", hdr+1, hdr->size);
- return;
- }
- spin_lock_irqsave(&g_alloc_lock, irq_state);
- g_total_alloc_size -= hdr->size;
- g_alloc_count--;
- list_del(&hdr->link);
- spin_unlock_irqrestore(&g_alloc_lock, irq_state);
- hdr->magic = MAGIC_3;
- kfree(hdr);
- } else {
- oz_trace("oz_free_debug: Invalid magic number %u\n",
- hdr->magic);
- }
- }
-}
-/*------------------------------------------------------------------------------
- * Context: process
- */
-void oz_trace_leaks(void)
-{
-#ifdef WANT_TRACE
- struct list_head *e;
- oz_trace("Total alloc size:%ld Alloc count:%d\n",
- g_total_alloc_size, g_alloc_count);
- if (g_alloc_count)
- oz_trace("Trace of leaks.\n");
- else
- oz_trace("No memory leaks.\n");
- list_for_each(e, &g_alloc_list) {
- struct oz_alloc_hdr *hdr =
- container_of(e, struct oz_alloc_hdr, link);
- oz_trace("LEAK size %d line %d\n", hdr->size, hdr->line);
- }
-#endif /* #ifdef WANT_TRACE */
-}
-#endif /* #ifdef WANT_DEBUG_KMALLOC */
-
+++ /dev/null
-/* -----------------------------------------------------------------------------
- * Copyright (c) 2011 Ozmo Inc
- * Released under the GNU General Public License Version 2 (GPLv2).
- * -----------------------------------------------------------------------------
- */
-#ifndef _OZALLOC_H
-#define _OZALLOC_H
-
-#include <linux/slab.h>
-
-#ifdef WANT_DEBUG_KMALLOC
-
-void *oz_alloc_debug(size_t size, gfp_t flags, int line);
-void oz_free_debug(void *p);
-void oz_trace_leaks(void);
-#define oz_alloc(__s, __f) oz_alloc_debug(__s, __f, __LINE__)
-#define oz_free oz_free_debug
-
-#else
-
-
-#define oz_alloc kmalloc
-#define oz_free kfree
-#define oz_trace_leaks()
-
-#endif /* #ifdef WANT_DEBUG_KMALLOC */
-
-#endif /* _OZALLOC_H */
#include "ozeltbuf.h"
#include "ozpd.h"
#include "ozproto.h"
-#include "ozalloc.h"
#include "ozevent.h"
/*------------------------------------------------------------------------------
*/
{
if (atomic_dec_and_test(&ctx->ref_count)) {
oz_trace("Dealloc serial context.\n");
- oz_free(ctx);
+ kfree(ctx);
}
}
/*------------------------------------------------------------------------------
oz_trace("Serial service resumed.\n");
return 0;
}
- ctx = (struct oz_serial_ctx *)
- oz_alloc(sizeof(struct oz_serial_ctx), GFP_ATOMIC);
+ ctx = kzalloc(sizeof(struct oz_serial_ctx), GFP_ATOMIC);
if (ctx == 0)
- return -1;
- memset(ctx, 0, sizeof(struct oz_serial_ctx));
+ return -ENOMEM;
atomic_set(&ctx->ref_count, 1);
ctx->tx_seq_num = 1;
spin_lock_bh(&pd->app_lock[OZ_APPID_SERIAL-1]);
old_ctx = pd->app_ctx[OZ_APPID_SERIAL-1];
if (old_ctx) {
spin_unlock_bh(&pd->app_lock[OZ_APPID_SERIAL-1]);
- oz_free(ctx);
+ kfree(ctx);
} else {
pd->app_ctx[OZ_APPID_SERIAL-1] = ctx;
spin_unlock_bh(&pd->app_lock[OZ_APPID_SERIAL-1]);
#ifndef _OZCONFIG_H
#define _OZCONFIG_H
-/* #define WANT_DEBUG_KMALLOC */
/* #define WANT_TRACE */
#ifdef WANT_TRACE
#define WANT_VERBOSE_TRACE
#include "ozeltbuf.h"
#include "ozpd.h"
#include "oztrace.h"
-#include "ozalloc.h"
/*------------------------------------------------------------------------------
*/
#define OZ_ELT_INFO_MAGIC_USED 0x35791057
struct oz_elt_info *ei =
container_of(e, struct oz_elt_info, link_order);
e = e->next;
- oz_free(ei);
+ kfree(ei);
}
}
/* Free any elelment in the pool. */
struct oz_elt_info *ei =
container_of(buf->elt_pool, struct oz_elt_info, link);
buf->elt_pool = buf->elt_pool->next;
- oz_free(ei);
+ kfree(ei);
}
buf->free_elts = 0;
}
}
} else {
spin_unlock_bh(&buf->lock);
- ei = oz_alloc(sizeof(struct oz_elt_info), GFP_ATOMIC);
+ ei = kmalloc(sizeof(struct oz_elt_info), GFP_ATOMIC);
}
if (ei) {
ei->flags = 0;
*/
int oz_elt_stream_create(struct oz_elt_buf *buf, u8 id, int max_buf_count)
{
- struct oz_elt_stream *st =
- oz_alloc(sizeof(struct oz_elt_stream), GFP_ATOMIC | __GFP_ZERO);
+ struct oz_elt_stream *st;
+
oz_trace("oz_elt_stream_create(0x%x)\n", id);
+
+ st = kzalloc(sizeof(struct oz_elt_stream), GFP_ATOMIC | __GFP_ZERO);
if (st == 0)
- return -1;
- memset(st, 0, sizeof(struct oz_elt_stream));
+ return -ENOMEM;
atomic_set(&st->ref_count, 1);
st->id = id;
st->max_buf_count = max_buf_count;
{
if (atomic_dec_and_test(&st->ref_count)) {
oz_trace("Stream destroyed\n");
- oz_free(st);
+ kfree(st);
}
}
/*------------------------------------------------------------------------------
struct oz_elt_info *ei =
container_of(free, struct oz_elt_info, link);
free = free->next;
- oz_free(ei);
+ kfree(ei);
}
}
#include "ozconfig.h"
#include "ozusbif.h"
#include "oztrace.h"
-#include "ozalloc.h"
#include "ozurbparanoia.h"
#include "ozevent.h"
/*------------------------------------------------------------------------------
}
spin_unlock_irqrestore(&g_link_lock, irq_state);
if (urbl == 0)
- urbl = oz_alloc(sizeof(struct oz_urb_link), GFP_ATOMIC);
+ urbl = kmalloc(sizeof(struct oz_urb_link), GFP_ATOMIC);
return urbl;
}
/*------------------------------------------------------------------------------
}
spin_unlock_irqrestore(&g_link_lock, irq_state);
if (urbl)
- oz_free(urbl);
+ kfree(urbl);
}
}
/*------------------------------------------------------------------------------
struct oz_urb_link *urbl =
container_of(e, struct oz_urb_link, link);
e = e->next;
- oz_free(urbl);
+ kfree(urbl);
}
}
/*------------------------------------------------------------------------------
static struct oz_endpoint *oz_ep_alloc(gfp_t mem_flags, int buffer_size)
{
struct oz_endpoint *ep =
- oz_alloc(sizeof(struct oz_endpoint)+buffer_size, mem_flags);
+ kzalloc(sizeof(struct oz_endpoint)+buffer_size, mem_flags);
if (ep) {
- memset(ep, 0, sizeof(*ep));
INIT_LIST_HEAD(&ep->urb_list);
INIT_LIST_HEAD(&ep->link);
ep->credit = -1;
spin_unlock_bh(&ozhcd->hcd_lock);
}
oz_trace("Freeing endpoint memory\n");
- oz_free(ep);
+ kfree(ep);
}
/*------------------------------------------------------------------------------
* Context: softirq
int i;
int num_iface = config->desc.bNumInterfaces;
if (num_iface) {
- struct oz_interface *iface = (struct oz_interface *)
- oz_alloc(num_iface*sizeof(struct oz_interface),
+ struct oz_interface *iface;
+
+ iface = kmalloc(num_iface*sizeof(struct oz_interface),
mem_flags | __GFP_ZERO);
if (!iface)
return -ENOMEM;
spin_lock_bh(&ozhcd->hcd_lock);
if (port->iface) {
oz_trace("Freeing interfaces object.\n");
- oz_free(port->iface);
+ kfree(port->iface);
port->iface = 0;
}
port->num_iface = 0;
#include "ozpd.h"
#include "ozproto.h"
#include "ozcdev.h"
-#include "ozalloc.h"
#include "oztrace.h"
#include "ozevent.h"
/*------------------------------------------------------------------------------
oz_protocol_term();
oz_apps_term();
oz_cdev_deregister();
- oz_trace_leaks();
oz_event_term();
}
/*------------------------------------------------------------------------------
#include "ozpd.h"
#include "ozproto.h"
#include "oztrace.h"
-#include "ozalloc.h"
#include "ozevent.h"
#include "ozcdev.h"
#include "ozusbsvc.h"
*/
struct oz_pd *oz_pd_alloc(u8 *mac_addr)
{
- struct oz_pd *pd = oz_alloc(sizeof(struct oz_pd), GFP_ATOMIC);
+ struct oz_pd *pd = kzalloc(sizeof(struct oz_pd), GFP_ATOMIC);
if (pd) {
int i;
- memset(pd, 0, sizeof(struct oz_pd));
atomic_set(&pd->ref_count, 2);
for (i = 0; i < OZ_APPID_MAX; i++)
spin_lock_init(&pd->app_lock[i]);
pd->max_tx_size = OZ_MAX_TX_SIZE;
memcpy(pd->mac_addr, mac_addr, ETH_ALEN);
if (0 != oz_elt_buf_init(&pd->elt_buff)) {
- oz_free(pd);
+ kfree(pd);
pd = 0;
}
spin_lock_init(&pd->tx_frame_lock);
while (e != &pd->farewell_list) {
fwell = container_of(e, struct oz_farewell, link);
e = e->next;
- oz_free(fwell);
+ kfree(fwell);
}
/* Deallocate all frames in tx pool.
*/
while (pd->tx_pool) {
e = pd->tx_pool;
pd->tx_pool = e->next;
- oz_free(container_of(e, struct oz_tx_frame, link));
+ kfree(container_of(e, struct oz_tx_frame, link));
}
if (pd->net_dev)
dev_put(pd->net_dev);
- oz_free(pd);
+ kfree(pd);
}
/*------------------------------------------------------------------------------
* Context: softirq-serialized
}
spin_unlock_bh(&pd->tx_frame_lock);
if (f == 0)
- f = oz_alloc(sizeof(struct oz_tx_frame), GFP_ATOMIC);
+ f = kmalloc(sizeof(struct oz_tx_frame), GFP_ATOMIC);
if (f) {
f->total_size = sizeof(struct oz_hdr);
INIT_LIST_HEAD(&f->link);
pd->tx_pool_count++;
f = 0;
} else {
- oz_free(f);
+ kfree(f);
}
spin_unlock_bh(&pd->tx_frame_lock);
if (f)
- oz_free(f);
+ kfree(f);
}
/*------------------------------------------------------------------------------
* Context: softirq
int oz_isoc_stream_create(struct oz_pd *pd, u8 ep_num)
{
struct oz_isoc_stream *st =
- oz_alloc(sizeof(struct oz_isoc_stream), GFP_ATOMIC);
+ kzalloc(sizeof(struct oz_isoc_stream), GFP_ATOMIC);
if (!st)
- return -1;
- memset(st, 0, sizeof(struct oz_isoc_stream));
+ return -ENOMEM;
st->ep_num = ep_num;
spin_lock_bh(&pd->stream_lock);
if (!pd_stream_find(pd, ep_num)) {
}
spin_unlock_bh(&pd->stream_lock);
if (st)
- oz_free(st);
+ kfree(st);
return 0;
}
/*------------------------------------------------------------------------------
{
if (st->skb)
kfree_skb(st->skb);
- oz_free(st);
+ kfree(st);
}
/*------------------------------------------------------------------------------
* Context: softirq
oz_polling_unlock_bh();
if (ai->farewell)
ai->farewell(pd, f->ep_num, f->report, f->len);
- oz_free(f);
+ kfree(f);
}
}
#include "oztrace.h"
#include "ozappif.h"
#include "ozevent.h"
-#include "ozalloc.h"
#include <asm/unaligned.h>
#include <linux/uaccess.h>
#include <net/psnap.h>
struct oz_farewell *f;
struct oz_farewell *f2;
int found = 0;
- f = oz_alloc(sizeof(struct oz_farewell) + len - 1, GFP_ATOMIC);
+ f = kmalloc(sizeof(struct oz_farewell) + len - 1, GFP_ATOMIC);
if (!f)
return;
f->ep_num = ep_num;
list_add_tail(&f->link, &pd->farewell_list);
spin_unlock(&g_polling_lock);
if (found)
- oz_free(f2);
+ kfree(f2);
}
/*------------------------------------------------------------------------------
* Context: softirq-serialized
dev_remove_pack(&b->ptype);
if (b->ptype.dev)
dev_put(b->ptype.dev);
- oz_free(b);
+ kfree(b);
spin_lock_bh(&g_binding_lock);
}
spin_unlock_bh(&g_binding_lock);
while (chain) {
struct oz_timer *t = container_of(chain, struct oz_timer, link);
chain = chain->next;
- oz_free(t);
+ kfree(t);
}
oz_trace("Protocol stopped\n");
}
spin_unlock_bh(&g_polling_lock);
oz_pd_put(pd);
if (t)
- oz_free(t);
+ kfree(t);
t = t2;
} while (t);
g_timer_state = OZ_TIMER_IDLE;
g_timer_pool = g_timer_pool->next;
g_timer_pool_count--;
} else {
- t = oz_alloc(sizeof(struct oz_timer), GFP_ATOMIC);
+ t = kmalloc(sizeof(struct oz_timer), GFP_ATOMIC);
}
if (t) {
t->pd = pd;
while (chain) {
t = container_of(chain, struct oz_timer, link);
chain = chain->next;
- oz_free(t);
+ kfree(t);
}
}
/*------------------------------------------------------------------------------
void oz_binding_add(char *net_dev)
{
struct oz_binding *binding;
- binding = oz_alloc(sizeof(struct oz_binding), GFP_ATOMIC);
+
+ binding = kmalloc(sizeof(struct oz_binding), GFP_ATOMIC);
if (binding) {
binding->ptype.type = __constant_htons(OZ_ETHERTYPE);
binding->ptype.func = oz_pkt_recv;
dev_get_by_name(&init_net, net_dev);
if (binding->ptype.dev == 0) {
oz_trace("Netdev %s not found\n", net_dev);
- oz_free(binding);
+ kfree(binding);
binding = 0;
}
} else {
dev_put(binding->ptype.dev);
pd_stop_all_for_device(binding->ptype.dev);
}
- oz_free(binding);
+ kfree(binding);
}
}
/*------------------------------------------------------------------------------
#include "ozusbif.h"
#include "ozhcd.h"
#include "oztrace.h"
-#include "ozalloc.h"
#include "ozusbsvc.h"
#include "ozevent.h"
/*------------------------------------------------------------------------------
/* Create a USB context in case we need one. If we find the PD already
* has a USB context then we will destroy it.
*/
- usb_ctx = (struct oz_usb_ctx *)
- oz_alloc(sizeof(struct oz_usb_ctx), GFP_ATOMIC);
+ usb_ctx = kzalloc(sizeof(struct oz_usb_ctx), GFP_ATOMIC);
if (usb_ctx == 0)
- return -1;
- memset(usb_ctx, 0, sizeof(struct oz_usb_ctx));
+ return -ENOMEM;
atomic_set(&usb_ctx->ref_count, 1);
usb_ctx->pd = pd;
usb_ctx->stopped = 0;
spin_unlock_bh(&pd->app_lock[OZ_APPID_USB-1]);
if (old_ctx) {
oz_trace("Already have USB context.\n");
- oz_free(usb_ctx);
+ kfree(usb_ctx);
usb_ctx = old_ctx;
} else if (usb_ctx) {
/* Take a reference to the PD. This will be released when
if (atomic_dec_and_test(&usb_ctx->ref_count)) {
oz_trace("Dealloc USB context.\n");
oz_pd_put(usb_ctx->pd);
- oz_free(usb_ctx);
+ kfree(usb_ctx);
}
}
/*------------------------------------------------------------------------------
#include "ozusbif.h"
#include "ozhcd.h"
#include "oztrace.h"
-#include "ozalloc.h"
#include "ozusbsvc.h"
#include "ozevent.h"
/*------------------------------------------------------------------------------