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>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/os/fio.c
          +++ new/usr/src/uts/common/os/fio.c
↓ open down ↓ 844 lines elided ↑ open up ↑
 845  845  
 846  846          mutex_init(&cfip->fi_lock, NULL, MUTEX_DEFAULT, NULL);
 847  847          cfip->fi_rlist = NULL;
 848  848  
 849  849          /*
 850  850           * We don't need to hold fi_lock because all other lwp's in the
 851  851           * parent have been held.
 852  852           */
 853  853          cfip->fi_nfiles = nfiles = flist_minsize(pfip);
 854  854  
 855      -        cfip->fi_list = kmem_zalloc(nfiles * sizeof (uf_entry_t), KM_SLEEP);
      855 +        cfip->fi_list = nfiles == 0 ? NULL :
      856 +            kmem_zalloc(nfiles * sizeof (uf_entry_t), KM_SLEEP);
 856  857  
 857  858          for (fd = 0, pufp = pfip->fi_list, cufp = cfip->fi_list; fd < nfiles;
 858  859              fd++, pufp++, cufp++) {
 859  860                  cufp->uf_file = pufp->uf_file;
 860  861                  cufp->uf_alloc = pufp->uf_alloc;
 861  862                  cufp->uf_flag = pufp->uf_flag;
 862  863                  cufp->uf_busy = pufp->uf_busy;
 863  864                  if (pufp->uf_file == NULL) {
 864  865                          ASSERT(pufp->uf_flag == 0);
 865  866                          if (pufp->uf_busy) {
↓ open down ↓ 619 lines elided ↑ open up ↑
1485 1486   * point for the lookup of the relative pathname 'path' (or, if path is
1486 1487   * NULL, generate a vnode pointer for the direct target of the operation).
1487 1488   *
1488 1489   * If we successfully return a non-NULL startvp, it has been the target
1489 1490   * of VN_HOLD() and the caller must call VN_RELE() on it.
1490 1491   */
1491 1492  int
1492 1493  fgetstartvp(int fd, char *path, vnode_t **startvpp)
1493 1494  {
1494 1495          vnode_t         *startvp;
1495      -        file_t          *startfp;
1496      -        char            startchar;
     1496 +        file_t          *startfp;
     1497 +        char            startchar;
1497 1498  
1498 1499          if (fd == AT_FDCWD && path == NULL)
1499 1500                  return (EFAULT);
1500 1501  
1501 1502          if (fd == AT_FDCWD) {
1502 1503                  /*
1503 1504                   * Start from the current working directory.
1504 1505                   */
1505 1506                  startvp = NULL;
1506 1507          } else {
↓ open down ↓ 25 lines elided ↑ open up ↑
1532 1533  
1533 1534  /*
1534 1535   * Called from fchownat() and fchmodat() to set ownership and mode.
1535 1536   * The contents of *vap must be set before calling here.
1536 1537   */
1537 1538  int
1538 1539  fsetattrat(int fd, char *path, int flags, struct vattr *vap)
1539 1540  {
1540 1541          vnode_t         *startvp;
1541 1542          vnode_t         *vp;
1542      -        int             error;
     1543 +        int             error;
1543 1544  
1544 1545          /*
1545 1546           * Since we are never called to set the size of a file, we don't
1546 1547           * need to check for non-blocking locks (via nbl_need_check(vp)).
1547 1548           */
1548 1549          ASSERT(!(vap->va_mask & AT_SIZE));
1549 1550  
1550 1551          if ((error = fgetstartvp(fd, path, &startvp)) != 0)
1551 1552                  return (error);
1552 1553          if (AU_AUDITING() && startvp != NULL)
↓ open down ↓ 276 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX