Print this page
    
10132 smatch fixes for MDB
Reviewed by: Andy Fiddaman <andy@omniosce.org>
    
      
        | Split | 
	Close | 
      
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/cmd/mdb/common/modules/genunix/ndievents.c
          +++ new/usr/src/cmd/mdb/common/modules/genunix/ndievents.c
   1    1  /*
   2    2   * CDDL HEADER START
   3    3   *
   4    4   * The contents of this file are subject to the terms of the
   5    5   * Common Development and Distribution License, Version 1.0 only
   6    6   * (the "License").  You may not use this file except in compliance
   7    7   * with the License.
   8    8   *
   9    9   * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10   10   * or http://www.opensolaris.org/os/licensing.
  11   11   * See the License for the specific language governing permissions
  12   12   * and limitations under the License.
  13   13   *
  14   14   * When distributing Covered Code, include this CDDL HEADER in each
  15   15   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16   16   * If applicable, add the following below this CDDL HEADER, with the
  
    | 
      ↓ open down ↓ | 
    16 lines elided | 
    
      ↑ open up ↑ | 
  
  17   17   * fields enclosed by brackets "[]" replaced with your own identifying
  18   18   * information: Portions Copyright [yyyy] [name of copyright owner]
  19   19   *
  20   20   * CDDL HEADER END
  21   21   */
  22   22  /*
  23   23   * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
  24   24   * Use is subject to license terms.
  25   25   */
  26   26  
  27      -#pragma ident   "%Z%%M% %I%     %E% SMI"
       27 +/*
       28 + * Copyright (c) 2018, Joyent, Inc.
       29 + */
  28   30  
  29   31  #include "ndievents.h"
  30   32  #include <sys/sunndi.h>
  31   33  #include <sys/ndi_impldefs.h>
  32   34  #include <sys/dditypes.h>
  33   35  #include <sys/ddi_impldefs.h>
  34   36  #include <sys/sunddi.h>
  35   37  #include <sys/param.h>
  36   38  
  37   39  
  38   40  int
  39   41  dip_to_pathname(struct dev_info *device, char *path, int buflen) {
  40   42  
  41   43          char *bp;
  42   44          char *addr;
  43   45          char addr_str[32];
  44   46          char nodename[MAXNAMELEN];
  45   47          struct dev_info devi_parent;
  46   48  
  47   49          if (!device) {
  48   50                  mdb_warn("Unable to access devinfo.");
  49   51                  return (-1);
  50   52          }
  51   53  
  52   54          if (device->devi_parent == NULL) {
  53   55                  if (mdb_readstr(nodename, sizeof (nodename),
  54   56                      (uintptr_t)device->devi_node_name) == -1) {
  55   57                      return (-1);
  56   58                  }
  57   59  
  58   60                  if (sizeof (nodename) > (buflen - strlen(path))) {
  59   61                          return (-1);
  60   62                  }
  61   63  
  62   64                  strncpy(path, nodename, sizeof (nodename));
  63   65                  return (0);
  64   66          }
  65   67  
  66   68          if (mdb_vread(&devi_parent, sizeof (struct dev_info),
  67   69              (uintptr_t)device->devi_parent) == -1) {
  68   70                  mdb_warn("Unable to access devi_parent at %p",
  69   71                      (uintptr_t)device->devi_parent);
  70   72                  return (-1);
  71   73          }
  72   74  
  
    | 
      ↓ open down ↓ | 
    35 lines elided | 
    
      ↑ open up ↑ | 
  
  73   75          if (dip_to_pathname(&devi_parent, path, buflen) == -1) {
  74   76                  return (-1);
  75   77          }
  76   78  
  77   79          if (mdb_readstr(nodename, sizeof (nodename),
  78   80              (uintptr_t)device->devi_node_name) == -1) {
  79   81                  return (-1);
  80   82          }
  81   83  
  82   84          if (device->devi_node_state < DS_INITIALIZED) {
  83      -                strncpy(addr_str, '\0', sizeof ('\0'));
       85 +                addr_str[0] = '\0';
  84   86          } else {
  85   87                  addr = device->devi_addr;
  86   88                  if (mdb_readstr(addr_str, sizeof (addr_str),
  87   89                      (uintptr_t)addr) == -1) {
  88   90                          return (-1);
  89   91                  }
  90   92          }
  91   93  
  92   94          bp = path + strlen(path);
  93   95  
  94   96          if (addr_str[0] == '\0') {
  95   97                  (void) mdb_snprintf(bp, buflen - strlen(path), "/%s", nodename);
  96   98          } else {
  97   99                  (void) mdb_snprintf(bp, buflen - strlen(path), "/%s@%s",
  98  100                      nodename, addr_str);
  99  101          }
 100  102          return (0);
 101  103  
 102  104  }
 103  105  
 104  106  /*ARGSUSED*/
 105  107  int
 106  108  ndi_callback_print(struct ndi_event_cookie *cookie, uint_t flags)
 107  109  {
 108  110  
 109  111          struct ndi_event_callbacks *callback_list;
 110  112          struct ndi_event_callbacks cb;
 111  113          char device_path[MAXPATHLEN];
 112  114          struct dev_info devi;
 113  115  
 114  116          if (!cookie) {
 115  117                  return (DCMD_ERR);
 116  118          }
 117  119  
 118  120          callback_list = cookie->callback_list;
 119  121  
 120  122          while (callback_list != NULL) {
 121  123                  if (mdb_vread(&cb, sizeof (struct ndi_event_callbacks),
 122  124                              (uintptr_t)callback_list) == -1) {
 123  125                          mdb_warn("Could not read callback structure at"
 124  126                              " %p", callback_list);
 125  127                          return (DCMD_ERR);
 126  128                  }
 127  129  
 128  130                  if (mdb_vread(&devi, sizeof (struct dev_info),
 129  131                      (uintptr_t)cb.ndi_evtcb_dip) == -1) {
 130  132                          mdb_warn("Could not read devinfo structure at"
 131  133                              " %p", cb.ndi_evtcb_dip);
 132  134                          return (DCMD_ERR);
 133  135                  }
 134  136  
 135  137                  if (dip_to_pathname(&devi, device_path, sizeof (device_path))
 136  138                      == -1) {
 137  139                          return (DCMD_ERR);
 138  140                  }
 139  141  
 140  142                  mdb_printf("\t\tCallback Registered By: %s\n", device_path);
 141  143                  mdb_printf("\t\t  Callback Address:\t%-?p\n"
 142  144                      "\t\t  Callback Function:\t%-p\n"
 143  145                      "\t\t  Callback Args:\t%-?p\n"
 144  146                      "\t\t  Callback Cookie:\t%-?p\n",
 145  147                      callback_list, cb.ndi_evtcb_callback, cb.ndi_evtcb_arg,
 146  148                      cb.ndi_evtcb_cookie);
 147  149  
 148  150                  callback_list = cb.ndi_evtcb_next;
 149  151  
 150  152          }
 151  153  
 152  154          return (DCMD_OK);
 153  155  }
 154  156  
 155  157  int
 156  158  ndi_event_print(struct ndi_event_hdl *hdl, uint_t flags)
 157  159  {
 158  160  
 159  161          struct  ndi_event_definition def;
 160  162          struct  ndi_event_cookie cookie;
 161  163          struct  ndi_event_cookie *cookie_list;
 162  164          char    ndi_event_name[256];
 163  165  
 164  166          if (!hdl)
 165  167                  return (DCMD_ERR);
 166  168  
 167  169          cookie_list = hdl->ndi_evthdl_cookie_list;
 168  170          if (cookie_list == NULL) {
 169  171                  mdb_printf("\tNo cookies defined for this handle.\n");
 170  172                  return (DCMD_OK);
 171  173          }
 172  174  
 173  175          while (cookie_list != NULL) {
 174  176                  if (mdb_vread(&cookie, sizeof (struct ndi_event_cookie),
 175  177                      (uintptr_t)cookie_list) == -1) {
 176  178                          mdb_warn("Unable to access cookie list");
 177  179                          return (DCMD_ERR);
 178  180                  }
 179  181  
 180  182                  if (mdb_vread(&def, sizeof (struct ndi_event_definition),
 181  183                      (uintptr_t)cookie.definition) == -1) {
 182  184                          mdb_warn("Unable to access definition at %p",
 183  185                              cookie.definition);
 184  186                          return (DCMD_ERR);
 185  187                  }
 186  188  
 187  189                  if (mdb_readstr(ndi_event_name, sizeof (ndi_event_name),
 188  190                      (uintptr_t)def.ndi_event_name) == -1) {
 189  191                          mdb_warn("Unable to read cookie name.");
 190  192                          return (DCMD_ERR);
 191  193                  }
 192  194  
 193  195                  mdb_printf("\tCookie(%s %p) :Plevel(%d)\n\tddip(%p)"
 194  196                      " : Attr(%d)\n",
 195  197                      ndi_event_name, cookie_list, def.ndi_event_plevel,
 196  198                      cookie.ddip, def.ndi_event_attributes);
 197  199  
 198  200                  ndi_callback_print(&cookie, flags);
 199  201                  cookie_list = cookie.next_cookie;
 200  202  
 201  203          }
 202  204          return (0);
 203  205  }
 204  206  
 205  207  /*ARGSUSED*/
 206  208  int
 207  209  ndi_event_hdl(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
 208  210  {
 209  211  
 210  212          struct dev_info devi;
 211  213          struct ndi_event_hdl handle;
 212  214          char path[MAXPATHLEN];
 213  215          int done;
 214  216  
 215  217          if (!(flags & DCMD_ADDRSPEC)) {
 216  218                  return (DCMD_USAGE);
 217  219          }
 218  220  
 219  221          if (mdb_vread(&handle, sizeof (struct ndi_event_hdl), addr) == -1) {
 220  222                  mdb_warn("failed to read ndi_event_hdl at %p", addr);
 221  223                  return (DCMD_ERR);
 222  224          }
 223  225  
 224  226          if (mdb_vread(&devi, sizeof (struct dev_info),
 225  227                      (uintptr_t)handle.ndi_evthdl_dip)
 226  228              == -1) {
 227  229                  mdb_warn("failed to read devinfo node at %p",
 228  230                      handle.ndi_evthdl_dip);
 229  231                  return (DCMD_ERR);
 230  232          }
 231  233  
 232  234          if (dip_to_pathname(&devi, path, sizeof (path)) == -1) {
 233  235                  return (DCMD_ERR);
 234  236          }
 235  237  
 236  238          done = 0;
 237  239          while (!done) {
 238  240  
 239  241                  mdb_printf("%<b>Handle%</b> (%p) :%<b> Path%</b> (%s) : %<b>"
 240  242                      "dip %</b>(%p) \n", addr, path, handle.ndi_evthdl_dip);
 241  243  
 242  244                  mdb_printf("mutexes:    handle(%p)      callback(%p)\n",
 243  245                      handle.ndi_evthdl_mutex, handle.ndi_evthdl_cb_mutex);
 244  246  
 245  247                  ndi_event_print(&handle, flags);
 246  248  
 247  249                  if (handle.ndi_next_hdl == NULL) {
 248  250                          done = 1;
 249  251                  } else {
 250  252                          addr = (uintptr_t)handle.ndi_next_hdl;
 251  253                          if (mdb_vread(&handle, sizeof (struct ndi_event_hdl),
 252  254                              (uintptr_t)addr) == -1) {
 253  255                              mdb_warn("failed to read ndi_event_hdl at %p",
 254  256                              addr);
 255  257                              break;
 256  258                          }
 257  259  
 258  260                  }
 259  261          }
 260  262  
 261  263          return (0);
 262  264  }
  
    | 
      ↓ open down ↓ | 
    169 lines elided | 
    
      ↑ open up ↑ | 
  
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX