Don't cast returns from malloc()
[openafs.git] / src / venus / kdump.c
index 03cc958..e70742f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID
-    ("$Header$");
-
-#include <stdio.h>
-#include <errno.h>
-#include <stdlib.h>            /* for malloc() */
+#include <roken.h>
 
 #include <afs/cmd.h>
-    
+
 #if !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
 /* Here be hacks. */
 #ifdef AFS_LINUX24_ENV
@@ -111,10 +106,6 @@ struct ncp_sb_info {
 #define _KERNEL 1
 #endif
 
-#ifndef        AFS_OSF_ENV
-#include <sys/param.h>
-#endif
-
 #ifndef AFS_LINUX20_ENV
 #include <nlist.h>
 #endif
@@ -124,7 +115,6 @@ struct ncp_sb_info {
 #endif
 
 #include <afs/stds.h>
-#include <sys/types.h>
 
 #if defined(AFS_OSF_ENV)
 #define        KERNEL
@@ -133,7 +123,6 @@ struct ncp_sb_info {
 #ifdef _KERN_LOCK_H_
 #include FFFFF
 #endif
-#include <sys/time.h>
 #include <kern/lock.h>
 #include <sys/vnode.h>
 #include <arch/alpha/pmap.h>
@@ -150,7 +139,7 @@ struct ncp_sb_info {
  * kseg_to_phys()
  * is_kseg_va()
  * is_seg1_va()
- * 
+ *
  * when _KERNEL is defined, and expressions otherwise.  Since need
  * to define _KERNEL, we redefine these kernel functions as macros
  * for the expressions that we would have gotten if _KERNEL had not
@@ -169,16 +158,6 @@ struct ncp_sb_info {
 #ifdef AFS_SUN5_ENV /*XXXXX*/
 #include <sys/t_lock.h>
 struct vnode foo;
-#ifdef AFS_SUN54_ENV
-#else
-#ifdef AFS_SUN52_ENV
-typedef struct stat_mutex stat_mutex_t;
-#define        kmutex_t                stat_mutex_t
-#else
-typedef struct adaptive_mutex2 adaptive_mutex2_t;
-#define        kmutex_t        adaptive_mutex2_t
-#endif
-#endif
 #endif
 
 #ifdef AFS_SGI53_ENV
@@ -202,10 +181,6 @@ typedef struct adaptive_mutex2 adaptive_mutex2_t;
 #include <sys/user.h>
 #endif
 
-#ifndef AFS_LINUX20_ENV
-#include <sys/socket.h>
-#endif
-
 #ifndef AFS_LINUX26_ENV
 #include <sys/file.h>
 #endif
@@ -228,8 +203,6 @@ typedef struct adaptive_mutex2 adaptive_mutex2_t;
 # include <netinet/in.h>       /* struct in_addr */
 #endif
 
-#include <arpa/inet.h>         /* inet_ntoa() */
-
 #if defined(AFS_SGI_ENV) || defined(AFS_OSF_ENV)
 #ifdef       AFS_SGI_ENV
 #include <sys/vnode.h>
@@ -354,7 +327,6 @@ typedef enum _spustate {    /* FROM /etc/conf/h/_types.h */
 #endif
 #endif
 #endif
-#include <signal.h>
 #endif
 
 /* AFS includes */
@@ -608,9 +580,6 @@ int Dgcpags = 0;
 #include <sys/elf.h>
 #include <libelf.h>
 #include <sys/elf_M32.h>
-#ifndef        AFS_SUN54_ENV
-typedef ulong_t k_fltset_t;    /* XXXXXXXXXXX */
-#endif /* !AFS_SUN54_ENV */
 #include <sys/proc.h>
 #include <sys/file.h>
 #define        _NLIST_H                /* XXXXXXXXXXXXX */
@@ -644,9 +613,6 @@ PrintIPAddr(int addr)
 
 #ifdef AFS_LINUX20_ENV
 /* Find symbols in a live kernel. */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
 
 #ifdef AFS_LINUX26_ENV
 #define KSYMS "/proc/kallsyms"
@@ -701,7 +667,7 @@ read_ksyms(void)
     }
 
     availksyms = KSYM_ALLOC_BASE;
-    ksyms = (symlist_t *) malloc(availksyms * sizeof(symlist_t));
+    ksyms = malloc(availksyms * sizeof(symlist_t));
     if (!ksyms) {
        printf("Can't malloc %d elements for symbol list.\n", availksyms);
        exit(1);
@@ -711,8 +677,7 @@ read_ksyms(void)
     while (fgets(line, MAXLINE, fp)) {
        if (nksyms >= availksyms) {
            availksyms += KSYM_ALLOC_STEP;
-           ksyms =
-               (symlist_t *) realloc(ksyms, availksyms * sizeof(symlist_t));
+           ksyms = realloc(ksyms, availksyms * sizeof(symlist_t));
            if (!ksyms) {
                printf("Failed to realloc %d symbols.\n", availksyms);
                exit(1);
@@ -830,11 +795,11 @@ symsrch(s)
 
 #ifndef AFS_KDUMP_LIB
 static int
-cmdproc(register struct cmd_syndesc *as, void *arock)
+cmdproc(struct cmd_syndesc *as, void *arock)
 {
-    register afs_int32 code = 0;
+    afs_int32 code = 0;
 
-#if !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV) 
+#if !defined(AFS_DARWIN_ENV) && !defined(AFS_FBSD_ENV)
     if (as->parms[0].items) {  /* -kobj */
        obj = as->parms[0].items->data;
     }
@@ -945,8 +910,8 @@ cmdproc(register struct cmd_syndesc *as, void *arock)
 int
 main(int argc, char **argv)
 {
-    register struct cmd_syndesc *ts;
-    register afs_int32 code;
+    struct cmd_syndesc *ts;
+    afs_int32 code;
 
 #ifdef AFS_AIX32_ENV
     struct sigaction nsa;
@@ -1023,7 +988,7 @@ main(int argc, char **argv)
 int
 Knlist(struct afs_nlist *sp, int cnt, int size)
 {
-    register int code;
+    int code;
 
     if (UserLevel)
        code = nlist(obj, sp);
@@ -1380,14 +1345,12 @@ add_found_server(struct server *sep)
     if (NserversFound >= NserversAllocated) {
        NserversAllocated += SF_ALLOCATION_STEP;
        if (!serversFound) {
-           serversFound =
-               (struct server **)malloc(NserversAllocated *
-                                        sizeof(struct server *));
+           serversFound = malloc(NserversAllocated *
+                                 sizeof(struct server *));
        } else {
-           serversFound =
-               (struct server **)realloc((char *)serversFound,
-                                         NserversAllocated *
-                                         sizeof(struct server *));
+           serversFound = realloc(serversFound,
+                                  NserversAllocated *
+                                  sizeof(struct server *));
        }
        if (!serversFound) {
            printf("Can't allocate %lu bytes for list of found servers.\n",
@@ -1425,7 +1388,7 @@ print_servers(int pnt)
     int chainCount[NSERVERS];
 
     if (pnt) {
-       memset((char *)chainCount, 0, sizeof(chainCount));
+       memset(chainCount, 0, sizeof(chainCount));
        printf("\n\nPrinting 'afs_servers' structures...\n");
     }
     findsym("afs_servers", &symoff);
@@ -1463,7 +1426,7 @@ print_servers(int pnt)
 
     /* Verify against afs_totalServers. */
     if (pnt) {
-       memset((char *)chainCount, 0, sizeof(chainCount));
+       memset(chainCount, 0, sizeof(chainCount));
        if (findsym("afs_totalServers", &symoff)) {
            kread(kmem, symoff, (char *)&afs_totalServers, sizeof(afs_int32));
            if (afs_totalServers != nServers) {
@@ -1647,7 +1610,7 @@ print_dcaches(int pnt)
     kread(kmem, symoff, (char *)&count, sizeof count);
     findsym("afs_indexTable", &symoff);
     kread(kmem, symoff, (char *)&table, sizeof(long));
-    ptr = (long *)malloc(count * sizeof(long));
+    ptr = malloc(count * sizeof(long));
     kread(kmem, table, (char *)ptr, count * sizeof(long));
     for (i = 0, j = 0; i < count; i++) {
        if (dp = (struct dcache *)ptr[i]) {
@@ -1686,7 +1649,7 @@ print_DindexTimes(int pnt)
     kread(kmem, symoff, (char *)&count, sizeof count);
     findsym("afs_indexTimes", &symoff);
     kread(kmem, symoff, (char *)&table, sizeof(long));
-    ptr = (afs_hyper_t *) malloc(count * sizeof(afs_hyper_t));
+    ptr = malloc(count * sizeof(afs_hyper_t));
     kread(kmem, table, (char *)ptr, count * sizeof(afs_hyper_t));
     for (i = 0, j = 0; i < count; i++) {
        if (pnt)
@@ -1722,7 +1685,7 @@ print_DdvnextTbl(int pnt)
     kread(kmem, symoff, (char *)&count, sizeof count);
     findsym("afs_dvnextTbl", &symoff);
     kread(kmem, symoff, (char *)&table, sizeof(long));
-    ptr = (afs_int32 *) malloc(count * sizeof(afs_int32));
+    ptr = malloc(count * sizeof(afs_int32));
     kread(kmem, table, (char *)ptr, count * sizeof(afs_int32));
     for (i = 0, j = 0; i < count; i++) {
        if (pnt)
@@ -1751,7 +1714,7 @@ print_DdcnextTbl(int pnt)
     kread(kmem, symoff, (char *)&count, sizeof count);
     findsym("afs_dcnextTbl", &symoff);
     kread(kmem, symoff, (char *)&table, sizeof(long));
-    ptr = (afs_int32 *) malloc(count * sizeof(afs_int32));
+    ptr = malloc(count * sizeof(afs_int32));
     kread(kmem, table, (char *)ptr, count * sizeof(afs_int32));
     for (i = 0, j = 0; i < count; i++) {
        if (pnt)
@@ -1781,7 +1744,7 @@ print_DindexFlags(int pnt)
     kread(kmem, symoff, (char *)&count, sizeof count);
     findsym("afs_indexFlags", &symoff);
     kread(kmem, symoff, (char *)&table, sizeof(long));
-    flags = (unsigned char *)malloc(count * sizeof(char));
+    flags = malloc(count * sizeof(char));
     kread(kmem, table, flags, count * sizeof(char));
     for (i = 0, j = 0; i < count; i++) {
        if (pnt)
@@ -1810,7 +1773,7 @@ print_buffers(int pnt)
     kread(kmem, symoff, (char *)&table, sizeof(long));
     findsym("nbuffers", &symoff);
     kread(kmem, symoff, (char *)&count, sizeof(int));
-    buffers = (unsigned char *)malloc(count * sizeof(struct buffer));
+    buffers = malloc(count * sizeof(struct buffer));
     kread(kmem, table, buffers, count * sizeof(struct buffer));
     bp = (struct buffer *)buffers;
     for (i = 0, j = 0; i < count; i++, bp++) {
@@ -2105,13 +2068,11 @@ print_allocs(int pnt)
     T += i;
     printf("%20s:\t%8d bytes\t[%d entries/%d bytes each]\n", "Buffer package",
           i, j, sizeof(struct buffer));
-#if    !AFS_USEBUFFERS
 #define        AFS_BUFFER_PAGESIZE 2048
     i = j * AFS_BUFFER_PAGESIZE;
     T += i;
     printf("%20s:\t%8d bytes\t[%d entries/%d bytes each]\n",
           "Xtra Buffer pkg area", i, j, AFS_BUFFER_PAGESIZE);
-#endif
 
     Sum_exps = 0;
     Sum_nfssysnames = 0;
@@ -2221,11 +2182,11 @@ print_allocs(int pnt)
 int
 readmem(kmem, buf, vad, len)
      int kmem, len;
-#ifdef AFS_SUN57_ENV
+#ifdef AFS_SUN5_ENV
      uintptr_t vad;
 #else
      int vad;
-#endif         /** AFS_SUN57_ENV **/
+#endif         /** AFS_SUN5_ENV **/
      char *buf;
 {
     int newlen;
@@ -2351,8 +2312,8 @@ kread(int kmem, off_t loc, void *buf, KDUMP_SIZE_T len)
        perror("lseek");
        exit(1);
     }
-    if (loc == 0) 
-       printf("WARNING: Read failed: loc=0\n"); 
+    if (loc == 0)
+       printf("WARNING: Read failed: loc=0\n");
     else
        if ((i = read(kmem, buf, len)) != len) {
            printf("WARNING: Read failed: ");
@@ -2477,7 +2438,7 @@ opencore(char *core)
 
 
 void
-print_exporter(int kmem, struct afs_exporter *exporter, 
+print_exporter(int kmem, struct afs_exporter *exporter,
               struct afs_exporter *ptr, int pnt)
 {
     if (pnt) {
@@ -2492,7 +2453,7 @@ print_exporter(int kmem, struct afs_exporter *exporter,
 
 
 void
-print_nfsclient(int kmem, struct nfsclientpag *ep, 
+print_nfsclient(int kmem, struct nfsclientpag *ep,
                struct nfsclientpag *ptr, int pnt)
 {
     char sysname[100];
@@ -2516,19 +2477,12 @@ print_nfsclient(int kmem, struct nfsclientpag *ep,
 void
 pmutex(char *sp, kmutex_t *mp)
 {
-#ifdef AFS_SUN54_ENV
-
-#else
-    struct stat_mutex *smp = (struct stat_mutex *)mp;
-
-    printf("%s mutex: %x %x\n", sp, smp->m_stats_lock, smp->m_type);
-#endif
 }
 
 #endif
 
 void
-print_unixuser(int kmem, struct unixuser *uep, 
+print_unixuser(int kmem, struct unixuser *uep,
               struct unixuser *ptr, int pnt)
 {
     Sum_userstp += uep->stLen;
@@ -2569,7 +2523,7 @@ print_cell(int kmem, struct cell *clep, struct cell *ptr, int pnt)
            printf("\tlinked cellp %lx\n", clep->lcellp);
 #endif
        printf("\tCell's servers: ");
-       for (i = 0; i < MAXCELLHOSTS; i++) {
+       for (i = 0; i < AFS_MAXCELLHOSTS; i++) {
            if (pretty && (clep->cellHosts[i] == 0))
                break;
            printf("[%lx] ", clep->cellHosts[i]);
@@ -2580,7 +2534,7 @@ print_cell(int kmem, struct cell *clep, struct cell *ptr, int pnt)
 
 
 void
-print_server(int kmem, struct server *sep, struct server *ptr, int conns, 
+print_server(int kmem, struct server *sep, struct server *ptr, int conns,
             int pnt)
 {
     struct srvAddr sa, *sap = &sa, *sap1;
@@ -2647,7 +2601,7 @@ print_server(int kmem, struct server *sep, struct server *ptr, int conns,
 
 
 void
-print_conns(int kmem, struct srvAddr *srv, struct afs_conn *conns, int Con, 
+print_conns(int kmem, struct srvAddr *srv, struct afs_conn *conns, int Con,
            int pnt)
 {
     struct afs_conn *cep, ce, *centry = &ce;
@@ -2712,12 +2666,12 @@ print_volume(int kmem, struct volume *vep, struct volume *ptr, int pnt)
         vep->states);
 #endif
     printf("\tVolume's statuses: ");
-    for (i = 0; i < MAXHOSTS && vep->serverHost[i]; i++)
+    for (i = 0; i < AFS_MAXHOSTS && vep->serverHost[i]; i++)
        printf("[%d] ", vep->status[i]);
     printf("\n");
 
     printf("\tVolume's servers: ");
-    for (i = 0; i < MAXHOSTS && vep->serverHost[i]; i++)
+    for (i = 0; i < AFS_MAXHOSTS && vep->serverHost[i]; i++)
        printf("[%lx] ", vep->serverHost[i]);
     printf("\n");
 
@@ -3160,7 +3114,7 @@ print_callout(int kmem)
     struct callo Co, *Coe = &Co, *Cop;
     struct tos To, *Toe = &To, *tos;
     struct trb Trb, *Trbe = &Trb, *trb;
-    register int i = 0;
+    int i = 0;
 
 
     printf("\n\nPrinting callout table info...\n\n");