Print this page
11927 Log, or optionally panic, on zero-length kmem allocations
Reviewed by: Dan McDonald <danmcd@joyent.com>
Reviewed by: Jason King <jason.brian.king@gmail.com>


   7  * with the License.
   8  *
   9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10  * or http://www.opensolaris.org/os/licensing.
  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 /*
  23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 #pragma ident   "%Z%%M% %I%     %E% SMI"


  28 
  29 #include <sys/promif.h>
  30 #include <sys/promimpl.h>
  31 #include <sys/prom_emul.h>
  32 #include <sys/obpdefs.h>
  33 #include <sys/sunddi.h>
  34 
  35 static prom_node_t *promif_top;
  36 
  37 static prom_node_t *promif_find_node(pnode_t nodeid);
  38 static int getproplen(prom_node_t *pnp, char *name);
  39 static void *getprop(prom_node_t *pnp, char *name);
  40 
  41 static void
  42 promif_create_prop(prom_node_t *pnp, char *name, void *val, int len, int flags)
  43 {
  44         struct prom_prop *p, *q;
  45 
  46         q = kmem_zalloc(sizeof (*q), KM_SLEEP);
  47         q->pp_name = kmem_zalloc(strlen(name) + 1, KM_SLEEP);
  48         (void) strcpy(q->pp_name, name);
  49         q->pp_val = kmem_alloc(len, KM_SLEEP);
  50         q->pp_len = len;
  51         switch (flags) {
  52         case DDI_PROP_TYPE_INT:
  53         case DDI_PROP_TYPE_INT64:
  54                 /*
  55                  * Technically, we need byte-swapping to conform to 1275.
  56                  * However, the old x86 prom simulator used little endian
  57                  * representation, so we don't swap here either.
  58                  *
  59                  * NOTE: this is inconsistent with ddi_prop_lookup_*()
  60                  * which does byte-swapping when looking up prom properties.
  61                  * Since all kernel nodes are SID nodes, drivers no longer
  62                  * access PROM properties on x86.
  63                  */
  64         default:        /* no byte swapping */
  65                 (void) bcopy(val, q->pp_val, len);
  66                 break;
  67         }
  68 
  69         if (pnp->pn_propp == NULL) {




   7  * with the License.
   8  *
   9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10  * or http://www.opensolaris.org/os/licensing.
  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 /*
  23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*
  28  * Copyright (c) 2015 Joyent, Inc.  All rights reserved.
  29  */
  30 
  31 #include <sys/promif.h>
  32 #include <sys/promimpl.h>
  33 #include <sys/prom_emul.h>
  34 #include <sys/obpdefs.h>
  35 #include <sys/sunddi.h>
  36 
  37 static prom_node_t *promif_top;
  38 
  39 static prom_node_t *promif_find_node(pnode_t nodeid);
  40 static int getproplen(prom_node_t *pnp, char *name);
  41 static void *getprop(prom_node_t *pnp, char *name);
  42 
  43 static void
  44 promif_create_prop(prom_node_t *pnp, char *name, void *val, int len, int flags)
  45 {
  46         struct prom_prop *p, *q;
  47 
  48         q = kmem_zalloc(sizeof (*q), KM_SLEEP);
  49         q->pp_name = kmem_zalloc(strlen(name) + 1, KM_SLEEP);
  50         (void) strcpy(q->pp_name, name);
  51         q->pp_val = len > 0 ? kmem_alloc(len, KM_SLEEP) : NULL;
  52         q->pp_len = len;
  53         switch (flags) {
  54         case DDI_PROP_TYPE_INT:
  55         case DDI_PROP_TYPE_INT64:
  56                 /*
  57                  * Technically, we need byte-swapping to conform to 1275.
  58                  * However, the old x86 prom simulator used little endian
  59                  * representation, so we don't swap here either.
  60                  *
  61                  * NOTE: this is inconsistent with ddi_prop_lookup_*()
  62                  * which does byte-swapping when looking up prom properties.
  63                  * Since all kernel nodes are SID nodes, drivers no longer
  64                  * access PROM properties on x86.
  65                  */
  66         default:        /* no byte swapping */
  67                 (void) bcopy(val, q->pp_val, len);
  68                 break;
  69         }
  70 
  71         if (pnp->pn_propp == NULL) {