[RTEMS Project] #4537: mutex is not initilaized in jffs2_new_inode

RTEMS trac trac at rtems.org
Wed Oct 27 14:59:07 UTC 2021


#4537: mutex is not initilaized in jffs2_new_inode
----------------------------+--------------------
  Reporter:  chenjin_zhong  |      Owner:  (none)
      Type:  defect         |     Status:  new
  Priority:  normal         |  Milestone:  5.1
 Component:  admin          |    Version:  5
  Severity:  normal         |   Keywords:
Blocked By:                 |   Blocking:
----------------------------+--------------------
 HI, I have found when call jffs2_new_inode to create inode. the f->sem is
 not initiliazed and lock, but it is be unlocked. The peice of source code
 is as follows:
   struct _inode *jffs2_new_inode (struct _inode *dir_i, int mode, struct
 jffs2_raw_inode *ri)
   {
         struct _inode *inode;
         struct super_block *sb = dir_i->i_sb;
         struct jffs2_sb_info *c;
         struct jffs2_inode_info *f;
         int ret;

         D1(printk(KERN_DEBUG "jffs2_new_inode(): dir_i %ld, mode 0x%x\n",
 dir_i->i_ino, mode));
         c = JFFS2_SB_INFO(sb);

         inode = new_inode(sb);

         if (!inode)
                 return ERR_PTR(-ENOMEM);

         f = JFFS2_INODE_INFO(inode);
         jffs2_init_inode_info(f);

         memset(ri, 0, sizeof(*ri));
         /* Set OS-specific defaults for new inodes */
         ri->uid = cpu_to_je16(geteuid());
         ri->gid = cpu_to_je16(getegid());
         ri->mode =  cpu_to_jemode(mode);
         ret = jffs2_do_new_inode (c, f, mode, ri);
         if (ret) {
                 // forceful evict: f->sem is locked already, and the
                 // inode is bad.
                 if (inode->i_cache_prev)
                        inode->i_cache_prev->i_cache_next =
 inode->i_cache_next;
                 if (inode->i_cache_next)
                        inode->i_cache_next->i_cache_prev =
 inode->i_cache_prev;
                 **mutex_unlock(&(f->sem))**;
                 jffs2_clear_inode(inode);
                 memset(inode, 0x6a, sizeof(*inode));
                 free(inode);
                 return ERR_PTR(ret);
         }
         inode->i_nlink = 1;
         inode->i_ino = je32_to_cpu(ri->ino);
         inode->i_mode = jemode_to_cpu(ri->mode);
         inode->i_gid = je16_to_cpu(ri->gid);
         inode->i_uid = je16_to_cpu(ri->uid);
         inode->i_atime = inode->i_ctime = inode->i_mtime = get_seconds();
         ri->atime = ri->mtime = ri->ctime = cpu_to_je32(inode->i_mtime);
         inode->i_size = 0;
         return inode;
 }

--
Ticket URL: <http://devel.rtems.org/ticket/4537>
RTEMS Project <http://www.rtems.org/>
RTEMS Project


More information about the bugs mailing list