CC: [email protected]
BCC: [email protected]
In-Reply-To: <[email protected]>
References: <[email protected]>
TO: Imran Khan <[email protected]>

Hi Imran,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on 3bf222d317a20170ee17f082626c1e0f83537e13]

url:    
https://github.com/intel-lab-lkp/linux/commits/Imran-Khan/kernfs-make-attr-open-RCU-protected/20220511-175730
base:   3bf222d317a20170ee17f082626c1e0f83537e13
:::::: branch date: 3 days ago
:::::: commit date: 3 days ago
config: i386-randconfig-m021 
(https://download.01.org/0day-ci/archive/20220514/[email protected]/config)
compiler: gcc-11 (Debian 11.2.0-20) 11.2.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>
Reported-by: Dan Carpenter <[email protected]>

New smatch warnings:
fs/kernfs/file.c:282 kernfs_file_read_iter() warn: inconsistent returns 
'&of->mutex'.

Old smatch warnings:
fs/kernfs/file.c:255 kernfs_file_read_iter() warn: possible memory leak of 'buf'
fs/kernfs/file.c:282 kernfs_file_read_iter() warn: possible memory leak of 'buf'

vim +282 fs/kernfs/file.c

414985ae23c031 Tejun Heo         2013-11-28  219  
414985ae23c031 Tejun Heo         2013-11-28  220  /*
414985ae23c031 Tejun Heo         2013-11-28  221   * As reading a bin file can 
have side-effects, the exact offset and bytes
414985ae23c031 Tejun Heo         2013-11-28  222   * specified in read(2) call 
should be passed to the read callback making
414985ae23c031 Tejun Heo         2013-11-28  223   * it difficult to use 
seq_file.  Implement simplistic custom buffering for
414985ae23c031 Tejun Heo         2013-11-28  224   * bin files.
414985ae23c031 Tejun Heo         2013-11-28  225   */
4eaad21a6ac986 Christoph Hellwig 2021-01-20  226  static ssize_t 
kernfs_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
414985ae23c031 Tejun Heo         2013-11-28  227  {
4eaad21a6ac986 Christoph Hellwig 2021-01-20  228        struct kernfs_open_file 
*of = kernfs_of(iocb->ki_filp);
4eaad21a6ac986 Christoph Hellwig 2021-01-20  229        ssize_t len = 
min_t(size_t, iov_iter_count(iter), PAGE_SIZE);
414985ae23c031 Tejun Heo         2013-11-28  230        const struct kernfs_ops 
*ops;
302de586c74f7b Imran Khan        2022-05-11  231        struct kernfs_open_node 
*on;
414985ae23c031 Tejun Heo         2013-11-28  232        char *buf;
414985ae23c031 Tejun Heo         2013-11-28  233  
4ef67a8c95f32e NeilBrown         2014-10-14  234        buf = of->prealloc_buf;
e4234a1fc343ca Chris Wilson      2016-03-31  235        if (buf)
e4234a1fc343ca Chris Wilson      2016-03-31  236                
mutex_lock(&of->prealloc_mutex);
e4234a1fc343ca Chris Wilson      2016-03-31  237        else
414985ae23c031 Tejun Heo         2013-11-28  238                buf = 
kmalloc(len, GFP_KERNEL);
414985ae23c031 Tejun Heo         2013-11-28  239        if (!buf)
414985ae23c031 Tejun Heo         2013-11-28  240                return -ENOMEM;
414985ae23c031 Tejun Heo         2013-11-28  241  
414985ae23c031 Tejun Heo         2013-11-28  242        /*
4ef67a8c95f32e NeilBrown         2014-10-14  243         * @of->mutex nests 
outside active ref and is used both to ensure that
e4234a1fc343ca Chris Wilson      2016-03-31  244         * the ops aren't 
called concurrently for the same open file.
414985ae23c031 Tejun Heo         2013-11-28  245         */
414985ae23c031 Tejun Heo         2013-11-28  246        mutex_lock(&of->mutex);
c637b8acbe079e Tejun Heo         2013-12-11  247        if 
(!kernfs_get_active(of->kn)) {
414985ae23c031 Tejun Heo         2013-11-28  248                len = -ENODEV;
414985ae23c031 Tejun Heo         2013-11-28  249                
mutex_unlock(&of->mutex);
414985ae23c031 Tejun Heo         2013-11-28  250                goto out_free;
414985ae23c031 Tejun Heo         2013-11-28  251        }
414985ae23c031 Tejun Heo         2013-11-28  252  
302de586c74f7b Imran Khan        2022-05-11  253        on = 
kernfs_deref_on_raw(of, of->kn);
302de586c74f7b Imran Khan        2022-05-11  254        if (!on)
302de586c74f7b Imran Khan        2022-05-11  255                return -EINVAL;
302de586c74f7b Imran Khan        2022-05-11  256  
302de586c74f7b Imran Khan        2022-05-11  257        of->event = 
atomic_read(&unrcu_pointer(on)->event);
324a56e16e44ba Tejun Heo         2013-12-11  258        ops = 
kernfs_ops(of->kn);
414985ae23c031 Tejun Heo         2013-11-28  259        if (ops->read)
4eaad21a6ac986 Christoph Hellwig 2021-01-20  260                len = 
ops->read(of, buf, len, iocb->ki_pos);
414985ae23c031 Tejun Heo         2013-11-28  261        else
414985ae23c031 Tejun Heo         2013-11-28  262                len = -EINVAL;
414985ae23c031 Tejun Heo         2013-11-28  263  
e4234a1fc343ca Chris Wilson      2016-03-31  264        
kernfs_put_active(of->kn);
e4234a1fc343ca Chris Wilson      2016-03-31  265        
mutex_unlock(&of->mutex);
e4234a1fc343ca Chris Wilson      2016-03-31  266  
414985ae23c031 Tejun Heo         2013-11-28  267        if (len < 0)
e4234a1fc343ca Chris Wilson      2016-03-31  268                goto out_free;
414985ae23c031 Tejun Heo         2013-11-28  269  
4eaad21a6ac986 Christoph Hellwig 2021-01-20  270        if (copy_to_iter(buf, 
len, iter) != len) {
414985ae23c031 Tejun Heo         2013-11-28  271                len = -EFAULT;
e4234a1fc343ca Chris Wilson      2016-03-31  272                goto out_free;
414985ae23c031 Tejun Heo         2013-11-28  273        }
414985ae23c031 Tejun Heo         2013-11-28  274  
4eaad21a6ac986 Christoph Hellwig 2021-01-20  275        iocb->ki_pos += len;
414985ae23c031 Tejun Heo         2013-11-28  276  
414985ae23c031 Tejun Heo         2013-11-28  277   out_free:
e4234a1fc343ca Chris Wilson      2016-03-31  278        if (buf == 
of->prealloc_buf)
e4234a1fc343ca Chris Wilson      2016-03-31  279                
mutex_unlock(&of->prealloc_mutex);
e4234a1fc343ca Chris Wilson      2016-03-31  280        else
414985ae23c031 Tejun Heo         2013-11-28  281                kfree(buf);
414985ae23c031 Tejun Heo         2013-11-28 @282        return len;
414985ae23c031 Tejun Heo         2013-11-28  283  }
414985ae23c031 Tejun Heo         2013-11-28  284  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp
_______________________________________________
kbuild mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to