Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1ec41a31 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman
Browse files

staging: ozwpan: remove debug allocator



The kernel already has a debug allocator, no need to have one unique to
a single driver.  So delete it, replace with kfree, kmalloc, and, in a
few places that need it, kzalloc().

Cc: Chris Kelly <ckelly@ozmodevices.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent cc55bb03
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -12,7 +12,6 @@ ozwpan-y := \
	ozeltbuf.o \
	ozproto.o \
	ozcdev.o \
	ozalloc.o \
	ozurbparanoia.o \
	oztrace.o \
	ozevent.o

drivers/staging/ozwpan/ozalloc.c

deleted100644 → 0
+0 −107
Original line number Diff line number Diff line
/* -----------------------------------------------------------------------------
 * 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 */

drivers/staging/ozwpan/ozalloc.h

deleted100644 → 0
+0 −28
Original line number Diff line number Diff line
/* -----------------------------------------------------------------------------
 * 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 */
+4 −7
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
#include "ozeltbuf.h"
#include "ozpd.h"
#include "ozproto.h"
#include "ozalloc.h"
#include "ozevent.h"
/*------------------------------------------------------------------------------
 */
@@ -66,7 +65,7 @@ static void oz_cdev_release_ctx(struct oz_serial_ctx *ctx)
{
	if (atomic_dec_and_test(&ctx->ref_count)) {
		oz_trace("Dealloc serial context.\n");
		oz_free(ctx);
		kfree(ctx);
	}
}
/*------------------------------------------------------------------------------
@@ -400,18 +399,16 @@ int oz_cdev_start(struct oz_pd *pd, int resume)
		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]);
+0 −1
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@
#ifndef _OZCONFIG_H
#define _OZCONFIG_H

/* #define WANT_DEBUG_KMALLOC */
/* #define WANT_TRACE */
#ifdef WANT_TRACE
#define WANT_VERBOSE_TRACE
Loading