diff options
author | Jordan Hargrave <jordan@cvs.openbsd.org> | 2008-09-25 19:12:29 +0000 |
---|---|---|
committer | Jordan Hargrave <jordan@cvs.openbsd.org> | 2008-09-25 19:12:29 +0000 |
commit | 56ada726e143f5d352ebf1fa5ac1015ed75f0b91 (patch) | |
tree | c83601ba61e1dfa8f2af55f242890f661bd5501f | |
parent | 4c7170d0ee12afde031ca6fbbf6b002767edfa19 (diff) |
Fixed memory leak bug during scope evaluation
Removed unused functions
ok marco@
-rw-r--r-- | sys/dev/acpi/dsdt.c | 143 | ||||
-rw-r--r-- | sys/dev/acpi/dsdt.h | 6 |
2 files changed, 73 insertions, 76 deletions
diff --git a/sys/dev/acpi/dsdt.c b/sys/dev/acpi/dsdt.c index e1f3baab262..95714a24fff 100644 --- a/sys/dev/acpi/dsdt.c +++ b/sys/dev/acpi/dsdt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dsdt.c,v 1.132 2008/09/10 14:01:22 blambert Exp $ */ +/* $OpenBSD: dsdt.c,v 1.133 2008/09/25 19:12:28 jordan Exp $ */ /* * Copyright (c) 2005 Jordan Hargrave <jordan@openbsd.org> * @@ -371,16 +371,6 @@ aml_mnem(int opcode, uint8_t *pos) } #endif /* SMALL_KERNEL */ -const char * -aml_args(int opcode) -{ - struct aml_opcode *tab; - - if ((tab = aml_findopcode(opcode)) != NULL) - return tab->args; - return (""); -} - struct aml_notify_data { struct aml_node *node; char pnpid[20]; @@ -403,7 +393,18 @@ long acpi_nalloc; struct acpi_memblock { size_t size; +#ifdef ACPI_MEMDEBUG + const char *fn; + int line; + int sig; + LIST_ENTRY(acpi_memblock) link; +#endif }; +#ifdef ACPI_MEMDEBUG +LIST_HEAD(, acpi_memblock) acpi_memhead; +#endif + +int acpi_memsig; void * _acpi_os_malloc(size_t size, const char *fn, int line) @@ -414,6 +415,14 @@ _acpi_os_malloc(size_t size, const char *fn, int line) dnprintf(99, "alloc: %x %s:%d\n", sptr, fn, line); acpi_nalloc += size; sptr->size = size; +#ifdef ACPI_MEMDEBUG + sptr->line = line; + sptr->fn = fn; + sptr->sig = ++acpi_memsig; + + LIST_INSERT_HEAD(&acpi_memhead, sptr, link); +#endif + return &sptr[1]; } @@ -426,11 +435,32 @@ _acpi_os_free(void *ptr, const char *fn, int line) sptr = &(((struct acpi_memblock *)ptr)[-1]); acpi_nalloc -= sptr->size; +#ifdef ACPI_MEMDEBUG + LIST_REMOVE(sptr, link); +#endif + dnprintf(99, "free: %x %s:%d\n", sptr, fn, line); free(sptr, M_ACPI); } } +int +acpi_walkmem(int sig, const char *lbl) +{ +#ifdef ACPI_MEMDEBUG + struct acpi_memblock *sptr; + + printf("--- walkmem:%s %x --- %x bytes alloced\n", lbl, sig, acpi_nalloc); + LIST_FOREACH(sptr, &acpi_memhead, link) { + if (sptr->sig < sig) + break; + printf("%.4x Alloc %.8lx bytes @ %s:%d\n", + sptr->sig, sptr->size, sptr->fn, sptr->line); + } +#endif + return acpi_memsig; +} + void acpi_sleep(int ms) { @@ -681,60 +711,6 @@ aml_delchildren(struct aml_node *node) * @@@: Value functions */ -struct aml_scope *aml_pushscope(struct aml_scope *, uint8_t *, - uint8_t *, struct aml_node *); -struct aml_scope *aml_popscope(struct aml_scope *); - -#define AML_LHS 0 -#define AML_RHS 1 -#define AML_DST 2 -#define AML_DST2 3 - -/* Allocate+push parser scope */ -struct aml_scope * -aml_pushscope(struct aml_scope *parent, uint8_t *start, uint8_t *end, - struct aml_node *node) -{ - struct aml_scope *scope; - - scope = acpi_os_malloc(sizeof(struct aml_scope)); - scope->pos = start; - scope->end = end; - scope->node = node; - scope->parent = parent; - scope->sc = dsdt_softc; - - aml_lastscope = scope; - - return scope; -} - -struct aml_scope * -aml_popscope(struct aml_scope *scope) -{ - struct aml_scope *nscope; - struct aml_vallist *ol; - int idx; - - if (scope == NULL) - return NULL; - nscope = scope->parent; - - /* Free temporary values */ - while ((ol = scope->tmpvals) != NULL) { - scope->tmpvals = ol->next; - for (idx = 0; idx < ol->nobj; idx++) { - aml_freevalue(&ol->obj[idx]); - } - acpi_os_free(ol); - } - acpi_os_free(scope); - - aml_lastscope = nscope; - - return nscope; -} - /* * Field I/O code */ @@ -1572,6 +1548,10 @@ aml_create_defaultobjects() struct aml_value *tmp; struct aml_defval *def; +#ifdef ACPI_MEMDEBUG + LIST_INIT(&acpi_memhead); +#endif + osstring[1] = 'i'; osstring[6] = 'o'; osstring[15] = 'w'; @@ -1890,8 +1870,21 @@ struct aml_scope * aml_xfindscope(struct aml_scope *scope, int type, int endscope) { while (scope) { - if (endscope) + switch (endscope) { + case AMLOP_RETURN: + scope->pos = scope->end; + break; + case AMLOP_CONTINUE: + scope->pos = scope->end; + if (scope->type == type) + scope->pos = scope->start; + break; + case AMLOP_BREAK: + scope->pos = scope->end; + if (scope->type == type) scope->pos = NULL; + break; + } if (scope->type == type) break; scope = scope->parent; @@ -2374,7 +2367,6 @@ void aml_xcreatefield(struct aml_value *, int, struct aml_value *, int, int, struct aml_value *, int, int); void aml_xparsefieldlist(struct aml_scope *, int, int, struct aml_value *, struct aml_value *, int); -int aml_evalhid(struct aml_node *, struct aml_value *); #define GAS_PCI_CFG_SPACE_UNEVAL 0xCC @@ -2729,6 +2721,7 @@ aml_xparsefieldlist(struct aml_scope *mscope, int opcode, int flags, } bpos += blen; } + aml_xpopscope(mscope); } /* @@ -4185,18 +4178,14 @@ aml_xparse(struct aml_scope *scope, int ret_type, const char *stype) break; case AMLOP_BREAK: /* Break: Find While Scope parent, mark type as null */ - mscope = aml_xfindscope(scope, AMLOP_WHILE, 1); - mscope->pos = NULL; - mscope = NULL; + aml_xfindscope(scope, AMLOP_WHILE, AMLOP_BREAK); break; case AMLOP_CONTINUE: /* Find Scope.. mark all objects as invalid on way to root */ - mscope = aml_xfindscope(scope, AMLOP_WHILE, 1); - mscope->pos = mscope->start; - mscope = NULL; + aml_xfindscope(scope, AMLOP_WHILE, AMLOP_CONTINUE); break; case AMLOP_RETURN: - mscope = aml_xfindscope(scope, AMLOP_METHOD, 1); + mscope = aml_xfindscope(scope, AMLOP_METHOD, AMLOP_RETURN); if (mscope->retv) { aml_die("already allocated\n"); } @@ -4288,6 +4277,9 @@ aml_evalnode(struct acpi_softc *sc, struct aml_node *node, int argc, struct aml_value *argv, struct aml_value *res) { struct aml_value *xres; +#ifdef ACPI_MEMDEBUG + static int wmstate; +#endif if (node == NULL || node->value == NULL) return (ACPI_E_BADVALUE); @@ -4309,6 +4301,9 @@ aml_evalnode(struct acpi_softc *sc, struct aml_node *node, case AML_OBJTYPE_FIELDUNIT: case AML_OBJTYPE_METHOD: aml_busy++; +#ifdef ACPI_MEMDEBUG + wmstate = acpi_walkmem(wmstate, aml_nodename(node)); +#endif xres = aml_xeval(NULL, node->value, 't', argc, argv); aml_busy--; if (res && xres) diff --git a/sys/dev/acpi/dsdt.h b/sys/dev/acpi/dsdt.h index 4b4ad3c74bc..42b24774226 100644 --- a/sys/dev/acpi/dsdt.h +++ b/sys/dev/acpi/dsdt.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dsdt.h,v 1.38 2008/06/13 00:04:33 jordan Exp $ */ +/* $OpenBSD: dsdt.h,v 1.39 2008/09/25 19:12:28 jordan Exp $ */ /* * Copyright (c) 2005 Marco Peereboom <marco@openbsd.org> * @@ -48,7 +48,6 @@ struct aml_opcode { }; const char *aml_eisaid(u_int32_t); -const char *aml_args(int); const char *aml_mnem(int, uint8_t *); int64_t aml_val2int(struct aml_value *); struct aml_node *aml_searchname(struct aml_node *, const void *); @@ -90,6 +89,7 @@ int acpi_mutex_acquire(struct aml_value *, int); void acpi_mutex_release(struct aml_value *); const char *aml_nodename(struct aml_node *); +int aml_evalhid(struct aml_node *, struct aml_value *); #define SR_IRQ 0x04 #define SR_DMA 0x05 @@ -255,6 +255,8 @@ void aml_disasm(struct aml_scope *scope, int lvl, void *arg); int aml_xgetpci(struct aml_node *, int64_t *); +int acpi_walkmem(int, const char *); + #define aml_get8(p) *(uint8_t *)(p) #define aml_get16(p) *(uint16_t *)(p) #define aml_get32(p) *(uint32_t *)(p) |