Print this page
10132 smatch fixes for MDB
Reviewed by: Andy Fiddaman <andy@omniosce.org>


   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  *
  25  * FCP mdb module
  26  */
  27 
  28 
  29 #include <sys/mdb_modapi.h>
  30 #include <sys/mutex.h>
  31 #include <sys/modctl.h>
  32 #include <sys/scsi/scsi.h>
  33 #include <sys/sunndi.h>
  34 #include <sys/fibre-channel/fc.h>
  35 #include <sys/fibre-channel/ulp/fcpvar.h>
  36 
  37 static struct fcp_port  port;
  38 static struct fcp_tgt   tgt;
  39 static struct fcp_lun   lun;
  40 static uint32_t tgt_hash_index;
  41 
  42 
  43 /*
  44  * Leadville fcp walker/dcmd code
  45  */


 311 targets_walk_i(mdb_walk_state_t *wsp)
 312 {
 313         if (wsp->walk_addr == NULL) {
 314                 mdb_warn("Can not perform global walk\n");
 315                 return (WALK_ERR);
 316         }
 317 
 318         /*
 319          * Input should be a fcp_port, so read it to get the port_tgt
 320          * table's head
 321          */
 322 
 323         if (mdb_vread(&port, sizeof (struct fcp_port), wsp->walk_addr) !=
 324             sizeof (struct fcp_port)) {
 325                 mdb_warn("Unable to read in the port structure address\n");
 326                 return (WALK_ERR);
 327         }
 328 
 329         tgt_hash_index = 0;
 330 
 331         while ((port.port_tgt_hash_table[tgt_hash_index] == NULL) &&
 332             (tgt_hash_index < FCP_NUM_HASH)) {
 333                 tgt_hash_index++;
 334         }
 335 
 336         wsp->walk_addr = (uintptr_t)(port.port_tgt_hash_table[tgt_hash_index]);
 337 
 338         wsp->walk_data = mdb_alloc(sizeof (struct fcp_tgt), UM_SLEEP);
 339 
 340         return (WALK_NEXT);
 341 }
 342 
 343 static int
 344 targets_walk_s(mdb_walk_state_t *wsp)
 345 {
 346         int status;
 347 
 348         if ((wsp->walk_addr == NULL) &&
 349             (tgt_hash_index >= (FCP_NUM_HASH - 1))) {
 350                 return (WALK_DONE);
 351         }
 352 
 353         if (mdb_vread(wsp->walk_data, sizeof (struct fcp_tgt),
 354             wsp->walk_addr) == -1) {
 355                 mdb_warn("failed to read fcp_tgt at %p", wsp->walk_addr);
 356                 return (WALK_DONE);
 357         }
 358 
 359         status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
 360             wsp->walk_cbdata);
 361 
 362         wsp->walk_addr =
 363             (uintptr_t)(((struct fcp_tgt *)wsp->walk_data)->tgt_next);
 364 
 365         if (wsp->walk_addr == NULL) {
 366                 /*
 367                  * locate the next hash list
 368                  */
 369 
 370                 tgt_hash_index++;
 371 
 372                 while ((port.port_tgt_hash_table[tgt_hash_index] == NULL) &&
 373                     (tgt_hash_index < FCP_NUM_HASH)) {
 374                         tgt_hash_index++;
 375                 }
 376 
 377                 if (tgt_hash_index == FCP_NUM_HASH) {
 378                         /* You're done */
 379                         return (status);
 380                 }
 381 
 382                 wsp->walk_addr =
 383                     (uintptr_t)(port.port_tgt_hash_table[tgt_hash_index]);
 384         }
 385 
 386         return (status);
 387 }
 388 
 389 /*
 390  * The walker's fini function is invoked at the end of each walk.
 391  */
 392 static void
 393 targets_walk_f(mdb_walk_state_t *wsp)
 394 {
 395         mdb_free(wsp->walk_data, sizeof (struct fcp_tgt));




   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  *
  25  * Copyright (c) 2018, Joyent, Inc.
  26  */
  27 
  28 
  29 #include <sys/mdb_modapi.h>
  30 #include <sys/mutex.h>
  31 #include <sys/modctl.h>
  32 #include <sys/scsi/scsi.h>
  33 #include <sys/sunndi.h>
  34 #include <sys/fibre-channel/fc.h>
  35 #include <sys/fibre-channel/ulp/fcpvar.h>
  36 
  37 static struct fcp_port  port;
  38 static struct fcp_tgt   tgt;
  39 static struct fcp_lun   lun;
  40 static uint32_t tgt_hash_index;
  41 
  42 
  43 /*
  44  * Leadville fcp walker/dcmd code
  45  */


 311 targets_walk_i(mdb_walk_state_t *wsp)
 312 {
 313         if (wsp->walk_addr == NULL) {
 314                 mdb_warn("Can not perform global walk\n");
 315                 return (WALK_ERR);
 316         }
 317 
 318         /*
 319          * Input should be a fcp_port, so read it to get the port_tgt
 320          * table's head
 321          */
 322 
 323         if (mdb_vread(&port, sizeof (struct fcp_port), wsp->walk_addr) !=
 324             sizeof (struct fcp_port)) {
 325                 mdb_warn("Unable to read in the port structure address\n");
 326                 return (WALK_ERR);
 327         }
 328 
 329         tgt_hash_index = 0;
 330 
 331         while (tgt_hash_index < FCP_NUM_HASH &&
 332             port.port_tgt_hash_table[tgt_hash_index] == NULL) {
 333                 tgt_hash_index++;
 334         }
 335 
 336         wsp->walk_addr = (uintptr_t)(port.port_tgt_hash_table[tgt_hash_index]);
 337 
 338         wsp->walk_data = mdb_alloc(sizeof (struct fcp_tgt), UM_SLEEP);
 339 
 340         return (WALK_NEXT);
 341 }
 342 
 343 static int
 344 targets_walk_s(mdb_walk_state_t *wsp)
 345 {
 346         int status;
 347 
 348         if ((wsp->walk_addr == NULL) &&
 349             (tgt_hash_index >= (FCP_NUM_HASH - 1))) {
 350                 return (WALK_DONE);
 351         }
 352 
 353         if (mdb_vread(wsp->walk_data, sizeof (struct fcp_tgt),
 354             wsp->walk_addr) == -1) {
 355                 mdb_warn("failed to read fcp_tgt at %p", wsp->walk_addr);
 356                 return (WALK_DONE);
 357         }
 358 
 359         status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
 360             wsp->walk_cbdata);
 361 
 362         wsp->walk_addr =
 363             (uintptr_t)(((struct fcp_tgt *)wsp->walk_data)->tgt_next);
 364 
 365         if (wsp->walk_addr == NULL) {
 366                 /*
 367                  * locate the next hash list
 368                  */
 369 
 370                 tgt_hash_index++;
 371 
 372                 while (tgt_hash_index < FCP_NUM_HASH &&
 373                     port.port_tgt_hash_table[tgt_hash_index] == NULL)
 374                         tgt_hash_index++;

 375 
 376                 if (tgt_hash_index == FCP_NUM_HASH) {
 377                         /* You're done */
 378                         return (status);
 379                 }
 380 
 381                 wsp->walk_addr =
 382                     (uintptr_t)(port.port_tgt_hash_table[tgt_hash_index]);
 383         }
 384 
 385         return (status);
 386 }
 387 
 388 /*
 389  * The walker's fini function is invoked at the end of each walk.
 390  */
 391 static void
 392 targets_walk_f(mdb_walk_state_t *wsp)
 393 {
 394         mdb_free(wsp->walk_data, sizeof (struct fcp_tgt));